10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-26 06:14:43 +01:00

Merge branch 'alpha_factory' of github.com:garniron/quantum_package

This commit is contained in:
Anthony Scemama 2018-02-26 17:19:53 +01:00
commit 02ff02256d
27 changed files with 2944 additions and 177 deletions

View File

@ -32,7 +32,7 @@ OPENMP : 1 ; Append OpenMP flags
# #
[OPT] [OPT]
FC : -traceback FC : -traceback
FCFLAGS : -xSSE4.2 -O2 -ip -ftz -g FCFLAGS : -xAVX -O2 -ip -ftz -g
# Profiling flags # Profiling flags
################# #################

View File

@ -31,8 +31,8 @@ OPENMP : 1 ; Append OpenMP flags
# -ftz : Flushes denormal results to zero # -ftz : Flushes denormal results to zero
# #
[OPT] [OPT]
FCFLAGS : -xAVX -O2 -ip -ftz -g -traceback FCFLAGS : -xSSE4.2 -O2 -ip -ftz -g -traceback
# !xAVX
# Profiling flags # Profiling flags
################# #################
# #

View File

@ -71,7 +71,6 @@ subroutine select_connected(i_generator,E0,pt2,b,subset)
hole_mask(k,2) = iand(generators_bitmask(k,2,s_hole,l), psi_det_generators(k,2,i_generator)) hole_mask(k,2) = iand(generators_bitmask(k,2,s_hole,l), psi_det_generators(k,2,i_generator))
particle_mask(k,1) = iand(generators_bitmask(k,1,s_part,l), not(psi_det_generators(k,1,i_generator)) ) particle_mask(k,1) = iand(generators_bitmask(k,1,s_part,l), not(psi_det_generators(k,1,i_generator)) )
particle_mask(k,2) = iand(generators_bitmask(k,2,s_part,l), not(psi_det_generators(k,2,i_generator)) ) particle_mask(k,2) = iand(generators_bitmask(k,2,s_part,l), not(psi_det_generators(k,2,i_generator)) )
enddo enddo
call select_singles_and_doubles(i_generator,hole_mask,particle_mask,fock_diag_tmp,E0,pt2,b,subset) call select_singles_and_doubles(i_generator,hole_mask,particle_mask,fock_diag_tmp,E0,pt2,b,subset)
enddo enddo
@ -300,6 +299,7 @@ subroutine select_singles_and_doubles(i_generator,hole_mask,particle_mask,fock_d
particle(k,2) = iand(not(psi_det_generators(k,2,i_generator)), particle_mask(k,2)) particle(k,2) = iand(not(psi_det_generators(k,2,i_generator)), particle_mask(k,2))
enddo enddo
integer :: N_holes(2), N_particles(2) integer :: N_holes(2), N_particles(2)
integer :: hole_list(N_int*bit_kind_size,2) integer :: hole_list(N_int*bit_kind_size,2)
integer :: particle_list(N_int*bit_kind_size,2) integer :: particle_list(N_int*bit_kind_size,2)

View File

@ -0,0 +1,39 @@
[lambda_type]
type: Positive_int
doc: lambda type
interface: ezfio,provider,ocaml
default: 0
[energy]
type: double precision
doc: Calculated energy
interface: ezfio
[energy_pt2]
type: double precision
doc: Calculated energy with PT2 contribution
interface: ezfio
[perturbative_triples]
type: logical
doc: Compute perturbative contribution of the Triples
interface: ezfio,provider,ocaml
default: false
[energy]
type: double precision
doc: Calculated energy
interface: ezfio
[thresh_dressed_ci]
type: Threshold
doc: Threshold on the convergence of the dressed CI energy
interface: ezfio,provider,ocaml
default: 1.e-5
[n_it_max_dressed_ci]
type: Strictly_positive_int
doc: Maximum number of dressed CI iterations
interface: ezfio,provider,ocaml
default: 10

View File

@ -0,0 +1,2 @@
Perturbation Selectors_full Generators_full Psiref_CAS MRCC_Utils ZMQ DavidsonDressed

View File

@ -0,0 +1,12 @@
=========
dress_zmq
=========
Needed Modules
==============
.. Do not edit this section It was auto-generated
.. by the `update_README.py` script.
Documentation
=============
.. Do not edit this section It was auto-generated
.. by the `update_README.py` script.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,134 @@
subroutine run(N_st,energy)
implicit none
integer, intent(in) :: N_st
double precision, intent(out) :: energy(N_st)
integer :: i,j
double precision :: E_new, E_old, delta_e
integer :: iteration
integer :: n_it_dress_max
double precision :: thresh_dress
double precision, allocatable :: lambda(:)
allocate (lambda(N_states))
thresh_dress = thresh_dressed_ci
n_it_dress_max = n_it_max_dressed_ci
if(n_it_dress_max == 1) then
do j=1,N_states
do i=1,N_det
psi_coef(i,j) = CI_eigenvectors_dressed(i,j)
enddo
enddo
SOFT_TOUCH psi_coef ci_energy_dressed
call write_double(6,ci_energy_dressed(1),"Final dress energy")
call ezfio_set_dress_zmq_energy(ci_energy_dressed(1))
call save_wavefunction
else
E_new = 0.d0
delta_E = 1.d0
iteration = 0
lambda = 1.d0
do while (delta_E > thresh_dress)
iteration += 1
print *, '==============================================='
print *, 'Iteration', iteration, '/', n_it_dress_max
print *, '==============================================='
print *, ''
E_old = dress_e0_denominator(1) !sum(ci_energy_dressed(1:N_states))
do i=1,N_st
call write_double(6,ci_energy_dressed(i),"Energy")
enddo
call diagonalize_ci_dressed(lambda)
E_new = dress_e0_denominator(1) !sum(ci_energy_dressed(1:N_states))
delta_E = (E_new - E_old)/dble(N_states)
print *, ''
call write_double(6,thresh_dress,"thresh_dress")
call write_double(6,delta_E,"delta_E")
delta_E = dabs(delta_E)
call save_wavefunction
call ezfio_set_dress_zmq_energy(ci_energy_dressed(1))
if (iteration >= n_it_dress_max) then
exit
endif
enddo
call write_double(6,ci_energy_dressed(1),"Final energy")
endif
energy(1:N_st) = ci_energy_dressed(1:N_st)
end
subroutine print_cas_coefs
implicit none
integer :: i,j
print *, 'CAS'
print *, '==='
do i=1,N_det_cas
print *, (psi_cas_coef(i,j), j=1,N_states)
call debug_det(psi_cas(1,1,i),N_int)
enddo
call write_double(6,ci_energy(1),"Initial CI energy")
end
subroutine run_pt2(N_st,energy)
implicit none
integer :: i,j,k
integer, intent(in) :: N_st
double precision, intent(in) :: energy(N_st)
double precision :: pt2(N_st)
double precision :: norm_pert(N_st),H_pert_diag(N_st)
pt2 = 0d0
print*,'Last iteration only to compute the PT2'
N_det_generators = N_det_cas
N_det_selectors = N_det_non_ref
do i=1,N_det_generators
do k=1,N_int
psi_det_generators(k,1,i) = psi_ref(k,1,i)
psi_det_generators(k,2,i) = psi_ref(k,2,i)
enddo
do k=1,N_st
psi_coef_generators(i,k) = psi_ref_coef(i,k)
enddo
enddo
do i=1,N_det
do k=1,N_int
psi_selectors(k,1,i) = psi_det_sorted(k,1,i)
psi_selectors(k,2,i) = psi_det_sorted(k,2,i)
enddo
do k=1,N_st
psi_selectors_coef(i,k) = psi_coef_sorted(i,k)
enddo
enddo
SOFT_TOUCH N_det_selectors psi_selectors_coef psi_selectors N_det_generators psi_det_generators psi_coef_generators ci_eigenvectors_dressed ci_eigenvectors_s2_dressed ci_electronic_energy_dressed
SOFT_TOUCH psi_ref_coef_diagonalized psi_ref_energy_diagonalized
call H_apply_mrcepa_PT2(pt2, norm_pert, H_pert_diag, N_st)
! call ezfio_set_full_ci_energy_pt2(energy+pt2)
print *, 'Final step'
print *, 'N_det = ', N_det
print *, 'N_states = ', N_states
print *, 'PT2 = ', pt2
print *, 'E = ', energy
print *, 'E+PT2 = ', energy+pt2
print *, '-----'
call ezfio_set_dress_zmq_energy_pt2(energy(1)+pt2(1))
end

View File

@ -0,0 +1,75 @@
subroutine dress_slave
implicit none
BEGIN_DOC
! Helper program to compute the dress in distributed mode.
END_DOC
read_wf = .False.
distributed_davidson = .False.
SOFT_TOUCH read_wf distributed_davidson
call provide_everything
call switch_qp_run_to_master
call run_wf
end
subroutine provide_everything
PROVIDE H_apply_buffer_allocated mo_bielec_integrals_in_map psi_det_generators psi_coef_generators psi_det_sorted_bit psi_selectors n_det_generators n_states generators_bitmask zmq_context
end
subroutine run_wf
use f77_zmq
implicit none
integer(ZMQ_PTR), external :: new_zmq_to_qp_run_socket
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
double precision :: energy(N_states_diag)
character*(64) :: states(1)
integer :: rc, i
call provide_everything
zmq_context = f77_zmq_ctx_new ()
states(1) = 'dress'
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
do
call wait_for_states(states,zmq_state,1)
if(trim(zmq_state) == 'Stopped') then
exit
else if (trim(zmq_state) == 'dress') then
! Selection
! ---------
print *, 'dress'
call zmq_get_psi(zmq_to_qp_run_socket,1,energy,N_states)
PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique
PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order
PROVIDE psi_bilinear_matrix_transp_rows_loc psi_bilinear_matrix_transp_columns
PROVIDE psi_bilinear_matrix_transp_order
!$OMP PARALLEL PRIVATE(i)
i = omp_get_thread_num()
call dress_slave_tcp(i, energy)
!$OMP END PARALLEL
print *, 'dress done'
endif
end do
end
subroutine dress_slave_tcp(i,energy)
implicit none
double precision, intent(in) :: energy(N_states_diag)
integer, intent(in) :: i
logical :: lstop
lstop = .False.
call run_dress_slave(0,i,energy,lstop)
end

View File

@ -0,0 +1,624 @@
BEGIN_PROVIDER [ integer, fragment_first ]
implicit none
fragment_first = first_det_of_teeth(1)
END_PROVIDER
subroutine ZMQ_dress(E, dress, delta, delta_s2, relative_error)
use f77_zmq
implicit none
character(len=64000) :: task
integer(ZMQ_PTR) :: zmq_to_qp_run_socket, zmq_socket_pull
integer, external :: omp_get_thread_num
double precision, intent(in) :: relative_error, E
double precision, intent(out) :: dress(N_states)
double precision, intent(out) :: delta(N_states, N_det)
double precision, intent(out) :: delta_s2(N_states, N_det)
integer :: i, j, k, Ncp
double precision, external :: omp_get_wtime
double precision :: time
double precision :: w(N_states)
integer, external :: add_task_to_taskserver
provide nproc fragment_first fragment_count mo_bielec_integrals_in_map mo_mono_elec_integral dress_weight psi_selectors
!!!!!!!!!!!!!!! demander a TOTO !!!!!!!
w(:) = 0.d0
w(dress_stoch_istate) = 1.d0
!call update_psi_average_norm_contrib(w)
print *, '========== ================= ================= ================='
print *, ' Samples Energy Stat. Error Seconds '
print *, '========== ================= ================= ================='
call new_parallel_job(zmq_to_qp_run_socket,zmq_socket_pull, 'dress')
integer, external :: zmq_put_psi
integer, external :: zmq_put_N_det_generators
integer, external :: zmq_put_N_det_selectors
integer, external :: zmq_put_dvector
integer, external :: zmq_set_running
if (zmq_put_psi(zmq_to_qp_run_socket,1) == -1) then
stop 'Unable to put psi on ZMQ server'
endif
if (zmq_put_N_det_generators(zmq_to_qp_run_socket, 1) == -1) then
stop 'Unable to put N_det_generators on ZMQ server'
endif
if (zmq_put_N_det_selectors(zmq_to_qp_run_socket, 1) == -1) then
stop 'Unable to put N_det_selectors on ZMQ server'
endif
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'energy',dress_e0_denominator,size(dress_e0_denominator)) == -1) then
stop 'Unable to put energy on ZMQ server'
endif
integer(ZMQ_PTR), external :: new_zmq_to_qp_run_socket
integer :: ipos
ipos=1
do i=1,N_dress_jobs
if(dress_jobs(i) > fragment_first) then
write(task(ipos:ipos+20),'(I9,1X,I9,''|'')') 0, dress_jobs(i)
ipos += 20
if (ipos > 63980) then
if (add_task_to_taskserver(zmq_to_qp_run_socket,trim(task(1:ipos))) == -1) then
stop 'Unable to add task to task server'
endif
ipos=1
endif
else
do j=1,fragment_count
write(task(ipos:ipos+20),'(I9,1X,I9,''|'')') j, dress_jobs(i)
ipos += 20
if (ipos > 63980) then
if (add_task_to_taskserver(zmq_to_qp_run_socket,trim(task(1:ipos))) == -1) then
stop 'Unable to add task to task server'
endif
ipos=1
endif
end do
end if
end do
if (ipos > 1) then
if (add_task_to_taskserver(zmq_to_qp_run_socket,trim(task(1:ipos))) == -1) then
stop 'Unable to add task to task server'
endif
endif
if (zmq_set_running(zmq_to_qp_run_socket) == -1) then
print *, irp_here, ': Failed in zmq_set_running'
endif
!$OMP PARALLEL DEFAULT(shared) NUM_THREADS(nproc+1) &
!$OMP PRIVATE(i)
i = omp_get_thread_num()
if (i==0) then
call dress_collector(zmq_socket_pull,E, relative_error, delta, delta_s2, dress)
else
call dress_slave_inproc(i)
endif
!$OMP END PARALLEL
call end_parallel_job(zmq_to_qp_run_socket, zmq_socket_pull, 'dress')
print *, '========== ================= ================= ================='
end subroutine
subroutine dress_slave_inproc(i)
implicit none
integer, intent(in) :: i
call run_dress_slave(1,i,dress_e0_denominator)
end
subroutine dress_collector(zmq_socket_pull, E, relative_error, delta, delta_s2, dress)
use f77_zmq
use bitmasks
implicit none
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
double precision, intent(in) :: relative_error, E
double precision, intent(out) :: dress(N_states)
double precision, allocatable :: cp(:,:,:,:)
double precision, intent(out) :: delta(N_states, N_det)
double precision, intent(out) :: delta_s2(N_states, N_det)
double precision, allocatable :: delta_loc(:,:,:), delta_det(:,:,:,:)
double precision, allocatable :: dress_detail(:,:)
double precision :: dress_mwen(N_states)
integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
integer(ZMQ_PTR), external :: new_zmq_pull_socket
integer :: more
integer :: i, j, k, i_state, N
integer :: task_id, ind
double precision, save :: time0 = -1.d0
double precision :: time, timeLast, old_tooth
double precision, external :: omp_get_wtime
integer :: cur_cp, old_cur_cp
integer, allocatable :: parts_to_get(:)
logical, allocatable :: actually_computed(:)
integer :: total_computed
delta = 0d0
delta_s2 = 0d0
allocate(delta_det(N_states, N_det, 0:comb_teeth+1, 2))
allocate(cp(N_states, N_det, N_cp, 2), dress_detail(N_states, N_det))
allocate(delta_loc(N_states, N_det, 2))
dress_detail = 0d0
delta_det = 0d0
cp = 0d0
total_computed = 0
character*(512) :: task
allocate(actually_computed(N_det_generators), parts_to_get(N_det_generators))
dress_mwen =0.d0
parts_to_get(:) = 1
if(fragment_first > 0) then
do i=1,fragment_first
parts_to_get(i) = fragment_count
enddo
endif
actually_computed = .false.
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
more = 1
if (time0 < 0.d0) then
call wall_time(time0)
endif
timeLast = time0
cur_cp = 0
old_cur_cp = 0
logical :: loop
loop = .true.
pullLoop : do while (loop)
call pull_dress_results(zmq_socket_pull, ind, delta_loc, task_id)
dress_mwen(:) = 0d0
!!!!! A VERIFIER !!!!!
do i_state=1,N_states
do i=1, N_det
dress_mwen(i_state) += delta_loc(i_state, i, 1) * psi_coef(i, i_state)
end do
end do
dress_detail(:, ind) += dress_mwen(:)
do j=1,N_cp !! optimizable
if(cps(ind, j) > 0d0) then
if(tooth_of_det(ind) < cp_first_tooth(j)) stop "coef on supposedely deterministic det"
double precision :: fac
integer :: toothMwen
logical :: fracted
fac = cps(ind, j) / cps_N(j) * dress_weight_inv(ind) * comb_step
do k=1,N_det
do i_state=1,N_states
cp(i_state,k,j,1) += delta_loc(i_state,k,1) * fac
cp(i_state,k,j,2) += delta_loc(i_state,k,2) * fac
end do
end do
end if
end do
toothMwen = tooth_of_det(ind)
fracted = (toothMwen /= 0)
if(fracted) fracted = (ind == first_det_of_teeth(toothMwen))
if(fracted) then
delta_det(:,:,toothMwen-1, 1) += delta_loc(:,:,1) * (1d0-fractage(toothMwen))
delta_det(:,:,toothMwen-1, 2) += delta_loc(:,:,2) * (1d0-fractage(toothMwen))
delta_det(:,:,toothMwen, 1) += delta_loc(:,:,1) * (fractage(toothMwen))
delta_det(:,:,toothMwen, 2) += delta_loc(:,:,2) * (fractage(toothMwen))
else
delta_det(:,:,toothMwen, 1) += delta_loc(:,:,1)
delta_det(:,:,toothMwen, 2) += delta_loc(:,:,2)
end if
parts_to_get(ind) -= 1
if(parts_to_get(ind) == 0) then
actually_computed(ind) = .true.
total_computed += 1
end if
integer, external :: zmq_delete_tasks
if (zmq_delete_tasks(zmq_to_qp_run_socket,zmq_socket_pull,task_id,1,more) == -1) then
stop 'Unable to delete tasks'
endif
if(more == 0) loop = .false.
time = omp_get_wtime()
if(time - timeLast > 1d0 .or. (.not. loop)) then
timeLast = time
cur_cp = N_cp
if(.not. actually_computed(dress_jobs(1))) cycle pullLoop
do i=2,N_det_generators
if(.not. actually_computed(dress_jobs(i))) then
cur_cp = done_cp_at(i-1)
exit
end if
end do
if(cur_cp == 0) cycle pullLoop
double precision :: su, su2, eqt, avg, E0, val
integer, external :: zmq_abort
su = 0d0
su2 = 0d0
do i=1, int(cps_N(cur_cp))
call get_comb_val(comb(i), dress_detail, cur_cp, val)
su += val
su2 += val**2
end do
avg = su / cps_N(cur_cp)
eqt = dsqrt( ((su2 / cps_N(cur_cp)) - avg**2) / cps_N(cur_cp) )
E0 = sum(dress_detail(1, :first_det_of_teeth(cp_first_tooth(cur_cp))-1))
if(cp_first_tooth(cur_cp) <= comb_teeth) then
E0 = E0 + dress_detail(1, first_det_of_teeth(cp_first_tooth(cur_cp))) * (1d0-fractage(cp_first_tooth(cur_cp)))
end if
call wall_time(time)
if ((dabs(eqt) < relative_error .and. cps_N(cur_cp) >= 30) .or. total_computed == N_det_generators) then
! Termination
!print '(G10.3, 2X, F16.7, 2X, G16.3, 2X, F16.4, A20)', Nabove(tooth), avg+E, eqt, time-time0, ''
! print *, "GREPME", cur_cp, E+E0+avg, eqt, time-time0, total_computed
if (zmq_abort(zmq_to_qp_run_socket) == -1) then
call sleep(1)
if (zmq_abort(zmq_to_qp_run_socket) == -1) then
print *, irp_here, ': Error in sending abort signal (2)'
endif
endif
else
if (cur_cp > old_cur_cp) then
old_cur_cp = cur_cp
! print *, "GREPME", cur_cp, E+E0+avg, eqt, time-time0, total_computed
!print '(G10.3, 2X, F16.7, 2X, G16.3, 2X, F16.4, A20)', Nabove(tooth), avg+E, eqt, time-time0, ''
endif
endif
end if
end do pullLoop
if(total_computed == N_det_generators) then
delta = 0d0
delta_s2 = 0d0
do i=comb_teeth+1,0,-1
delta += delta_det(:,:,i,1)
delta_s2 += delta_det(:,:,i,2)
end do
else
delta = cp(:,:,cur_cp,1)
delta_s2 = cp(:,:,cur_cp,2)
do i=cp_first_tooth(cur_cp)-1,0,-1
delta += delta_det(:,:,i,1)
delta_s2 += delta_det(:,:,i,2)
end do
end if
dress(1) = E
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
end subroutine
integer function dress_find(v, w, sze, imin, imax)
implicit none
integer, intent(in) :: sze, imin, imax
double precision, intent(in) :: v, w(sze)
integer :: i,l,h
integer, parameter :: block=64
l = imin
h = imax-1
do while(h-l >= block)
i = ishft(h+l,-1)
if(w(i+1) > v) then
h = i-1
else
l = i+1
end if
end do
!DIR$ LOOP COUNT (64)
do dress_find=l,h
if(w(dress_find) >= v) then
exit
end if
end do
end function
BEGIN_PROVIDER [ integer, gen_per_cp ]
&BEGIN_PROVIDER [ integer, comb_teeth ]
&BEGIN_PROVIDER [ integer, N_cps_max ]
implicit none
comb_teeth = 16
N_cps_max = 32
gen_per_cp = (N_det_generators / N_cps_max) + 1
N_cps_max += 1
END_PROVIDER
BEGIN_PROVIDER [ integer, N_cp ]
&BEGIN_PROVIDER [ double precision, cps_N, (N_cps_max) ]
&BEGIN_PROVIDER [ integer, cp_first_tooth, (N_cps_max) ]
&BEGIN_PROVIDER [ integer, done_cp_at, (N_det_generators) ]
&BEGIN_PROVIDER [ double precision, cps, (N_det_generators, N_cps_max) ]
&BEGIN_PROVIDER [ integer, N_dress_jobs ]
&BEGIN_PROVIDER [ integer, dress_jobs, (N_det_generators) ]
&BEGIN_PROVIDER [ double precision, comb, (N_det_generators) ]
implicit none
logical, allocatable :: computed(:)
integer :: i, j, last_full, dets(comb_teeth)
integer :: k, l, cur_cp, under_det(comb_teeth+1)
integer, allocatable :: iorder(:), first_cp(:)
allocate(iorder(N_det_generators), first_cp(N_cps_max+1))
allocate(computed(N_det_generators))
first_cp = 1
cps = 0d0
cur_cp = 1
done_cp_at = 0
computed = .false.
N_dress_jobs = first_det_of_comb - 1
do i=1, N_dress_jobs
dress_jobs(i) = i
computed(i) = .true.
end do
l=first_det_of_comb
call RANDOM_NUMBER(comb)
do i=1,N_det_generators
comb(i) = comb(i) * comb_step
!DIR$ FORCEINLINE
call add_comb(comb(i), computed, cps(1, cur_cp), N_dress_jobs, dress_jobs)
if(N_dress_jobs / gen_per_cp > (cur_cp-1) .or. N_dress_jobs == N_det_generators) then
first_cp(cur_cp+1) = N_dress_jobs
done_cp_at(N_dress_jobs) = cur_cp
cps_N(cur_cp) = dfloat(i)
if(N_dress_jobs /= N_det_generators) then
cps(:, cur_cp+1) = cps(:, cur_cp)
cur_cp += 1
end if
if (N_dress_jobs == N_det_generators) exit
end if
do while (computed(l))
l=l+1
enddo
k=N_dress_jobs+1
dress_jobs(k) = l
computed(l) = .True.
N_dress_jobs = k
enddo
N_cp = cur_cp
if(N_dress_jobs /= N_det_generators .or. N_cp > N_cps_max) then
print *, N_dress_jobs, N_det_generators, N_cp, N_cps_max
stop "error in jobs creation"
end if
cur_cp = 0
do i=1,N_dress_jobs
if(done_cp_at(i) /= 0) cur_cp = done_cp_at(i)
done_cp_at(i) = cur_cp
end do
under_det = 0
cp_first_tooth = 0
do i=1,N_dress_jobs
do j=comb_teeth+1,1,-1
if(dress_jobs(i) <= first_det_of_teeth(j)) then
under_det(j) = under_det(j) + 1
if(under_det(j) == first_det_of_teeth(j))then
do l=done_cp_at(i)+1, N_cp
cps(:first_det_of_teeth(j)-1, l) = 0d0
cp_first_tooth(l) = j
end do
cps(first_det_of_teeth(j), done_cp_at(i)+1) = &
cps(first_det_of_teeth(j), done_cp_at(i)+1) * fractage(j)
end if
else
exit
end if
end do
end do
cps(:, N_cp) = 0d0
cp_first_tooth(N_cp) = comb_teeth+1
iorder = -1
do i=1,N_cp-1
call isort(dress_jobs(first_cp(i)+1:first_cp(i+1)),iorder,first_cp(i+1)-first_cp(i))
end do
END_PROVIDER
subroutine get_comb_val(stato, detail, cur_cp, val)
implicit none
integer, intent(in) :: cur_cp
integer :: first
double precision, intent(in) :: stato, detail(N_states, N_det_generators)
double precision, intent(out) :: val
double precision :: curs
integer :: j, k
integer, external :: dress_find
curs = 1d0 - stato
val = 0d0
first = cp_first_tooth(cur_cp)
do j = comb_teeth, first, -1
!DIR$ FORCEINLINE
k = dress_find(curs, dress_cweight,size(dress_cweight), first_det_of_teeth(j), first_det_of_teeth(j+1))
if(k == first_det_of_teeth(first)) then
val += detail(1, k) * dress_weight_inv(k) * comb_step * fractage(first)
else
val += detail(1, k) * dress_weight_inv(k) * comb_step
end if
curs -= comb_step
end do
end subroutine
subroutine get_comb(stato, dets)
implicit none
double precision, intent(in) :: stato
integer, intent(out) :: dets(comb_teeth)
double precision :: curs
integer :: j
integer, external :: dress_find
curs = 1d0 - stato
do j = comb_teeth, 1, -1
!DIR$ FORCEINLINE
dets(j) = dress_find(curs, dress_cweight,size(dress_cweight), first_det_of_teeth(j), first_det_of_teeth(j+1))
curs -= comb_step
end do
end subroutine
subroutine add_comb(com, computed, cp, N, tbc)
implicit none
double precision, intent(in) :: com
integer, intent(inout) :: N
double precision, intent(inout) :: cp(N_det)
logical, intent(inout) :: computed(N_det_generators)
integer, intent(inout) :: tbc(N_det_generators)
integer :: i, k, l, dets(comb_teeth)
!DIR$ FORCEINLINE
call get_comb(com, dets)
k=N+1
do i = 1, comb_teeth
l = dets(i)
cp(l) += 1d0
if(.not.(computed(l))) then
tbc(k) = l
k = k+1
computed(l) = .true.
end if
end do
N = k-1
end subroutine
BEGIN_PROVIDER [ integer, dress_stoch_istate ]
implicit none
dress_stoch_istate = 1
END_PROVIDER
BEGIN_PROVIDER [ double precision, dress_weight, (N_det_generators) ]
&BEGIN_PROVIDER [ double precision, dress_weight_inv, (N_det_generators) ]
&BEGIN_PROVIDER [ double precision, dress_cweight, (N_det_generators) ]
&BEGIN_PROVIDER [ double precision, dress_cweight_cache, (N_det_generators) ]
&BEGIN_PROVIDER [ double precision, fractage, (comb_teeth) ]
&BEGIN_PROVIDER [ double precision, comb_step ]
&BEGIN_PROVIDER [ integer, first_det_of_teeth, (comb_teeth+1) ]
&BEGIN_PROVIDER [ integer, first_det_of_comb ]
&BEGIN_PROVIDER [ integer, tooth_of_det, (N_det_generators) ]
implicit none
integer :: i
double precision :: norm_left, stato
integer, external :: dress_find
dress_weight(1) = psi_coef_generators(1,dress_stoch_istate)**2
dress_cweight(1) = psi_coef_generators(1,dress_stoch_istate)**2
do i=1,N_det_generators
dress_weight(i) = psi_coef_generators(i,dress_stoch_istate)**2
enddo
! Important to loop backwards for numerical precision
dress_cweight(N_det_generators) = dress_weight(N_det_generators)
do i=N_det_generators-1,1,-1
dress_cweight(i) = dress_weight(i) + dress_cweight(i+1)
end do
do i=1,N_det_generators
dress_weight(i) = dress_weight(i) / dress_cweight(1)
dress_cweight(i) = dress_cweight(i) / dress_cweight(1)
enddo
do i=1,N_det_generators-1
dress_cweight(i) = 1.d0 - dress_cweight(i+1)
end do
dress_cweight(N_det_generators) = 1.d0
norm_left = 1d0
comb_step = 1d0/dfloat(comb_teeth)
first_det_of_comb = 1
do i=1,N_det_generators
if(dress_weight(i)/norm_left < .25d0*comb_step) then
first_det_of_comb = i
exit
end if
norm_left -= dress_weight(i)
end do
first_det_of_comb = max(2,first_det_of_comb)
call write_int(6, first_det_of_comb-1, 'Size of deterministic set')
comb_step = (1d0 - dress_cweight(first_det_of_comb-1)) * comb_step
stato = 1d0 - comb_step
iloc = N_det_generators
do i=comb_teeth, 1, -1
integer :: iloc
iloc = dress_find(stato, dress_cweight, N_det_generators, 1, iloc)
first_det_of_teeth(i) = iloc
fractage(i) = (dress_cweight(iloc) - stato) / dress_weight(iloc)
stato -= comb_step
end do
first_det_of_teeth(comb_teeth+1) = N_det_generators + 1
first_det_of_teeth(1) = first_det_of_comb
if(first_det_of_teeth(1) /= first_det_of_comb) then
print *, 'Error in ', irp_here
stop "comb provider"
endif
do i=1,N_det_generators
dress_weight_inv(i) = 1.d0/dress_weight(i)
enddo
tooth_of_det(:first_det_of_teeth(1)-1) = 0
do i=1,comb_teeth
tooth_of_det(first_det_of_teeth(i):first_det_of_teeth(i+1)-1) = i
end do
END_PROVIDER

