1

How to perform efficient copying of values from a vector of reducers to another vector as follows?

std::vector<cilk::reducer_opadd<int>> v(10000000); 

//....

Code that populates the vector v
...//

std::vector<int> res(v.size(), 0);

int i = 0;
for (auto& x : v) res[i++] = x.get_value;
//cilk_for(int i = 0; i < v.size(); ++i) res[i] = v[i].get_value();

Is it possible to have a SIMD instruction to perform the above copying more efficiently?

letsBeePolite
  • 2,183
  • 1
  • 22
  • 37
  • 1
    To begin with I would drop the explicit loop and use [`std::transform`](http://en.cppreference.com/w/cpp/algorithm/transform) instead. Then I would *measure* to see if it was quick enough for my requirements. And if not use the parallel transform introduced with C++17 if available, and if not use my own threads (possibly using [`std::async`](http://en.cppreference.com/w/cpp/thread/async) with the [asynch launch policy](http://en.cppreference.com/w/cpp/thread/launch)). However, the important bit is to build with optimizations and *measure*! – Some programmer dude Mar 03 '17 at 06:52
  • 2
    Don't initialize the vectors with default values. Use `reserve` and `push_back` or `emplace_back` instead. – Joseph Thomson Mar 03 '17 at 07:26

0 Answers0