Openmp and abbreviation for std :: vector?

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 paper we propose to use:

#pragma omp parallel for reduction(+:myArray[:6])

In this matter, the same approach is proposed in the comments section.

I have two questions:

  • I do not know mat compile time, and from these two examples it seems that this is necessary. This is true? Or, if I can use it for this case, what do I need to replace ?in the next command #pragma omp parallel for reduction(+:res[:?])? mor n?
  • Is it appropriate that the indices forrelate to indexesand vals, and not to res, especially considering what reductionis being done on the latter?

However, if so, how can I solve this problem?

+5
1

C++ :

#include <algorithm>
#include <vector>

#pragma omp declare reduction(vec_float_plus : std::vector<float> : \
                              std::transform(omp_out.begin(), omp_out.end(), omp_in.begin(), omp_out.begin(), std::plus<float>())) \
                    initializer(omp_priv = decltype(omp_orig)(omp_orig.size()))

std::vector<float> res(n,0);
#pragma omp parallel for reduction(vec_float_plus : res)
for(size_t i=0; i<m; i++){
    res[...] += ...;
}

1a) m .

1b) std::vector, ( std::vector::data ). , n, .

2) indexes vals, .

: initializer : initializer(omp_priv = omp_orig). , , . , .

+8

Source: https://habr.com/ru/post/1673808/


All Articles