View File

@ -0,0 +1,24 @@
subroutine dress_zmq()
implicit none
double precision, allocatable :: energy(:)
allocate (energy(N_states))
read_wf = .True.
SOFT_TOUCH read_wf
call set_generators_bitmasks_as_holes_and_particles
if (.True.) then
integer :: i,j
do j=1,N_states
do i=1,N_det
psi_coef(i,j) = CI_eigenvectors(i,j)
enddo
enddo
SOFT_TOUCH psi_coef
endif
call run(N_states,energy)
if(do_pt2)then
call run_pt2(N_states,energy)
endif
deallocate(energy)
end

View File

@ -0,0 +1,103 @@
use bitmasks
BEGIN_PROVIDER [ integer, N_dress_teeth ]
N_dress_teeth = 10
END_PROVIDER
BEGIN_PROVIDER [ double precision, dress_norm_acc, (0:N_det_non_ref, N_states) ]
&BEGIN_PROVIDER [ double precision, dress_norm, (0:N_det_non_ref, N_states) ]
&BEGIN_PROVIDER [ double precision, dress_teeth_size, (0:N_det_non_ref, N_states) ]
&BEGIN_PROVIDER [ integer, dress_teeth, (0:N_dress_teeth+1, N_states) ]
implicit none
integer :: i, j, st, nt
double precision :: norm_sto, jump, norm_mwen, norm_loc
if(N_states /= 1) stop "dress_sto may not work with N_states /= 1"
do st=1,N_states
dress_teeth(0,st) = 1
norm_sto = 1d0
do i=1,N_det
dress_teeth(1,st) = i
jump = (1d0 / dfloat(N_dress_teeth)) * norm_sto
if(psi_coef_generators(i,1)**2 < jump / 2d0) exit
norm_sto -= psi_coef_generators(i,1)**2
end do
norm_loc = 0d0
dress_norm_acc(0,st) = 0d0
nt = 1
do i=1,dress_teeth(1,st)-1
dress_norm_acc(i,st) = dress_norm_acc(i-1,st) + psi_coef_generators(i,st)**2
end do
do i=dress_teeth(1,st), N_det_generators!-dress_teeth(1,st)+1
norm_mwen = psi_coef_generators(i,st)**2!-1+dress_teeth(1,st),st)**2
dress_norm_acc(i,st) = dress_norm_acc(i-1,st) + norm_mwen
norm_loc += norm_mwen
if(norm_loc > (jump*dfloat(nt))) then
nt = nt + 1
dress_teeth(nt,st) = i
end if
end do
if(nt > N_dress_teeth+1) then
print *, "foireouse dress_teeth", nt, dress_teeth(nt,st), N_det_non_ref
stop
end if
dress_teeth(N_dress_teeth+1,st) = N_det_non_ref+1
norm_loc = 0d0
do i=N_dress_teeth, 0, -1
dress_teeth_size(i,st) = dress_norm_acc(dress_teeth(i+1,st)-1,st) - dress_norm_acc(dress_teeth(i,st)-1, st)
dress_norm_acc(dress_teeth(i,st):dress_teeth(i+1,st)-1,st) -= dress_norm_acc(dress_teeth(i,st)-1, st)
dress_norm_acc(dress_teeth(i,st):dress_teeth(i+1,st)-1,st) = &
dress_norm_acc(dress_teeth(i,st):dress_teeth(i+1,st)-1,st) / dress_teeth_size(i,st)
dress_norm(dress_teeth(i,st), st) = dress_norm_acc(dress_teeth(i,st), st)
do j=dress_teeth(i,st)+1, dress_teeth(i+1,1)-1
dress_norm(j,1) = dress_norm_acc(j, st) - dress_norm_acc(j-1, st)
end do
end do
end do
END_PROVIDER
BEGIN_PROVIDER [ double precision, delta_ij, (N_states,N_det,2) ]
use bitmasks
implicit none
integer :: i,j,k
double precision, allocatable :: dress(:), del(:,:), del_s2(:,:)
double precision :: E_CI_before, relative_error
double precision, save :: errr = 0d0
allocate(dress(N_states), del(N_states, N_det), del_s2(N_states, N_det))
delta_ij = 0d0
E_CI_before = dress_E0_denominator(1) + nuclear_repulsion
threshold_selectors = 1.d0
threshold_generators = 1d0
if(errr /= 0d0) then
errr = errr / 2d0
else
errr = 1d-4
end if
relative_error = errr * 0d0
print *, "RELATIVE ERROR", relative_error
call ZMQ_dress(E_CI_before, dress, del, del_s2, abs(relative_error))
delta_ij(:,:,1) = del(:,:)
!delta_ij_s2(:,:,1) = del_s2(:,:)
delta_ij(:,:,2) = del_s2(:,:)
!do i=N_det,1,-1
! delta_ii(dress_stoch_istate,1) -= delta_ij(dress_stoch_istate, i, 1) / psi_ref_coef(1,dress_stoch_istate) * psi_coef(i, dress_stoch_istate)
! delta_ii_s2(dress_stoch_istate,1) -= delta_ij_s2(dress_stoch_istate, i, 1) / psi_ref_coef(1,dress_stoch_istate) * psi_coef(i, dress_stoch_istate)
!end do
END_PROVIDER

