OpenMP: an ordered sentence without an index

Suppose that I want to want to fill an object in parallel in an std::vectorordered manner, for example:

std::vector<T> v;
#pragma omp parallel for ordered
for (int i=0;i<n;i++){
    T result = //some expensive fun here...
    #pragma omp ordered
    v.push_back(result);
}

As you can see, the instruction v.push_back(result)is independent of i.

My question is: vwill it still be filled in an orderly manner in accordance with i?

+4
source share

All Articles