I need to setup OpenMP for my coursework and I am still new to C & C++
So far I have been using Apple's built in Clang and GCC compilers,
I assumed this would have support for OpenMP out of the box.
I have read a few answers here but they are either incomplete or I find them very confusing
I installed llvm, but Im not sure what's the point of this,
I followed the instructions and added it to my path but it still doesn't make a difference.
What's the best way to setup C/C++ environment on Mac M1, that has support for OpenMP?
Here is the basic program:
#include <stdio.h>#include <omp.h>#define THREADS 8int main(){ int tid, nthreads; omp_set_num_threads(THREADS); // start of parallel section // Fork a team of threads with each thread having a private tid variable #pragma omp parallel private(tid) { tid=omp_get_thread_num(); printf("Hello world from thread %d\n", tid); /* Only master thread does this */ if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } }//end of parallel section // All threads join master thread and terminate return 0;} // end main()
I have also done:
brew install libomp
Which works fine, but how am I supposed to get the OpenMP in the file to work?There doesn't seem to be any further details anywhere
I have watched this video, I assume She is speaking Spanish, although I can't understand what is being said, I followed it and I am not getting the new gcc already installed: https://www.youtube.com/watch?v=54S0tw0UrUg
I have downloaded gcc but it is still showing the same apple clang:
gcc -vApple clang version 13.1.6 (clang-1316.0.21.2.5)Target: arm64-apple-darwin21.5.0Thread model: posixInstalledDir: /Library/Developer/CommandLineTools/usr/bin
I have managed to get the gcc installed as well as libomp
When I ran the program I got this error:
Undefined symbols for architecture arm64:"_omp_get_num_threads", referenced from: _main in ccK3z6BU.o"_omp_get_thread_num", referenced from: _main in ccK3z6BU.o"_omp_set_num_threads", referenced from: _main in ccK3z6BU.old: symbol(s) not found for architecture arm64collect2: error: ld returned 1 exit status