From 3c9944225cdbe12804c02f27b0c81f97d34a1c14 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 26 Feb 2021 14:51:10 +0100 Subject: [PATCH 1/3] Removed useless function --- src/csf/configuration_CI_sigma_helpers.irp.f | 230 ------------------ src/davidson/diagonalization_h_dressed.irp.f | 16 -- .../diagonalization_hcsf_dressed.irp.f | 18 +- .../diagonalization_hs2_dressed.irp.f | 23 -- 4 files changed, 1 insertion(+), 286 deletions(-) diff --git a/src/csf/configuration_CI_sigma_helpers.irp.f b/src/csf/configuration_CI_sigma_helpers.irp.f index 079c9541..f73362eb 100644 --- a/src/csf/configuration_CI_sigma_helpers.irp.f +++ b/src/csf/configuration_CI_sigma_helpers.irp.f @@ -1,233 +1,3 @@ - subroutine obtain_associated_alphaI(idxI, Icfg, alphasIcfg, NalphaIcfg, factor_alphaI) - implicit none - use bitmasks - BEGIN_DOC - ! Documentation for alphasI - ! Returns the associated alpha's for - ! the input configuration Icfg. - END_DOC - - integer,intent(in) :: idxI ! The id of the Ith CFG - integer(bit_kind),intent(in) :: Icfg(N_int,2) - integer,intent(out) :: NalphaIcfg - real*8 ,intent(out) :: factor_alphaI(*) - integer(bit_kind),intent(out) :: alphasIcfg(N_int,2,*) - logical,dimension(:,:),allocatable :: tableUniqueAlphas - integer :: listholes(mo_num) - integer :: holetype(mo_num) ! 1-> SOMO 2->DOMO - integer :: nholes - integer :: nvmos - integer :: listvmos(mo_num) - integer :: vmotype(mo_num) ! 1 -> VMO 2 -> SOMO - integer*8 :: Idomo - integer*8 :: Isomo - integer*8 :: Jdomo - integer*8 :: Jsomo - integer*8 :: diffSOMO - integer*8 :: diffDOMO - integer :: ndiffSOMO - integer :: ndiffDOMO - integer :: ndiffAll - integer :: i - integer :: j - integer :: k - integer :: hole - integer :: p - integer :: q - integer :: countalphas - logical :: pqAlreadyGenQ - logical :: pqExistsQ - Isomo = iand(reunion_of_act_virt_bitmask(1,1),Icfg(1,1)) - Idomo = iand(reunion_of_act_virt_bitmask(1,1),Icfg(1,2)) - !print*,"Input cfg" - !call debug_spindet(Isomo,1) - !call debug_spindet(Idomo,1) - - !print*,n_act_orb, "monum=",mo_num," n_core=",n_core_orb - - ! find out all pq holes possible - nholes = 0 - ! holes in SOMO - do i = n_core_orb+1,n_core_orb + n_act_orb - if(POPCNT(IAND(Isomo,IBSET(0_8,i-1))) .EQ. 1) then - nholes += 1 - listholes(nholes) = i - holetype(nholes) = 1 - endif - end do - ! holes in DOMO - do i = n_core_orb+1,n_core_orb + n_act_orb - if(POPCNT(IAND(Idomo,IBSET(0_8,i-1))) .EQ. 1) then - nholes += 1 - listholes(nholes) = i - holetype(nholes) = 2 - endif - end do - - ! find vmos - listvmos = -1 - vmotype = -1 - nvmos = 0 - do i = n_core_orb+1,n_core_orb + n_act_orb - !print *,i,IBSET(0,i-1),POPCNT(IAND(Isomo,(IBSET(0_8,i-1)))), POPCNT(IAND(Idomo,(IBSET(0_8,i-1)))) - if(POPCNT(IAND(Isomo,(IBSET(0_8,i-1)))) .EQ. 0 .AND. POPCNT(IAND(Idomo,(IBSET(0_8,i-1)))) .EQ. 0) then - nvmos += 1 - listvmos(nvmos) = i - vmotype(nvmos) = 1 - else if(POPCNT(IAND(Isomo,(IBSET(0_8,i-1)))) .EQ. 1 .AND. POPCNT(IAND(Idomo,(IBSET(0_8,i-1)))) .EQ. 0 ) then - nvmos += 1 - listvmos(nvmos) = i - vmotype(nvmos) = 2 - end if - end do - - !print *,"Nvmo=",nvmos - !print *,listvmos - !print *,vmotype - - allocate(tableUniqueAlphas(mo_num,mo_num)) - tableUniqueAlphas = .FALSE. - - ! Now find the allowed (p,q) excitations - Isomo = iand(reunion_of_act_virt_bitmask(1,1),Icfg(1,1)) - Idomo = iand(reunion_of_act_virt_bitmask(1,1),Icfg(1,2)) - !print *,"Isomo" - !call debug_spindet(Isomo,1) - !call debug_spindet(Idomo,1) - - !print *,"Nholes=",nholes," Nvmos=",nvmos, " idxi=",idxI - !do i = 1,nholes - ! print *,i,"->",listholes(i) - !enddo - !do i = 1,nvmos - ! print *,i,"->",listvmos(i) - !enddo - - ! TODO cfg_seniority_index - do i = 1,nholes - p = listholes(i) - do j = 1,nvmos - q = listvmos(j) - if(p == q) cycle - if(holetype(i) .EQ. 1 .AND. vmotype(j) .EQ. 1) then - ! SOMO -> VMO - Jsomo = IBCLR(Isomo,p-1) - Jsomo = IBSET(Jsomo,q-1) - Jdomo = Idomo - else if(holetype(i) .EQ. 1 .AND. vmotype(j) .EQ. 2) then - ! SOMO -> SOMO - Jsomo = IBCLR(Isomo,p-1) - Jsomo = IBCLR(Jsomo,q-1) - Jdomo = IBSET(Idomo,q-1) - else if(holetype(i) .EQ. 2 .AND. vmotype(j) .EQ. 1) then - ! DOMO -> VMO - Jsomo = IBSET(Isomo,p-1) - Jsomo = IBSET(Jsomo,q-1) - Jdomo = IBCLR(Idomo,p-1) - else if(holetype(i) .EQ. 2 .AND. vmotype(j) .EQ. 2) then - ! DOMO -> SOMO - Jsomo = IBSET(Isomo,p-1) - Jsomo = IBCLR(Jsomo,q-1) - Jdomo = IBCLR(Idomo,p-1) - Jdomo = IBSET(Jdomo,q-1) - else - print*,"Something went wrong in obtain_associated_alphaI" - endif - - - pqAlreadyGenQ = .FALSE. - ! First check if it can be generated before - do k = 1, idxI-1 - diffSOMO = IEOR(Jsomo,iand(reunion_of_act_virt_bitmask(1,1),psi_configuration(1,1,k))) - diffDOMO = IEOR(Jdomo,iand(reunion_of_act_virt_bitmask(1,1),psi_configuration(1,2,k))) - ndiffSOMO = POPCNT(diffSOMO) - ndiffDOMO = POPCNT(diffDOMO) - if(POPCNT(IEOR(diffSOMO,diffDOMO)) .LE. 1 .AND. ndiffDOMO .LT. 3) then - pqAlreadyGenQ = .TRUE. - !print *,i,k,ndiffSOMO,ndiffDOMO - !call debug_spindet(Jsomo,1) - !call debug_spindet(Jdomo,1) - !call debug_spindet(iand(reunion_of_act_virt_bitmask(1,1),psi_configuration(1,1,k)),1) - !call debug_spindet(iand(reunion_of_act_virt_bitmask(1,1),psi_configuration(1,2,k)),1) - EXIT - endif - end do - - if(pqAlreadyGenQ) cycle - - pqExistsQ = .FALSE. - ! now check if this exists in the selected list - do k = idxI, N_configuration - diffSOMO = IEOR(OR(reunion_of_act_virt_bitmask(1,1),Jsomo),psi_configuration(1,1,k)) - diffDOMO = IEOR(OR(reunion_of_act_virt_bitmask(1,1),Jdomo),psi_configuration(1,2,k)) - ndiffSOMO = POPCNT(diffSOMO) - ndiffDOMO = POPCNT(diffDOMO) - if((ndiffSOMO + ndiffDOMO) .EQ. 0) then - pqExistsQ = .TRUE. - EXIT - endif - end do - - if(.NOT. pqExistsQ) then - tableUniqueAlphas(p,q) = .TRUE. - !print *,p,q - !call debug_spindet(Jsomo,1) - !call debug_spindet(Jdomo,1) - endif - end do - end do - - !print *,tableUniqueAlphas(:,:) - - ! prune list of alphas - Isomo = Icfg(1,1) - Idomo = Icfg(1,2) - Jsomo = Icfg(1,1) - Jdomo = Icfg(1,2) - NalphaIcfg = 0 - do i = 1, nholes - p = listholes(i) - do j = 1, nvmos - q = listvmos(j) - if(p .EQ. q) cycle - if(tableUniqueAlphas(p,q)) then - if(holetype(i) .EQ. 1 .AND. vmotype(j) .EQ. 1) then - ! SOMO -> VMO - Jsomo = IBCLR(Isomo,p-1) - Jsomo = IBSET(Jsomo,q-1) - Jdomo = Idomo - else if(holetype(i) .EQ. 1 .AND. vmotype(j) .EQ. 2) then - ! SOMO -> SOMO - Jsomo = IBCLR(Isomo,p-1) - Jsomo = IBCLR(Jsomo,q-1) - Jdomo = IBSET(Idomo,q-1) - else if(holetype(i) .EQ. 2 .AND. vmotype(j) .EQ. 1) then - ! DOMO -> VMO - Jsomo = IBSET(Isomo,p-1) - Jsomo = IBSET(Jsomo,q-1) - Jdomo = IBCLR(Idomo,p-1) - else if(holetype(i) .EQ. 2 .AND. vmotype(j) .EQ. 2) then - ! DOMO -> SOMO - Jsomo = IBSET(Isomo,p-1) - Jsomo = IBCLR(Jsomo,q-1) - Jdomo = IBCLR(Idomo,p-1) - Jdomo = IBSET(Jdomo,q-1) - else - print*,"Something went wrong in obtain_associated_alphaI" - endif - - NalphaIcfg += 1 - !print *,p,q,"|",holetype(i),vmotype(j),NalphaIcfg - !call debug_spindet(Idomo,1) - !call debug_spindet(Jdomo,1) - alphasIcfg(1,1,NalphaIcfg) = Jsomo - alphasIcfg(1,2,NalphaIcfg) = IOR(Jdomo,ISHFT(1_8,n_core_orb)-1) - endif - end do - end do - - end subroutine - function getNSOMO(Icfg) result(NSOMO) implicit none integer(bit_kind),intent(in) :: Icfg(N_int,2) diff --git a/src/davidson/diagonalization_h_dressed.irp.f b/src/davidson/diagonalization_h_dressed.irp.f index f9ea6c77..26853df9 100644 --- a/src/davidson/diagonalization_h_dressed.irp.f +++ b/src/davidson/diagonalization_h_dressed.irp.f @@ -508,22 +508,6 @@ subroutine davidson_diag_hjj(dets_in,u_in,H_jj,energies,dim_in,sze,N_st,N_st_dia enddo enddo - - ! Adjust the phase - do j=1,N_st_diag - ! Find first non-zero - k=1 - do while ((k Date: Fri, 26 Feb 2021 16:28:39 +0100 Subject: [PATCH 2/3] Fixed distributed davidson --- src/davidson/davidson_parallel.irp.f | 4 +++- src/davidson/davidson_parallel_csf.irp.f | 4 ++-- src/davidson/davidson_parallel_nos2.irp.f | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/davidson/davidson_parallel.irp.f b/src/davidson/davidson_parallel.irp.f index ac56fad7..be1873c7 100644 --- a/src/davidson/davidson_parallel.irp.f +++ b/src/davidson/davidson_parallel.irp.f @@ -270,10 +270,12 @@ subroutine davidson_push_results_async_recv(zmq_socket_push,sending) ! Activate is zmq_socket_push is a REQ IRP_IF ZMQ_PUSH IRP_ELSE - character*(2) :: ok + character*(256) :: ok rc = f77_zmq_recv( zmq_socket_push, ok, 2, 0) if ((rc /= 2).and.(ok(1:2)/='ok')) then print *, irp_here, ': f77_zmq_recv( zmq_socket_push, ok, 2, 0)' + print *, rc + print *, ok stop -1 endif IRP_ENDIF diff --git a/src/davidson/davidson_parallel_csf.irp.f b/src/davidson/davidson_parallel_csf.irp.f index 6e32dc11..fe651b1d 100644 --- a/src/davidson/davidson_parallel_csf.irp.f +++ b/src/davidson/davidson_parallel_csf.irp.f @@ -193,7 +193,7 @@ subroutine davidson_csf_push_results(zmq_socket_push, v_t, imin, imax, task_id) rc = f77_zmq_send( zmq_socket_push, imax, 4, ZMQ_SNDMORE) if(rc /= 4) stop 'davidson_csf_push_results failed to push imax' - rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, ZMQ_SNDMORE) + rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, 0) if(rc8 /= 8_8*sz) stop 'davidson_csf_push_results failed to push vt' ! Activate is zmq_socket_push is a REQ @@ -240,7 +240,7 @@ subroutine davidson_csf_push_results_async_send(zmq_socket_push, v_t, imin, imax rc = f77_zmq_send( zmq_socket_push, imax, 4, ZMQ_SNDMORE) if(rc /= 4) stop 'davidson_csf_push_results failed to push imax' - rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, ZMQ_SNDMORE) + rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, 0) if(rc8 /= 8_8*sz) stop 'davidson_csf_push_results failed to push vt' diff --git a/src/davidson/davidson_parallel_nos2.irp.f b/src/davidson/davidson_parallel_nos2.irp.f index c332281a..84cbe3af 100644 --- a/src/davidson/davidson_parallel_nos2.irp.f +++ b/src/davidson/davidson_parallel_nos2.irp.f @@ -193,7 +193,7 @@ subroutine davidson_nos2_push_results(zmq_socket_push, v_t, imin, imax, task_id) rc = f77_zmq_send( zmq_socket_push, imax, 4, ZMQ_SNDMORE) if(rc /= 4) stop 'davidson_nos2_push_results failed to push imax' - rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, ZMQ_SNDMORE) + rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, 0) if(rc8 /= 8_8*sz) stop 'davidson_nos2_push_results failed to push vt' ! Activate is zmq_socket_push is a REQ @@ -240,7 +240,7 @@ subroutine davidson_nos2_push_results_async_send(zmq_socket_push, v_t, imin, ima rc = f77_zmq_send( zmq_socket_push, imax, 4, ZMQ_SNDMORE) if(rc /= 4) stop 'davidson_nos2_push_results failed to push imax' - rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, ZMQ_SNDMORE) + rc8 = f77_zmq_send8( zmq_socket_push, v_t(1,imin), 8_8*sz, 0) if(rc8 /= 8_8*sz) stop 'davidson_nos2_push_results failed to push vt' From 52701979ceded525d1832fc5a8ac2afd3e9df658 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 26 Feb 2021 17:28:03 +0100 Subject: [PATCH 3/3] Rewrite get_phase_qp_to_cfg --- src/csf/sigma_vector.irp.f | 108 +++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/src/csf/sigma_vector.irp.f b/src/csf/sigma_vector.irp.f index 48ae3c2b..9c1ac56a 100644 --- a/src/csf/sigma_vector.irp.f +++ b/src/csf/sigma_vector.irp.f @@ -1,9 +1,9 @@ - BEGIN_PROVIDER [ integer, NSOMOMax] - &BEGIN_PROVIDER [ integer, NCSFMax] - &BEGIN_PROVIDER [ integer*8, NMO] - &BEGIN_PROVIDER [ integer, NBFMax] - &BEGIN_PROVIDER [ integer, n_CSF] - &BEGIN_PROVIDER [ integer, maxDetDimPerBF] + BEGIN_PROVIDER [ integer, NSOMOMax] +&BEGIN_PROVIDER [ integer, NCSFMax] +&BEGIN_PROVIDER [ integer*8, NMO] +&BEGIN_PROVIDER [ integer, NBFMax] +&BEGIN_PROVIDER [ integer, n_CSF] +&BEGIN_PROVIDER [ integer, maxDetDimPerBF] implicit none BEGIN_DOC ! Documentation for NSOMOMax @@ -22,7 +22,7 @@ integer NSOMO integer dimcsfpercfg integer detDimperBF - real*8 :: coeff + real*8 :: coeff integer MS integer ncfgpersomo detDimperBF = 0 @@ -31,21 +31,20 @@ n_CSF = cfg_seniority_index(0)-1 ncfgprev = cfg_seniority_index(0) do i = 0-iand(MS,1)+2, NSOMOMax,2 - if(cfg_seniority_index(i) .EQ. -1)then - ncfgpersomo = N_configuration + 1 - else - ncfgpersomo = cfg_seniority_index(i) - endif - ncfg = ncfgpersomo - ncfgprev - !detDimperBF = max(1,nint((binom(i,(i+1)/2)))) - dimcsfpercfg = max(1,nint((binom(i-2,(i-2+1)/2)-binom(i-2,((i-2+1)/2)+1)))) - n_CSF += ncfg * dimcsfpercfg - !if(cfg_seniority_index(i+2) == -1) EXIT - !if(detDimperBF > maxDetDimPerBF) maxDetDimPerBF = detDimperBF - ncfgprev = cfg_seniority_index(i) + if(cfg_seniority_index(i) .EQ. -1)then + ncfgpersomo = N_configuration + 1 + else + ncfgpersomo = cfg_seniority_index(i) + endif + ncfg = ncfgpersomo - ncfgprev + !detDimperBF = max(1,nint((binom(i,(i+1)/2)))) + dimcsfpercfg = max(1,nint((binom(i-2,(i-2+1)/2)-binom(i-2,((i-2+1)/2)+1)))) + n_CSF += ncfg * dimcsfpercfg + !if(cfg_seniority_index(i+2) == -1) EXIT + !if(detDimperBF > maxDetDimPerBF) maxDetDimPerBF = detDimperBF + ncfgprev = cfg_seniority_index(i) enddo - END_PROVIDER - +END_PROVIDER subroutine get_phase_qp_to_cfg(Ialpha, Ibeta, phaseout) use bitmasks @@ -62,41 +61,44 @@ subroutine get_phase_qp_to_cfg(Ialpha, Ibeta, phaseout) integer(bit_kind),intent(in) :: Ialpha(N_int) integer(bit_kind),intent(in) :: Ibeta(N_int) real*8,intent(out) :: phaseout - integer(bit_kind) :: mask(N_int), deta(N_int), detb(N_int) + integer(bit_kind) :: mask, mask2(N_int), deta(N_int), detb(N_int) integer :: nbetas integer :: count, k -if (N_int >1 ) then - stop 'TODO: get_phase_qp_to_cfg ' -endif - nbetas = 0 - mask = 0_bit_kind - count = 0 - deta = Ialpha - detb = Ibeta - ! remove the domos - mask = IAND(deta,detb) - deta = IEOR(deta,mask) - detb = IEOR(detb,mask) - mask = 0 - phaseout = 1.0 - k = 1 - do while((deta(k)).GT.0_8) - mask(k) = ISHFT(1_8,count) - if(POPCNT(IAND(deta(k),mask(k))).EQ.1)then - if(IAND(nbetas,1).EQ.0) then - phaseout *= 1.0d0 - else - phaseout *= -1.0d0 - endif - deta(k) = IEOR(deta(k),mask(k)) - else - if(POPCNT(IAND(detb(k),mask(k))).EQ.1) then - nbetas += 1 - detb(k) = IEOR(detb(k),mask(k)) - endif - endif - count += 1 + ! Remove the DOMOs + mask2 = IAND(Ialpha,Ibeta) + deta = IEOR(Ialpha,mask2) + detb = IEOR(Ibeta ,mask2) + + ! Find how many alpha electrons there are in all the N_ints + integer :: Na(N_int) + do k=1,N_int + Na(k) = popcnt(deta(k)) + enddo + + integer :: shift, ipos, nperm + phaseout = 1.d0 + do k=1,N_int + + do while(detb(k) /= 0_bit_kind) + ! Find the lowest beta electron and clear it + ipos = trailz(detb(k)) + detb(k) = ibclr(detb(k),ipos) + + ! Create a mask will all MOs higher than the beta electron + mask = not(shiftl(1_bit_kind,ipos+1) - 1_bit_kind) + + ! Apply the mask to the alpha string to count how many electrons to cross + nperm = popcnt( iand(mask, deta(k)) ) + + ! Count how many alpha electrons are above the beta electron in the other integers + nperm = nperm + sum(Na(k+1:N_int)) + if (iand(nperm,1) == 1) then + phaseout = -phaseout + endif + + enddo + enddo end subroutine get_phase_qp_to_cfg