2018-09-06 15:19:51 +02:00
|
|
|
BEGIN_PROVIDER [ integer, dress_stoch_istate ]
|
|
|
|
implicit none
|
|
|
|
BEGIN_DOC
|
|
|
|
! State for stochatsic dressing
|
|
|
|
END_DOC
|
|
|
|
dress_stoch_istate = 1
|
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
BEGIN_PROVIDER [ integer, pt2_N_teeth ]
|
|
|
|
&BEGIN_PROVIDER [ integer, pt2_minDetInFirstTeeth ]
|
|
|
|
&BEGIN_PROVIDER [ integer, pt2_n_tasks_max ]
|
|
|
|
&BEGIN_PROVIDER [ integer, pt2_F, (N_det_generators) ]
|
2017-12-15 16:21:04 +01:00
|
|
|
implicit none
|
2018-09-06 15:19:51 +02:00
|
|
|
logical, external :: testTeethBuilding
|
|
|
|
integer :: i
|
2018-09-14 15:45:38 +02:00
|
|
|
integer :: e
|
|
|
|
e = elec_num - n_core_orb * 2
|
|
|
|
pt2_n_tasks_max = 1 + min((e*(e-1))/2, int(dsqrt(dble(N_det_generators)))/10)
|
|
|
|
do i=1,N_det_generators
|
|
|
|
if (maxval(dabs(psi_coef_sorted_gen(i,1:N_states))) > 0.001d0) then
|
|
|
|
pt2_F(i) = pt2_n_tasks_max
|
|
|
|
else
|
|
|
|
pt2_F(i) = 1
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
|
2018-09-28 09:09:27 +02:00
|
|
|
if(N_det_generators < 128) then
|
2018-09-06 15:19:51 +02:00
|
|
|
pt2_minDetInFirstTeeth = 1
|
|
|
|
pt2_N_teeth = 1
|
|
|
|
else
|
|
|
|
pt2_minDetInFirstTeeth = min(5, N_det_generators)
|
2018-09-26 15:53:54 +02:00
|
|
|
do pt2_N_teeth=100,2,-1
|
2018-09-06 15:19:51 +02:00
|
|
|
if(testTeethBuilding(pt2_minDetInFirstTeeth, pt2_N_teeth)) exit
|
|
|
|
end do
|
|
|
|
end if
|
|
|
|
call write_int(6,pt2_N_teeth,'Number of comb teeth')
|
2017-12-15 16:21:04 +01:00
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
logical function testTeethBuilding(minF, N)
|
|
|
|
implicit none
|
|
|
|
integer, intent(in) :: minF, N
|
|
|
|
integer :: n0, i
|
|
|
|
double precision :: u0, Wt, r
|
|
|
|
|
|
|
|
double precision, allocatable :: tilde_w(:), tilde_cW(:)
|
|
|
|
integer, external :: dress_find_sample
|
|
|
|
|
|
|
|
allocate(tilde_w(N_det_generators), tilde_cW(0:N_det_generators))
|
|
|
|
|
|
|
|
do i=1,N_det_generators
|
|
|
|
tilde_w(i) = psi_coef_sorted_gen(i,dress_stoch_istate)**2 + 1.d-20
|
|
|
|
enddo
|
|
|
|
|
|
|
|
double precision :: norm
|
|
|
|
norm = 0.d0
|
|
|
|
do i=N_det_generators,1,-1
|
|
|
|
norm += tilde_w(i)
|
|
|
|
enddo
|
|
|
|
|
|
|
|
tilde_w(:) = tilde_w(:) / norm
|
|
|
|
|
|
|
|
tilde_cW(0) = -1.d0
|
|
|
|
do i=1,N_det_generators
|
|
|
|
tilde_cW(i) = tilde_cW(i-1) + tilde_w(i)
|
|
|
|
enddo
|
|
|
|
tilde_cW(:) = tilde_cW(:) + 1.d0
|
|
|
|
|
|
|
|
n0 = 0
|
|
|
|
testTeethBuilding = .false.
|
|
|
|
do
|
|
|
|
u0 = tilde_cW(n0)
|
|
|
|
r = tilde_cW(n0 + minF)
|
|
|
|
Wt = (1d0 - u0) / dble(N)
|
|
|
|
if (dabs(Wt) <= 1.d-3) then
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
if(Wt >= r - u0) then
|
|
|
|
testTeethBuilding = .true.
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
n0 += 1
|
|
|
|
if(N_det_generators - n0 < minF * N) then
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
stop "exited testTeethBuilding"
|
|
|
|
end function
|
|
|
|
|
|
|
|
BEGIN_PROVIDER[ integer, dress_N_cp_max ]
|
2018-09-26 15:53:54 +02:00
|
|
|
dress_N_cp_max = 28
|
2018-09-06 15:19:51 +02:00
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
BEGIN_PROVIDER[integer, pt2_J, (N_det_generators)]
|
|
|
|
&BEGIN_PROVIDER [integer, dress_R1, (0:N_det_generators) ]
|
|
|
|
implicit none
|
|
|
|
integer :: m,j
|
|
|
|
integer :: l,nmov
|
|
|
|
integer, allocatable :: iorder(:)
|
|
|
|
allocate(iorder(N_det_generators))
|
|
|
|
|
|
|
|
pt2_J = pt2_J_
|
|
|
|
dress_R1 = dress_R1_
|
2018-09-26 15:53:54 +02:00
|
|
|
!return
|
2018-09-06 15:19:51 +02:00
|
|
|
|
|
|
|
do m=1,dress_N_cp
|
|
|
|
nmov = 0
|
|
|
|
l=dress_R1(m-1)+1
|
|
|
|
do j=l, dress_R1(m)
|
|
|
|
if(dress_M_mi(m, pt2_J(j)) == 0 .and. pt2_J(j) > dress_dot_n_0(m)) then
|
|
|
|
pt2_J(j) += N_det_generators
|
|
|
|
nmov += 1
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
if(dress_R1(m)-dress_R1(m-1) > 0) then
|
|
|
|
call isort(pt2_J(l), iorder, dress_R1(m)-dress_R1(m-1))
|
|
|
|
end if
|
|
|
|
dress_R1(m) -= nmov
|
|
|
|
do j=dress_R1(m)+1, dress_R1(m) + nmov
|
|
|
|
pt2_J(j) -= N_det_generators
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
BEGIN_PROVIDER[ integer, dress_M_m, (dress_N_cp_max)]
|
|
|
|
&BEGIN_PROVIDER[ integer, pt2_J_, (N_det_generators)]
|
|
|
|
&BEGIN_PROVIDER[ double precision, pt2_u, (N_det_generators)]
|
|
|
|
&BEGIN_PROVIDER[ integer, dress_R1_, (0:N_det_generators)]
|
|
|
|
&BEGIN_PROVIDER[ double precision, dress_M_mi, (dress_N_cp_max, N_det_generators+1)]
|
|
|
|
&BEGIN_PROVIDER [ integer, dress_T, (N_det_generators) ]
|
|
|
|
&BEGIN_PROVIDER [ integer, dress_N_cp ]
|
|
|
|
implicit none
|
|
|
|
integer :: N_c, N_j, U, t, i, m
|
|
|
|
double precision :: v
|
|
|
|
double precision, allocatable :: tilde_M(:)
|
|
|
|
logical, allocatable :: d(:)
|
|
|
|
integer, external :: dress_find_sample
|
|
|
|
|
|
|
|
allocate(d(N_det_generators), tilde_M(N_det_generators))
|
|
|
|
|
|
|
|
dress_M_mi = 0d0
|
|
|
|
tilde_M = 0d0
|
|
|
|
dress_R1_(:) = 0
|
|
|
|
N_c = 0
|
|
|
|
N_j = pt2_n_0(1)
|
|
|
|
d(:) = .false.
|
|
|
|
|
|
|
|
! Set here the positions of the checkpoints
|
|
|
|
! U = N_det_generators/((dress_N_cp_max**2+dress_N_cp_max)/2)+1
|
|
|
|
! do i=1, dress_N_cp_max-1
|
|
|
|
! dress_M_m(i) = U * (((i*i)+i)/2) + 10
|
|
|
|
! end do
|
|
|
|
! dress_M_m(dress_N_cp_max) = N_det_generators+1
|
|
|
|
do i=1, dress_N_cp_max-1
|
|
|
|
dress_M_m(i) = ishft(1,i+3)
|
|
|
|
end do
|
|
|
|
dress_M_m(dress_N_cp_max) = N_det_generators+1
|
|
|
|
|
|
|
|
do i=1,N_j
|
|
|
|
d(i) = .true.
|
|
|
|
pt2_J_(i) = i
|
|
|
|
end do
|
2018-09-14 16:23:25 +02:00
|
|
|
|
|
|
|
integer, allocatable :: seed(:)
|
|
|
|
call random_seed(size=m)
|
|
|
|
allocate(seed(m))
|
|
|
|
do i=1,m
|
|
|
|
seed(i) = i
|
|
|
|
enddo
|
|
|
|
call random_seed(put=seed)
|
|
|
|
deallocate(seed)
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
call RANDOM_NUMBER(pt2_u)
|
|
|
|
call RANDOM_NUMBER(pt2_u)
|
|
|
|
|
|
|
|
U = 0
|
|
|
|
|
|
|
|
m = 1
|
|
|
|
do while(N_j < N_det_generators)
|
|
|
|
!ADD_COMB
|
|
|
|
N_c += 1
|
|
|
|
do t=0, pt2_N_teeth-1
|
|
|
|
v = pt2_u_0 + pt2_W_T * (dble(t) + pt2_u(N_c))
|
|
|
|
i = dress_find_sample(v, pt2_cW)
|
|
|
|
tilde_M(i) += 1d0
|
|
|
|
if(.not. d(i)) then
|
|
|
|
N_j += 1
|
|
|
|
pt2_J_(N_j) = i
|
|
|
|
d(i) = .true.
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
|
|
|
|
!FILL_TOOTH
|
|
|
|
do while(U < N_det_generators)
|
|
|
|
U += 1
|
|
|
|
if(.not. d(U)) then
|
|
|
|
N_j += 1
|
|
|
|
pt2_J_(N_j) = U
|
|
|
|
d(U) = .true.
|
|
|
|
exit;
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
|
|
|
|
if(N_c == dress_M_m(m)) then
|
|
|
|
dress_R1_(m) = N_j
|
|
|
|
dress_M_mi(m, :N_det_generators) = tilde_M(:)
|
|
|
|
m += 1
|
|
|
|
end if
|
|
|
|
enddo
|
|
|
|
|
|
|
|
dress_N_cp = m-1
|
2018-09-26 15:53:54 +02:00
|
|
|
if (dress_N_cp == 0) then
|
2018-09-26 16:39:57 +02:00
|
|
|
dress_N_cp = 1
|
2018-09-26 15:53:54 +02:00
|
|
|
endif
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
dress_R1_(dress_N_cp) = N_j
|
|
|
|
dress_M_m(dress_N_cp) = N_c
|
|
|
|
!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
do i=1, pt2_n_0(1)
|
|
|
|
dress_T(i) = 0
|
|
|
|
end do
|
|
|
|
|
|
|
|
do t=2,pt2_N_teeth+1
|
|
|
|
do i=pt2_n_0(t-1)+1, pt2_n_0(t)
|
|
|
|
dress_T(i) = t-1
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
!!!!!!!!!!!!!
|
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
|
|
|
|
subroutine ZMQ_dress(E, dress, delta_out, delta_s2_out, relative_error)
|
2017-12-15 16:21:04 +01:00
|
|
|
use f77_zmq
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
integer(ZMQ_PTR) :: zmq_to_qp_run_socket, zmq_socket_pull
|
|
|
|
integer, external :: omp_get_thread_num
|
2018-03-05 17:04:26 +01:00
|
|
|
double precision, intent(in) :: E(N_states), relative_error
|
2017-12-15 16:21:04 +01:00
|
|
|
double precision, intent(out) :: dress(N_states)
|
2018-03-23 13:37:03 +01:00
|
|
|
double precision, intent(out) :: delta_out(N_states, N_det)
|
|
|
|
double precision, intent(out) :: delta_s2_out(N_states, N_det)
|
2017-12-15 16:21:04 +01:00
|
|
|
|
2018-03-23 13:37:03 +01:00
|
|
|
double precision, allocatable :: delta(:,:)
|
|
|
|
double precision, allocatable :: delta_s2(:,:)
|
2017-12-15 16:21:04 +01:00
|
|
|
|
|
|
|
integer :: i, j, k, Ncp
|
|
|
|
|
2018-03-05 17:04:26 +01:00
|
|
|
double precision :: state_average_weight_save(N_states)
|
2018-09-14 19:44:55 +02:00
|
|
|
character(100000) :: task
|
2018-09-14 15:45:38 +02:00
|
|
|
PROVIDE Nproc
|
2018-04-27 12:41:39 +02:00
|
|
|
task(:) = CHAR(0)
|
2018-05-17 16:02:51 +02:00
|
|
|
allocate(delta(N_states,N_det), delta_s2(N_states, N_det))
|
2018-03-05 17:04:26 +01:00
|
|
|
state_average_weight_save(:) = state_average_weight(:)
|
|
|
|
do dress_stoch_istate=1,N_states
|
|
|
|
state_average_weight(:) = 0.d0
|
|
|
|
state_average_weight(dress_stoch_istate) = 1.d0
|
2018-09-06 15:19:51 +02:00
|
|
|
TOUCH state_average_weight dress_stoch_istate
|
2018-03-05 17:04:26 +01:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
provide nproc mo_bielec_integrals_in_map mo_mono_elec_integral psi_selectors pt2_F
|
2018-03-05 17:04:26 +01:00
|
|
|
|
|
|
|
print *, '========== ================= ================= ================='
|
|
|
|
print *, ' Samples Energy Stat. Error Seconds '
|
|
|
|
print *, '========== ================= ================= ================='
|
2018-05-17 16:02:51 +02:00
|
|
|
|
2018-03-05 17:04:26 +01:00
|
|
|
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
|
2018-09-14 15:45:38 +02:00
|
|
|
integer, external :: zmq_put_int
|
2018-05-17 16:02:51 +02:00
|
|
|
|
2018-03-05 17:04:26 +01:00
|
|
|
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
|
2018-05-17 16:02:51 +02:00
|
|
|
if (zmq_put_dvector(zmq_to_qp_run_socket,1,"state_average_weight",state_average_weight,N_states) == -1) then
|
|
|
|
stop 'Unable to put state_average_weight on ZMQ server'
|
|
|
|
endif
|
2018-09-25 09:49:33 +02:00
|
|
|
if (zmq_put_int(zmq_to_qp_run_socket,1,'dress_stoch_istate',dress_stoch_istate) == -1) then
|
2018-05-17 16:02:51 +02:00
|
|
|
stop 'Unable to put dress_stoch_istate on ZMQ server'
|
|
|
|
endif
|
2018-09-14 15:45:38 +02:00
|
|
|
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'threshold_selectors',threshold_selectors,1) == -1) then
|
|
|
|
stop 'Unable to put threshold_selectors on ZMQ server'
|
|
|
|
endif
|
|
|
|
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'threshold_generators',threshold_generators,1) == -1) then
|
|
|
|
stop 'Unable to put threshold_generators on ZMQ server'
|
|
|
|
endif
|
2018-05-17 16:02:51 +02:00
|
|
|
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
|
2018-09-14 15:45:38 +02:00
|
|
|
call write_int(6,pt2_n_tasks_max,'Max number of task fragments')
|
2018-09-06 15:19:51 +02:00
|
|
|
|
|
|
|
|
2018-09-14 15:45:38 +02:00
|
|
|
integer, external :: add_task_to_taskserver
|
|
|
|
integer :: ipos
|
|
|
|
ipos=0
|
|
|
|
do i=1,N_det_generators
|
|
|
|
if (pt2_F(i) > 1) then
|
|
|
|
ipos += 1
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
call write_int(6,ipos,'Number of fragmented tasks')
|
2018-09-06 15:19:51 +02:00
|
|
|
|
2018-09-14 15:45:38 +02:00
|
|
|
|
|
|
|
ipos=1
|
|
|
|
|
|
|
|
do i= 1, N_det_generators
|
|
|
|
do j=1,pt2_F(pt2_J(i))
|
|
|
|
write(task(ipos:ipos+20),'(I9,1X,I9,''|'')') j, pt2_J(i)
|
|
|
|
ipos += 20
|
|
|
|
if (ipos > len(task)-20) 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
|
|
|
|
enddo
|
|
|
|
if (ipos > 1) then
|
|
|
|
if (add_task_to_taskserver(zmq_to_qp_run_socket,trim(task(1:ipos))) == -1) then
|
2018-09-06 15:19:51 +02:00
|
|
|
stop 'Unable to add task to task server'
|
|
|
|
endif
|
2018-09-14 15:45:38 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
integer, external :: zmq_set_running
|
|
|
|
if (zmq_set_running(zmq_to_qp_run_socket) == -1) then
|
|
|
|
print *, irp_here, ': Failed in zmq_set_running'
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2018-03-05 17:04:26 +01:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
integer :: nproc_target
|
|
|
|
nproc_target = nproc
|
|
|
|
double precision :: mem
|
|
|
|
mem = 8.d0 * N_det * (N_int * 2.d0 * 3.d0 + 3.d0 + 5.d0) / (1024.d0**3)
|
|
|
|
call write_double(6,mem,'Estimated memory/thread (Gb)')
|
|
|
|
if (qp_max_mem > 0) then
|
|
|
|
nproc_target = max(1,int(dble(qp_max_mem)/mem))
|
|
|
|
nproc_target = min(nproc_target,nproc)
|
|
|
|
endif
|
|
|
|
|
2018-05-22 19:11:10 +02:00
|
|
|
call omp_set_nested(.true.)
|
2018-09-06 15:19:51 +02:00
|
|
|
|
2018-05-22 19:11:10 +02:00
|
|
|
!$OMP PARALLEL DEFAULT(shared) NUM_THREADS(2) &
|
|
|
|
!$OMP PRIVATE(i)
|
|
|
|
i = omp_get_thread_num()
|
|
|
|
if (i==0) then
|
2018-03-05 17:04:26 +01:00
|
|
|
call dress_collector(zmq_socket_pull,E, relative_error, delta, delta_s2, dress,&
|
2018-05-17 16:02:51 +02:00
|
|
|
dress_stoch_istate)
|
2018-05-22 19:11:10 +02:00
|
|
|
else
|
|
|
|
call dress_slave_inproc(i)
|
|
|
|
endif
|
|
|
|
!$OMP END PARALLEL
|
2018-09-06 15:19:51 +02:00
|
|
|
|
2018-03-23 13:37:03 +01:00
|
|
|
delta_out(dress_stoch_istate,1:N_det) = delta(dress_stoch_istate,1:N_det)
|
2018-05-17 16:02:51 +02:00
|
|
|
delta_s2_out(dress_stoch_istate,1:N_det) = delta_s2(dress_stoch_istate,1:N_det)
|
2018-09-06 15:19:51 +02:00
|
|
|
|
2018-03-05 17:04:26 +01:00
|
|
|
call end_parallel_job(zmq_to_qp_run_socket, zmq_socket_pull, 'dress')
|
|
|
|
|
|
|
|
print *, '========== ================= ================= ================='
|
|
|
|
enddo
|
|
|
|
FREE dress_stoch_istate
|
|
|
|
state_average_weight(:) = state_average_weight_save(:)
|
2018-09-06 15:19:51 +02:00
|
|
|
! call omp_set_nested(.false.)
|
2018-03-05 17:04:26 +01:00
|
|
|
TOUCH state_average_weight
|
2018-03-23 13:37:03 +01:00
|
|
|
deallocate(delta,delta_s2)
|
2017-12-15 16:21:04 +01:00
|
|
|
|
|
|
|
end subroutine
|
|
|
|
|
|
|
|
|
|
|
|
subroutine dress_slave_inproc(i)
|
|
|
|
implicit none
|
|
|
|
integer, intent(in) :: i
|
2018-03-05 17:04:26 +01:00
|
|
|
|
2017-12-15 16:21:04 +01:00
|
|
|
call run_dress_slave(1,i,dress_e0_denominator)
|
|
|
|
end
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
BEGIN_PROVIDER [integer, dress_dot_F, (dress_N_cp)]
|
|
|
|
&BEGIN_PROVIDER [ integer, dress_P, (N_det_generators) ]
|
|
|
|
implicit none
|
|
|
|
integer :: m,i
|
|
|
|
|
|
|
|
do m=1,dress_N_cp
|
|
|
|
do i=dress_R1(m-1)+1, dress_R1(m)
|
|
|
|
dress_P(pt2_J(i)) = m
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
|
|
|
|
dress_dot_F = 0
|
|
|
|
do m=1,dress_N_cp
|
|
|
|
do i=dress_R1(m-1)+1,dress_R1(m)
|
|
|
|
dress_dot_F(m) += pt2_F(pt2_J(i))
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
do m=2,dress_N_cp
|
|
|
|
dress_dot_F(m) += dress_dot_F(m-1)
|
|
|
|
end do
|
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
BEGIN_PROVIDER [double precision, dress_e, (N_det_generators, dress_N_cp)]
|
|
|
|
&BEGIN_PROVIDER [integer, dress_dot_t, (0:dress_N_cp)]
|
|
|
|
&BEGIN_PROVIDER [integer, dress_dot_n_0, (0:dress_N_cp)]
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
logical, allocatable :: d(:)
|
|
|
|
integer :: U, m, t, i
|
|
|
|
|
|
|
|
allocate(d(N_det_generators+1))
|
|
|
|
|
|
|
|
dress_e(:,:) = 0d0
|
|
|
|
dress_dot_t(:) = 0
|
|
|
|
dress_dot_n_0(:) = 0
|
|
|
|
d(:) = .false.
|
|
|
|
U=0
|
|
|
|
|
|
|
|
do m=1,dress_N_cp
|
|
|
|
do i=dress_R1_(m-1)+1,dress_R1_(m)
|
|
|
|
!dress_dot_F(m) += pt2_F(pt2_J_(i))
|
|
|
|
d(pt2_J_(i)) = .true.
|
|
|
|
end do
|
|
|
|
|
|
|
|
do while(d(U+1))
|
|
|
|
U += 1
|
|
|
|
end do
|
|
|
|
|
|
|
|
dress_dot_t(m) = pt2_N_teeth + 1
|
|
|
|
dress_dot_n_0(m) = N_det_generators
|
|
|
|
|
|
|
|
do t = 2, pt2_N_teeth+1
|
|
|
|
if(U < pt2_n_0(t)) then
|
|
|
|
dress_dot_t(m) = t-1
|
|
|
|
dress_dot_n_0(m) = pt2_n_0(t-1)
|
|
|
|
exit
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
do i=dress_dot_n_0(m)+1, N_det_generators !pt2_n_0(t+1)
|
|
|
|
dress_e(i,m) = pt2_W_T * dress_M_mi(m,i) / pt2_w(i)
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
|
|
|
|
do m=dress_N_cp, 2, -1
|
|
|
|
dress_e(:,m) -= dress_e(:,m-1)
|
|
|
|
end do
|
|
|
|
END_PROVIDER
|
2017-12-15 16:21:04 +01:00
|
|
|
|
|
|
|
|
2018-03-05 17:04:26 +01:00
|
|
|
subroutine dress_collector(zmq_socket_pull, E, relative_error, delta, delta_s2, dress, istate)
|
2017-12-15 16:21:04 +01:00
|
|
|
use f77_zmq
|
|
|
|
use bitmasks
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
|
|
|
|
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
|
2018-03-05 17:04:26 +01:00
|
|
|
integer, intent(in) :: istate
|
2017-12-15 16:21:04 +01:00
|
|
|
|
2018-03-05 17:04:26 +01:00
|
|
|
double precision, intent(in) :: relative_error, E(N_states)
|
2017-12-15 16:21:04 +01:00
|
|
|
double precision, intent(out) :: dress(N_states)
|
|
|
|
|
2018-02-14 10:33:11 +01:00
|
|
|
double precision, intent(out) :: delta(N_states, N_det)
|
|
|
|
double precision, intent(out) :: delta_s2(N_states, N_det)
|
2018-09-06 15:19:51 +02:00
|
|
|
double precision, allocatable :: breve_delta_m(:,:,:), S(:), S2(:)
|
|
|
|
double precision, allocatable :: edI(:), edI_task(:)
|
|
|
|
integer, allocatable :: edI_index(:)
|
2017-12-15 16:21:04 +01:00
|
|
|
integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket
|
|
|
|
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
integer(ZMQ_PTR), external :: new_zmq_pull_socket, zmq_abort
|
|
|
|
integer, allocatable :: task_id(:)
|
|
|
|
integer :: i, c, j, k, f, t, m, p, m_task
|
|
|
|
integer :: more, n_tasks
|
|
|
|
double precision :: E0, error, x, v, time, time0
|
|
|
|
double precision :: avg, eqt
|
2017-12-15 16:21:04 +01:00
|
|
|
double precision, external :: omp_get_wtime
|
2018-09-06 15:19:51 +02:00
|
|
|
integer, allocatable :: dot_f(:)
|
|
|
|
integer, external :: zmq_delete_tasks, dress_find_sample
|
2018-09-28 09:09:27 +02:00
|
|
|
logical :: do_exit
|
2018-09-06 15:19:51 +02:00
|
|
|
integer :: worker_id
|
2018-09-25 09:49:33 +02:00
|
|
|
worker_id=1
|
2018-09-06 15:19:51 +02:00
|
|
|
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
|
2018-03-27 16:22:14 +02:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
|
2018-09-28 09:09:27 +02:00
|
|
|
do_exit = .false.
|
2017-12-15 16:21:04 +01:00
|
|
|
delta = 0d0
|
|
|
|
delta_s2 = 0d0
|
2018-09-06 15:19:51 +02:00
|
|
|
allocate(task_id(pt2_n_tasks_max))
|
|
|
|
allocate(edI(N_det_generators))
|
|
|
|
allocate(edI_task(N_det_generators), edI_index(N_det_generators))
|
|
|
|
allocate(breve_delta_m(N_states, N_det, 2))
|
|
|
|
allocate(dot_f(dress_N_cp+1))
|
|
|
|
allocate(S(pt2_N_teeth+1), S2(pt2_N_teeth+1))
|
|
|
|
edI = 0d0
|
|
|
|
|
|
|
|
dot_f(:dress_N_cp) = dress_dot_F(:)
|
|
|
|
dot_f(dress_N_cp+1) = 1
|
|
|
|
more = 1
|
|
|
|
m = 1
|
|
|
|
c = 0
|
|
|
|
S(:) = 0d0
|
|
|
|
S2(:) = 0d0
|
|
|
|
time = omp_get_wtime()
|
|
|
|
time0 = -1d0 ! omp_get_wtime()
|
2017-12-15 16:21:04 +01:00
|
|
|
more = 1
|
|
|
|
|
2018-09-28 09:09:27 +02:00
|
|
|
do
|
2018-09-06 15:19:51 +02:00
|
|
|
if(dot_f(m) == 0) then
|
|
|
|
E0 = 0
|
|
|
|
do i=dress_dot_n_0(m),1,-1
|
|
|
|
E0 += edI(i)
|
2017-12-15 16:21:04 +01:00
|
|
|
end do
|
2018-09-06 15:19:51 +02:00
|
|
|
do while(c < dress_M_m(m))
|
|
|
|
c = c+1
|
|
|
|
x = 0d0
|
|
|
|
do p=pt2_N_teeth, 1, -1
|
|
|
|
v = pt2_u_0 + pt2_W_T * (pt2_u(c) + dble(p-1))
|
|
|
|
i = dress_find_sample(v, pt2_cW)
|
|
|
|
x += edI(i) * pt2_W_T / pt2_w(i)
|
|
|
|
S(p) += x
|
|
|
|
S2(p) += x**2
|
|
|
|
end do
|
2017-12-15 16:21:04 +01:00
|
|
|
end do
|
2018-09-06 15:19:51 +02:00
|
|
|
t = dress_dot_t(m)
|
|
|
|
avg = E0 + S(t) / dble(c)
|
2018-09-28 09:09:27 +02:00
|
|
|
if ((avg /= 0.d0) .or. (m == dress_N_cp) ) then
|
|
|
|
do_exit = .true.
|
|
|
|
endif
|
2018-09-06 15:19:51 +02:00
|
|
|
if (c > 2) then
|
|
|
|
eqt = dabs((S2(t) / c) - (S(t)/c)**2)
|
2018-09-26 15:53:54 +02:00
|
|
|
error = sqrt(eqt / (dble(c)-1.5d0))
|
2018-09-06 15:19:51 +02:00
|
|
|
time = omp_get_wtime()
|
2018-09-26 15:53:54 +02:00
|
|
|
print '(G10.3, 2X, F16.10, 2X, G16.3, 2X, F16.4, A20)', c, avg+E(istate), error, time-time0, ''
|
|
|
|
else if ( m==dress_N_cp ) then
|
|
|
|
error = 0.d0
|
2018-09-06 15:19:51 +02:00
|
|
|
else
|
2018-09-26 15:53:54 +02:00
|
|
|
error =1.d0
|
2017-12-15 16:21:04 +01:00
|
|
|
endif
|
2018-09-06 15:19:51 +02:00
|
|
|
m += 1
|
2018-09-28 09:09:27 +02:00
|
|
|
if(do_exit .and. (dabs(error) / (1.d-20 + dabs(avg) ) <= relative_error)) then
|
2018-09-06 15:19:51 +02:00
|
|
|
integer, external :: zmq_put_dvector
|
2018-09-14 15:45:38 +02:00
|
|
|
integer, external :: zmq_put_int
|
2018-09-25 09:49:33 +02:00
|
|
|
i= zmq_put_int(zmq_to_qp_run_socket, worker_id, 'ending', (m-1))
|
2018-09-28 09:09:27 +02:00
|
|
|
exit
|
2018-09-06 15:19:51 +02:00
|
|
|
end if
|
2017-12-15 16:21:04 +01:00
|
|
|
else
|
2018-09-06 15:19:51 +02:00
|
|
|
do
|
|
|
|
call pull_dress_results(zmq_socket_pull, m_task, f, edI_task, edI_index, breve_delta_m, task_id, n_tasks)
|
|
|
|
if(time0 == -1d0) then
|
|
|
|
time0 = omp_get_wtime()
|
|
|
|
end if
|
|
|
|
if(m_task == 0) then
|
|
|
|
if (zmq_delete_tasks(zmq_to_qp_run_socket,zmq_socket_pull,task_id,n_tasks,more) == -1) then
|
|
|
|
stop 'Unable to delete tasks'
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
!if(task_id(1) /= 0) stop "TASKID"
|
|
|
|
!i= zmq_delete_tasks(zmq_to_qp_run_socket,zmq_socket_pull,task_id,1,more)
|
|
|
|
exit
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
do i=1,n_tasks
|
|
|
|
edI(edI_index(i)) += edI_task(i)
|
|
|
|
end do
|
|
|
|
dot_f(m_task) -= f
|
2017-12-15 16:21:04 +01:00
|
|
|
end if
|
|
|
|
end do
|
2018-09-06 15:19:51 +02:00
|
|
|
if (zmq_abort(zmq_to_qp_run_socket) == -1) then
|
2018-09-14 15:45:38 +02:00
|
|
|
call sleep(10)
|
2018-09-06 15:19:51 +02:00
|
|
|
if (zmq_abort(zmq_to_qp_run_socket) == -1) then
|
|
|
|
print *, irp_here, ': Error in sending abort signal (2)'
|
|
|
|
endif
|
|
|
|
endif
|
2018-05-02 14:32:41 +02:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
integer :: ff
|
2018-05-02 14:32:41 +02:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
ff = dress_dot_F(m-1)
|
|
|
|
delta= 0d0
|
|
|
|
delta_s2 = 0d0
|
|
|
|
do while(more /= 0)
|
|
|
|
call pull_dress_results(zmq_socket_pull, m_task, f, edI_task, edI_index, breve_delta_m, task_id, n_tasks)
|
2018-03-28 16:23:30 +02:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
!if(task_id(0) == 0) cycle
|
|
|
|
if(m_task == 0) then
|
|
|
|
i = zmq_delete_tasks(zmq_to_qp_run_socket,zmq_socket_pull,task_id,n_tasks,more)
|
|
|
|
else if(m_task < 0) then
|
|
|
|
i = zmq_delete_tasks(zmq_to_qp_run_socket,zmq_socket_pull,task_id,1,more)
|
2018-03-28 16:23:30 +02:00
|
|
|
end if
|
2018-05-22 19:11:10 +02:00
|
|
|
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
if(m_task >= 0) cycle
|
|
|
|
ff = ff - f
|
|
|
|
delta(:,:) += breve_delta_m(:,:,1)
|
|
|
|
delta_s2(:,:) += breve_delta_m(:,:,2)
|
2018-03-27 16:22:14 +02:00
|
|
|
end do
|
2018-09-06 15:19:51 +02:00
|
|
|
dress(istate) = E(istate)+E0+avg
|
|
|
|
if(ff /= 0) stop "WRONG NUMBER OF FRAGMENTS COLLECTED"
|
|
|
|
!double precision :: tmp
|
2018-04-27 12:41:39 +02:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
!tmp = 0d0
|
|
|
|
|
|
|
|
!do i=1,N_det
|
|
|
|
! if(edi(i) == 0d0) stop "EMPTY"
|
|
|
|
! tmp += psi_coef(i, 1) * delta(1, i)
|
|
|
|
!end do
|
|
|
|
!print *, "SUM", E(1)+sum(edi(:))
|
|
|
|
!print *, "DOT", E(1)+tmp
|
|
|
|
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
|
2017-12-15 16:21:04 +01:00
|
|
|
end subroutine
|
|
|
|
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
integer function dress_find_sample(v, w)
|
2017-12-15 16:21:04 +01:00
|
|
|
implicit none
|
2018-09-06 15:19:51 +02:00
|
|
|
double precision, intent(in) :: v, w(0:N_det_generators)
|
|
|
|
integer :: i,l,r
|
2017-12-15 16:21:04 +01:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
l = 0
|
|
|
|
r = N_det_generators
|
2017-12-15 16:21:04 +01:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
do while(r-l > 1)
|
|
|
|
i = (r+l) / 2
|
|
|
|
if(w(i) < v) then
|
|
|
|
l = i
|
|
|
|
else
|
|
|
|
r = i
|
2017-12-15 16:21:04 +01:00
|
|
|
end if
|
|
|
|
end do
|
2018-09-06 15:19:51 +02:00
|
|
|
i = r
|
|
|
|
do r=i+1,N_det_generators
|
|
|
|
if (w(r) /= w(i)) then
|
|
|
|
exit
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
dress_find_sample = r-1
|
|
|
|
end function
|
2017-12-15 16:21:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
BEGIN_PROVIDER [ double precision, pt2_w, (N_det_generators) ]
|
|
|
|
&BEGIN_PROVIDER [ double precision, pt2_cW, (0:N_det_generators) ]
|
|
|
|
&BEGIN_PROVIDER [ double precision, pt2_W_T ]
|
|
|
|
&BEGIN_PROVIDER [ double precision, pt2_u_0 ]
|
|
|
|
&BEGIN_PROVIDER [ integer, pt2_n_0, (pt2_N_teeth+1) ]
|
2017-12-15 16:21:04 +01:00
|
|
|
implicit none
|
2018-09-06 15:19:51 +02:00
|
|
|
integer :: i, t
|
|
|
|
double precision, allocatable :: tilde_w(:), tilde_cW(:)
|
|
|
|
double precision :: r, tooth_width
|
|
|
|
integer, external :: dress_find_sample
|
2017-12-15 16:21:04 +01:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
allocate(tilde_w(N_det_generators), tilde_cW(0:N_det_generators))
|
2017-12-15 16:21:04 +01:00
|
|
|
|
|
|
|
do i=1,N_det_generators
|
2018-09-06 15:19:51 +02:00
|
|
|
tilde_w(i) = psi_coef_sorted_gen(i,dress_stoch_istate)**2 + 1.d-20
|
|
|
|
tilde_cW(i) = tilde_cW(i-1) + tilde_w(i)
|
2017-12-15 16:21:04 +01:00
|
|
|
enddo
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
double precision :: norm
|
|
|
|
norm = 0.d0
|
|
|
|
do i=N_det_generators,1,-1
|
|
|
|
norm += tilde_w(i)
|
2017-12-15 16:21:04 +01:00
|
|
|
enddo
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
tilde_w(:) = tilde_w(:) / norm
|
|
|
|
|
|
|
|
tilde_cW(0) = -1.d0
|
|
|
|
do i=1,N_det_generators
|
|
|
|
tilde_cW(i) = tilde_cW(i-1) + tilde_w(i)
|
|
|
|
enddo
|
|
|
|
tilde_cW(:) = tilde_cW(:) + 1.d0
|
2017-12-15 16:21:04 +01:00
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
pt2_n_0(1) = 0
|
|
|
|
do
|
|
|
|
pt2_u_0 = tilde_cW(pt2_n_0(1))
|
|
|
|
r = tilde_cW(pt2_n_0(1) + pt2_minDetInFirstTeeth)
|
|
|
|
pt2_W_T = (1d0 - pt2_u_0) / dble(pt2_N_teeth)
|
|
|
|
if(pt2_W_T >= r - pt2_u_0) then
|
2017-12-15 16:21:04 +01:00
|
|
|
exit
|
|
|
|
end if
|
2018-09-06 15:19:51 +02:00
|
|
|
pt2_n_0(1) += 1
|
|
|
|
if(N_det_generators - pt2_n_0(1) < pt2_minDetInFirstTeeth * pt2_N_teeth) then
|
|
|
|
stop "teeth building failed"
|
|
|
|
end if
|
2017-12-15 16:21:04 +01:00
|
|
|
end do
|
2018-09-06 15:19:51 +02:00
|
|
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
do t=2, pt2_N_teeth
|
|
|
|
r = pt2_u_0 + pt2_W_T * dble(t-1)
|
|
|
|
pt2_n_0(t) = dress_find_sample(r, tilde_cW)
|
|
|
|
end do
|
|
|
|
pt2_n_0(pt2_N_teeth+1) = N_det_generators
|
|
|
|
|
|
|
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
pt2_w(:pt2_n_0(1)) = tilde_w(:pt2_n_0(1))
|
|
|
|
do t=1, pt2_N_teeth
|
|
|
|
tooth_width = tilde_cW(pt2_n_0(t+1)) - tilde_cW(pt2_n_0(t))
|
|
|
|
if (tooth_width == 0.d0) then
|
|
|
|
tooth_width = sum(tilde_w(pt2_n_0(t):pt2_n_0(t+1)))
|
|
|
|
endif
|
|
|
|
ASSERT(tooth_width > 0.d0)
|
|
|
|
do i=pt2_n_0(t)+1, pt2_n_0(t+1)
|
|
|
|
pt2_w(i) = tilde_w(i) * pt2_W_T / tooth_width
|
|
|
|
end do
|
2017-12-15 16:21:04 +01:00
|
|
|
end do
|
|
|
|
|
2018-09-06 15:19:51 +02:00
|
|
|
pt2_cW(0) = 0d0
|
2017-12-15 16:21:04 +01:00
|
|
|
do i=1,N_det_generators
|
2018-09-06 15:19:51 +02:00
|
|
|
pt2_cW(i) = pt2_cW(i-1) + pt2_w(i)
|
2017-12-15 16:21:04 +01:00
|
|
|
end do
|
2018-09-06 15:19:51 +02:00
|
|
|
pt2_n_0(pt2_N_teeth+1) = N_det_generators
|
2017-12-15 16:21:04 +01:00
|
|
|
END_PROVIDER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|