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

Porting TBB Parallel Stable Sort to VisualStudio 2015

victor_d_1
Beginner
423 Views

Arch Robinson of TBB team implemented nice sorting a couple of years ago

https://software.intel.com/en-us/articles/a-parallel-stable-sort-using-c11-for-tbb-cilk-plus-and-openmp

I'm having trouble building his awesome work on Windows in any version of VisualStudio, but would love to have it in VisualStudio 2015. Has anyone succeeded building this project on Windows?

0 Kudos
5 Replies
Alexei_K_Intel
Employee
423 Views

Hi Victor,

I am not sure if someone has tried it with Microsoft Visual Studio 2015. Could you share your compilation/building logs to try to resolve the issues.

Regards, Alex 

0 Kudos
victor_d_1
Beginner
423 Views

I created VS2015 (update 3) project and getting the following errors:

1>------ Rebuild All started: Project: parallel_stable_sort, Configuration: Debug x64 ------
1>  stdafx.cpp
1>  test.cpp
1>d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\pss_common.h(95): warning C4800: 'void *const ': forcing value to bool 'true' or 'false' (performance warning)
1>d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\test.cpp(144): warning C4312: 'type cast': conversion from 'long' to 'Key *' of greater size
1>d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\test.cpp(224): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data
1>d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\test.cpp(226): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
1>d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\test.cpp(229): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
1>d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\test.cpp(291): warning C4244: '=': conversion from 'float' to 'int', possible loss of data
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2636): error C4996: 'std::move::_Unchecked_iterators::_Deprecate': Call to 'std::move' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2636): note: see declaration of 'std::move::_Unchecked_iterators::_Deprecate'
1>  d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\pss_common.h(68): note: see reference to function template instantiation '_OutIt std::move<RandomAccessIterator2,RandomAccessIterator3>(_InIt,_InIt,_OutIt)' being compiled
1>          with
1>          [
1>              _OutIt=Iterator,
1>              RandomAccessIterator2=T *,
1>              RandomAccessIterator3=Iterator,
1>              _InIt=T *
1>          ]
1>  d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\openmp\parallel_stable_sort.h(70): note: see reference to function template instantiation 'void pss::internal::serial_move_merge<RandomAccessIterator1,RandomAccessIterator2,RandomAccessIterator3,Compare>(RandomAccessIterator1,RandomAccessIterator1,RandomAccessIterator2,RandomAccessIterator2,RandomAccessIterator3,Compare)' being compiled
1>          with
1>          [
1>              RandomAccessIterator1=T *,
1>              RandomAccessIterator2=T *,
1>              RandomAccessIterator3=Iterator,
1>              Compare=KeyCompare
1>          ]
1>  d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\openmp\parallel_stable_sort.h(95): note: see reference to function template instantiation 'void pss::internal::parallel_move_merge<RandomAccessIterator2,RandomAccessIterator2,RandomAccessIterator1,Compare>(Key*,Key*,RandomAccessIterator2,RandomAccessIterator2,RandomAccessIterator3,bool,Compare)' being compiled
1>          with
1>          [
1>              RandomAccessIterator2=T *,
1>              RandomAccessIterator1=Iterator,
1>              Compare=KeyCompare,
1>              RandomAccessIterator3=Iterator
1>          ]
1>  d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\openmp\parallel_stable_sort.h(108): note: see reference to function template instantiation 'void pss::internal::parallel_stable_sort_aux<RandomAccessIterator,T*,Compare>(RandomAccessIterator1,RandomAccessIterator1,RandomAccessIterator2,int,Compare)' being compiled
1>          with
1>          [
1>              RandomAccessIterator=Iterator,
1>              Compare=KeyCompare,
1>              RandomAccessIterator1=Iterator,
1>              RandomAccessIterator2=T *
1>          ]
1>  d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\test.cpp(275): note: see reference to function template instantiation 'void pss::parallel_stable_sort<Iterator,KeyCompare>(RandomAccessIterator,RandomAccessIterator,Compare)' being compiled
1>          with
1>          [
1>              RandomAccessIterator=Iterator,
1>              Compare=KeyCompare
1>          ]
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2518): error C2676: binary '++': 'Iterator' does not define this operator or a conversion to a type acceptable to the predefined operator
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2555): note: see reference to function template instantiation '_OutIt std::_Buffered_merge_unchecked<Key*,_BidIt,_BidIt,_Pr>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt,_Pr &,bool)' being compiled
1>          with
1>          [
1>              _OutIt=Iterator,
1>              _BidIt=Iterator,
1>              _Pr=KeyCompare,
1>              _InIt1=Key *,
1>              _InIt2=Iterator
1>          ]
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2879): note: see reference to function template instantiation 'void std::_Buffered_merge_unchecked<_BidIt,_Diff,Key,_Pr>(_BidIt,_BidIt,_BidIt,_Diff,_Diff,std::_Temp_iterator<Key> &,_Pr &)' being compiled
1>          with
1>          [
1>              _BidIt=Iterator,
1>              _Diff=__int64,
1>              _Pr=KeyCompare
1>          ]
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2891): note: see reference to function template instantiation 'void std::_Stable_sort_unchecked1<_BidIt,__int64,Key,_Pr>(_BidIt,_BidIt,_Diff,std::_Temp_iterator<Key> &,_Pr &)' being compiled
1>          with
1>          [
1>              _BidIt=Iterator,
1>              _Pr=KeyCompare,
1>              _Diff=__int64
1>          ]
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2900): note: see reference to function template instantiation 'void std::_Stable_sort_unchecked<_Iter,_Pr>(_BidIt,_BidIt,_Pr &)' being compiled
1>          with
1>          [
1>              _Iter=Iterator,
1>              _Pr=KeyCompare,
1>              _BidIt=Iterator
1>          ]
1>  d:\victor\visual studio projects\minmaxsort\parallel_stable_sort\openmp\parallel_stable_sort.h(115): note: see reference to function template instantiation 'void std::stable_sort<RandomAccessIterator,Compare>(_BidIt,_BidIt,_Pr)' being compiled
1>          with
1>          [
1>              RandomAccessIterator=Iterator,
1>              Compare=KeyCompare,
1>              _BidIt=Iterator,
1>              _Pr=KeyCompare
1>          ]
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2518): error C2088: '++': illegal for class
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2518): error C2672: 'std::move': no matching overloaded function found
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2518): error C2780: '_OutTy *std::move(_InIt,_InIt,_OutTy (&)[_OutSize])': expects 3 arguments - 1 provided
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2644): note: see declaration of 'std::move'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2518): error C2780: '_OutIt std::move(_InIt,_InIt,_OutIt)': expects 3 arguments - 1 provided
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2633): note: see declaration of 'std::move'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(2524): error C2676: binary '++': 'Iterator' does not define this operator or a conversion to a type acceptable to the predefined operator
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Here are the compiler switches for my project:

