Skip to content

Commit 2926173

Browse files
author
Daniel J Vickers
committed
Fixed GPU issue on NVHPC compiler
1 parent 80bd4b5 commit 2926173

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/simulation/m_ibm.fpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ contains
291291
! compute the linear velocity of the ghost point due to rotation
292292
radial_vector = physical_loc - [patch_ib(patch_id)%x_centroid, &
293293
patch_ib(patch_id)%y_centroid, patch_ib(patch_id)%z_centroid]
294-
rotation_velocity = cross_product(matmul(patch_ib(patch_id)%rotation_matrix, patch_ib(patch_id)%angular_vel), radial_vector)
294+
call s_cross_product(matmul(patch_ib(patch_id)%rotation_matrix, patch_ib(patch_id)%angular_vel), radial_vector, rotation_velocity)
295295

296296
! add only the component of the IB's motion that is normal to the surface
297297
vel_g = vel_g + sum((patch_ib(patch_id)%vel + rotation_velocity)*norm)*norm
@@ -305,7 +305,7 @@ contains
305305
radial_vector = physical_loc - [patch_ib(patch_id)%x_centroid, &
306306
patch_ib(patch_id)%y_centroid, patch_ib(patch_id)%z_centroid]
307307
! convert the angular velocity from the inertial reference frame to the fluids frame, then convert to linear velocity
308-
rotation_velocity = cross_product(matmul(patch_ib(patch_id)%rotation_matrix, patch_ib(patch_id)%angular_vel), radial_vector)
308+
call s_cross_product(matmul(patch_ib(patch_id)%rotation_matrix, patch_ib(patch_id)%angular_vel), radial_vector, rotation_velocity)
309309
do q = 1, 3
310310
! if mibm is 1 or 2, then the boundary may be moving
311311
vel_g(q) = patch_ib(patch_id)%vel(q) ! add the linear velocity
@@ -1006,14 +1006,14 @@ contains
10061006
10071007
integer :: i, j, k, l, ib_idx
10081008
real(wp), dimension(num_ibs, 3) :: forces, torques
1009-
real(wp), dimension(1:3) :: pressure_divergence, radial_vector, temp_torque_vector
1009+
real(wp), dimension(1:3) :: pressure_divergence, radial_vector, local_torque_contribution
10101010
real(wp) :: cell_volume, dx, dy, dz
10111011
10121012
forces = 0._wp
10131013
torques = 0._wp
10141014
10151015
! TODO :: This is currently only valid inviscid, and needs to be extended to add viscocity
1016-
$:GPU_PARALLEL_LOOP(private='[ib_idx,radial_vector,pressure_divergence,cell_volume,temp_torque_vector, dx, dy, dz]', copy='[forces,torques]', copyin='[ib_markers]', collapse=3)
1016+
$:GPU_PARALLEL_LOOP(private='[ib_idx,radial_vector,pressure_divergence,cell_volume,local_torque_contribution, dx, dy, dz]', copy='[forces,torques]', copyin='[ib_markers,patch_ib]', collapse=3)
10171017
do i = 0, m
10181018
do j = 0, n
10191019
do k = 0, p
@@ -1044,12 +1044,13 @@ contains
10441044
end if
10451045
10461046
! Update the force values atomically to prevent race conditions
1047-
temp_torque_vector = cross_product(radial_vector, pressure_divergence)*cell_volume ! separate out to make atomics safe
1047+
call s_cross_product(radial_vector, pressure_divergence, local_torque_contribution) ! separate out to make atomics safe
1048+
local_torque_contribution = local_torque_contribution * cell_volume
10481049
do l = 1, 3
10491050
$:GPU_ATOMIC(atomic='update')
10501051
forces(ib_idx, l) = forces(ib_idx, l) - (pressure_divergence(l)*cell_volume)
10511052
$:GPU_ATOMIC(atomic='update')
1052-
torques(ib_idx, l) = torques(ib_idx, l) - temp_torque_vector(l)
1053+
torques(ib_idx, l) = torques(ib_idx, l) - local_torque_contribution(l)
10531054
end do
10541055
end if
10551056
end if
@@ -1150,14 +1151,15 @@ contains
11501151
11511152
end subroutine s_compute_moment_of_inertia
11521153
1153-
function cross_product(a, b) result(c)
1154+
subroutine s_cross_product(a, b, c)
1155+
$:GPU_ROUTINE(parallelism='[seq]')
11541156
implicit none
11551157
real(wp), intent(in) :: a(3), b(3)
1156-
real(wp) :: c(3)
1158+
real(wp), intent(out) :: c(3)
11571159
11581160
c(1) = a(2)*b(3) - a(3)*b(2)
11591161
c(2) = a(3)*b(1) - a(1)*b(3)
11601162
c(3) = a(1)*b(2) - a(2)*b(1)
1161-
end function cross_product
1163+
end subroutine s_cross_product
11621164
11631165
end module m_ibm

0 commit comments

Comments
 (0)