Skip to content

Commit 753c8b4

Browse files
committed
OpenMP on advection
1 parent ea55bbe commit 753c8b4

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

pygyro/advection/accelerated_advection_steps.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@ def poloidal_advection_step_expl(f: 'float[:,:]',
4141
multFactor = dt / B0
4242
multFactor_half = 0.5 * multFactor
4343

44-
phi_spline.eval_vector(qPts, rPts, drPhi_0, 0, 1)
45-
phi_spline.eval_vector(qPts, rPts, dthetaPhi_0, 1, 0)
46-
4744
nPts_r = rPts.shape[0]
4845
nPts_q = qPts.shape[0]
4946

47+
#$omp parallel for collapse(2)
48+
for i in range(nPts_r):
49+
for j, q in enumerate(qPts):
50+
r = rPts[i]
51+
drPhi_0[i, j] = phi_spline.eval(q, r, 0, 1)
52+
dthetaPhi_0[i, j] = phi_spline.eval(q, r, 1, 0)
53+
5054
idx = nPts_r-1
5155
rMax = rPts[idx]
5256

57+
#$omp parallel for collapse(2)
5358
for i in range(nPts_q):
5459
for j in range(nPts_r):
5560
# Step one of Heun method
@@ -88,6 +93,7 @@ def poloidal_advection_step_expl(f: 'float[:,:]',
8893

8994
# Find value at the determined point
9095
if (nulBound):
96+
#$omp parallel for collapse(2)
9197
for i in range(nPts_q): # theta
9298
for j in range(nPts_r): # r
9399
if (endPts_k2_r[i, j] < rPts[0]):
@@ -99,6 +105,7 @@ def poloidal_advection_step_expl(f: 'float[:,:]',
99105
f[i, j] = pol_spline.eval(
100106
endPts_k2_q[i, j], endPts_k2_r[i, j])
101107
else:
108+
#$omp parallel for collapse(2)
102109
for i in range(nPts_q): # theta
103110
for j in range(nPts_r): # r
104111
if (endPts_k2_r[i, j] < rPts[0]):
@@ -152,6 +159,7 @@ def v_parallel_advection_eval_step_loop(f: 'float[:,:,:]', vPts: 'float[:]',
152159
CN0: 'float', kN0: 'float', deltaRN0: 'float', rp: 'float',
153160
CTi: 'float', kTi: 'float', deltaRTi: 'float', bound: 'int'):
154161
n1, n2, _ = f.shape
162+
#$omp parallel for collapse(2) firstprivate(spl, vPts) private(coeffs)
155163
for j in range(n1): # z
156164
for k in range(n2): # q
157165
coeffs = spl.coeffs
@@ -197,6 +205,7 @@ def flux_advection_loop(f: 'float[:,:,:,:]', thetaSpline: Spline1D, theta_offset
197205
thetaShifts: 'float[:,:,:]', lagrange_coeffs: 'float[:,:,:]'):
198206
nr, nv, nq, nz = f.shape
199207

208+
#$omp parallel for collapse(2) firstprivate(thetaSpline)
200209
for rIdx in range(nr): # r
201210
for cIdx in range(nv): # v
202211
# find the values of the function at each required point
@@ -252,6 +261,7 @@ def poloidal_advection_step_impl(f: 'float[:,:]', dt: 'float', v: 'float', rPts:
252261
idx = nPts_r-1
253262
rMax = rPts[idx]
254263

264+
#$omp parallel for collapse(2)
255265
for i in range(nPts_q):
256266
for j in range(nPts_r):
257267
# Step one of Heun method
@@ -266,6 +276,7 @@ def poloidal_advection_step_impl(f: 'float[:,:]', dt: 'float', v: 'float', rPts:
266276
norm = tol+1
267277
while (norm > tol):
268278
norm = 0.0
279+
#$omp parallel for collapse(2)
269280
for i in range(nPts_q):
270281
for j in range(nPts_r):
271282
# Handle theta boundary conditions
@@ -315,6 +326,7 @@ def poloidal_advection_step_impl(f: 'float[:,:]', dt: 'float', v: 'float', rPts:
315326

316327
# Find value at the determined point
317328
if (nulBound):
329+
#$omp parallel for collapse(2)
318330
for i in range(nPts_q):
319331
for j in range(nPts_r):
320332
if (endPts_k2_r[i, j] < rPts[0]):
@@ -326,6 +338,7 @@ def poloidal_advection_step_impl(f: 'float[:,:]', dt: 'float', v: 'float', rPts:
326338
f[i, j] = pol_spline.eval(
327339
endPts_k2_q[i, j], endPts_k2_r[i, j])
328340
else:
341+
#$omp parallel for collapse(2)
329342
for i in range(nPts_q):
330343
for j in range(nPts_r):
331344
if (endPts_k2_r[i, j] < rPts[0]):
@@ -351,6 +364,7 @@ def poloidal_advection_loop(f: 'float[:,:,:,:]', phi: 'float[:,:,:]', dt: 'float
351364
CN0: 'float', kN0: 'float', deltaRN0: 'float', rp: 'float', CTi: 'float', kTi: 'float', deltaRTi: 'float',
352365
B0: 'float', tol: 'float', nulBound: 'bool'):
353366
_, nz, _, _ = f.shape
367+
#$omp parallel for firstprivate(phi_spline, pol_spline) private(interp_wt, drPhi_0, dthetaPhi_0, drPhi_k, dthetaPhi_k, endPts_k1_q, endPts_k1_r, endPts_k2_q, endPts_k2_r)
354368
for j in range(nz):
355369
solve_2d_system(phi[j], phi_spline, interp_wt, r_bmat, r_l, r_u,
356370
r_ipiv, theta_offset, theta_splu)

0 commit comments

Comments
 (0)