OpenACC: Difference between revisions

Jump to navigation Jump to search
Tabs and file format for easy download
(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++.


In C (<code>pi.c</code>):
<tabs>
#include <stdio.h>
<tab name="C">
The following example computes an approximation of Pi:
#define N 2000000000
{{File
#define vl 512
  |name=pi.c
  |lang="C"
int main(void) {
  |contents=
  double pi = 0.0f;
#include <stdio.h>
  long long i;
 
#define N 2000000000
  #pragma acc parallel vector_length(vl)  
#define vl 512
  #pragma acc loop reduction(+:pi)
 
  for (i = 0; i < N; i++) {
int main(void) {
    double t = (double)((i + 0.5) / N);
  double pi = 0.0f;
    pi += 4.0 / (1.0 + t * t);
  long long i;
  }
 
  printf("pi = %11.10f\n", pi / N);
  #pragma acc parallel vector_length(vl)  
  return 0;
  #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 =
cc_staff
782

edits

Navigation menu