Bastien
Bastien

Reputation: 45

How to use OpenMP in Xcode 9.0

Does anyone know how to enable the use of OpenMP in Xcode 9.0?

In Xcode 8, I procide as described in this tutorial but it doesn't work anymore in Xcode 9.0 ...

The error is : clang-5.0: error: cannot specify -o when generating multiple output files

Thanks in advance for help

Upvotes: 3

Views: 994

Answers (2)

Marek H
Marek H

Reputation: 5566

Xcode 11.7

There are 2 ways (no need to use both)

  1. using llvm
  2. using libomp

Follows libomp :

Install libomp

brew install libomp

Write some code:

#include <omp.h>

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    #pragma omp parallel num_threads(4)
    {
      printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
    }
}

In build setting make following changes

  • Other linker flags: -lomp
  • Header Search paths: /usr/local/opt/libomp/include
  • Library Search paths: /usr/local/opt/libomp/lib
  • Other C flags: -Xpreprocessor AND -fopenmp

OpenMP

Mission success:

2020-09-30 17:23:58.449045+0800 QRGenerator2[24352:3549441] Metal API Validation Enabled
Hello from thread 0, nthreads 4
Hello from thread 1, nthreads 4
Hello from thread 3, nthreads 4
Hello from thread 2, nthreads 4

Upvotes: 0

infoshoc
infoshoc

Reputation: 128

I think the problem is in flag -index-store-path In build settings > build options set Enable Index-While-Building Functionality to No

Upvotes: 5

Related Questions