-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaccpi.cpp
More file actions
42 lines (41 loc) · 784 Bytes
/
accpi.cpp
File metadata and controls
42 lines (41 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
double niter = 100000;
double x,y;
int count=0;
double z;
double pi;
int a = 0;
time_t t;
double randomnums[200000];
double output[100000];
srand48(((unsigned)time(&t)));
for (a = 0; a<=2*niter; a++)
randomnums[a] = (double)drand48();
int i = 0;
#pragma acc parallel copy(randomnums[0:200000]) copyout(output[0:100000]) create(x,y,z)
{
for (i = 0; i<100000; i++)
{
int temp = i+i;
x = randomnums[temp];
y = randomnums[temp+1];
z = ((x*x)+(y*y));
output[i] = z;
}
for (i = 0; i<100000; i++)
{
if (output[i]<=1)
{
++count;
}
else
continue;
}
}
pi = ((double)count/(double)niter)*4.0;
printf("Pi: %f\n", pi);
}