Installing OpenMP on Mac OS X 10.11

前端 未结 6 1866
悲&欢浪女
悲&欢浪女 2020-11-30 03:35

How can I get OpenMP to run on Mac OSX 10.11, so that I can execute scripts via terminal?

I have installed OpenMP: brew install clang-omp

6条回答
  •  忘掉有多难
    2020-11-30 04:01

    • install clang-omp

      brew install clang-omp
      
    • make sure you xcode command line tool

      xcode-select --install
      
    • I actually had one error while running a sample openmp code

      /usr/local/opt/libiomp/include/libiomp/omp.h:139:21: error: expected ';' after top level declarator extern void   __ KAI_KMPC_CONVENTION kmp_set_stacksize_s        (size_t);
      
    • Just remove one space that is present between __ and KAI from the file

    • Now use the command

      clang-omp -fopenmp helloopenmp.c
      

      and run the following code

      #include 
      #include 
      int main() {
          #pragma omp parallel
          printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
      }
      
    • You should get output similar to this

      Hello from thread 3, nthreads 4
      Hello from thread 2, nthreads 4
      Hello from thread 0, nthreads 4
      Hello from thread 1, nthreads 4
      
    • Worked on OS X 10.11.3 and with brew update dated 18th Feb 2016

提交回复
热议问题