OpenMP 4.5+ provides the capability to do vector/array reductions in C++ (press release)
Using said capability allows us to write, e.g.:
#include <vector>
#include <iostream>
int main(){
std::vector<int> vec;
#pragma omp declare reduction (merge : std::vector<int> : omp_out.insert(omp_out.end(), omp_in.begin(), omp_in.end()))
#pragma omp parallel for default(none) schedule(static) reduction(merge: vec)
for(int i=0;i<100;i++)
vec.push_back(i);
for(const auto x: vec)
std::cout<<x<<"\n";
return 0;
}
The problem is, upon executing such code, the results of the various threads may be ordered in any which way.
Is there a way to enforce order such that thread 0's results preceed thread 1's, and so on?