I'm trying to write quicksort with OpenMP, and I'm getting stuck in the splitting part. The literature says that this is a parallel prefix operation. Here's the relevant bit:
vector<int> under_pivot(values.size()), over_pivot(values.size());
int count_under=0, count_over=0;
#pragma omp parallel for \
reduction(+:count_under,count_over) \
reduction(inscan,+:under_pivot,over_pivot)
for (int i=0; i<values.size(); i++) {
auto v = values[i];
# pragma omp scan inclusive(under_pivot,over_pivot)
{
under_pivot[i] = count_under;
over_pivot[i] = count_over;
}
count_under += 1 ? v<pivot : 0;
count_over += 1 ? v>pivot : 0;
}
(Yes, I've defined the +
operator for vectors). The problem seems to be the double reduction, if I understand the compiler error correctly:
quicksort.cxx:59:9: error: expected 'reduction' clause with the 'inscan' modifier
reduction(+:count_under,count_over) \
^
quicksort.cxx:60:19: note: 'reduction' clause with 'inscan' modifier is used here
reduction(inscan,+:under_pivot,over_pivot)
^
1 error generated.
But I really need two reductions because the scalars are not in a scan: a scan only pertains to arrays.
Compiler explorer with full code: https://godbolt.org/z/6xPrnGjMY