1

我想编译一个简单的 openacc 示例(已附加),它已正确编译,但是当我运行它时出现错误:

  1. 编译:gcc-5 -fopenacc accVetAdd.c -lm
  2. 运行:./a.out
  3. 运行时出错

错误: libgomp:加载 libgomp-plugin-host_nonshm.so.1:libgomp-plugin-host_nonshm.so.1:无法打开共享对象文件:没有这样的文件或目录

我用谷歌搜索,只找到一页!然后我问如何解决这个问题?

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

int main(int argc, char* argv[])
{
    // Size of vectors
    int n = 10000;

    // Input vectors
    double *restrict a;
    double *restrict b;
    // Output vector
    double *restrict c;

    // Size, in bytes, of each vector
    size_t bytes = n*sizeof(double);

    // Allocate memory for each vector
    a = (double*)malloc(bytes);
    b = (double*)malloc(bytes);
    c = (double*)malloc(bytes);

    // Initialize content of input vectors, vector a[i] = sin(i)^2 vector b[i] = cos(i)^2
    int i;
    for (i = 0; i<n; i++) {
        a[i] = sin(i)*sin(i);
        b[i] = cos(i)*cos(i);
    }

    // sum component wise and save result into vector c
    #pragma acc kernels copyin(a[0:n],b[0:n]), copyout(c[0:n])
    for (i = 0; i<n; i++) {
        c[i] = a[i] + b[i];
    }
    // Sum up vector c and print result divided by n, this should equal 1 within error
    double sum = 0.0;
    for (i = 0; i<n; i++) {
        sum += c[i];
    }
    sum = sum / n;
    printf("final result: %f\n", sum);

    // Release memory
    free(a);
    free(b);
    free(c);
    return 0;
}
4

1 回答 1

1

libgomp 为它支持的插件动态加载共享对象文件,例如实现host_nonshm设备的插件。如果它们安装在非标准目录中(即不在系统的默认搜索路径中),您需要告诉动态链接器在哪里查找这些共享对象文件:使用 编译-Wl,-rpath,[...]或设置LD_LIBRARY_PATH环境变量。

于 2015-07-29T08:58:19.507 回答