I want to make this code parallel:
std::vector<float> res(n,0);
std::vector<float> vals(m);
std::vector<float> indexes(m);
// fill indexes with values in range [0,n)
// fill vals and indexes
for(size_t i=0; i<m; i++){
res[indexes[i]] += //something using vas[i];
}
In this article it's suggested to use:
#pragma omp parallel for reduction(+:myArray[:6])
In this question the same approach is proposed in the comments section.
I have two questions:
- I don't know
m
at compile time, and from these two examples it seems that's required. Is it so? Or if I can use it for this case, what do I have to replace?
with in the following command#pragma omp parallel for reduction(+:res[:?])
?m
orn
? - Is it relevant that the indexes of the
for
are relative toindexes
andvals
and not tores
, especially considering thatreduction
is done on the latter one?
However, If so, how can I solve this problem?
See Question&Answers more detail:os