/Yu"stdafx.h" /GS /GL /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc140.pdb" /Zc:inline /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /D "USE_TBB_LOWLEVEL" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /openmp /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\parallel_stable_sort.pch" 

I have also tried compiling with /std:c++latest  and /std:c++14 switches, but with the same results.

Thank you for looking into this

0 Kudos
victor_d_1
Beginner
423 Views

I've also tried /D "USE_OPENMP" switch with the same results

0 Kudos
Alexei_K_Intel
Employee
423 Views

Hi Victor,

I see two issues in the error log:

  1. There is no postfix increment in Iterator class. Try to add the following code inside the Iterator class (iside lines test.cpp:150-206):
        Iterator operator++(int) {
            Iterator i(*this);
            this->operator++();
            return i;
        }

    Note that I have not tested the code snippet so some issues are possible.

  2. Visual Studio complains about unsafeness of std::move. Try to add -D_SCL_SECURE_NO_WARNINGS to command line to suppress the diagnostic.

I hope it will help.

Regards,
Alex

0 Kudos
victor_d_1
Beginner
423 Views

Hi Alex,

Thank you very much for providing the missing code. This fixed the project and these TBB parallel sorting algorithms are showing signs of life. To fix the other error I had to add a #define in the source code, right next to a similar one for either GCC or Intel compiler. Now, I can benchmark these parallel sorting algorithms and compare them in performance with others (sequential and parallel) I've been developing

https://duvanenko.tech.blog/2016/12/07/sorting-algorithms/

Thanks, Victor

0 Kudos
Reply