Skip to content

Commit

Permalink
Low-scaling RPA: enable MEMORY_CUT 5 / batched contraction by default
Browse files Browse the repository at this point in the history
- fix bugs for memory cut larger than number of blocks
- explicitly use MEMORY_CUT 1 for most regtests due to overhead for small
systems
  • Loading branch information
pseewald committed Feb 24, 2020
1 parent 8784d52 commit 7d7496d
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 25 deletions.
9 changes: 5 additions & 4 deletions src/input_cp2k_mp2.F
Original file line number Diff line number Diff line change
Expand Up @@ -1166,11 +1166,12 @@ SUBROUTINE create_low_scaling(section)
CALL keyword_release(keyword)

CALL keyword_create(keyword, __LOCATION__, name="MEMORY_CUT", &
description="Cuts the memory of the M_munu_P^occ/virt matrix by the factor given. "// &
"The calculation is slowed down when using a high value of MEMORY_CUT. A high value for "// &
"MEMORY_CUT is recommended for large systems in order not to run out of memory.", &
description="Reduces memory for sparse tensor contractions by this factor. "// &
"A high value leads to some loss of performance. "// &
"This memory reduction factor applies to storage of the tensors 'M occ' / 'M virt' "// &
"but does not reduce storage of '3c ints'.", &
usage="MEMORY_CUT 16", &
default_i_val=1)
default_i_val=5)
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)

