Skip to content

Commit 906eba6

Browse files
s_mpi_allreduce_integer_sum integer overflow #1601 (#1605)
Co-authored-by: Spencer Bryngelson <sbryngelson@gmail.com>
1 parent cd429e1 commit 906eba6

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/common/m_mpi_common.fpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ contains
367367
!> Reduce a local integer value to its global sum across all MPI ranks.
368368
impure subroutine s_mpi_allreduce_integer_sum(var_loc, var_glb)
369369

370-
integer, intent(in) :: var_loc
371-
integer, intent(out) :: var_glb
370+
integer(kind=8), intent(in) :: var_loc
371+
integer(kind=8), intent(out) :: var_glb
372372

373373
#ifdef MFC_MPI
374374
integer :: ierr !< Generic flag used to identify and report MPI errors
375375

376-
call MPI_ALLREDUCE(var_loc, var_glb, 1, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD, ierr)
376+
call MPI_ALLREDUCE(var_loc, var_glb, 1, MPI_INTEGER8, MPI_SUM, MPI_COMM_WORLD, ierr)
377377
#else
378378
var_glb = var_loc
379379
#endif

src/simulation/m_ibm.fpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ contains
7272
!> Initializes the values of various IBM variables, such as ghost points and image points.
7373
impure subroutine s_ibm_setup()
7474

75-
integer :: i, j, k
76-
integer :: max_num_gps
75+
integer :: i, j, k
76+
integer(kind=8) :: max_num_gps
7777

7878
call nvtxStartRange("SETUP-IBM-MODULE")
7979

@@ -119,10 +119,10 @@ contains
119119
! find the number of ghost points and set them to be the maximum total across ranks
120120
call s_find_num_ghost_points(num_gps)
121121
if (moving_immersed_boundary_flag) then
122-
call s_mpi_allreduce_integer_sum(num_gps, max_num_gps)
123-
max_num_gps = min(max_num_gps*2, (m + 1)*(n + 1)*(p + 1))
122+
call s_mpi_allreduce_integer_sum(int(num_gps, 8), max_num_gps)
123+
max_num_gps = min(max_num_gps*2_8, int(m + 1, 8)*int(n + 1, 8)*int(p + 1, 8))
124124
else
125-
max_num_gps = num_gps
125+
max_num_gps = int(num_gps, 8)
126126
end if
127127

128128
! set the size of the ghost point arrays to be the amount of points total, plus a factor of 2 buffer
@@ -1071,7 +1071,8 @@ contains
10711071
subroutine s_compute_centroid_offset(ib_marker)
10721072

10731073
integer, intent(in) :: ib_marker
1074-
integer :: i, j, k, num_cells, num_cells_local, decoded_gbl_id
1074+
integer :: i, j, k, num_cells_local, decoded_gbl_id
1075+
integer(kind=8) :: num_cells
10751076
real(wp), dimension(1:3) :: center_of_mass, center_of_mass_local
10761077

10771078
! Offset only needs to be computes for specific geometries
@@ -1098,7 +1099,7 @@ contains
10981099
end do
10991100

11001101
! reduce the mass contribution over all MPI ranks and compute COM
1101-
call s_mpi_allreduce_integer_sum(num_cells_local, num_cells)
1102+
call s_mpi_allreduce_integer_sum(int(num_cells_local, 8), num_cells)
11021103
if (num_cells /= 0) then
11031104
call s_mpi_allreduce_sum(center_of_mass_local(1), center_of_mass(1))
11041105
call s_mpi_allreduce_sum(center_of_mass_local(2), center_of_mass(2))

0 commit comments

Comments
 (0)