multithreading - openmp runs single threaded on my mac -
i trying parallelize program using openmp on mac, can not manage make multi-threaded. i've tried building llvm/clang/openmp 3.7.1 source (after svn co) documented, have tried using prebuild versions of clang , openmp 3.7.0 given llvm project. in each case, resulting compiler works fine -fopenmp flag , produce executable links openmp runtime.
i use following openmp 'hello world' program:
#include <omp.h> #include <stdio.h> #include <stdlib.h> int main (int argc, char *argv[]) { int nthreads, tid; /* fork team of threads giving them own copies of variables */ #pragma omp parallel private(nthreads, tid) { /* obtain thread number */ tid = omp_get_thread_num(); printf("hello world thread = %d\n", tid); /* master thread */ if (tid == 0) { nthreads = omp_get_num_threads(); printf("number of threads = %d\n", nthreads); } } /* threads join master thread , disband */ }
i compile using:
clang -fopenmp hello.c -o hello
and run resulting program with:
env omp_num_threads=2 ./hello
which gives:
hello world thread = 0 number of threads = 1
any idea?
clang < 3.8.0 requires -fopenmp=libomp generate openmp code. clang >= 3.8.0 supports -fopenmp (-fopenmp=libomp can used also).
Comments
Post a Comment