Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Researching??

GiCodeBlu
Beginner
436 Views

1)  I thought use of std::sort was same as tbb::paralllel_sort though simply changing func leads to a compile error .. Visual Studio ...

Error 38 error C3848: expression having type 'const less_than_key' would lose some const-volatile qualifiers in order to call 'bool less_than_key::operator ()(FaceDistance &,FaceDistance &)'

struct FaceDistance
{
    uint     nFace;
    float    fAvgZ;
}; 
struct less_than_key
{
    inline bool operator() (const FaceDistance& struct1, const FaceDistance& struct2)
    {
        return (struct1.fAvgZ > struct2.fAvgZ);
    }
};

and literally one topic (really!) via google searching this error text, which did not help. 

And generally, why would no one on the internet use examples of  a similar {sort_value, index} implementation as sorting a single element is somewhat useless without a way to associate the sort to some larger struct.  And why does TBB not have simple examples of parallel_sort

2) General newbie question: is there an option to use TBB and not use a distributable dll, rather embed the binary into a commercial EXE or DLL with no dependency (and no open source issues). Granted if the answer is no, then this solution loses potential. 

3) After installing the TBB for Windows eval, none of my projects actually run?  Why don't any of the examples actually work (MSVC10) by simply loading the project,granted adjusting the include directories.  Seems MS is not supported??  

 

 

0 Kudos
6 Replies
Vladimir_P_1234567890
436 Views

hello,

1) you need to add const to your operator():

inline bool operator() (const FaceDistance& struct1, const FaceDistance& struct2) const

2) the is no such option by design to keep tbb a single tone and to share tbb workers pools inside application.

3) you need to set "Use Intel TBB" option to 'yes' in the "project properties" -> "Intel Performance Libraries". But for embedded example this should be set automatically. Have you checked the option to integrate to Visual Studio during install? Which example does not work? 

thanks.
--Vladimir

0 Kudos
GiCodeBlu
Beginner
436 Views

Thank you for the fast response.  

1) Thanks, I never knew or had a need for a const at the backend of a function decl. I tried several places but never the back. This got me compiling, and then after a bit of searching for the correct lib dir, got it linking, and then I verified it was using the tbb.dll.  

Unfortunately, and to my surprise and bit of disappointment  I did not see any performance improvements over std::sort.  1M of my FaceDistance structs sorted in 300 ms +/-50 with both std:sort and parallel_sort.  And parallel_sort used more of my cpu, but seems to have wasted cpu as the time was actually a bit slower for twice as much cpu usage.  The system  has 12 cores older/expensive i7-3960X 24GB.  

This is a release build (as the debug build was crazy slow) and I placed a tick count at top of chart to monitor. 

std:sort  

gigasoft net c++ charting 3D scatter with additional 1M polygon/face translucent alphablending sorting via std:sort

parallel_sort, note more overall cpu, and various difference in core usage. 

similar 3D scatter with 1M  face/polygons sorted with parallel_sort

Newbie Question: it looks like std::sort is actually using more than one core?  Is this possible, compiled with VS2008 standard ms runtimes of this era. Note this image is rotating and without the sorting stuff, normally uses zero cpu as it's all on the video card. Granted the alphablending is somewhat broke if one does not sort and I still need to research OIT as another option. 

2) That is a bummer, though, I have no problem making the use an option, if it would actually show more benefit than what I'm seeing.

3) I did notice the install mentioning prompts about VS2012 but there is no VS2012 on this system.  And no such Use TBB option to be found  anywhere in VS2010.  Granted my VS2008 real world test project used parallel_sort pretty easily just by adding the header and lib.  
Newbie Question : is it possible that my test results above are not actually using parallel_sort efficiently due to a setup issue? 

Thanks again.

-Robert

 

 

 

 

 

 

 

 

 

0 Kudos
RafSchietekat
Valued Contributor III
436 Views

Just regarding the 300 ms: you have to give TBB a bit of time to get out of the starting blocks, although I'm not sure how much in general. What are the results later in the lifetime of that same program?

0 Kudos
GiCodeBlu
Beginner
436 Views

For Raf, as this logic is related to rotation, I've let it run quite a bit, and the FaceDistance vector is pre-sized and never re-allocated for this test run. 

Seems multi cores are already being used via std::sort and maybe why parallel_sort does not show any improvement.  Though I wasn't expecting std::sort to use multi cores, it may be related to frame rendering timing.  

0 Kudos
RafSchietekat
Valued Contributor III
436 Views

How would std::sort know whether this is safe?

0 Kudos
Alex_H_4
Beginner
436 Views

I doubt std::sort is using any sort of parallelism, the thread is just getting switched from core to core quickly so the individual core graphs look more utilized than they actually are. 7% utilization is right about 1/12th of utilization, or one maxed out core.

0 Kudos
Reply