cc_staff
782
edits
(Modified the cheat-sheet name) |
(Tabs and file format for easy download) |
||
Line 21: | Line 21: | ||
= Code examples = | = Code examples = | ||
OpenACC can be used in FORTRAN, C and C++. | |||
<tabs> | |||
<tab name="C"> | |||
The following example computes an approximation of Pi: | |||
{{File | |||
|name=pi.c | |||
|lang="C" | |||
|contents= | |||
#include <stdio.h> | |||
#define N 2000000000 | |||
#define vl 512 | |||
int main(void) { | |||
double pi = 0.0f; | |||
long long i; | |||
#pragma acc parallel vector_length(vl) | |||
#pragma acc loop reduction(+:pi) | |||
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; | |||
} | |||
}} | |||
</tab> | |||
</tabs> | |||
= Compilers = | = Compilers = |