一直在尝试在OSX 10.12上编译并运行一个简单的OpenMP程序(Hello World)。我用brew安装了gcc 6。 我一直在使用' -fopenmp'旗。 该程序编译良好,但当我尝试执行该程序时,我得到以下内容:
dyld: lazy symbol binding failed: Symbol not found: ___emutls_get_address
Referenced from: /usr/local/opt/gcc/lib/gcc/6/libgomp.1.dylib (which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: ___emutls_get_address
Referenced from: /usr/local/opt/gcc/lib/gcc/6/libgomp.1.dylib (which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
Abort trap: 6
有什么想法吗?
答案 0 :(得分:0)
以下是使用g ++ - 6在我的iMac上运行的示例,编译如下:
g++-6 -std=c++11 -fopenmp -O3 demo.cpp -o demo
运行如下:
./demo
Time: 4.132ms, 1000000 elements.
代码如下:
#include "omp.h"
#include <iostream>
#include <cmath>
#include <cstdio>
#include <chrono>
int main()
{
const int size = 1000000;
int i;
double sinTable[size];
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
#pragma omp parallel for
for(int n=0; n<size; ++n)
sinTable[n] = sqrt(std::sin(2 * M_PI * n / size));
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
std::uint64_t duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end-start).count();
float ms=duration/1000000.0;
std::cout << "Time: " << ms << "ms, " << size << " elements." << std::endl;
}