Why does gcc-10 fail to link with error "error: array section is not contiguous in ‘map’ clause" in 2D array openacc application?
Why does gcc-10 fail to link with error "error: array section is not contiguous in ‘map’ clause" in 2D array openacc application?
我正在尝试使用 gcc-10 在 C 中编译一个基本的 openacc 程序。它适用于一维数组和通过“A[N_x][N_y]”分配的数组,但是当尝试使用 malloc 分配的二维数组时,无论是否连续,我都会收到一条错误消息编译时。下面的例子失败了:
#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 位 Ubuntu 18.04 LTS 系统上使用此 GPU 卡:GeForce GTX 1050 Ti/PCIe/SSE2
代码很好,但我认为 GNU 不支持非连续数据段。我需要推迟 GNU 人员,但相信他们会在未来版本的编译器中开发这种支持。
现在,您需要切换到使用 NVIDIA HPC 编译器 (https://developer.nvidia.com/hpc-sdk) 或重构代码以使用大小为 N_x*[=17= 的一维数组] 与计算索引。类似于:
#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;
}
我正在尝试使用 gcc-10 在 C 中编译一个基本的 openacc 程序。它适用于一维数组和通过“A[N_x][N_y]”分配的数组,但是当尝试使用 malloc 分配的二维数组时,无论是否连续,我都会收到一条错误消息编译时。下面的例子失败了:
#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 位 Ubuntu 18.04 LTS 系统上使用此 GPU 卡:GeForce GTX 1050 Ti/PCIe/SSE2
代码很好,但我认为 GNU 不支持非连续数据段。我需要推迟 GNU 人员,但相信他们会在未来版本的编译器中开发这种支持。
现在,您需要切换到使用 NVIDIA HPC 编译器 (https://developer.nvidia.com/hpc-sdk) 或重构代码以使用大小为 N_x*[=17= 的一维数组] 与计算索引。类似于:
#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;
}