subroutine fixed_number_SI_generation()
use semi_stoch_gen, only: generate_space_most_populated
use semi_stoch_procs, only: GLOBAL_RUN
use LoggingData, only: ref_filename, tWriteRefs
implicit none
integer(MPIArg) :: mpi_refs_found
integer :: ierr, i, all_refs_found, refs_found
integer(MPIArg) :: refs_found_per_proc(0:nProcessors - 1), refs_displs(0:nProcessors - 1)
integer(n_int) :: ref_buf(0:NIfTot, maxNRefs)
! we need to be sure ilutRefAdi has the right size
call reallocate_ilutRefAdi(maxNRefs)
if (maxNRefs > 0) then
! Get the nRefs most populated determinants
refs_found = 0
call generate_space_most_populated(maxNRefs, .false., 1, ref_buf, refs_found, &
GLOBAL_RUN, CurrentDets(0:NifTot, :), TotWalkers)
! Communicate the refs_found info
mpi_refs_found = int(refs_found, MPIArg)
call MPIAllGather(mpi_refs_found, refs_found_per_proc, ierr)
all_refs_found = sum(refs_found_per_proc)
if (all_refs_found /= maxNRefs) then
write(stdout, *) "Warning: Less than ", maxNRefs, &
" superinitiators found, using only ", all_refs_found, " superinitiators"
end if
! Set the number of SIs to the number actually found
nRefs = all_refs_found
! Prepare communication of SIs
refs_displs(0) = 0
do i = 1, nProcessors - 1
refs_displs(i) = refs_displs(i - 1) + refs_found_per_proc(i - 1)
end do
! Store them on all processors
call MPIAllGatherV(ref_buf(0:NIfTot, 1:refs_found), ilutRefAdi, &
refs_found_per_proc, refs_displs)
if (tWriteRefs) call output_reference_space(ref_filename)
else
nRefs = 0
end if
end subroutine fixed_number_SI_generation