Skip to content

Commit

Permalink
RI HFX: Fix stack overflow
Browse files Browse the repository at this point in the history
by reducing recursion depth of `neighbor_list_3c_iterate`

Stack size of regtest `H2O-hfx-periodic-ri-truncated.inp` was exceeding
8MB (now less than 0.3MB)
  • Loading branch information
pseewald committed Mar 7, 2020
1 parent 4f6b32e commit f21a202
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/hfx_ri.F
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,10 @@ SUBROUTINE hfx_ri_pre_scf_calc_tensors(qs_env, ri_data, t_2c_int_RI, t_2c_int_po
CALL init_interaction_radii_orb_basis(orb_basis, ri_data%eps_pgf_orb)
ENDDO

n_mem = ri_data%n_mem
CALL create_tensor_batches(sizes_AO, n_mem, starts_array_mc_int, ends_array_mc_int, &
CALL create_tensor_batches(sizes_AO, ri_data%n_mem, starts_array_mc_int, ends_array_mc_int, &
starts_array_mc_block_int, ends_array_mc_block_int)

n_mem = ri_data%n_mem
DEALLOCATE (starts_array_mc_int, ends_array_mc_int)

CALL create_3c_tensor(t_3c_int_batched(1, 1), dist_RI, dist_AO_1, dist_AO_2, ri_data%pgrid, &
Expand Down
17 changes: 13 additions & 4 deletions src/qs_tensors.F
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,19 @@ RECURSIVE FUNCTION neighbor_list_3c_iterate(iterator) RESULT(iter_stat)
IF (iter_stat /= 0) THEN
RETURN
ENDIF

CALL get_iterator_info(iterator%iter_ij, iatom=iatom, jatom=jatom)
skip_this = .FALSE.
IF ((iterator%bounds_i(1) > 0 .AND. iatom < iterator%bounds_i(1)) &
.OR. (iterator%bounds_i(2) > 0 .AND. iatom > iterator%bounds_i(2))) skip_this = .TRUE.
IF ((iterator%bounds_j(1) > 0 .AND. jatom < iterator%bounds_j(1)) &
.OR. (iterator%bounds_j(2) > 0 .AND. jatom > iterator%bounds_j(2))) skip_this = .TRUE.

IF (skip_this) THEN
iter_stat = neighbor_list_3c_iterate(iterator)
RETURN
ENDIF

ENDIF
iter_stat = nl_sub_iterate(iterator%iter_jk, iterator%iter_ij)
IF (iter_stat /= 0) THEN
Expand All @@ -481,10 +494,6 @@ RECURSIVE FUNCTION neighbor_list_3c_iterate(iterator) RESULT(iter_stat)
jatom = jatom_1

skip_this = .FALSE.
IF ((iterator%bounds_i(1) > 0 .AND. iatom < iterator%bounds_i(1)) &
.OR. (iterator%bounds_i(2) > 0 .AND. iatom > iterator%bounds_i(2))) skip_this = .TRUE.
IF ((iterator%bounds_j(1) > 0 .AND. jatom < iterator%bounds_j(1)) &
.OR. (iterator%bounds_j(2) > 0 .AND. jatom > iterator%bounds_j(2))) skip_this = .TRUE.
IF ((iterator%bounds_k(1) > 0 .AND. katom < iterator%bounds_k(1)) &
.OR. (iterator%bounds_k(2) > 0 .AND. katom > iterator%bounds_k(2))) skip_this = .TRUE.

Expand Down

0 comments on commit f21a202

Please sign in to comment.