我将通过 openacc 优化这段代码,但输出计算为零。我很高兴有机会以这种方式帮助我,并使用您的指导来取得成功并解决我的问题。
不耐烦,我期待着很快听到你的消息。国王问候,
萨贾德·穆罕默德
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <openacc.h>
#include<time.h>
#include <string.h>
#include <malloc.h>
// #include <cuda_runtime_api.h>
#define NX 4
#define NY 4
#define NZ 4
int main(void)
{
int i, j,p, k;
static double A[NX-1][NY-1][NZ-1]={10.} ,B[NX-1][NY-1][NZ-1]={10.},C[NX-1][NY-1][NZ-1]={10.};
FILE *file;
file = fopen("B-and-A.csv", "w");
#pragma acc data copyin(B,C),copyout(A)
{
for (p = 0; p <=2; p++) {
#pragma acc kernels loop private(i,j,k)
for ( i = 1; i < NX - 1; i++ ) {
for ( j = 0; j < NY - 1; j++ ) {
for ( k = 0; k < NZ - 1; k++ ) {
A[i][j][k] = A[i][j][k]+2.
+ 1.*( B[i][j+1][k] + C[i][j][k] )
+ 1.*( C[i][j][k+1] + B[i][j][k] );
}
}
}
fprintf(file,"%e\n",A[2][2][2]);
}
}
fclose(file);
}