Expand Down
18 changes: 9 additions & 9 deletions src/mp2_integrals.F
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,6 @@ SUBROUTINE mp2_ri_gpw_compute_in(BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd
ELSE
cut_memory = qs_env%mp2_env%ri_rpa_im_time%cut_memory
impose_split = .NOT. qs_env%mp2_env%ri_rpa_im_time%group_size_internal
IF (impose_split) THEN
Expand Down Expand Up @@ -759,6 +757,7 @@ SUBROUTINE mp2_ri_gpw_compute_in(BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd
CALL basis_set_list_setup(basis_set_ao, "ORB", qs_kind_set)
CALL get_particle_set(particle_set, qs_kind_set, nsgf=sizes_AO, basis=basis_set_ao)
cut_memory = qs_env%mp2_env%ri_rpa_im_time%cut_memory
CALL create_contraction_batches(sizes_AO, cut_memory, starts_array_mc_int, ends_array_mc_int, &
starts_array_mc_block_int, ends_array_mc_block_int)
DEALLOCATE (starts_array_mc_int, ends_array_mc_int)
Expand Down Expand Up @@ -816,8 +815,11 @@ SUBROUTINE mp2_ri_gpw_compute_in(BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd
pgrid_t3c_M = get_pgrid_from_ngroup(para_env, ngroup_im_time_P, map1_2d=[1], map2_2d=[2, 3])
ENDIF
CALL create_contraction_batches(sizes_AO_split, cut_memory, starts_array_mc, ends_array_mc, &
starts_array_mc_block, ends_array_mc_block)
ASSOCIATE (cut_memory=>qs_env%mp2_env%ri_rpa_im_time%cut_memory)
CALL create_contraction_batches(sizes_AO_split, cut_memory, starts_array_mc, ends_array_mc, &
starts_array_mc_block, ends_array_mc_block)
END ASSOCIATE
cut_memory = qs_env%mp2_env%ri_rpa_im_time%cut_memory
CALL create_3c_tensor(t_3c_M, dist_RI, dist_AO_1, dist_AO_2, pgrid_t3c_M, &
sizes_RI_split, sizes_AO_split, sizes_AO_split, &
Expand Down Expand Up @@ -947,20 +949,18 @@ FUNCTION get_pgrid_from_ngroup(para_env, ngroup, map1_2d, map2_2d) RESULT(pgrid)
SUBROUTINE create_contraction_batches(sizes, nbatches, starts_array, ends_array, &
starts_array_block, ends_array_block)
INTEGER, DIMENSION(:), INTENT(IN) :: sizes
INTEGER, INTENT(IN) :: nbatches
INTEGER, INTENT(INOUT) :: nbatches
INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT) :: starts_array, ends_array, &
starts_array_block, ends_array_block
INTEGER :: bsum, imem, nblocks
nblocks = SIZE(sizes)
CALL contiguous_tensor_dist(nblocks, nbatches, sizes, limits_start=starts_array_block, limits_end=ends_array_block)
ALLOCATE (starts_array(nbatches))
ALLOCATE (ends_array(nbatches))
ALLOCATE (starts_array_block(nbatches))
ALLOCATE (ends_array_block(nbatches))
CALL contiguous_tensor_dist(nblocks, nbatches, sizes, limits_start=starts_array_block, limits_end=ends_array_block)
bsum = 0
DO imem = 1, nbatches
Expand Down
25 changes: 21 additions & 4 deletions src/qs_tensors.F
Original file line number Diff line number Diff line change
Expand Up @@ -1266,14 +1266,20 @@ SUBROUTINE build_3c_integrals(t3c, filter_eps, qs_env, &
!> \param dist ...
! **************************************************************************************************
SUBROUTINE contiguous_tensor_dist(nel, nbin, weights, limits_start, limits_end, dist)
INTEGER, INTENT(IN) :: nel, nbin
INTEGER, INTENT(IN) :: nel
INTEGER, INTENT(INOUT) :: nbin
INTEGER, DIMENSION(nel), INTENT(IN) :: weights
INTEGER, DIMENSION(nbin), INTENT(OUT), OPTIONAL :: limits_start, limits_end
INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT), &
OPTIONAL :: limits_start, limits_end
INTEGER, DIMENSION(nel), INTENT(OUT), OPTIONAL :: dist

INTEGER :: el_end, el_start, end_weight, ibin, &
nel_div, nel_rem, nel_split, nel_w, &
w_partialsum
INTEGER, ALLOCATABLE, DIMENSION(:) :: lim_e, lim_s

ALLOCATE (lim_s(nbin), lim_e(nbin))
lim_s = 0; lim_e = 0

nel_w = SUM(weights)
nel_div = nel_w/nbin
Expand All @@ -1295,12 +1301,23 @@ SUBROUTINE contiguous_tensor_dist(nel, nbin, weights, limits_start, limits_end,
!IF (ABS(w_partialsum + weights(el_end) - end_weight) > ABS(w_partialsum - end_weight)) EXIT
el_end = el_end + 1
w_partialsum = w_partialsum + weights(el_end)
IF (el_end == nel) EXIT
ENDDO

IF (PRESENT(dist)) dist(el_start:el_end) = ibin - 1
IF (PRESENT(limits_start)) limits_start(ibin) = el_start
IF (PRESENT(limits_end)) limits_end(ibin) = el_end
lim_s(ibin) = el_start
lim_e(ibin) = el_end

IF (el_end == nel) EXIT
ENDDO

IF (PRESENT(limits_start) .AND. PRESENT(limits_end)) THEN
ALLOCATE (limits_start(ibin)); limits_start(:ibin) = lim_s(:ibin)
ALLOCATE (limits_end(ibin)); limits_end(:ibin) = lim_e(:ibin)
ENDIF

nbin = ibin

END SUBROUTINE contiguous_tensor_dist

! **************************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/rpa_im_time.F
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ SUBROUTINE compute_mat_P_omega(mat_P_omega, fm_scaled_dm_occ_tau, &

ibounds_2(:, 1) = [starts_array_mc(i_mem), ends_array_mc(i_mem)]

IF (unit_nr_dbcsr > 0) WRITE (UNIT=unit_nr_dbcsr, FMT="(T3,A,I2,1X,I2)") &
IF (unit_nr_dbcsr > 0) WRITE (UNIT=unit_nr_dbcsr, FMT="(T3,A,I3,1X,I3)") &
"RPA_LOW_SCALING_INFO| Memory Cut iteration", i_mem, j_mem

IF (do_Gamma_RPA) THEN
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw-cubic/G0W0_H2O_PBE0.inp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
&END
&LOW_SCALING
EPS_FILTER 1.0E-7
MEMORY_CUT 1
&END
&RI_RPA
&HF
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw-cubic/G0W0_H2O_PBE0_trunc_Clenshaw.inp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
&END
&LOW_SCALING
EPS_FILTER 1.0E-7
MEMORY_CUT 1
&END
&RI_RPA
&HF
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw-cubic/G0W0_H2O_PBE_periodic.inp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
&END
&LOW_SCALING
EPS_FILTER 1.0E-7
MEMORY_CUT 1
&END
&RI_RPA
&HF
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw-cubic/G0W0_OH_PBE.inp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
POTENTIAL_TYPE IDENTITY
&END
&LOW_SCALING
MEMORY_CUT 1
&END LOW_SCALING
&RI_RPA
&HF
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw-cubic/G0W0_OH_PBE_svd.inp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
POTENTIAL_TYPE IDENTITY
&END
&LOW_SCALING
MEMORY_CUT 1
&END LOW_SCALING
&RI_RPA
&HF
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw-cubic/evGW_H2O_PBE0_trunc_Clenshaw.inp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
CUTOFF_RADIUS 3.0
&END
&LOW_SCALING
MEMORY_CUT 1
EPS_FILTER 1.0E-7
&END
&RI_RPA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
&END
&LOW_SCALING
EPS_FILTER 1.0E-7
MEMORY_CUT 1
&END
&RI_RPA
&HF
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw-cubic/scGW0_H2O_PBE0_trunc_minimax.inp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
CUTOFF_RADIUS 3.0
&END
&LOW_SCALING
MEMORY_CUT 1
EPS_FILTER 1.0E-7
&END
&RI_RPA
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw-ic-model/IC_no_wf_update.inp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
POTENTIAL_TYPE IDENTITY
&END
&LOW_SCALING
MEMORY_CUT 1
&END
&RI_RPA
RPA_NUM_QUAD_POINTS 5
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-gw/evGW_H2O_PBE_Fermi_level_offset.inp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
EPS_FILTER 1.0E-12
&END
&LOW_SCALING
MEMORY_CUT 1
&END
&RI_RPA
&HF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
QUADRATURE_POINTS 5
&END
&LOW_SCALING
MEMORY_CUT 1
&END
&WFC_GPW
CUTOFF 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
QUADRATURE_POINTS 5
&END
&LOW_SCALING
MEMORY_CUT 1
&END
&WFC_GPW
CUTOFF 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
QUADRATURE_POINTS 5
&END
&LOW_SCALING
MEMORY_CUT 1
&END
&WFC_GPW
CUTOFF 100
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-ri-rpa-rse/Cubic_RPA_RSE_H2.inp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
! ERI_METHOD MME
ERI_METHOD OS
&LOW_SCALING
MEMORY_CUT 1
&END
&RI_RPA
RPA_NUM_QUAD_POINTS 6
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-rpa-cubic-scaling/Cubic_RPA_CH3.inp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
&END
&LOW_SCALING
EPS_FILTER 1.0E-7
MEMORY_CUT 1
&END
&RI_RPA
RPA_NUM_QUAD_POINTS 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@
ERI_METHOD MME
&LOW_SCALING
EPS_FILTER 1.0E-7
!MEMORY_INFO
! normally, increase MEMORY_CUT for large systems
! not to run out of memory
MEMORY_CUT 2
! should be increased with N^2 (N: group size) not
! to run OOM
&TEST
GROUP_SIZE_3c 2
! normally, GROUP_SIZE_P 1 is fine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
! ERI_METHOD MME
ERI_METHOD OS
&LOW_SCALING
MEMORY_CUT 1
&END
&RI_RPA
RPA_NUM_QUAD_POINTS 6
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-rpa-cubic-scaling/Cubic_RPA_H2O_trunc.inp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
&END
&LOW_SCALING
EPS_FILTER 1.0E-6
MEMORY_CUT 1
&END
&RI_RPA
RPA_NUM_QUAD_POINTS 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
NUMBER_PROC 1
&LOW_SCALING
EPS_FILTER 1.0E-7
MEMORY_CUT 2
!MEMORY_INFO
DO_KPOINTS
&END LOW_SCALING
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-rpa-lr/H2O-rpa-cubic-lr-mme.inp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
&END
ERI_METHOD MME
&LOW_SCALING
MEMORY_CUT 1
&END
&RI_RPA
RPA_NUM_QUAD_POINTS 6
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-rpa-lr/H2O-rpa-cubic-lr.inp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
&END
ERI_METHOD OS
&LOW_SCALING
MEMORY_CUT 1
&END
&RI_RPA
RPA_NUM_QUAD_POINTS 6
Expand Down
1 change: 1 addition & 0 deletions tests/QS/regtest-sos-mp2-lr/H2O-sos-mp2-cubic-lr.inp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
QUADRATURE_POINTS 5
&END
&LOW_SCALING
MEMORY_CUT 1
&END
&WFC_GPW
CUTOFF 100
Expand Down

0 comments on commit 7d7496d

Please sign in to comment.