Hi Mat,
My question is about routine directive and bind clause. From the OpenACC Application Programming Interface, I don’t know the meaning of bind clause. Simple example is :
#include<stdio.h>
#pragma acc routine worker bind(sum1)
int sum(int ,float *);
int sum(int n,float *A)
{
int i;
float s=0.0f;
for(i=0;i<n;i++){
s=s+A[i];
}
return s;
}
#pragma acc routine worker
int sum1(int n,float *A)
{
int i;
float s=0.0f;
#pragma acc loop vector reduction(+:s)
for(i=0;i<n;i++){
s=s+A[i]+2;
}
return s;
}
int main()
{
float *X,*Y;
X=(float*)malloc(sizeof(float)*100*200);
Y=(float*)malloc(sizeof(float)*100);
int j,i;
for(j=0;j<100;j++){
for(i=0;i<200;i++){
X[j*200+i]=j;
}
}
#pragma acc parallel copyout(Y[0:100]) copyin(X[0:100*200])
{
#pragma acc loop gangs
for(j=0;j<100;j++){
Y[j]=sum(200,(X+j*200));
}
}
for(j=0;j<10;j++){
printf("Y[%d]=%f\n",j,Y[j]);
}
free(X);
free(Y);
return 0;
}
Referencing to the PPT, I code this simple example, but I don’t understand the code .