View File

@ -0,0 +1,29 @@
BEGIN_PROVIDER [ double precision, dressing_column_h, (N_det,N_states) ]
&BEGIN_PROVIDER [ double precision, dressing_column_s, (N_det,N_states) ]
implicit none
BEGIN_DOC
! Null dressing vectors
END_DOC
dressing_column_h(:,:) = 0.d0
dressing_column_s(:,:) = 0.d0
integer :: i,ii,k,j,jj, l
double precision :: f, tmp
double precision, external :: u_dot_v
do k=1,N_states
l = dressed_column_idx(k)
f = 1.d0/psi_coef(l,k)
do jj = 1, n_det
j = jj !idx_non_ref(jj)
dressing_column_h(j,k) = delta_ij (k,jj,1) * f
dressing_column_s(j,k) = delta_ij (k,jj,2) * f!delta_ij_s2(k,jj)
enddo
tmp = u_dot_v(dressing_column_h(1,k), psi_coef(1,k), N_det)
dressing_column_h(l,k) -= tmp * f
tmp = u_dot_v(dressing_column_s(1,k), psi_coef(1,k), N_det)
dressing_column_s(l,k) -= tmp * f
enddo
END_PROVIDER

View File

@ -0,0 +1,23 @@
BEGIN_PROVIDER [ logical, initialize_dress_E0_denominator ]
implicit none
BEGIN_DOC
! If true, initialize dress_E0_denominator
END_DOC
initialize_dress_E0_denominator = .True.
END_PROVIDER
BEGIN_PROVIDER [ double precision, dress_E0_denominator, (N_states) ]
implicit none
BEGIN_DOC
! E0 in the denominator of the dress
END_DOC
if (initialize_dress_E0_denominator) then
dress_E0_denominator(1:N_states) = psi_energy(1:N_states)
! dress_E0_denominator(1:N_states) = HF_energy - nuclear_repulsion
! dress_E0_denominator(1:N_states) = barycentric_electronic_energy(1:N_states)
call write_double(6,dress_E0_denominator(1)+nuclear_repulsion, 'dress Energy denominator')
else
dress_E0_denominator = -huge(1.d0)
endif
END_PROVIDER

