Recently, there have been some efforts in GCC community to support OpenACC in their compiler. So, I wanted to try it out.
Using this step-by-step tutorial (tutorial), which was close to the main documentation on GCC website, I was able to compile and build GCC 6.1 with OpenACC support.
Then, I compiled my program using following command:
gcc pi.c -fopenacc -foffload=nvptx-none -foffload="-O3" -O3
And, everything goes without any errors.
The execution is without error, but no correct answer.
Here are my C code and the output of the running program:
#include <stdio.h>
#include <openacc.h>
#define N 20000
#define vl 1024
int main(void) {
double pi = 0.0f;
long long i;
int change = 0;
printf("Number of devices: %d\n", acc_get_num_devices(acc_device_nvidia));
#pragma acc parallel
{
change = 1;
#pragma acc loop reduction(+:pi) private(i)
for (i=0; i<N; i++) {
double t= (double)((i+0.5)/N);
pi +=4.0/(1.0+t*t);
}
}
printf("Change: %d\n", change);
printf("pi=%11.10f\n",pi/N);
pi = 0.0;
for (i=0; i<N; i++) {
double t= (double)((i+0.5)/N);
pi +=4.0/(1.0+t*t);
}
printf("pi=%11.10f\n",pi/N);
return 0;
}
And this is the output after running a.out
:
Number of devices: 1
Change: 0
pi=0.0000000000
pi=3.1415926538
Any ideas?