Skip to content

Commit a69067a

Browse files
committed
Added synchronization to fix a strange i/o behaviour when Warp backend was used
1 parent cfb4cfb commit a69067a

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

examples/cfd/flow_past_sphere_3d.py

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def post_process(step, f_current):
158158
f_0, f_1 = f_1, f_0 # Swap the buffers
159159

160160
if step % post_process_interval == 0 or step == num_steps - 1:
161+
if compute_backend == ComputeBackend.WARP:
162+
wp.synchronize()
161163
post_process(step, f_0)
162164
end_time = time.time()
163165
elapsed = end_time - start_time

examples/cfd/turbulent_channel_3d.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,11 @@ def plot_uplus(u, timestep, grid_shape, u_tau, visc):
206206
f_0, f_1 = stepper(f_0, f_1, bc_mask, missing_mask, omega, step)
207207
f_0, f_1 = f_1, f_0 # Swap the buffers
208208

209-
if (step + 1) % print_interval == 0:
209+
if step % print_interval == 0:
210+
if compute_backend == ComputeBackend.WARP:
211+
wp.synchronize()
210212
elapsed_time = time.time() - start_time
211-
print(f"Iteration: {step + 1}/{num_steps} | Time elapsed: {elapsed_time:.2f}s")
213+
print(f"Iteration: {step}/{num_steps} | Time elapsed: {elapsed_time:.2f}s")
212214
start_time = time.time()
213215

214216
if (step % post_process_interval == 0) or (step == num_steps - 1):

examples/cfd/windtunnel_3d.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ def post_process(
199199

200200
# Compute lift and drag
201201
boundary_force = momentum_transfer(f_0, f_1, bc_mask, missing_mask)
202-
drag = np.sqrt(boundary_force[0] ** 2 + boundary_force[1] ** 2) # xy-plane
202+
drag = boundary_force[0] # x-direction
203203
lift = boundary_force[2]
204-
c_d = 2.0 * drag / (wind_speed**2 * car_cross_section)
205-
c_l = 2.0 * lift / (wind_speed**2 * car_cross_section)
206-
drag_coefficients.append(c_d)
207-
lift_coefficients.append(c_l)
204+
cd = 2.0 * drag / (wind_speed**2 * car_cross_section)
205+
cl = 2.0 * lift / (wind_speed**2 * car_cross_section)
206+
drag_coefficients.append(cd)
207+
lift_coefficients.append(cl)
208208
time_steps.append(step)
209209

210210
# Plot drag coefficient
@@ -236,9 +236,11 @@ def post_process(
236236
f_0, f_1 = f_1, f_0 # Swap the buffers
237237

238238
# Print progress at intervals
239-
if (step + 1) % print_interval == 0:
239+
if step % print_interval == 0:
240+
if compute_backend == ComputeBackend.WARP:
241+
wp.synchronize()
240242
elapsed_time = time.time() - start_time
241-
print(f"Iteration: {step + 1}/{num_steps} | Time elapsed: {elapsed_time:.2f}s")
243+
print(f"Iteration: {step}/{num_steps} | Time elapsed: {elapsed_time:.2f}s")
242244
start_time = time.time()
243245

244246
# Post-process at intervals and final step

0 commit comments

Comments
 (0)