0

I am trying to run a simple "Hello world" program using OpenMP. This is my program (helloworld.cpp):

#include <iostream> 

int main (){

    // begin parallel region 
    #pragma omp parallel 
    {
        std::cout << "Hello world!" << std::endl;
    }

    return 0; 

}

I am trying to get this to run with the default number of threads, whatever that might be.

This is what I am running:

$ g++ -Xpreprocessor -fopenmp helloworld.cpp 
Undefined symbols for architecture arm64:
  "___kmpc_fork_call", referenced from:
      _main in helloworld-e5c8d6.o
ld: symbol(s) not found for architecture arm64

The version of clang++ I have is:

g++ --version
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I am running my work on a M1 Big Sur, 2021.

I have installed the compilers and libomp using Homebrew.

How do I go about making this work?

megamence
  • 433
  • 4
  • 6
  • The compiler you are using says Apple so you have not installed it via Homebrew. What complier installed by Homebrew were you hoping to use? – mmmmmm Aug 09 '22 at 15:47
  • well, i was hoping to use g++. i assumed g++ was being used by the gcc compiler i downloaded using homebrew, but evidently not... – megamence Aug 09 '22 at 15:49
  • If you use Xcode and produce a command line tool with just that file and no chnage in build configuration it works. So look at the logs and see what extra flags you need. – mmmmmm Aug 09 '22 at 16:00
  • For gcc I think you need to use something like gcc-12 See https://apple.stackexchange.com/q/245891/237 but don't use aliases us some forma of build. On my Macports gcc for openmp is called g++-mp-12 SO you might have to use a special openmp version. But then again what is wrong with Apple's clang++ – mmmmmm Aug 09 '22 at 16:07

0 Answers0