Skip to content

Commit

Permalink
PW: Drop non-cartesian communicator in favor of the cartesian one
Browse files Browse the repository at this point in the history
This step saves a communicator and ensures the use of correct information on the distribution.
  • Loading branch information
fstein93 committed May 7, 2024
1 parent 1295dfb commit e14b23f
Show file tree
Hide file tree
Showing 22 changed files with 272 additions and 339 deletions.
2 changes: 1 addition & 1 deletion src/cp_realspace_grid_cube.F
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ SUBROUTINE cp_cube_to_pw(grid, filename, scaling, silent)
! Parallel routine falls back to stream read in serial mode,
! but it has slight overhead compared to sequential read
! Therefore, we use sequential version in serial mode
IF (grid%pw_grid%para%group_size == 1) parallel_read = .FALSE.
IF (grid%pw_grid%para%group%num_pe == 1) parallel_read = .FALSE.
! Check if MPI I/O was disabled in GLOBAL section
IF (.NOT. cp_mpi_io_get()) parallel_read = .FALSE.

Expand Down
10 changes: 5 additions & 5 deletions src/ewald_spline_util.F
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ SUBROUTINE eval_pw_TabLR(grid, pw_pool, TabLR, Lg, gx, gy, gz, hmat_mm, &

!NB use DGEMM to compute sum over kg for each i, j, k
! number of elements per node, round down
NLg_loc = SIZE(Lg)/grid%pw_grid%para%group_size
NLg_loc = SIZE(Lg)/grid%pw_grid%para%group%num_pe
! number of extra elements not yet accounted for
n_extra = MOD(SIZE(Lg), grid%pw_grid%para%group_size)
n_extra = MOD(SIZE(Lg), grid%pw_grid%para%group%num_pe)
! first n_extra nodes get NLg_loc+1, remaining get NLg_loc
IF (grid%pw_grid%para%my_pos < n_extra) THEN
Lg_loc_min = (NLg_loc + 1)*grid%pw_grid%para%my_pos + 1
IF (grid%pw_grid%para%group%mepos < n_extra) THEN
Lg_loc_min = (NLg_loc + 1)*grid%pw_grid%para%group%mepos + 1
Lg_loc_max = Lg_loc_min + (NLg_loc + 1) - 1
ELSE
Lg_loc_min = (NLg_loc + 1)*n_extra + NLg_loc*(grid%pw_grid%para%my_pos - n_extra) + 1
Lg_loc_min = (NLg_loc + 1)*n_extra + NLg_loc*(grid%pw_grid%para%group%mepos - n_extra) + 1
Lg_loc_max = Lg_loc_min + NLg_loc - 1
END IF
! shouldn't be necessary
Expand Down
4 changes: 2 additions & 2 deletions src/maxwell_solver_interface.F
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ SUBROUTINE maxwell_solver(maxwell_control, v_ee, sim_step, sim_time, scaling_fac
logger => cp_get_default_logger()
iounit = cp_logger_get_default_io_unit(logger)

my_rank = v_ee%pw_grid%para%my_pos
num_pe = v_ee%pw_grid%para%group_size
my_rank = v_ee%pw_grid%para%group%mepos
num_pe = v_ee%pw_grid%para%group%num_pe
gid = v_ee%pw_grid%para%group
tag = 1

Expand Down
20 changes: 10 additions & 10 deletions src/mixed_cdft_utils.F
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ SUBROUTINE mixed_cdft_parse_settings(force_env, mixed_env, mixed_cdft, &
settings%cutoff(iforce_eval) = auxbas_pw_pool%pw_grid%cutoff
settings%rel_cutoff(iforce_eval) = dft_control%qs_control%relative_cutoff
IF (auxbas_pw_pool%pw_grid%spherical) settings%spherical(iforce_eval) = 1
settings%rs_dims(:, iforce_eval) = auxbas_pw_pool%pw_grid%para%rs_dims
settings%rs_dims(:, iforce_eval) = auxbas_pw_pool%pw_grid%para%group%num_pe_cart
IF (auxbas_pw_pool%pw_grid%grid_span == HALFSPACE) settings%odd(iforce_eval) = 1
! Becke constraint atoms/coeffs
IF (cdft_control%natoms .GT. SIZE(settings%atoms, 1)) &
Expand Down Expand Up @@ -733,11 +733,11 @@ SUBROUTINE mixed_cdft_init_structures(force_env, force_env_qs, mixed_env, mixed_
iounit=iounit)
! Check if the layout was successfully created
IF (mixed_cdft%is_special) THEN
IF (.NOT. pw_grid%para%rs_dims(2) /= 1) is_match = .FALSE.
IF (.NOT. pw_grid%para%group%num_pe_cart(2) /= 1) is_match = .FALSE.
ELSE IF (mixed_cdft%is_pencil) THEN
IF (.NOT. pw_grid%para%rs_dims(1) == mixed_rs_dims(1)) is_match = .FALSE.
IF (.NOT. pw_grid%para%group%num_pe_cart(1) == mixed_rs_dims(1)) is_match = .FALSE.
ELSE
IF (.NOT. pw_grid%para%rs_dims(2) == 1) is_match = .FALSE.
IF (.NOT. pw_grid%para%group%num_pe_cart(2) == 1) is_match = .FALSE.
END IF
IF (.NOT. is_match) &
CALL cp_abort(__LOCATION__, &
Expand Down Expand Up @@ -856,16 +856,16 @@ SUBROUTINE mixed_cdft_init_structures(force_env, force_env_qs, mixed_env, mixed_
CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
! work out the pw grid points each proc holds in the two (identical) parallel proc groups
! note we only care about the x dir since we assume the y dir is not subdivided
ALLOCATE (bounds(0:auxbas_pw_pool%pw_grid%para%group_size - 1, 1:2))
DO i = 0, auxbas_pw_pool%pw_grid%para%group_size - 1
ALLOCATE (bounds(0:auxbas_pw_pool%pw_grid%para%group%num_pe - 1, 1:2))
DO i = 0, auxbas_pw_pool%pw_grid%para%group%num_pe - 1
bounds(i, 1:2) = auxbas_pw_pool%pw_grid%para%bo(1:2, 1, i, 1)
bounds(i, 1:2) = bounds(i, 1:2) - auxbas_pw_pool%pw_grid%npts(1)/2 - 1
END DO
! work out which procs to send my grid points
! first get the number of target procs per group
ntargets = 0
offset = -1
DO i = 0, auxbas_pw_pool%pw_grid%para%group_size - 1
DO i = 0, auxbas_pw_pool%pw_grid%para%group%num_pe - 1
IF ((bounds(i, 1) .GE. bo_mixed(1, 1) .AND. bounds(i, 1) .LE. bo_mixed(2, 1)) .OR. &
(bounds(i, 2) .GE. bo_mixed(1, 1) .AND. bounds(i, 2) .LE. bo_mixed(2, 1))) THEN
ntargets = ntargets + 1
Expand Down Expand Up @@ -893,16 +893,16 @@ SUBROUTINE mixed_cdft_init_structures(force_env, force_env_qs, mixed_env, mixed_
! finally determine which procs will send me grid points
! now we need info about y dir also
DEALLOCATE (bounds)
ALLOCATE (bounds(0:pw_pools(1)%pool%pw_grid%para%group_size - 1, 1:4))
DO i = 0, pw_pools(1)%pool%pw_grid%para%group_size - 1
ALLOCATE (bounds(0:pw_pools(1)%pool%pw_grid%para%group%num_pe - 1, 1:4))
DO i = 0, pw_pools(1)%pool%pw_grid%para%group%num_pe - 1
bounds(i, 1:2) = pw_pools(1)%pool%pw_grid%para%bo(1:2, 1, i, 1)
bounds(i, 3:4) = pw_pools(1)%pool%pw_grid%para%bo(1:2, 2, i, 1)
bounds(i, 1:2) = bounds(i, 1:2) - pw_pools(1)%pool%pw_grid%npts(1)/2 - 1
bounds(i, 3:4) = bounds(i, 3:4) - pw_pools(1)%pool%pw_grid%npts(2)/2 - 1
END DO
ntargets = 0
offset = -1
DO i = 0, pw_pools(1)%pool%pw_grid%para%group_size - 1
DO i = 0, pw_pools(1)%pool%pw_grid%para%group%num_pe - 1
IF ((bo(1, 1) .GE. bounds(i, 1) .AND. bo(1, 1) .LE. bounds(i, 2)) .OR. &
(bo(2, 1) .GE. bounds(i, 1) .AND. bo(2, 1) .LE. bounds(i, 2))) THEN
ntargets = ntargets + 1
Expand Down
34 changes: 17 additions & 17 deletions src/pw/dct.F
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ SUBROUTINE setup_dct_pw_grids(pw_grid, cell_hmat, neumann_directions, dct_pw_gri
blocked = 0
END IF

CALL pw_grid_create(dct_pw_grid, pw_grid%para%rs_group, hmat2, &
CALL pw_grid_create(dct_pw_grid, pw_grid%para%group, hmat2, &
bounds=bounds_new, &
rs_dims=pw_grid%para%rs_dims, &
rs_dims=pw_grid%para%group%num_pe_cart, &
blocked=blocked, &
bounds_local=bounds_local_new)

Expand Down Expand Up @@ -320,12 +320,12 @@ SUBROUTINE set_dests_srcs_pid(pw_grid, neumann_directions, dests_expand, srcs_ex
! rs_dim1 = 3 --> src_pos1 = [1 2 3]
! rs_dim2 = 4 --> src_pos2 = [1 2 3 4]

rs_group = pw_grid%para%rs_group
rs_mpo = pw_grid%para%rs_mpo
group_size = pw_grid%para%group_size
rs_dims = pw_grid%para%rs_dims
rs_group = pw_grid%para%group
rs_mpo = pw_grid%para%group%mepos
group_size = pw_grid%para%group%num_pe
rs_dims = pw_grid%para%group%num_pe_cart

rs_pos = pw_grid%para%rs_pos
rs_pos = pw_grid%para%group%mepos_cart
rs_dim1 = rs_dims(1); rs_dim2 = rs_dims(2)

! prepare srcs_coord
Expand Down Expand Up @@ -434,7 +434,7 @@ SUBROUTINE set_dests_srcs_pid(pw_grid, neumann_directions, dests_expand, srcs_ex

DO k = 1, maxn_sendrecv
! convert srcs_coord to pid
CALL pw_grid%para%rs_group%rank_cart(ABS(srcs_coord(:, k)) - 1, srcs_expand(k))
CALL pw_grid%para%group%rank_cart(ABS(srcs_coord(:, k)) - 1, srcs_expand(k))
! find out the flipping status
IF ((srcs_coord(1, k) .GT. 0) .AND. (srcs_coord(2, k) .GT. 0)) THEN
flipg_stat(k) = NOT_FLIPPED
Expand Down Expand Up @@ -538,9 +538,9 @@ SUBROUTINE pw_expand(neumann_directions, recv_msgs_bnds, dests_expand, srcs_expa
CALL timeset(routineN, handle)
pw_grid => pw_in%pw_grid
rs_group = pw_grid%para%rs_group
rs_mpo = pw_grid%para%my_pos
group_size = pw_grid%para%group_size
rs_group = pw_grid%para%group
rs_mpo = pw_grid%para%group%mepos
group_size = pw_grid%para%group%num_pe
bounds_local_new = pw_expanded%pw_grid%bounds_local
Expand Down Expand Up @@ -719,9 +719,9 @@ SUBROUTINE pw_shrink(neumann_directions, dests_shrink, srcs_shrink, bounds_local
CALL timeset(routineN, handle)
pw_grid_orig => pw_shrinked%pw_grid
rs_group = pw_grid_orig%para%rs_group
rs_mpo = pw_grid_orig%para%my_pos
group_size = pw_grid_orig%para%group_size
rs_group = pw_grid_orig%para%group
rs_mpo = pw_grid_orig%para%group%mepos
group_size = pw_grid_orig%para%group%num_pe
bounds_local_xpnd = pw_in%pw_grid%bounds_local
tag = 1
Expand Down Expand Up @@ -1054,9 +1054,9 @@ SUBROUTINE expansion_bounds(pw_grid, neumann_directions, srcs_expand, flipg_stat
CALL timeset(routineN, handle)
rs_group = pw_grid%para%rs_group
rs_mpo = pw_grid%para%my_pos
group_size = pw_grid%para%group_size
rs_group = pw_grid%para%group
rs_mpo = pw_grid%para%group%mepos
group_size = pw_grid%para%group%num_pe
bounds = pw_grid%bounds
bounds_local = pw_grid%bounds_local
Expand Down
Loading

0 comments on commit e14b23f

Please sign in to comment.