WriteFCIMCStats Subroutine

public subroutine WriteFCIMCStats()

Arguments

None

Contents

Source Code


Source Code

    subroutine WriteFCIMCStats()

        INTEGER :: i, j, run
        real(dp),dimension(inum_runs) :: FracFromSing
        real(dp) :: E_ref_tmp(inum_runs)

        ! get the offset for the projected energy (i.e. reference energy)
        call getProjEOffset()

        ! What is the current value of S2
        if (tCalcInstantS2) then
            if (mod(iter / StepsPrint, instant_s2_multiplier) == 0) then
                if (tSpatialOnlyhash) then
                    curr_S2 = calc_s_squared (.false.)
                else
                    curr_S2 = calc_s_squared_star (.false.)
                end if
            end if
        else
            curr_S2 = -1
        end if

        ! What is the current value of S2 considering only initiators
        if (tCalcInstantS2Init) then
            if (mod(iter / StepsPrint, instant_s2_multiplier_init) == 0) then
                if (tSpatialOnlyhash) then
                    curr_S2_init = calc_s_squared (.true.)
                else
                    curr_S2_init = calc_s_squared_star (.true.)
                end if
            end if
        else
            curr_S2_init = -1
        end if

        !To prevent /0 problems
        do run=1,inum_runs
            if(.not. near_zero(AllNoBorn(run))) then
                FracFromSing(run)=real(AllSpawnFromSing(run),dp) / real(AllNoBorn(run),dp)
            else
                FracFromSing(run)=0.0_dp
            end if

            if(t_no_ref_shift)then
                if (tHPHF) then
                    E_ref_tmp(run) = hphf_diag_helement (ProjEDet(:,run), iLutRef(:,run))
                else if(tguga)then
                    E_ref_tmp(run) = calcDiagMatEleGUGA_nI(ProjEDet(:,run))
                else
                    E_ref_tmp(run) = get_helement (ProjEDet(:,run), ProjEDet(:,run), 0)
                end if
            else
                E_ref_tmp(run) = 0.0_dp
            end if


        end do

        if (iProcIndex == root) then

