Openmp runs single-threaded on my mac

I am trying to parallelize a program using openmp on a Mac, but I cannot make it multithreaded. I tried to create llvm / clang / openmp 3.7.1 from the source (after svn co), as it is documented , I also tried to use the preinstalled versions of clang and OpenMP 3.7.0 defined by the llvm project . In each case, the resulting compiler works fine with the -fopenmp flag and creates an executable that references runtime runtime.

I use the following openmp program 'hello world':

#include <omp.h> #include <stdio.h> #include <stdlib.h> int main (int argc, char *argv[]) { int nthreads, tid; /* Fork a team of threads giving them their own copies of variables */ #pragma omp parallel private(nthreads, tid) { /* Obtain thread number */ tid = omp_get_thread_num(); printf("Hello World from thread = %d\n", tid); /* Only master thread does this */ if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } } /* All threads join master thread and disband */ } 

I will compile using:

 clang -fopenmp hello.c -o hello 

and then run the resulting program with:

 env OMP_NUM_THREADS=2 ./hello 

which gives:

 Hello World from thread = 0 Number of threads = 1 

Any idea?

+2
source share
1 answer

clang <3.8.0 requires -fopenmp = libomp to generate OpenMP code. clang> = 3.8.0 also supports -fopenmp (-fopenmp = libomp can also be used).

+3
source

Source: https://habr.com/ru/post/1270869/


All Articles