我正在尝试用C编写一个基本的openacc程序,使用的是gcc-10。它适用于一维数组和通过"AN_x“分配的数组,但是当尝试使用malloc分配的2D数组时,无论是连续的还是非连续的,编译时都会收到错误消息。以下示例失败:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int N_x = 1000;
int N_y = 1000;
int i_x;
// allocate
double **A;
A = malloc(N_x * sizeof(double*));
A[0] = malloc(N_x * N_y * sizeof(double));
for (i_x = 0; i_x < N_x; i_x++)
{
A[i_x] = A[0] + i_x * N_y; // contiguous allocation
// A[i_x] = malloc(sizeof(double) * N_y); // non-contiguous allocation
}
// another example of same error
// get onto the GPU
//#pragma acc enter data create (A[0:N_x][0:N_y])
// get out of the GPU
//#pragma acc exit data copyout (A[0:N_x][0:N_y])
// following pragma triggers the "error: array section is not contiguous in ‘map’ clause" error
#pragma acc parallel loop copy(A[0:N_x][0:N_y])
for (i_x = 0; i_x < N_x; i_x++)
A[i_x][i_x] = (double) i_x;
// free
free(A[0]);
free(A);
return 0;
}我是不是漏掉了什么明显的东西?谢谢你的帮助。顺便说一句,我用
gcc-10 test2.c -fopenacc在64位Ubuntu18.04LTS系统上使用此GPU卡: GeForce GTX1050Ti/PCIe/SSE2
发布于 2020-12-08 02:44:57
代码很好,但我不相信GNU支持非连续的数据段。我需要推迟GNU人员的工作,但我相信他们会在编译器的未来版本中开发这种支持。
现在,您需要切换到使用NVIDIA HPC Compiler (https://developer.nvidia.com/hpc-sdk),或者重构代码以使用带有计算索引的N_x*N_y大小的一维数组。类似于:
#include <stdio.h>
#include <stdlib.h>
#define IDX(n,m,s) ((n*s)+m)
int main()
{
int N_x = 1000;
int N_y = 1000;
int i_x;
// allocate
double *A;
A = malloc(N_x * N_y * sizeof(double*));
#pragma acc enter data create(A[:N_x*N_y])
#pragma acc parallel loop present(A)
for (i_x = 0; i_x < N_x; i_x++)
A[IDX(i_x,i_x,N_x)] = (double) i_x;
// free
free(A);
return 0;
}https://stackoverflow.com/questions/65173987
复制相似问题