Fill histograms (array reduction) in parallel with OpenMP without using a critical section

You could allocate the big array inside the parallel region, where you can query about the actual number of threads being used: int *hista; #pragma omp parallel { const int nthreads = omp_get_num_threads(); const int ithread = omp_get_thread_num(); #pragma omp single hista = new int[nbins*nthreads]; … } delete[] hista; For better performance I would advise … Read more