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
2 answers

Can the GCC compiler use nVidia GPU to speed up compilation and/or linking?

I'm looking at GCC with NVPTX offloading (specifically on Windows/MinGW-w64), and I was wondering if GCC itself can take advantage of this, so it has more processing power to do faster compiling/linking? Or does this question make little sense as…
Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
2
votes
1 answer

OpenMP atomic compare and swap

I have a shared variable s and private variable p inside parallel region. How can I do the following atomically (or at least better than with critical section): if ( p > s ) s = p; else p = s; I.e., I need to update the global maximum (if…
user2052436
  • 4,321
  • 1
  • 25
  • 46
2
votes
0 answers

Generating random number for a parallel loop in cpp

I have written code in which I use parallel computing. Because adding random numbers to a parallel loop is tricky, I have tried to generate independent random numbers by generating the random numbers just before the parallel loop. However, I am…
user258046
  • 53
  • 4
2
votes
1 answer

Bug related to g++/OpenMP when using std::thread?

I've distilled the problem I have to its bare essentials. Here is the first example piece of code: #include #include #include std::vector vec(10000); void run(void) { for(int l = 0; l < 500000; l++) { …
qshn
  • 61
  • 4
2
votes
2 answers

OpenMP outputs incorrect answers

I have typed this simple code to calculate the number of prime numbers between 2 and 5,000,000. The algorithm works fine and it outputs the correct answer, however when I try to use OpenMP to speedup the execution it outputs a different answer every…
Mohamed Rady
  • 118
  • 1
  • 6
2
votes
0 answers

Compile OpenMP application with target pragma on Nvidia GPU

I’m trying to compile and run an application with OpenMP target pragma that checks if it runs on GPU or CPU. #include #include int main() { int runningOnGPU = 0; /* Test if GPU is available using OpenMP4.5 */ #pragma omp target…
Yaron Kaen
  • 21
  • 3
2
votes
0 answers

pymc3 does not use all cores specified by OMP_NUM_THREADS

I have a fitting procedure written in pymc3 which utilizes dot products of matrices which are functions of random variables. On the original machine on which I wrote the program, it would run and by default use all available cores, as…
unfitter
  • 21
  • 1
2
votes
1 answer

Combine mpi with openMP

I am trying to solve a problem with MPI, openMP and the combination of those two. Both MPI and openMP are running fine but when I try the MPI-openMP version of the code I can't get pass an error shows up at the end of the post. MPI…
2
votes
1 answer

Speeding up matrix multiplication using SIMD and openMP

I am trying to speed up matrix multiplication so it will have much better performance than the naive implementation. My goal is to speed it up to be 150 times faster. Here are things that I have tried in my implementation so far: Allocating…
2
votes
1 answer

Calculate PI using OpenMP task directive

I need to parallelize code that calculates number π using Leibniz formula for π with OpenMP task directive. Leibniz formula So, I got a sequential code: double sequential_execution(long long n) { long long i; double factor; double sum =…
someguy
  • 23
  • 4
2
votes
1 answer

CMake: How can I force cmake to static link openmp?

I know the way to use cmake to link openmp in a cross-platform way find_package(OpenMP REQUIRED) link_libraries(OpenMP::OpenMP_CXX) But I don't know how to force cmake to static link openmp, in fact, all of cmake official variable about openmp…
Wongboo
  • 124
  • 1
  • 6
2
votes
1 answer

Do I have to build gcc-10 from source on Ubuntu 18.04 to have OpenMP GPU target offload?

When I use gcc-10 (and 9, 8, 7) from default repositories on Ubuntu 18.04, omp_get_num_devices() returns 0, even though I have: paul@desktop:~$ nvidia-smi ... | NVIDIA-SMI 450.80.02 Driver Version: 450.80.02 CUDA Version: 11.0 | Do I need…
Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72
2
votes
1 answer

openmp two consecutive loops, problem with reduction clause

There is two consecutive loops and there is a reduction clause in the second loop. #pragma opm parallel { #pragma omp for for (size_t i = 0; i < N; ++i) { } #pragma omp barrier #pragma omp for reduction(+ \ :…
Abolfazl
  • 1,047
  • 2
  • 12
  • 29
2
votes
1 answer

OpenMP not waiting all threads finish before end C program

I have the following problem: My C program must count the number of occurrences of a list of words in a text file. I use OpenMP for this, and the program, in theory, has the correct logic. When I put some printfs inside a For Loop the result of the…
2
votes
1 answer

How to avoid reinitializing a vector every time though an openmp for loop?

I have a for loop that looks like this: for (int i = 0;i vec; //then do work on vec, such as resize or push_back } This is inefficient because every time through the loop, vec is resized, and this may force a dynamic…
pah52
  • 85
  • 6