Skip to content

Commit 05827a9

Browse files
Clean up calculate pi GPU example
1 parent 71809bb commit 05827a9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,23 @@ from numba.openmp import njit
125125
from numba.openmp import openmp_context as openmp
126126
from numba.openmp import omp_get_thread_num
127127

128+
128129
@njit
129130
def calc_pi(num_steps):
130-
step = 1.0/num_steps
131+
step = 1.0 / num_steps
131132
red_sum = 0.0
132133
with openmp("target map(tofrom: red_sum)"):
133134
with openmp("loop private(x) reduction(+:red_sum)"):
134-
for i in range(num_steps):
135-
tid = omp_get_thread_num()
136-
x = (i+0.5)*step
137-
red_sum += 4.0 / (1.0 + x*x)
135+
for i in range(num_steps):
136+
x = (i + 0.5) * step
137+
red_sum += 4.0 / (1.0 + x * x)
138138

139139
pi = step * red_sum
140-
print("pi=", pi)
140+
return pi
141+
141142

142143
print("pi =", calc_pi(1000000))
144+
143145
```
144146

145147
## Support

0 commit comments

Comments
 (0)