#ifdef CMPLX_
            write(fcimcstats_unit,"(I12,5G16.7,8G18.9e3,&
                                  &G13.5,I12,G13.5,G17.5,I13,G13.5,8G18.9e3,I13,&

                                  &g16.7)",advance='no') &
                Iter + PreviousCycles, &                !1.
                DiagSft + E_ref_tmp, &                  !2.
                AllTotParts(1) - AllTotPartsLastOutput(1), &   !3.
                AllTotParts(2) - AllTotPartsLastOutput(2), &   !4.
                AllTotParts(1), &                       !5.
                AllTotParts(2), &                       !6.
                real(ProjectionE, dp), &                !7.     real \sum[ nj H0j / n0 ]
                aimag(projectionE), &                   !8.     Im   \sum[ nj H0j / n0 ]
                real(proje_iter, dp), &                 !9.
                aimag(proje_iter), &                    !10.
                real(proje_iter,dp) + OutputHii, &            !11.
                AllNoatHF(1), &                         !12.
                AllNoatHF(2), &                         !13.
                AllNoatDoubs, &                         !14.
                AccRat, &                               !15.
                AllTotWalkers, &                        !16.
                IterTime, &                             !17.
                FracFromSing(1), &                      !18.
                WalkersDiffProc, &                           !19.
                TotImagTime, &                               !20.
                HFShift, &                                   !21.
                InstShift, &                                 !22.
                real((AllHFOut*conjg(AllHFOut)),dp), &     !23 |n0|^2  denominator for both calcs
                real((AllENumOut*conjg(AllHFOut)),dp), &   !24. Re[\sum njH0j]xRe[n0]+Im[\sum njH0j]xIm[n0]   No div by StepsPrint
                aimag(AllENumOut*conjg(AllHFOut)), &       !25.Im[\sum njH0j]xRe[n0]-Re[\sum njH0j]xIm[n0]   since no physicality
                sqrt(sum(AllNoatHF**2)) / norm_psi, & !26
                norm_psi, &                           !27
                curr_S2, &                            !28
                PartsDiffProc, &                      !29
                all_max_cyc_spawn                     !30
                if (tTrialWavefunction .or. tStartTrialLater) then
                    write(fcimcstats_unit, "(7(1X,es18.11))", advance = 'no') &
                    (tot_trial_numerator(1) / StepsPrint), &              ! 31. 32
                    (tot_trial_denom(1) / StepsPrint), &                  ! 33. 34
                    abs((tot_trial_denom(1) / (norm_psi(1)*StepsPrint))), &  ! 35.
                    tot_trial_numerator(1)/tot_trial_denom(1)           ! 36. 37.
                end if
                write(fcimcstats_unit, "()", advance = 'yes')

            if(tMCOutput) then
                write(stdout, "(I12,13G16.7,2I12,G13.5)") &
                    Iter + PreviousCycles, &
                    DiagSft + E_ref_tmp, &
                    AllTotParts(1) - AllTotPartsLastOutput(1), &
                    AllTotParts(2) - AllTotPartsLastOutput(2), &
                    AllTotParts(1), &
                    AllTotParts(2), &
                    real(ProjectionE, dp), &
                    aimag(ProjectionE), &
                    real(proje_iter, dp), &
                    aimag(proje_iter), &
                    AllNoatHF(1), &
                    AllNoatHF(2), &
                    AllNoatDoubs, &
                    AccRat, &
                    AllTotWalkers, &
                    nspawned_tot, &
                    IterTime
            end if
            if (tTruncInitiator) then
               write(initiatorstats_unit,"(I12,4G16.7,3I20,4G16.7,F16.9,2G16.7,2I20,1G16.7,1I20)", &
                    advance = 'no')&
                   Iter + PreviousCycles, sum(AllTotParts), &
                   AllAnnihilated(1), AllNoDied(1), AllNoBorn(1), AllTotWalkers,&
                   AllNoInitDets(1), AllNoNonInitDets(1), AllNoInitWalk(1), &
                   AllNoNonInitWalk(1),AllNoAborted(1), AllNoRemoved(1), &
                   inits_proje_iter(1) + Hii, all_n_core_non_init
               if(tTrialWavefunction .or. tStartTrialLater) &
                    write(initiatorstats_unit, "(2G16.7)", advance = 'no') &
                    tot_init_trial_numerator(1)/StepsPrint, tot_init_trial_denom(1)/StepsPrint
               do j = 1, maxInitExLvlWrite
                  write(initiatorstats_unit,'(1I20)', advance ='no') AllInitsPerExLvl(j)/StepsPrint
               end do
               write(initiatorstats_unit,'()', advance = 'yes')
            end if
            if (tLogComplexPops) then
                write(complexstats_unit,"(I12,6G16.7)") &
                    Iter + PreviousCycles, DiagSft, DiagSftRe, DiagSftIm, &
                    sum(AllTotParts), AllTotParts(1), AllTotParts(lenof_sign)
            end if
