Skip to content

Commit

Permalink
Added synchronization to fix a strange i/o behaviour when Warp backen…
Browse files Browse the repository at this point in the history
…d was used
  • Loading branch information
hsalehipour committed Feb 13, 2025
1 parent cfb4cfb commit a69067a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions examples/cfd/flow_past_sphere_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def post_process(step, f_current):
f_0, f_1 = f_1, f_0 # Swap the buffers

if step % post_process_interval == 0 or step == num_steps - 1:
if compute_backend == ComputeBackend.WARP:
wp.synchronize()
post_process(step, f_0)
end_time = time.time()
elapsed = end_time - start_time
Expand Down
6 changes: 4 additions & 2 deletions examples/cfd/turbulent_channel_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ def plot_uplus(u, timestep, grid_shape, u_tau, visc):
f_0, f_1 = stepper(f_0, f_1, bc_mask, missing_mask, omega, step)
f_0, f_1 = f_1, f_0 # Swap the buffers

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

if (step % post_process_interval == 0) or (step == num_steps - 1):
Expand Down
16 changes: 9 additions & 7 deletions examples/cfd/windtunnel_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ def post_process(

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

# Plot drag coefficient
Expand Down Expand Up @@ -236,9 +236,11 @@ def post_process(
f_0, f_1 = f_1, f_0 # Swap the buffers

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

# Post-process at intervals and final step
Expand Down

0 comments on commit a69067a

Please sign in to comment.