View File

@ -0,0 +1,137 @@
BEGIN_PROVIDER [ integer, fragment_count ]
implicit none
BEGIN_DOC
! Number of fragments for the deterministic part
END_DOC
fragment_count = 1
END_PROVIDER
subroutine run_dress_slave(thread,iproc,energy)
use f77_zmq
implicit none
double precision, intent(in) :: energy(N_states_diag)
integer, intent(in) :: thread, iproc
integer :: rc, i, subset, i_generator
integer :: worker_id, task_id, ctask, ltask
character*(512) :: task
integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
integer(ZMQ_PTR), external :: new_zmq_push_socket
integer(ZMQ_PTR) :: zmq_socket_push
logical :: done
double precision,allocatable :: dress_detail(:)
integer :: ind
double precision,allocatable :: delta_ij_loc(:,:,:)
double precision :: div(N_states)
integer :: h,p,n,i_state
logical :: ok
allocate(delta_ij_loc(N_states,N_det,2))
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
zmq_socket_push = new_zmq_push_socket(thread)
call connect_to_taskserver(zmq_to_qp_run_socket,worker_id,thread)
if(worker_id == -1) then
print *, "WORKER -1"
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
call end_zmq_push_socket(zmq_socket_push,thread)
return
end if
do i=1,N_states
div(i) = psi_ref_coef(dressed_column_idx(i), i)
end do
do
call get_task_from_taskserver(zmq_to_qp_run_socket,worker_id, task_id, task)
if(task_id /= 0) then
read (task,*) subset, i_generator
delta_ij_loc = 0d0
call alpha_callback(delta_ij_loc, i_generator, subset, iproc)
!!! SET DRESSING COLUMN?
!do i=1,N_det
! do i_state=1,N_states
! delta_ij_loc(i_state,i,1) = delta_ij_loc(i_state,i,1) / div(i_state)
! delta_ij_loc(i_state,i,2) = delta_ij_loc(i_state,i,2) / div(i_state)
! end do
!end do
call task_done_to_taskserver(zmq_to_qp_run_socket,worker_id,task_id)
call push_dress_results(zmq_socket_push, i_generator, delta_ij_loc, task_id)
else
exit
end if
end do
call disconnect_from_taskserver(zmq_to_qp_run_socket,zmq_socket_push,worker_id)
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
call end_zmq_push_socket(zmq_socket_push,thread)
end subroutine
subroutine push_dress_results(zmq_socket_push, ind, delta_loc, task_id)
use f77_zmq
implicit none
integer(ZMQ_PTR), intent(in) :: zmq_socket_push
double precision, intent(in) :: delta_loc(N_states, N_det, 2)
integer, intent(in) :: ind, task_id
integer :: rc, i
rc = f77_zmq_send( zmq_socket_push, ind, 4, ZMQ_SNDMORE)
if(rc /= 4) stop "push"
rc = f77_zmq_send( zmq_socket_push, delta_loc, 8*N_states*N_det*2, ZMQ_SNDMORE)
if(rc /= 8*N_states*N_det*2) stop "push"
rc = f77_zmq_send( zmq_socket_push, task_id, 4, 0)
if(rc /= 4) stop "push"
! Activate is zmq_socket_push is a REQ
IRP_IF ZMQ_PUSH
IRP_ELSE
character*(2) :: ok
rc = f77_zmq_recv( zmq_socket_push, ok, 2, 0)
IRP_ENDIF
end subroutine
subroutine pull_dress_results(zmq_socket_pull, ind, delta_loc, task_id)
use f77_zmq
implicit none
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
double precision, intent(inout) :: delta_loc(N_states, N_det, 2)
integer, intent(out) :: ind
integer, intent(out) :: task_id
integer :: rc, i
rc = f77_zmq_recv( zmq_socket_pull, ind, 4, 0)
if(rc /= 4) stop "pull"
rc = f77_zmq_recv( zmq_socket_pull, delta_loc, N_states*8*N_det*2, 0)
if(rc /= 8*N_states*N_det*2) stop "pull"
rc = f77_zmq_recv( zmq_socket_pull, task_id, 4, 0)
if(rc /= 4) stop "pull"
! Activate is zmq_socket_pull is a REP
IRP_IF ZMQ_PUSH
IRP_ELSE
rc = f77_zmq_send( zmq_socket_pull, 'ok', 2, 0)
IRP_ENDIF
end subroutine