#elif defined(DOUBLERUN_)
            write(fcimcstats_unit2,"(i12,7g16.7,5g18.9e3,g13.5,i12,g13.5,g17.5,&
                                   &i13,g13.5,4g18.9e3,1X,2(es18.11,1X),5g18.9e3,&
                                   &i13,2g16.7)",advance = 'no') &
                Iter + PreviousCycles, &                   ! 1.
                DiagSft(2) + E_ref_tmp(2), &                              ! 2.
                AllTotParts(2) - AllTotPartsLastOutput(2), &      ! 3.
                AllGrowRate(2), &                          ! 4.
                AllTotParts(2), &                          ! 5.
                AllAnnihilated(2), &                       ! 6.
                AllNoDied(2), &                            ! 7.
                AllNoBorn(2), &                            ! 8.
                ProjectionE(2), &                          ! 9.
                AvDiagSft(2), &                            ! 10.
                proje_iter(2), &                           ! 11.
                AllNoatHF(2), &                            ! 12.
                AllNoatDoubs(2), &                         ! 13.
                AccRat(2), &                               ! 14.
                AllTotWalkers, &                           ! 15.
                IterTime, &                                ! 16.
                FracFromSing(2), &                         ! 17.
                WalkersDiffProc, &                         ! 18.
                TotImagTime, &                             ! 19.
                0.0_dp, &                                  ! 20.
                HFShift(2), &                              ! 21.
                InstShift(2), &                            ! 22.
                proje_iter(2) + OutputHii, &                     ! 23.
                (AllHFOut(2) / StepsPrint), &                ! 24.
                (AllENumOut(2) / StepsPrint), &              ! 25.
                AllNoatHF(2) / norm_psi(2), &              ! 26.
                norm_psi(2), &                             ! 27.
                curr_S2(2), curr_S2_init(2), &             ! 28, 29.
                AbsProjE(2), &                             ! 30.
                PartsDiffProc, &                           ! 31.
                norm_semistoch(2)/norm_psi(2), &           ! 32.
                all_max_cyc_spawn                          ! 33.
                if (tTrialWavefunction .or. tStartTrialLater) then
                    write(fcimcstats_unit2, "(3(1X,es17.10))", advance = 'no') &
                    (tot_trial_numerator(2) / StepsPrint), &
                    (tot_trial_denom(2) / StepsPrint), &
                    abs(tot_trial_denom(2) / (norm_psi(2)*StepsPrint))
                end if
                if(t_truncate_spawns) then
                   write(fcimcstats_unit2, "(1X,es18.11)", advance = 'no') AllTruncatedWeight
                end if

                write(fcimcstats_unit2, "()", advance = 'yes')
#endif
#ifndef CMPLX_

            write(fcimcstats_unit,"(i12,7g16.7,5g18.9e3,g13.5,i12,g13.5,g17.5,&
                                   &i13,g13.5,4g18.9e3,1X,2(es18.11,1X),5g18.9e3,&
                                   &i13,4g16.7)",advance = 'no') &
                Iter + PreviousCycles, &                   ! 1.
                DiagSft(1) + E_ref_tmp(1), &                              ! 2.
                AllTotParts(1) - AllTotPartsLastOutput(1), &      ! 3.
                AllGrowRate(1), &                          ! 4.
                AllTotParts(1), &                          ! 5.
                AllAnnihilated(1)/StepsPrint, &            ! 6.
                AllNoDied(1)/StepsPrint, &                 ! 7.
                AllNoBorn(1)/StepsPrint, &                 ! 8.
                ProjectionE(1), &                          ! 9.
                AvDiagSft(1), &                            ! 10.
                proje_iter(1), &                           ! 11.
                AllNoatHF(1), &                            ! 12.
                AllNoatDoubs(1), &                         ! 13.
                AccRat(1), &                               ! 14.
                AllTotWalkers, &                           ! 15.
                IterTime, &                                ! 16.
                FracFromSing(1), &                         ! 17.
                WalkersDiffProc, &                         ! 18.
                TotImagTime, &                             ! 19.
                0.0_dp, &                                  ! 20.
                HFShift(1), &                              ! 21.
                InstShift(1), &                            ! 22.
                proje_iter(1) + OutputHii, &                     ! 23.
                (AllHFOut(1) / StepsPrint), &                ! 24.
                (AllENumOut(1) / StepsPrint), &              ! 25.
                AllNoatHF(1) / norm_psi(1), &              ! 26.
                norm_psi(1), &                             ! 27.
                curr_S2(1), curr_S2_init(1), &             ! 28, 29.
                AbsProjE(1), &                             ! 30.
                PartsDiffProc, &                           ! 31.
                norm_semistoch(1)/norm_psi(1), &           ! 32.
                all_max_cyc_spawn                          ! 33
                if (tTrialWavefunction .or. tStartTrialLater) then
                    write(fcimcstats_unit, "(3(1X,es18.11))", advance = 'no') &
                    (tot_trial_numerator(1) / StepsPrint), &              ! 34.
                    (tot_trial_denom(1) / StepsPrint), &                  ! 35.
                    abs((tot_trial_denom(1) / (norm_psi(1)*StepsPrint)))  ! 36.
                 end if
                 write(fcimcstats_unit, "(2g16.7)", advance = 'no') &
                      allNInvalidExcits, & ! 34/37.
                      allNValidExcits      ! 35/38.
                if(t_truncate_spawns) then
                   write(fcimcstats_unit, "(1X,es18.11)", advance = 'no') AllTruncatedWeight
                end if
                write(fcimcstats_unit, "()", advance = 'yes')

            if(tMCOutput) then
                write(stdout, "(I12,10G16.7)", advance = 'no') &
                    Iter + PreviousCycles, &
                    DiagSft(1)+E_ref_tmp(1), &
                    AllTotParts(1) - AllTotPartsLastOutput(1), &
                    AllGrowRate(1), &
                    AllTotParts(1), &
                    AllAnnihilated(1), &
                    AllNoDied(1), &
                    AllNoBorn(1), &
                    ProjectionE(1), &
                    AvDiagSft(1), &
                    proje_iter(1)
                if (tTrialWavefunction) then
                     write(stdout, "(G20.11)", advance = 'no') &
                         (tot_trial_numerator(1)/tot_trial_denom(1))
                else if (tStartTrialLater) then
                     write(stdout, "(G20.11)", advance = 'no') 0.0_dp
                end if
                write(stdout, "(3G16.7,2I12,G13.5)", advance = 'yes') &
                    AllNoatHF(1), &
                    AllNoatDoubs(1), &
                    AccRat(1), &
                    AllTotWalkers, &
                    nspawned_tot, &
                    IterTime
            end if
            if (tTruncInitiator) then
               write(initiatorstats_unit,"(I12,4G16.7,3I20,4G16.7,F16.9,2G16.7,2I20,1G16.7,1I20)", &
                    advance = 'no')&
                   Iter + PreviousCycles, AllTotParts(1), &
                   AllAnnihilated(1), AllNoDied(1), AllNoBorn(1), AllTotWalkers,&
                   AllNoInitDets(1), AllNoNonInitDets(1), AllNoInitWalk(1), &
                   AllNoNonInitWalk(1),AllNoAborted(1), AllNoRemoved(1), &
                   inits_proje_iter(1) + Hii, all_n_core_non_init
               if(tTrialWavefunction .or. tStartTrialLater) &
                    write(initiatorstats_unit, "(2G16.7)", advance = 'no') &
                    tot_init_trial_numerator(1)/StepsPrint, tot_init_trial_denom(1)/StepsPrint
               do j = 1, maxInitExLvlWrite
                  write(initiatorstats_unit,'(1I20)', advance ='no') AllInitsPerExLvl(j)
               end do
               write(initiatorstats_unit,'()', advance = 'yes')
            end if
