If statement 如果条件不工作,打开ACC?

If statement 如果条件不工作,打开ACC?,if-statement,openacc,If Statement,Openacc,我有以下代码: #pragma acc kernels for (i = 0; i<shape1Count; i++){ for (j = 0; j<shape2Count; j++){ if (kkk==1){ intersectionsCount++; } else { intersectionsCount++; } } } #pragma acc内核 对于(i=

我有以下代码:

#pragma acc kernels
for (i = 0; i<shape1Count; i++){
    for (j = 0; j<shape2Count; j++){

        if (kkk==1){
            intersectionsCount++;
        } else {
            intersectionsCount++;
        }

    }
}
#pragma acc内核

对于(i=0;i编译器通常可以自动检测缩减,但在这种情况下不能。因此,您需要自己添加一个缩减子句。以下是使用pgcc版本16.4时的输出:

% cat test.c
#include <stdlib.h>
#include <stdio.h>

int main() {

int i, j, kkk, intersectionsCount;
int shape1Count,shape2Count;

shape1Count=32;
shape2Count=32;
intersectionsCount=0;
kkk=1;

#pragma acc kernels loop reduction(+:intersectionsCount)
for (i = 0; i<shape1Count; i++){
    for (j = 0; j<shape2Count; j++){
        if (kkk==1){
            intersectionsCount++;
        } else {
            intersectionsCount++;
        }
    }
}
printf("%d\n",intersectionsCount);
exit(0);
}
% pgcc test.c -Minfo=accel -acc; a.out
main:
     15, Loop is parallelizable
     16, Loop is parallelizable
         Accelerator kernel generated
         Generating Tesla code
         15, #pragma acc loop gang, vector(4) /* blockIdx.y threadIdx.y */
         16, #pragma acc loop gang, vector(32) /* blockIdx.x threadIdx.x */
             Generating reduction(+:intersectionsCount)
1024
%cat test.c
#包括
#包括
int main(){
int i,j,kkk,交叉计数;
int shape1计数,shape2计数;
形状1计数=32;
shape2Count=32;
交叉计数=0;
kkk=1;
#pragma acc内核循环缩减(+:intersectionsCount)

对于(i=0;i编译器通常可以自动检测缩减,但在这种情况下不能。因此,您需要自己添加一个缩减子句。以下是使用pgcc版本16.4时的输出:

% cat test.c
#include <stdlib.h>
#include <stdio.h>

int main() {

int i, j, kkk, intersectionsCount;
int shape1Count,shape2Count;

shape1Count=32;
shape2Count=32;
intersectionsCount=0;
kkk=1;

#pragma acc kernels loop reduction(+:intersectionsCount)
for (i = 0; i<shape1Count; i++){
    for (j = 0; j<shape2Count; j++){
        if (kkk==1){
            intersectionsCount++;
        } else {
            intersectionsCount++;
        }
    }
}
printf("%d\n",intersectionsCount);
exit(0);
}
% pgcc test.c -Minfo=accel -acc; a.out
main:
     15, Loop is parallelizable
     16, Loop is parallelizable
         Accelerator kernel generated
         Generating Tesla code
         15, #pragma acc loop gang, vector(4) /* blockIdx.y threadIdx.y */
         16, #pragma acc loop gang, vector(32) /* blockIdx.x threadIdx.x */
             Generating reduction(+:intersectionsCount)
1024
%cat test.c
#包括
#包括
int main(){
int i,j,kkk,交叉计数;
int shape1计数,shape2计数;
形状1计数=32;
shape2Count=32;
交叉计数=0;
kkk=1;
#pragma acc内核循环缩减(+:intersectionsCount)

对于(i=0;i您使用的编译器是什么,在什么平台上运行?这应该会运行,不过如果增量是用原子指令实现的,它可能会运行得更好。您使用的编译器是什么,在什么平台上运行?这应该会运行,不过如果增量是用原子指令实现的,它可能会运行得更好。伙计!你救了我的命!“减少”是我在这里学到的新东西。谢谢你!你救了我的命!“减少”是我在这里学到的新东西。非常感谢