osx汇编程序错误

时间:2015-10-12 07:42:47

标签: c++ c parallel-processing openmp

我一直在尝试在我的mac上运行openMp。最后,我终于成功完成了它。

此程序完美无缺

https://computing.llnl.gov/tutorials/openMP/samples/C/omp_hello.c

但是这个:

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

static long num_steps = 100000;
double step;

int main(){

int i, nthreads;
double x,pi,sum[2] ;
double start = omp_get_wtime();
double end;

step = 1.0/(double)num_steps;

omp_set_num_threads(2);

#pragma omp parallel
{
    int i, id,nthrds;
    double x;
    id = omp_get_thread_num();
    nthreads = omp_get_num_threads();
    if(id == 0) nthreads = nthrds;

    for(i = 0 ; i < num_steps ; i = i+nthrds){
        x = (i+0.5)*step;
        sum[id] += 4.0/(1.0+x*x);
        //printf("Thread_num : %d ,%f\n", omp_get_thread_num(),sum);
    }

}
//pi = step*sum;

for (int i = 0, pi =0.0; i < nthreads; ++i)
{
    /* code */
    pi += sum[i] * step;
}

end = omp_get_wtime();
printf("%f\n", end-start);

return 0;
}

..把这些错误扔给我

gcc -fopenmp helloWorld.c -o helloWorld
/var/folders/d7/2jjg9ygj7zscb67wnskcxsk40000gp/T//cc4hIbK6.s:19:suffix         or operands invalid for `movq'
/var/folders/d7/2jjg9ygj7zscb67wnskcxsk40000gp/T//cc4hIbK6.s:64:suffix or operands invalid for `movq'
/var/folders/d7/2jjg9ygj7zscb67wnskcxsk40000gp/T//cc4hIbK6.s:68:suffix or operands invalid for `movq'
/var/folders/d7/2jjg9ygj7zscb67wnskcxsk40000gp/T//cc4hIbK6.s:69:suffix or operands invalid for `movq'

我不知道为什么会这样做。在我问这里之前,我在网上搜索过,但是我找不到有人用openMP这个问题。

(我不完全确定编译器安装得很好。我安装了很多东西,其中一些有用,有些没用)

1 个答案:

答案 0 :(得分:0)

对于每个人都会读到这个: 我更新了gcc(使用brew),然后用gcc-5运行程序..希望你们也能让它发挥作用。祝你好运。