#endif
            if (tLogEXLEVELStats) then
                write(EXLEVELStats_unit, '(i12)', advance='no') &
                      &Iter + PreviousCycles
                do run = 1, inum_runs
                    do i = 0, 2
                        do j = 0, NEl
                            write(EXLEVELStats_unit, '(1x,G18.9e3)', &
                                   advance='no') AllEXLEVEL_WNorm(i,j,run)
                        end do ! j
                    end do ! i
                end do ! run
                write(EXLEVELStats_unit, '()', advance='yes')
            end if ! tLogEXLEVELStats

            if (tMCOutput .and. tLMatCalc .and. mod(Iter, lMatCalcStatsIters) == 0) then
                write(stdout, *) "============ LMatCalc Caching Stats ==============="
                write(stdout, *) "LMatCalc Cache Fill Ratio: ", &
                    real(lMatCalcHUsed,dp)/real(lMatCalcHSize,dp)
                write(stdout, *) "LMatCalc Cache Hit Rate  : ", lMatCalcHit/real(lMatCalcTot)
                lMatCalcHit = 0
                lMatCalcTot = 0
                write(stdout, *) "==================================================="
            end if

            if(tMCOutput) then
                call neci_flush(stdout)
            end if
            call neci_flush(fcimcstats_unit)
            if (inum_runs.eq.2) call neci_flush(fcimcstats_unit2)
            if (tLogEXLEVELStats) call neci_flush(EXLEVELStats_unit)

        end if

    end subroutine WriteFCIMCStats