[Solved] How to make threads write their numbers in reverse order using OpenMP?

I don’t really understand the purpose of what you are asking but this works #include “omp.h” #include <iostream> using namespace std; int main() { #pragma omp parallel { int nthreads = omp_get_num_threads(); for(int i=nthreads-1; i>=0; i–) { #pragma omp barrier { if(i==omp_get_thread_num()) { #pragma omp critical cout << “I am thread “<< i <<endl; } … Read more

[Solved] OpenMP – simplest accumulator in loops gives incorrect result

You’ve programmed a canonical data-race. All the threads in your program are contending to update the variable count and there are no guarantees about the order in which each thread reads, updates, then writes the values to the variable. Whatever you may believe C++ does not guarantee that ++ is applied atomically. You should read … Read more

[Solved] fortran & openmp: put multiple do-s and section-s in the same parallel enviroment

You can and probably should amortize the runtime overhead of creating and destroying an OpenMP parallel region by putting all of your parallel constructions – in this case, two do loops and a pair of sections – within a single parallel region. The following code compiles and executes as expected. program main implicit none integer … Read more