0

I have a number of arrays of which I would like to sum elements at corresponding positions into a "results" array with the same number of elements as the originals. The arrays I am trying to add together are stored in a vector.

That is R = A0 + A1 + ... + AN where R and all Ai are arrays of the same size.

I can't post images, so here's a link illustrating the situation.

What is the best way to do this computation in parallel with OpenMP (C++)? I'd like to take advantage of SIMD if possible, but really I'd appreciate any direction at all.

Thanks!

thekamz
  • 13
  • 5
  • I believe this question covers the sort of thing you're trying to do? http://stackoverflow.com/questions/20413995/reducing-on-array-in-openmp – Theolodus Mar 20 '15 at 14:13
  • @Theolodus: The question isn't exactly the same, but the answers there look like they may be able to be modified for this situation. Thanks!! – thekamz Mar 20 '15 at 14:35

1 Answers1

0

For your example, you don't have data race... That means using #pragma omp parallel for simd.

  • My understanding is that the results array is shared between several threads that write to all elements of the results array, and there is thus a potential race. Am I incorrect? – thekamz Mar 24 '15 at 12:53
  • Yes, several threads write the same array, but different elments of this result array. Elements of an array have different physical addresses, i.e. different memory cells. Data race happens, only if a single memory cell, such as an cell for an integer, is written by several threads. – not-cs-player Mar 24 '15 at 18:11