Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Thank you so much for your help. I have modified the example code in my post, regarding the variables ki. Your answer is very helpful to me. Can I ask one more question? You used OpenMP technique to parallelize the inner loop. It is truly enough only to parallelize the inner loop. However, the real code that I am programming is much more complex this example and I want to parallelize both inner and outer loop. The real code has the same structure as this example code. Is it possible to parallelize both inner and outer loops? Thank you very much again for your help. Commented Jan 5, 2021 at 19:22
  • 1
    @Kieran By concept of OpenMP, it is not possible to parallelize both loops. The best is always to parallelize the outer loops, but for the case you have mentionned it seems to me enough efficient to prallelize the inner one. Indeed, since you do a sum on "es" for each index "i" while "es" is not a vector, it seems more convenient to parallelize the inner loops in order to take benifits of the reduction clause without using ATOMIC or CRITICAL synchronization option. Note that reduction is the most efficient. Now to parallelize the outer loops you have to rethink the structur of your variables. Commented Jan 6, 2021 at 13:21
  • 1
    @Kieran Also if you parallelize the outer loops, you might write "et(i),es" in an order that is not the desired one. Commented Jan 6, 2021 at 14:53
  • 1
    Thank you very much for your help. I am trying to use MPI to parallelize the outer loop and OpenMP to parallelize the inner loop now. Your suggestion on the 'reduction clause' is really useful to me. Commented Jan 7, 2021 at 15:22