Questions tagged [openmp]

OpenMP is a cross-platform multi-threading API which allows fine-grained task parallelization and synchronization using special compiler directives.

OpenMP is a cross-platform multi-threading API which allows fine-grained task parallelization and synchronization using special compiler directives. OpenMP offers easy access to multi-threading without requiring knowledge of system-dependent details. At the same time, it is reasonably efficient compared to fine-tuned implementations with the bonus of being easiest to write multi-threads code. Forums and complete information on OpenMP is at https://openmp.org/.

OpenMP is based on multi-thread model, and offers Shared Memory parallelism and heterogeneous programming for coprocessors through compiler directives, library routines and environment variables. It is restricted to C/C++ and Fortran applications, however provides portability across different Shared Memory architectures.

It is through directives, added by the programmer to the code, that the compiler adds parallelism in the application. OpenMP can be used in single or multi-cores machines, in the first architecture the compiler directives are ignored, thus the application is executed in a sequential manner, promoting portability between the two architectures.

Latest version is 5.2 (November 2021): Official OpenMP specifications.

Definitive Book Guide

Helpful links

6462 questions
2
votes
0 answers

Parallelizing for loop with unknown increment condition using OpenMP

I am finding all primes using the Sieve of Eratosthenes algorithm. I attempted to parallelize this algorithm. However, speedup stops increasing after two threads! My code is essentially two for loops. The outer for loop is the one increments the…
Casey
  • 444
  • 1
  • 7
  • 22
2
votes
1 answer

openMP initialization of the iterator in the for loop with curly braces

I have this main : int main() { std::size_t n{10000}; std::vector A(n); for (size_t k{0}; k < 10000; ++k) { // repeating the same task over and over again. #pragma omp parallel default(shared) { #pragma omp for …
Marine Galantin
  • 1,634
  • 1
  • 17
  • 28
2
votes
2 answers

How can I speed up a code C++ using OpenMP?

I am trying to parallelize the following code C++ using OpenMP: int np = 1000000; double kk = 1 / pow(2 * pi, 2); for (int kes = 1; kes <= 100; kes++) { double E1 = 0; #pragma omp parallel for reduction(+: E1) for (int ies = 0; ies < np;…
Luc Nguyen
  • 101
  • 9
2
votes
1 answer

What's the meaning of "C6993: code analysis ignores OpenMP construct" in omp?

I am using omp with visual studio 2019 and c++. But it keeps giving me the hint "C6993: code analysis ignores OpenMP". Does that mean omp will run the program in a single thread? Why? Following is the code. I have measured the time before and after…
CharlesQHappy
  • 45
  • 1
  • 4
2
votes
0 answers

Clang overload resolution failure with templates and openmp collapse

It seems to me that clang has some problems when using omp collapse in template function. I've attached a minimal example. Clang (9, 10, 11) can't compile it, while gcc compiles it just fine. Is this a compiler error or is my code doing something…
S. Kaczor
  • 401
  • 3
  • 8
2
votes
1 answer

Is this the correct use of 'restrict' in C?

Currently I'm learning about parallel programming. I have the following loop that needs to be parallelized. for(i=0; i
Tim
  • 415
  • 2
  • 10
2
votes
1 answer

OpenMP tasks - and the cost of "OpenMP if"

I am trying to understand the way OpenMP's task works. So I started with the simplest possible test, following OpenMP 4.5's example of Fibonacci computations: // Listing 1 #include #include long fib(int n) { int i, j; if…
ttsiodras
  • 10,602
  • 6
  • 55
  • 71
2
votes
1 answer

OpenMP: apparent race condition when increasing number of threads

I have this piece of code (removed just the initialisation of variable that's rather long and outside the parallel region). I am testing it on a local machine (4 physical cores, 8 threads) and comparing speed and result with its serial version. When…
Giovanni
  • 43
  • 5
2
votes
2 answers

The difference between these two OpenMP constructs

Is there any reason to use 2nd construct if I have only 1 for loop and nothing else? Thank you! #pragma omp parallel for // for loop goes here #pragma omp parallel { #pragma omp for // for loop goes here }
pic11
  • 14,267
  • 21
  • 83
  • 119
2
votes
0 answers

Calling fftw routines from pure subroutines in Fortran90

Multithreaded FFTW can be implemented as in this from FFTW homepage. Instead, we want to call the serial FFTW routines within OpenMP parallel environment using multiple threads. We want variable and fourier_variable to be thread-safe. This could be…
RTh
  • 107
  • 1
  • 1
  • 4
2
votes
1 answer

Can capturing a variable obtained by dereferencing a pointer be atomic?

I have the following C code, which I compile with OpenMP: ( int a[100] is a global array ) int update (int * x, const int c) { int v; #pragma omp atomic capture { v = a[*x]; a[*x] = c; } return v; } Neither of…
Ujjwal Rajput
  • 181
  • 2
  • 8
2
votes
2 answers

Pragma omp parallel for inside inner loop is not correctly ignored in nested loop

I'm trying to implement the following codes to see how OpenMP threads are managed over the nested loop where each inner/outer loops are separately implemented in a function and its caller. Each loop is implemented with the statement #pragma omp…
user9414424
  • 498
  • 3
  • 15
2
votes
1 answer

Using OpenMP and Intel Visual Fortran with Windows GetProcAddress

I am using the Intel Fortran Compiler 15.0 via the Microsoft Visual Studio 2015 IDE. I am learning OpenMP to (eventually) run sections of my code in parallel. My code will necessitate loading subroutines from .dlls. I have the following program that…
A_Weiss
  • 21
  • 2
2
votes
0 answers

OpenMP - Is that possible to use only lastprivate(var) instead of firstprivate(var) lastprivate(var) in all cases?

Code for test(my cpu has 6 cores, you can replace omp_set_num_threads(12) to omp_set_num_threads(4) if you don't have that much cores: #include #include #include int main() { int A; omp_set_num_threads(12); …
Yiling Liu
  • 666
  • 1
  • 6
  • 21
2
votes
0 answers

omp causing R to crash

The following portion of the function rl_compute compiles fine but causes R to crash when I run it. Not sure why. It works with 1 thread. // [[Rcpp::export]] void rl_compute(NumericVector covparms, NumericMatrix locs, NumericMatrix…
yf297
  • 21
  • 2
1 2 3
99
100