You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
739 B

void sample_qsort(float* begin, float* end) { ... }
void sample_qsort_serial(float* begin, float* end) { ... }
void sample_qsort_adaptive(float* begin, float* end, const long nthreshold)
{
if (begin != end) {
// parition ...
if (end - begin + 1 <= nthreshold) {
sample_qsort_serial(begin, middle);
sample_qsort_serial(++middle, ++end);
} else {
#pragma omp task
sample_qsort_adaptive(begin, middle, nthreshold);
#pragma omp task
sample_qsort_adaptive(++middle, ++end, nthreshold);
}
}
}
void sample_qsort_adaptive(float* begin, float* end)
{
long nthreshold = ceil(sqrt(end - begin + 1)) / 2;
#pragma omp parallel
#pragma omp single nowait
sample_qsort_adaptive(begin, end, nthreshold);
}