OpenMP -Mac M1 GCC和Libomp无法正常工作
我需要为我的课程设置OpenMP,但我仍然是C& 到目前为止,
我一直在使用Apple内置的Clang和GCC编译器,
我认为这将支持OpenMP开箱即用。
我在这里阅读了一些答案,但它们要么不完整,要么发现它们非常混乱,
我安装了LLVM,但是我不确定这是什么意义,
我遵循说明并将其添加到我的路上,但仍然没有不同之处。
在Mac M1上设置C/C ++环境的最佳方法是支持OpenMP的?
这是基本程序:
#include <stdio.h>
#include <omp.h>
#define THREADS 8
int 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()
我也做过:
brew install libomp
哪个工作正常,但是我应该如何将openMP在文件中工作? 我看过这段视频的任何地方似乎都没有任何其他细节
,我认为她在说西班牙语,尽管我不明白说什么,但我遵循了它,但我没有安装新的GCC:< a href =“ https://www.youtube.com/watch?v=54S0TW0URUG” rel =“ nofollow noreferrer”> https://www.youtube.com/watch?v=54S0TW0URUG
我已经下载了GCC 但是它仍然显示出同样的苹果叮当声:
gcc -v
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
我设法安装了海湾室高管以及libomp,我遇到了这个错误:
当我运行程序时,
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.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
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 8
int 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 -v
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /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.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用M1芯片在MacBook Air上安装Brew后也有类似的问题。
运行使用Homebrew安装的G ++,而不是默认一个为我解决了它。
G ++的完整路径是
现在我可以与这样的-fopenmp进行编译:
示例程序:
它应该运行:
Had similar issues after installing with brew on MacBook Air with M1 chip.
Running the g++ installed with homebrew instead of default one solved it for me.
The full path for g++ was
Now I can compile with -fopenmp like this:
Sample program:
And it works as it should: