I need to sort a set of vectors with OpenMP in C ++. I really think this should be a common problem; however, I did not find anything about it.
Of course, I could just use
#pragma omp parallel for schedule(dynamic,1)
for(int i =0; i<narrays; ++i)
sortSerial(array[i]);
and leave planning at runtime.
However, one array may take longer than all the others together. In fact, I may well have only one array. Or maybe I have twenty thousand one hundred elements, plus two with a million each. In this case, if I have 8 cores, I would assign five thousand partitions per thread for the first four threads, and then two threads in each partition with the last four. So that the total time is constant.
Then I could use nested parallelism. But if I do it
#pragma omp parallel for schedule(dynamic,1)
for(int i =0; i<narrays; ++i)
sortParallel(array[i]);
sortParallel , OMP ; parallelism, , . , , sortParallel .
, , , , , .
, , VisualStudio 2013, , , OpenMP 2.0 - , , .
. . - , ?
, , ( ) , total/threads. , . , ; (, ) .
, [i] , ,
void sort(int i,int threads){
if(i<nbigintervals)
sortParallel(bigInterval[i],threads);
else
#pragma omp parallel for schedule(dynamic,1) num_threads(threads)
for(int j=0;j<nsmallintervals;++j)
sortSerial(smallInterval[j]);
}
int main() {
omp_set_nested(true);
#pragma omp parallel for schedule(static,1) num_threads(nbigintervals +1)
for(int i=0; i<=nbigintervals; ++i)
sort(i,threads[i]);
}
, , , . / / ?