OpenACC: Difference between revisions

Line 44: Line 44:
   }
   }
   printf("pi = %11.10f\n", pi / N);
   printf("pi = %11.10f\n", pi / N);
  return 0;
}
}}
</tab>
<tab name="C++">
{{File
  |name=pi.cxx
  |lang="C++"
  |contents=
#include <iostream>
#include <iomanip>
const long long N=2000000000;
const int vl=512;
int main(int argc,char** argv) {
  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);
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(10);
  std::cout << "pi = " << pi/double(N) << std::endl;
   return 0;
   return 0;
}
}
Bureaucrats, cc_docs_admin, cc_staff
2,318

edits