File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -125,21 +125,23 @@ from numba.openmp import njit
125125from numba.openmp import openmp_context as openmp
126126from numba.openmp import omp_get_thread_num
127127
128+
128129@njit
129130def 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
142143print (" pi =" , calc_pi(1000000 ))
144+
143145```
144146
145147## Support
You can’t perform that action at this time.
0 commit comments