1

I followed the instructions from this answer in clang-omp in Xcode under El Capitan

I was able to run openmp programs on xcode. But there was only 1 thread.

Also, I am able to run from terminal, refer to my answer for this Installing OpenMP on Mac OS X 10.11

how to increase no. of threads in xcode?

I am running sample program:

    #include <omp.h>
    #include <stdio.h>
    int main() {
    #pragma omp parallel
    printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
    }

I get only one thread in output in xcode.

I have tried Xcode->Edit Schemes-> Arguments-> Env variables-> OMP_NUM_THREADS with value 4

I have also tried omp_set_num_threads(4)

Community
  • 1
  • 1
prakharjain
  • 254
  • 2
  • 15
  • I have absolutely no idea how to modify the environment of the executable from within Xcode, but you could add a call to `omp_set_num_threads()` before the parallel region or add the `num_threads` clause, e.g. `#pragma omp parallel num_threads(4)`. If it still executes single-threaded, then you haven't linked against the correct OpenMP runtime or something. – Hristo Iliev Feb 17 '16 at 22:17
  • I have tried omp_set_num_threads(). Any idea on how to do it, it works in terminal!!! – prakharjain Feb 17 '16 at 22:27
  • How do you compile your code? Is the option `-fopenmp` set? – Mathieu Feb 18 '16 at 11:27
  • Yes, I have added -fopenmp to Other C Flags under the project's build settings. Look at http://stackoverflow.com/questions/33668323/clang-omp-in-xcode-under-el-capitan on how I build. Look at http://stackoverflow.com/questions/35134681/installing-openmp-on-mac-os-x-10-11/35467142#35467142 on how I run in Terminal. – prakharjain Feb 18 '16 at 13:59
  • What does `otool -L /path/to/executable` show? `/path/to/execuable` should be the path to the executable produced by Xcode. It is usually located in a folder with some randomly generated name and there is a shortcut icon somewhere on the GUI that opens the folder in Finder. – Hristo Iliev Feb 19 '16 at 11:00
  • /usr/local/opt/libiomp/lib/libiomp5.dylib (compatibility version 5.0.0, current version 5.0.0) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1) – prakharjain Feb 19 '16 at 13:34

1 Answers1

1

I am sure this answer is coming way too late. But hopefully might help someone else. I was struggling with the same issue and solved it by : Adding -fopenmp to Other C++ flags as well as C flags.

Hope this helps someone.

Thayjes
  • 26
  • 1