View File

@ -0,0 +1 @@
dress_zmq

View File

@ -0,0 +1,12 @@
========
mrcc_sto
========
Needed Modules
==============
.. Do not edit this section It was auto-generated
.. by the `update_README.py` script.
Documentation
=============
.. Do not edit this section It was auto-generated
.. by the `update_README.py` script.

View File

@ -0,0 +1,238 @@
program mrcc_sto
implicit none
BEGIN_DOC
! TODO
END_DOC
call dress_zmq()
end
BEGIN_PROVIDER [ double precision, hij_cache_, (N_det,Nproc) ]
&BEGIN_PROVIDER [ double precision, sij_cache_, (N_det,Nproc) ]
&BEGIN_PROVIDER [ double precision, dIa_hla_, (N_states,N_det,Nproc) ]
&BEGIN_PROVIDER [ double precision, dIa_sla_, (N_states,N_det,Nproc) ]
&BEGIN_PROVIDER [ integer, excs_ , (0:2,2,2,N_det,Nproc) ]
&BEGIN_PROVIDER [ double precision, phases_, (N_det, Nproc) ]
BEGIN_DOC
! temporay arrays for dress_with_alpha_buffer. Avoids realocation.
END_DOC
END_PROVIDER
subroutine dress_with_alpha_buffer(delta_ij_loc, minilist, det_minilist, n_minilist, alpha, iproc)
use bitmasks
implicit none
BEGIN_DOC
!delta_ij_loc(:,:,1) : dressing column for H
!delta_ij_loc(:,:,2) : dressing column for S2
!minilist : indices of determinants connected to alpha ( in psi_det_sorted )
!n_minilist : size of minilist
!alpha : alpha determinant
END_DOC
integer(bit_kind), intent(in) :: alpha(N_int,2), det_minilist(N_int, 2, n_minilist)
integer,intent(in) :: minilist(n_minilist), n_minilist, iproc
double precision, intent(inout) :: delta_ij_loc(N_states,N_det,2)
integer :: i,j,k,l,m
integer :: degree1, degree2, degree
double precision :: hIk, hla, hIl, sla, dIk(N_states), dka(N_states), dIa(N_states), hka
double precision :: phase, phase2
integer :: exc(0:2,2,2)
integer :: h1,h2,p1,p2,s1,s2
integer(bit_kind) :: tmp_det(N_int,2), ctrl
integer :: i_state, k_sd, l_sd, m_sd, ll_sd, i_I
double precision :: Delta_E_inv(N_states)
double precision :: sdress, hdress
logical :: ok, ok2
integer :: canbediamond
PROVIDE mo_class
if(n_minilist == 1) return
do i=1,n_minilist
if(idx_non_ref_rev(minilist(i)) == 0) return
end do
if (perturbative_triples) then
PROVIDE one_anhil fock_virt_total fock_core_inactive_total one_creat
endif
canbediamond = 0
do l_sd=1,n_minilist
call get_excitation(det_minilist(1,1,l_sd),alpha,exc,degree1,phase,N_int)
call decode_exc(exc,degree1,h1,p1,h2,p2,s1,s2)
ok = (mo_class(h1)(1:1) == 'A' .or. mo_class(h1)(1:1) == 'I') .and. &
(mo_class(p1)(1:1) == 'A' .or. mo_class(p1)(1:1) == 'V')
if(ok .and. degree1 == 2) then
ok = (mo_class(h2)(1:1) == 'A' .or. mo_class(h2)(1:1) == 'I') .and. &
(mo_class(p2)(1:1) == 'A' .or. mo_class(p2)(1:1) == 'V')
end if
if(ok) then
canbediamond += 1
excs_(:,:,:,l_sd,iproc) = exc(:,:,:)
phases_(l_sd, iproc) = phase
else
phases_(l_sd, iproc) = 0d0
end if
!call i_h_j(alpha,det_minilist(1,1,l_sd),N_int,hij_cache_(l_sd,iproc))
!call get_s2(alpha,det_minilist(1,1,l_sd),N_int,sij_cache_(l_sd,iproc))
call i_h_j_s2(alpha,det_minilist(1,1,l_sd),N_int,hij_cache_(l_sd,iproc), sij_cache_(l_sd,iproc))
enddo
if(canbediamond <= 1) return
do i_I=1,N_det_ref
call get_excitation_degree(alpha,psi_ref(1,1,i_I),degree1,N_int)
if (degree1 > 4) then
cycle
endif
do i_state=1,N_states
dIa(i_state) = 0.d0
enddo
do k_sd=1,n_minilist
if(phases_(k_sd,iproc) == 0d0) cycle
call get_excitation_degree(psi_ref(1,1,i_I),det_minilist(1,1,k_sd),degree,N_int)
if (degree > 2) then
cycle
endif
!call get_excitation(det_minilist(1,1,k_sd),alpha,exc,degree2,phase,N_int)
phase = phases_(k_sd, iproc)
exc(:,:,:) = excs_(:,:,:,k_sd,iproc)
degree2 = exc(0,1,1) + exc(0,1,2)
call apply_excitation(psi_ref(1,1,i_I), exc, tmp_det, ok, N_int)
if((.not. ok) .and. (.not. perturbative_triples)) cycle
do i_state=1,N_states
dka(i_state) = 0.d0
enddo
ok2 = .false.
!do i_state=1,N_states
! !if(dka(i_state) == 0) cycle
! dIk(i_state) = dij(i_I, idx_non_ref_rev(minilist(k_sd)), i_state)
! if(dIk(i_state) /= 0d0) then
! ok2 = .true.
! endif
!enddo
!if(.not. ok2) cycle
if (ok) then
phase2 = 0d0
do l_sd=k_sd+1,n_minilist
if(phases_(l_sd, iproc) == 0d0) cycle
call get_excitation_degree(tmp_det,det_minilist(1,1,l_sd),degree,N_int)
if (degree == 0) then
do i_state=1,N_states
dIk(i_state) = dij(i_I, idx_non_ref_rev(minilist(k_sd)), i_state)
if(dIk(i_state) /= 0d0) then
if(phase2 == 0d0) call get_excitation(psi_ref(1,1,i_I),det_minilist(1,1,l_sd),exc,degree,phase2,N_int)
dka(i_state) = dij(i_I, idx_non_ref_rev(minilist(l_sd)), i_state) * phase * phase2
end if
end do
!call get_excitation(psi_ref(1,1,i_I),det_minilist(1,1,l_sd),exc,degree,phase2,N_int)
!do i_state=1,N_states
! if(dIk(i_state) /= 0d0) dka(i_state) = dij(i_I, idx_non_ref_rev(minilist(l_sd)), i_state) * phase * phase2
!enddo
exit
endif
enddo
else if (perturbative_triples) then
hka = hij_cache_(k_sd,iproc)
if (dabs(hka) > 1.d-12) then
call get_delta_e_dyall_general_mp(psi_ref(1,1,i_I),alpha,Delta_E_inv)
do i_state=1,N_states
ASSERT (Delta_E_inv(i_state) < 0.d0)
dka(i_state) = hka / Delta_E_inv(i_state)
enddo
endif
endif
if (perturbative_triples.and. (degree2 == 1) ) then
call i_h_j(psi_ref(1,1,i_I),tmp_det,N_int,hka)
hka = hij_cache_(k_sd,iproc) - hka
if (dabs(hka) > 1.d-12) then
call get_delta_e_dyall_general_mp(psi_ref(1,1,i_I),alpha,Delta_E_inv)
do i_state=1,N_states
ASSERT (Delta_E_inv(i_state) < 0.d0)
dka(i_state) = hka / Delta_E_inv(i_state)
enddo
endif
endif
do i_state=1,N_states
dIa(i_state) = dIa(i_state) + dIk(i_state) * dka(i_state)
enddo
enddo
ok2 = .false.
do i_state=1,N_states
if(dIa(i_state) /= 0d0) ok2 = .true.
enddo
if(.not. ok2) cycle
do l_sd=1,n_minilist
k_sd = minilist(l_sd)
hla = hij_cache_(l_sd,iproc)
sla = sij_cache_(l_sd,iproc)
do i_state=1,N_states
hdress = dIa(i_state) * hla * psi_ref_coef(i_I,i_state)
sdress = dIa(i_state) * sla * psi_ref_coef(i_I,i_state)
!$OMP ATOMIC
delta_ij_loc(i_state,k_sd,1) += hdress
!$OMP ATOMIC
delta_ij_loc(i_state,k_sd,2) += sdress
enddo
enddo
enddo
end subroutine
!! TESTS MINILIST
subroutine test_minilist(minilist, n_minilist, alpha)
use bitmasks
implicit none
integer, intent(in) :: n_minilist
integer(bit_kind),intent(in) :: alpha(N_int, 2)
integer, intent(in) :: minilist(n_minilist)
integer :: a, i, deg
integer :: refc(N_det), testc(N_det)
refc = 0
testc = 0
do i=1,N_det
call get_excitation_degree(psi_det(1,1,i), alpha, deg, N_int)
if(deg <= 2) refc(i) = refc(i) + 1
end do
do i=1,n_minilist
call get_excitation_degree(psi_det(1,1,minilist(i)), alpha, deg, N_int)
if(deg <= 2) then
testc(minilist(i)) += 1
else
stop "NON LINKED IN MINILIST"
end if
end do
do i=1,N_det
if(refc(i) /= testc(i)) then
print *, "MINILIST FAIL ", sum(refc), sum(testc), n_minilist
exit
end if
end do
end subroutine

View File

@ -1 +1 @@
Perturbation Selectors_full Generators_full Psiref_CAS MRCC_Utils ZMQ DavidsonDressed DavidsonDressed Perturbation Selectors_full Generators_full Psiref_CAS MRCC_Utils ZMQ

View File

