/// from http://berenger.eu/blog/2011/10/06/c-openmp-a-shared-memory-quick-sort-with-openmp-tasks-example-source-code/ #include template inline void Swap(NumType& value, NumType& other) { NumType temp = value; value = other; other = temp; } template long QsPartition(SortType outputArray[], long left, long right) { const long part = right; Swap(outputArray[part],outputArray[left + (right - left ) / 2]); const SortType partValue = outputArray[part]; --right; while(true) { while(outputArray[left] < partValue) ++left; while(right >= left && partValue <= outputArray[right]) --right; if(right < left) break; Swap(outputArray[left],outputArray[right]); ++left; --right; } Swap(outputArray[part],outputArray[left]); return left; } template void QsSequential(SortType array[], const long left, const long right) { if (left < right) { const long part = QsPartition(array, left, right); QsSequential(array,part + 1,right); QsSequential(array,left,part - 1); } } template void QuickSortTask (SortType array[], const long left, const long right, const int deep) { if (left < right) { if (deep) { const long part = QsPartition(array, left, right); QtConcurrent::run(QuickSortTask, array, part + 1, right, deep - 1); QtConcurrent::run(QuickSortTask, array, left, part - 1, deep - 1); } else { const long part = QsPartition(array, left, right); QsSequential(array,part + 1,right); QsSequential(array,left,part - 1); } } }