@ -345,6 +345,7 @@ subroutine mrcc_part_dress(delta_ij_, delta_ij_s2_, i_generator,n_selected,det_b
double precision, intent(inout) :: contrib(N_states) double precision, intent(inout) :: contrib(N_states)
double precision :: sdress, hdress double precision :: sdress, hdress
if (perturbative_triples) then if (perturbative_triples) then
PROVIDE one_anhil fock_virt_total fock_core_inactive_total one_creat PROVIDE one_anhil fock_virt_total fock_core_inactive_total one_creat
endif endif
@ -545,6 +546,7 @@ subroutine mrcc_part_dress(delta_ij_, delta_ij_s2_, i_generator,n_selected,det_b
k_sd = idx_alpha(l_sd) k_sd = idx_alpha(l_sd)
hdress = dIa_hla(i_state,k_sd) * psi_ref_coef(i_I,i_state) hdress = dIa_hla(i_state,k_sd) * psi_ref_coef(i_I,i_state)
sdress = dIa_sla(i_state,k_sd) * psi_ref_coef(i_I,i_state) sdress = dIa_sla(i_state,k_sd) * psi_ref_coef(i_I,i_state)
!!$OMP ATOMIC
!$OMP ATOMIC !$OMP ATOMIC
contrib(i_state) += hdress * psi_coef(dressed_column_idx(i_state), i_state) * psi_non_ref_coef(k_sd, i_state) contrib(i_state) += hdress * psi_coef(dressed_column_idx(i_state), i_state) * psi_non_ref_coef(k_sd, i_state)
!$OMP ATOMIC !$OMP ATOMIC
@ -555,6 +557,7 @@ subroutine mrcc_part_dress(delta_ij_, delta_ij_s2_, i_generator,n_selected,det_b
enddo enddo
enddo enddo
enddo enddo
deallocate (dIa_hla,dIa_sla,hij_cache,sij_cache) deallocate (dIa_hla,dIa_sla,hij_cache,sij_cache)
deallocate(miniList, idx_miniList) deallocate(miniList, idx_miniList)
end end
@ -577,8 +580,8 @@ END_PROVIDER
integer :: i,j,k integer :: i,j,k
double precision, allocatable :: mrcc(:) double precision, allocatable :: mrcc(:)
double precision :: E_CI_before, relative_error double precision :: E_CI_before!, relative_error
double precision, save :: errr = 0d0 double precision, save :: target_error = 0d0
allocate(mrcc(N_states)) allocate(mrcc(N_states))
@ -590,14 +593,13 @@ END_PROVIDER
E_CI_before = mrcc_E0_denominator(1) + nuclear_repulsion E_CI_before = mrcc_E0_denominator(1) + nuclear_repulsion
threshold_selectors = 1.d0 threshold_selectors = 1.d0
threshold_generators = 1d0 threshold_generators = 1d0
if(errr /= 0d0) then if(target_error /= 0d0) then
errr = errr / 2d0 ! (-mrcc_E0_denominator(1) + mrcc_previous_E(1)) / 1d1 target_error = target_error / 2d0 ! (-mrcc_E0_denominator(1) + mrcc_previous_E(1)) / 1d1
else else
errr = 1d-4 target_error = 1d-4
end if end if
relative_error = errr target_error = 0d0
print *, "RELATIVE ERROR", relative_error call ZMQ_mrcc(E_CI_before, mrcc, delta_ij_mrcc_zmq, delta_ij_s2_mrcc_zmq, abs(target_error))
call ZMQ_mrcc(E_CI_before, mrcc, delta_ij_mrcc_zmq, delta_ij_s2_mrcc_zmq, abs(relative_error))
mrcc_previous_E(:) = mrcc_E0_denominator(:) mrcc_previous_E(:) = mrcc_E0_denominator(:)
END_PROVIDER END_PROVIDER

View File

@ -1,3 +1,5 @@
BEGIN_PROVIDER [ double precision, dressing_column_h, (N_det,N_states) ] BEGIN_PROVIDER [ double precision, dressing_column_h, (N_det,N_states) ]
&BEGIN_PROVIDER [ double precision, dressing_column_s, (N_det,N_states) ] &BEGIN_PROVIDER [ double precision, dressing_column_s, (N_det,N_states) ]
implicit none implicit none
@ -24,6 +26,6 @@
tmp = u_dot_v(dressing_column_s(1,k), psi_coef(1,k), N_det) tmp = u_dot_v(dressing_column_s(1,k), psi_coef(1,k), N_det)
dressing_column_s(l,k) -= tmp * f dressing_column_s(l,k) -= tmp * f
enddo enddo
! stop
END_PROVIDER END_PROVIDER

View File

@ -26,6 +26,10 @@ subroutine run_wf
character*(64) :: states(1) character*(64) :: states(1)
integer :: rc, i integer :: rc, i
integer, external :: zmq_get_dvector, zmq_get_N_det_generators
integer, external :: zmq_get_psi, zmq_get_N_det_selectors
integer, external :: zmq_get_N_states_diag
call provide_everything call provide_everything
zmq_context = f77_zmq_ctx_new () zmq_context = f77_zmq_ctx_new ()
@ -34,20 +38,24 @@ subroutine run_wf
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket() zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
do do
call wait_for_states(states,zmq_state,1) call wait_for_states(states,zmq_state,1)
if(zmq_state(1:7) == 'Stopped') then
if(trim(zmq_state) == 'Stopped') then
exit exit
else if (trim(zmq_state) == 'mrcc') then else if (zmq_state(1:4) == 'mrcc') then
! Selection ! Selection
! --------- ! ---------
print *, 'mrcc' !call wall_time(t0)
call zmq_get_psi(zmq_to_qp_run_socket,1,energy,N_states) if (zmq_get_psi(zmq_to_qp_run_socket,1) == -1) cycle
if (zmq_get_N_det_generators (zmq_to_qp_run_socket, 1) == -1) cycle
if (zmq_get_N_det_selectors(zmq_to_qp_run_socket, 1) == -1) cycle
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'energy',energy,N_states) == -1) cycle
!call wall_time(t1)
!call write_double(6,(t1-t0),'Broadcast time')
PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique
PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order

View File

@ -1,38 +0,0 @@
program mrcc_stoch
implicit none
read_wf = .True.
SOFT_TOUCH read_wf
PROVIDE mo_bielec_integrals_in_map
call run
end
subroutine run
implicit none
integer :: i,j,k
logical, external :: detEq
double precision, allocatable :: mrcc(:)
integer :: degree
integer :: n_det_before, to_select
double precision :: threshold_davidson_in
double precision :: E_CI_before, relative_error
allocate (mrcc(N_states))
mrcc = 0.d0
!call random_seed()
E_CI_before = mrcc_E0_denominator(1) + nuclear_repulsion
threshold_selectors = 1.d0
threshold_generators = 1d0
relative_error = 5.d-2
call ZMQ_mrcc(E_CI_before, mrcc, relative_error)
!print *, 'Final step'
!print *, 'N_det = ', N_det
print *, 'mrcc = ', mrcc
!print *, 'E = ', E_CI_before
!print *, 'E+mrcc = ', E_CI_before+mrcc
!print *, '-----'
!call ezfio_set_full_ci_zmq_energy_mrcc(E_CI_before+mrcc(1))
end

View File

@ -13,7 +13,7 @@ BEGIN_PROVIDER [ integer, mrcc_stoch_istate ]
END_PROVIDER END_PROVIDER
subroutine ZMQ_mrcc(E, mrcc, delta, delta_s2, relative_error) subroutine ZMQ_mrcc(E, mrcc, delta, delta_s2, relative_error)
use dress_types !use dress_types
use f77_zmq use f77_zmq
implicit none implicit none
@ -32,7 +32,7 @@ subroutine ZMQ_mrcc(E, mrcc, delta, delta_s2, relative_error)
double precision, external :: omp_get_wtime double precision, external :: omp_get_wtime
double precision :: time double precision :: time
integer, external :: add_task_to_taskserver
state_average_weight(:) = 0.d0 state_average_weight(:) = 0.d0
state_average_weight(mrcc_stoch_istate) = 1.d0 state_average_weight(mrcc_stoch_istate) = 1.d0
@ -54,7 +54,7 @@ subroutine ZMQ_mrcc(E, mrcc, delta, delta_s2, relative_error)
integer, external :: zmq_put_N_det_generators integer, external :: zmq_put_N_det_generators
integer, external :: zmq_put_N_det_selectors integer, external :: zmq_put_N_det_selectors
integer, external :: zmq_put_dvector integer, external :: zmq_put_dvector
integer, external :: zmq_set_running
if (zmq_put_psi(zmq_to_qp_run_socket,1) == -1) then if (zmq_put_psi(zmq_to_qp_run_socket,1) == -1) then
stop 'Unable to put psi on ZMQ server' stop 'Unable to put psi on ZMQ server'
endif endif
@ -73,7 +73,6 @@ subroutine ZMQ_mrcc(E, mrcc, delta, delta_s2, relative_error)
! end do ! end do
integer(ZMQ_PTR), external :: new_zmq_to_qp_run_socket integer(ZMQ_PTR), external :: new_zmq_to_qp_run_socket
integer, external :: add_task_to_taskserver, zmq_set_running
integer :: ipos integer :: ipos
ipos=1 ipos=1
do i=1,N_mrcc_jobs do i=1,N_mrcc_jobs
@ -105,7 +104,6 @@ subroutine ZMQ_mrcc(E, mrcc, delta, delta_s2, relative_error)
stop 'Unable to add task to task server' stop 'Unable to add task to task server'
endif endif
endif endif
if (zmq_set_running(zmq_to_qp_run_socket) == -1) then if (zmq_set_running(zmq_to_qp_run_socket) == -1) then
print *, irp_here, ': Failed in zmq_set_running' print *, irp_here, ': Failed in zmq_set_running'
endif endif
@ -114,8 +112,7 @@ subroutine ZMQ_mrcc(E, mrcc, delta, delta_s2, relative_error)
!$OMP PRIVATE(i) !$OMP PRIVATE(i)
i = omp_get_thread_num() i = omp_get_thread_num()
if (i==0) then if (i==0) then
call mrcc_collector(zmq_socket_pull,E(mrcc_stoch_istate), relative_error, delta, delta_s2, mrcc) call mrcc_collector(zmq_socket_pull,E, relative_error, delta, delta_s2, mrcc)
else else
call mrcc_slave_inproc(i) call mrcc_slave_inproc(i)
endif endif
@ -146,15 +143,14 @@ subroutine mrcc_collector(zmq_socket_pull, E, relative_error, delta, delta_s2, m
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
double precision, intent(in) :: relative_error, E double precision, intent(in) :: relative_error, E(N_states)
double precision, intent(out) :: mrcc(N_states) double precision, intent(out) :: mrcc(N_states)
double precision, allocatable :: cp(:,:,:,:) double precision, allocatable :: cp(:,:,:,:)
double precision, intent(out) :: delta(N_states, N_det_non_ref) double precision, intent(out) :: delta(N_states, N_det_non_ref)
double precision, intent(out) :: delta_s2(N_states, N_det_non_ref) double precision, intent(out) :: delta_s2(N_states, N_det_non_ref)
double precision, allocatable :: delta_loc(:,:,:), delta_det(:,:,:,:) double precision, allocatable :: delta_loc(:,:,:,:), delta_det(:,:,:,:)
double precision, allocatable :: mrcc_detail(:,:) double precision, allocatable :: mrcc_detail(:,:)
double precision :: mrcc_mwen(N_states)
integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket
integer(ZMQ_PTR) :: zmq_to_qp_run_socket integer(ZMQ_PTR) :: zmq_to_qp_run_socket
@ -164,21 +160,31 @@ subroutine mrcc_collector(zmq_socket_pull, E, relative_error, delta, delta_s2, m
integer :: i, j, k, i_state, N, ntask integer :: i, j, k, i_state, N, ntask
integer, allocatable :: task_id(:) integer, allocatable :: task_id(:)
integer :: Nindex integer :: Nindex
integer, allocatable :: ind(:) integer :: ind
double precision, save :: time0 = -1.d0 double precision :: time, time0, timeInit, old_tooth
double precision :: time, timeLast, old_tooth
double precision, external :: omp_get_wtime double precision, external :: omp_get_wtime
integer :: cur_cp, old_cur_cp integer :: cur_cp, old_cur_cp
integer, allocatable :: parts_to_get(:) integer, allocatable :: parts_to_get(:)
logical, allocatable :: actually_computed(:) logical, allocatable :: actually_computed(:)
integer :: total_computed integer :: total_computed
integer, parameter :: delta_loc_N = 4
integer :: delta_loc_slot, delta_loc_i(delta_loc_N)
double precision :: mrcc_mwen(N_states, delta_loc_N), lcoef(delta_loc_N)
logical :: ok
double precision :: usf, num
integer(8), save :: rezo = 0_8
usf = 0d0
num = 0d0
print *, "TARGET ERROR :", relative_error
delta = 0d0
delta_s2 = 0d0
allocate(delta_det(N_states, N_det_non_ref, 0:comb_teeth+1, 2)) allocate(delta_det(N_states, N_det_non_ref, 0:comb_teeth+1, 2))
allocate(cp(N_states, N_det_non_ref, N_cp, 2), mrcc_detail(N_states, N_det_generators)) allocate(cp(N_states, N_det_non_ref, N_cp, 2), mrcc_detail(N_states, N_det_generators))
allocate(delta_loc(N_states, N_det_non_ref, 2)) allocate(delta_loc(N_states, N_det_non_ref, 2, delta_loc_N))
mrcc_detail = 0d0 mrcc_detail = 0d0
delta_det = 0d0 delta_det = 0d0
!mrcc_detail = mrcc_detail / 0d0
cp = 0d0 cp = 0d0
total_computed = 0 total_computed = 0
character*(512) :: task character*(512) :: task
@ -197,83 +203,116 @@ subroutine mrcc_collector(zmq_socket_pull, E, relative_error, delta, delta_s2, m
actually_computed = .false. actually_computed = .false.
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket() zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
allocate(task_id(N_det_generators), ind(1)) allocate(task_id(N_det_generators))
more = 1 more = 1
if (time0 < 0.d0) then time = omp_get_wtime()
call wall_time(time0) time0 = time
endif timeInit = time
timeLast = time0
cur_cp = 0 cur_cp = 0
old_cur_cp = 0 old_cur_cp = 0
delta_loc_slot = 1
delta_loc_i = 0
pullLoop : do while (more == 1) pullLoop : do while (more == 1)
call pull_mrcc_results(zmq_socket_pull, Nindex, ind, mrcc_mwen, delta_loc, task_id, ntask) call pull_mrcc_results(zmq_socket_pull, Nindex, ind, mrcc_mwen(1, delta_loc_slot), delta_loc(1,1,1,delta_loc_slot), task_id, ntask)
if(Nindex /= 1) stop "tried pull multiple Nindex" if(Nindex /= 1) stop "tried pull multiple Nindex"
delta_loc_i(delta_loc_slot) = ind
do i=1,Nindex
mrcc_detail(:, ind(i)) += mrcc_mwen(:)
do j=1,N_cp !! optimizable
if(cps(ind(i), j) > 0d0) then
if(tooth_of_det(ind(i)) < cp_first_tooth(j)) stop "coef on supposedely deterministic det"
double precision :: fac
integer :: toothMwen
logical :: fracted
fac = cps(ind(i), j) / cps_N(j) * mrcc_weight_inv(ind(i)) * comb_step
do k=1,N_det_non_ref
do i_state=1,N_states
cp(i_state,k,j,1) += delta_loc(i_state,k,1) * fac
cp(i_state,k,j,2) += delta_loc(i_state,k,2) * fac
end do
end do
end if
end do
toothMwen = tooth_of_det(ind(i))
fracted = (toothMwen /= 0)
if(fracted) fracted = (ind(i) == first_det_of_teeth(toothMwen))
if(fracted) then
delta_det(:,:,toothMwen-1, 1) += delta_loc(:,:,1) * (1d0-fractage(toothMwen))
delta_det(:,:,toothMwen-1, 2) += delta_loc(:,:,2) * (1d0-fractage(toothMwen))
delta_det(:,:,toothMwen, 1) += delta_loc(:,:,1) * (fractage(toothMwen))
delta_det(:,:,toothMwen, 2) += delta_loc(:,:,2) * (fractage(toothMwen))
else
delta_det(:,:,toothMwen, 1) += delta_loc(:,:,1)
delta_det(:,:,toothMwen, 2) += delta_loc(:,:,2)
end if
parts_to_get(ind(i)) -= 1
if(parts_to_get(ind(i)) == 0) then
actually_computed(ind(i)) = .true.
!print *, "CONTRIB", ind(i), psi_non_ref_coef(ind(i),1), mrcc_detail(1, ind(i))
total_computed += 1
end if
end do
integer, external :: zmq_delete_tasks integer, external :: zmq_delete_tasks
if (zmq_delete_tasks(zmq_to_qp_run_socket,zmq_socket_pull,task_id,ntask,more) == -1) then if (zmq_delete_tasks(zmq_to_qp_run_socket,zmq_socket_pull,task_id,ntask,more) == -1) then
stop 'Unable to delete tasks' stop 'Unable to delete tasks'
endif endif
time = omp_get_wtime() time = omp_get_wtime()
if(more /= 1 .or. delta_loc_slot == delta_loc_N) then
time0 = time
do i=1,delta_loc_N
if(delta_loc_i(i) /= 0) then
mrcc_detail(:, delta_loc_i(i)) += mrcc_mwen(:,i)
end if
end do
do j=1,N_cp !! optimizable
ok = .false.
do i=1,delta_loc_N
if(delta_loc_i(i) == 0) then
lcoef(i) = 0d0
else
lcoef(i) = cps(delta_loc_i(i), j) / cps_N(j) * mrcc_weight_inv(delta_loc_i(i)) * comb_step
if(lcoef(i) /= 0d0) then
ok = .true.
end if
end if
end do
if(.not. ok) cycle
double precision :: fac
integer :: toothMwen
logical :: fracted, toothMwendid(0:10000)
do k=1,N_det_non_ref
do i_state=1,N_states
cp(i_state,k,j,1) += delta_loc(i_state,k,1,1) * lcoef(1) + &
delta_loc(i_state,k,1,2) * lcoef(2) + &
delta_loc(i_state,k,1,3) * lcoef(3) + &
delta_loc(i_state,k,1,4) * lcoef(4)
end do
end do
do k=1,N_det_non_ref
do i_state=1,N_states
cp(i_state,k,j,2) += delta_loc(i_state,k,2,1) * lcoef(1) + &
delta_loc(i_state,k,2,2) * lcoef(2) + &
delta_loc(i_state,k,2,3) * lcoef(3) + &
delta_loc(i_state,k,2,4) * lcoef(4)
end do
end do
end do
do i=1,delta_loc_N
ind = delta_loc_i(i)
if(ind == 0) cycle
toothMwen = tooth_of_det(ind)
fracted = (toothMwen /= 0)
if(fracted) fracted = (ind == first_det_of_teeth(toothMwen))
if(fracted) then
delta_det(:,:,toothMwen-1, 1) += delta_loc(:,:,1,i) * (1d0-fractage(toothMwen))
delta_det(:,:,toothMwen-1, 2) += delta_loc(:,:,2,i) * (1d0-fractage(toothMwen))
delta_det(:,:,toothMwen, 1) += delta_loc(:,:,1,i) * (fractage(toothMwen))
delta_det(:,:,toothMwen, 2) += delta_loc(:,:,2,i) * (fractage(toothMwen))
else
delta_det(:,:,toothMwen, 1) += delta_loc(:,:,1,i)
delta_det(:,:,toothMwen, 2) += delta_loc(:,:,2,i)
end if
parts_to_get(ind) -= 1
if(parts_to_get(ind) == 0) then
actually_computed(ind) = .true.
total_computed += 1
end if
end do
delta_loc_slot = 1
delta_loc_i = 0
!if(time - time0 > 10d0 .or. more /= 1) then
if(time - timeLast > 1d0 .or. more /= 1) then
timeLast = time
cur_cp = N_cp cur_cp = N_cp
if(.not. actually_computed(mrcc_jobs(1))) cycle pullLoop !if(.not. actually_computed(mrcc_jobs(1))) cycle pullLoop
do i=2,N_det_generators do i=1,N_det_generators
if(.not. actually_computed(mrcc_jobs(i))) then if(.not. actually_computed(mrcc_jobs(i))) then
print *, "first not comp", i if(i==1) then
cur_cp = 0
else
cur_cp = done_cp_at(i-1) cur_cp = done_cp_at(i-1)
end if
exit exit
end if end if
end do end do
if(cur_cp == 0) cycle pullLoop if(cur_cp == 0) then
print *, "no checkpoint reached so far..."
cycle pullLoop
end if
!!!!!!!!!!!! !!!!!!!!!!!!
double precision :: su, su2, eqt, avg, E0, val double precision :: su, su2, eqt, avg, E0, val
integer, external :: zmq_abort integer, external :: zmq_abort
@ -281,14 +320,10 @@ subroutine mrcc_collector(zmq_socket_pull, E, relative_error, delta, delta_s2, m
su = 0d0 su = 0d0
su2 = 0d0 su2 = 0d0
if(N_states > 1) stop "mrcc_stoch : N_states == 1"
do i=1, int(cps_N(cur_cp)) do i=1, int(cps_N(cur_cp))
!if(.not. actually_computed(i)) stop "not computed"
!call get_comb_val(comb(i), mrcc_detail, cp_first_tooth(cur_cp), val)
call get_comb_val(comb(i), mrcc_detail, cur_cp, val) call get_comb_val(comb(i), mrcc_detail, cur_cp, val)
!val = mrcc_detail(1, i) * mrcc_weight_inv(i) * comb_step su += val
su += val ! cps(i, cur_cp) * val su2 += val**2
su2 += val**2 ! cps(i, cur_cp) * val**2
end do end do
avg = su / cps_N(cur_cp) avg = su / cps_N(cur_cp)
eqt = dsqrt( ((su2 / cps_N(cur_cp)) - avg**2) / cps_N(cur_cp) ) eqt = dsqrt( ((su2 / cps_N(cur_cp)) - avg**2) / cps_N(cur_cp) )
@ -296,32 +331,23 @@ subroutine mrcc_collector(zmq_socket_pull, E, relative_error, delta, delta_s2, m
if(cp_first_tooth(cur_cp) <= comb_teeth) then if(cp_first_tooth(cur_cp) <= comb_teeth) then
E0 = E0 + mrcc_detail(1, first_det_of_teeth(cp_first_tooth(cur_cp))) * (1d0-fractage(cp_first_tooth(cur_cp))) E0 = E0 + mrcc_detail(1, first_det_of_teeth(cp_first_tooth(cur_cp))) * (1d0-fractage(cp_first_tooth(cur_cp)))
end if end if
call wall_time(time)
if ((dabs(eqt) < relative_error .and. cps_N(cur_cp) >= 30) .or. total_computed == N_det_generators) then
! Termination
!print '(G10.3, 2X, F16.7, 2X, G16.3, 2X, F16.4, A20)', Nabove(tooth), avg+E, eqt, time-time0, ''
! print *, "GREPME", cur_cp, E+E0+avg, eqt, time-time0, total_computed print '(I5,F15.7,E12.4,F10.2)', cur_cp, E(mrcc_stoch_istate)+E0+avg, eqt, time-timeInit
if ((dabs(eqt) < relative_error .and. cps_N(cur_cp) >= 30) .or. total_computed == N_det_generators) then
if (zmq_abort(zmq_to_qp_run_socket) == -1) then if (zmq_abort(zmq_to_qp_run_socket) == -1) then
call sleep(1) call sleep(1)
if (zmq_abort(zmq_to_qp_run_socket) == -1) then if (zmq_abort(zmq_to_qp_run_socket) == -1) then
print *, irp_here, ': Error in sending abort signal (2)' print *, irp_here, ': Error in sending abort signal (2)'
endif endif
endif endif
endif
else else
if (cur_cp > old_cur_cp) then delta_loc_slot += 1
old_cur_cp = cur_cp
! print *, "GREPME", cur_cp, E+E0+avg, eqt, time-time0, total_computed
!print '(G10.3, 2X, F16.7, 2X, G16.3, 2X, F16.4, A20)', Nabove(tooth), avg+E, eqt, time-time0, ''
endif
endif
end if end if
end do pullLoop end do pullLoop
if(total_computed == N_det_generators) then if(total_computed == N_det_generators) then
print *, "TOTALLY COMPUTED"
delta = 0d0 delta = 0d0
delta_s2 = 0d0 delta_s2 = 0d0
do i=comb_teeth+1,0,-1 do i=comb_teeth+1,0,-1
@ -329,22 +355,15 @@ subroutine mrcc_collector(zmq_socket_pull, E, relative_error, delta, delta_s2, m
delta_s2 += delta_det(:,:,i,2) delta_s2 += delta_det(:,:,i,2)
end do end do
else else
delta = cp(:,:,cur_cp,1) delta = cp(:,:,cur_cp,1)
delta_s2 = cp(:,:,cur_cp,2) delta_s2 = cp(:,:,cur_cp,2)
do i=cp_first_tooth(cur_cp)-1,0,-1 do i=cp_first_tooth(cur_cp)-1,0,-1
delta += delta_det(:,:,i,1) delta += delta_det(:,:,i,1)
delta_s2 += delta_det(:,:,i,2) delta_s2 += delta_det(:,:,i,2)
end do end do
end if end if
mrcc = E
mrcc(1) = E
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket) call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
end subroutine end subroutine
@ -380,7 +399,7 @@ end function
&BEGIN_PROVIDER [ integer, N_cps_max ] &BEGIN_PROVIDER [ integer, N_cps_max ]
implicit none implicit none
comb_teeth = 16 comb_teeth = 16
N_cps_max = 32 N_cps_max = 64
!comb_per_cp = 64 !comb_per_cp = 64
gen_per_cp = (N_det_generators / N_cps_max) + 1 gen_per_cp = (N_det_generators / N_cps_max) + 1
N_cps_max += 1 N_cps_max += 1
@ -402,6 +421,8 @@ END_PROVIDER
integer :: i, j, last_full, dets(comb_teeth) integer :: i, j, last_full, dets(comb_teeth)
integer :: k, l, cur_cp, under_det(comb_teeth+1) integer :: k, l, cur_cp, under_det(comb_teeth+1)
integer, allocatable :: iorder(:), first_cp(:) integer, allocatable :: iorder(:), first_cp(:)
double precision :: tmp
allocate(iorder(N_det_generators), first_cp(N_cps_max+1)) allocate(iorder(N_det_generators), first_cp(N_cps_max+1))
allocate(computed(N_det_generators)) allocate(computed(N_det_generators))
@ -481,11 +502,10 @@ END_PROVIDER
cps(:, N_cp) = 0d0 cps(:, N_cp) = 0d0
cp_first_tooth(N_cp) = comb_teeth+1 cp_first_tooth(N_cp) = comb_teeth+1
iorder = -1132154665 !iorder = -1132154665
do i=1,N_cp-1 !do i=1,N_cp-1
call isort(mrcc_jobs(first_cp(i)+1:first_cp(i+1)),iorder,first_cp(i+1)-first_cp(i)) ! call isort(mrcc_jobs(first_cp(i)+1:first_cp(i+1)),iorder,first_cp(i+1)-first_cp(i))
end do !end do
! end subroutine
END_PROVIDER END_PROVIDER

View File

@ -69,7 +69,6 @@ subroutine run_mrcc_slave(thread,iproc,energy)
else else
integer :: i_generator, i_i_generator, subset integer :: i_generator, i_i_generator, subset
read (task,*) subset, ind read (task,*) subset, ind
! if(buf%N == 0) then ! if(buf%N == 0) then
! ! Only first time ! ! Only first time
! call create_selection_buffer(1, 2, buf) ! call create_selection_buffer(1, 2, buf)

View File

@ -474,6 +474,107 @@ subroutine bitstring_to_list_ab_old( string, list, n_elements, Nint)
end end
subroutine i_H_j_s2(key_i,key_j,Nint,hij,s2)
use bitmasks
implicit none
BEGIN_DOC
! Returns <i|H|j> where i and j are determinants
END_DOC
integer, intent(in) :: Nint
integer(bit_kind), intent(in) :: key_i(Nint,2), key_j(Nint,2)
double precision, intent(out) :: hij, s2
integer :: exc(0:2,2,2)
integer :: degree
double precision :: get_mo_bielec_integral
integer :: m,n,p,q
integer :: i,j,k
integer :: occ(Nint*bit_kind_size,2)
double precision :: diag_H_mat_elem, phase,phase_2
integer :: n_occ_ab(2)
PROVIDE mo_bielec_integrals_in_map mo_integrals_map big_array_exchange_integrals
ASSERT (Nint > 0)
ASSERT (Nint == N_int)
ASSERT (sum(popcnt(key_i(:,1))) == elec_alpha_num)
ASSERT (sum(popcnt(key_i(:,2))) == elec_beta_num)
ASSERT (sum(popcnt(key_j(:,1))) == elec_alpha_num)
ASSERT (sum(popcnt(key_j(:,2))) == elec_beta_num)
hij = 0.d0
s2 = 0d0
!DIR$ FORCEINLINE
call get_excitation_degree(key_i,key_j,degree,Nint)
integer :: spin
select case (degree)
case (2)
call get_double_excitation(key_i,key_j,exc,phase,Nint)
if (exc(0,1,1) == 1) then
! Mono alpha, mono beta
if(exc(1,1,1) == exc(1,2,2) )then
if(exc(1,1,2) == exc(1,2,1)) s2 = -phase !!!!!
hij = phase * big_array_exchange_integrals(exc(1,1,1),exc(1,1,2),exc(1,2,1))
else if (exc(1,2,1) ==exc(1,1,2))then
hij = phase * big_array_exchange_integrals(exc(1,2,1),exc(1,1,1),exc(1,2,2))
else
hij = phase*get_mo_bielec_integral( &
exc(1,1,1), &
exc(1,1,2), &
exc(1,2,1), &
exc(1,2,2) ,mo_integrals_map)
endif
else if (exc(0,1,1) == 2) then
! Double alpha
hij = phase*(get_mo_bielec_integral( &
exc(1,1,1), &
exc(2,1,1), &
exc(1,2,1), &
exc(2,2,1) ,mo_integrals_map) - &
get_mo_bielec_integral( &
exc(1,1,1), &
exc(2,1,1), &
exc(2,2,1), &
exc(1,2,1) ,mo_integrals_map) )
else if (exc(0,1,2) == 2) then
! Double beta
hij = phase*(get_mo_bielec_integral( &
exc(1,1,2), &
exc(2,1,2), &
exc(1,2,2), &
exc(2,2,2) ,mo_integrals_map) - &
get_mo_bielec_integral( &
exc(1,1,2), &
exc(2,1,2), &
exc(2,2,2), &
exc(1,2,2) ,mo_integrals_map) )
endif
case (1)
call get_mono_excitation(key_i,key_j,exc,phase,Nint)
!DIR$ FORCEINLINE
call bitstring_to_list_ab(key_i, occ, n_occ_ab, Nint)
if (exc(0,1,1) == 1) then
! Mono alpha
m = exc(1,1,1)
p = exc(1,2,1)
spin = 1
else
! Mono beta
m = exc(1,1,2)
p = exc(1,2,2)
spin = 2
endif
call get_mono_excitation_from_fock(key_i,key_j,p,m,spin,phase,hij)
case (0)
print *," ZERO"
double precision, external :: diag_S_mat_elem
s2 = diag_S_mat_elem(key_i,Nint)
hij = diag_H_mat_elem(key_i,Nint)
end select
end
subroutine i_H_j(key_i,key_j,Nint,hij) subroutine i_H_j(key_i,key_j,Nint,hij)
use bitmasks use bitmasks