2016-07-19 10:15:26 +02:00
|
|
|
program fci_zmq
|
|
|
|
implicit none
|
2016-09-08 10:12:28 +02:00
|
|
|
integer :: i,j,k
|
2016-09-25 22:14:17 +02:00
|
|
|
logical, external :: detEq
|
2016-07-19 10:15:26 +02:00
|
|
|
|
2016-09-23 16:16:48 +02:00
|
|
|
double precision, allocatable :: pt2(:)
|
|
|
|
integer :: degree
|
2016-11-22 12:55:42 +01:00
|
|
|
integer :: n_det_before, to_select
|
2016-11-22 13:00:02 +01:00
|
|
|
double precision :: threshold_davidson_in
|
2016-09-25 22:14:17 +02:00
|
|
|
|
2016-09-23 16:16:48 +02:00
|
|
|
allocate (pt2(N_states))
|
2016-07-19 10:15:26 +02:00
|
|
|
|
|
|
|
pt2 = 1.d0
|
2016-11-22 13:00:02 +01:00
|
|
|
threshold_davidson_in = threshold_davidson
|
2016-11-30 17:33:34 +01:00
|
|
|
threshold_davidson = 1.d-5
|
2016-11-22 13:00:02 +01:00
|
|
|
SOFT_TOUCH threshold_davidson
|
2016-07-19 10:15:26 +02:00
|
|
|
|
|
|
|
if (N_det > N_det_max) then
|
|
|
|
call diagonalize_CI
|
|
|
|
call save_wavefunction
|
|
|
|
psi_det = psi_det_sorted
|
|
|
|
psi_coef = psi_coef_sorted
|
|
|
|
N_det = N_det_max
|
|
|
|
soft_touch N_det psi_det psi_coef
|
|
|
|
call diagonalize_CI
|
|
|
|
call save_wavefunction
|
|
|
|
print *, 'N_det = ', N_det
|
|
|
|
print *, 'N_states = ', N_states
|
2016-09-23 16:16:48 +02:00
|
|
|
do k=1,N_states
|
|
|
|
print*,'State ',k
|
|
|
|
print *, 'PT2 = ', pt2(k)
|
|
|
|
print *, 'E = ', CI_energy(k)
|
|
|
|
print *, 'E+PT2 = ', CI_energy(k) + pt2(k)
|
|
|
|
print *, '-----'
|
|
|
|
enddo
|
2016-07-19 10:15:26 +02:00
|
|
|
endif
|
2016-09-25 22:14:17 +02:00
|
|
|
double precision :: E_CI_before(N_states)
|
2016-07-21 13:24:25 +02:00
|
|
|
|
2016-09-25 22:14:17 +02:00
|
|
|
|
2016-07-19 10:15:26 +02:00
|
|
|
print*,'Beginning the selection ...'
|
2016-09-23 16:16:48 +02:00
|
|
|
E_CI_before(1:N_states) = CI_energy(1:N_states)
|
2016-11-22 12:55:42 +01:00
|
|
|
n_det_before = 0
|
2016-08-01 16:05:40 +02:00
|
|
|
|
2016-09-23 16:16:48 +02:00
|
|
|
do while ( (N_det < N_det_max) .and. (maxval(abs(pt2(1:N_states))) > pt2_max) )
|
2016-09-25 22:14:17 +02:00
|
|
|
|
2016-07-19 10:15:26 +02:00
|
|
|
print *, 'N_det = ', N_det
|
|
|
|
print *, 'N_states = ', N_states
|
2016-09-23 16:16:48 +02:00
|
|
|
do k=1, N_states
|
|
|
|
print*,'State ',k
|
|
|
|
print *, 'PT2 = ', pt2(k)
|
|
|
|
print *, 'E = ', CI_energy(k)
|
|
|
|
print *, 'E(before)+PT2 = ', E_CI_before(k)+pt2(k)
|
2016-07-19 10:15:26 +02:00
|
|
|
enddo
|
|
|
|
print *, '-----'
|
|
|
|
if(N_states.gt.1)then
|
2016-09-25 22:14:17 +02:00
|
|
|
print*,'Variational Energy difference'
|
|
|
|
do i = 2, N_states
|
|
|
|
print*,'Delta E = ',CI_energy(i) - CI_energy(1)
|
|
|
|
enddo
|
2016-07-19 10:15:26 +02:00
|
|
|
endif
|
|
|
|
if(N_states.gt.1)then
|
2016-09-25 22:14:17 +02:00
|
|
|
print*,'Variational + perturbative Energy difference'
|
|
|
|
do i = 2, N_states
|
|
|
|
print*,'Delta E = ',E_CI_before(i)+ pt2(i) - (E_CI_before(1) + pt2(1))
|
|
|
|
enddo
|
2016-07-19 10:15:26 +02:00
|
|
|
endif
|
2016-09-23 16:16:48 +02:00
|
|
|
E_CI_before(1:N_states) = CI_energy(1:N_states)
|
2016-11-30 17:33:34 +01:00
|
|
|
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
|
|
|
|
|
|
|
|
n_det_before = N_det
|
|
|
|
to_select = 3*N_det
|
|
|
|
to_select = max(1024-to_select, to_select)
|
|
|
|
to_select = min(to_select, N_det_max-n_det_before)
|
|
|
|
call ZMQ_selection(to_select, pt2)
|
|
|
|
|
|
|
|
PROVIDE psi_coef
|
|
|
|
PROVIDE psi_det
|
|
|
|
PROVIDE psi_det_sorted
|
|
|
|
|
|
|
|
if (N_det == N_det_max) then
|
|
|
|
threshold_davidson = threshold_davidson_in
|
2016-12-01 16:28:56 +01:00
|
|
|
SOFT_TOUCH threshold_davidson
|
2016-11-30 17:33:34 +01:00
|
|
|
endif
|
|
|
|
call diagonalize_CI
|
|
|
|
call save_wavefunction
|
|
|
|
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
|
2016-07-19 10:15:26 +02:00
|
|
|
enddo
|
2016-10-10 16:03:56 +02:00
|
|
|
|
2016-11-30 17:33:34 +01:00
|
|
|
if (N_det < N_det_max) then
|
|
|
|
threshold_davidson = threshold_davidson_in
|
|
|
|
SOFT_TOUCH threshold_davidson
|
|
|
|
call diagonalize_CI
|
|
|
|
call save_wavefunction
|
|
|
|
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
|
|
|
|
endif
|
|
|
|
|
2016-09-25 22:14:17 +02:00
|
|
|
if(do_pt2_end)then
|
|
|
|
print*,'Last iteration only to compute the PT2'
|
2016-11-10 14:42:41 +01:00
|
|
|
threshold_selectors = max(threshold_selectors,threshold_selectors_pt2)
|
|
|
|
threshold_generators = max(threshold_generators,threshold_generators_pt2)
|
2016-11-02 12:12:36 +01:00
|
|
|
TOUCH threshold_selectors threshold_generators
|
2016-09-25 22:14:17 +02:00
|
|
|
E_CI_before(1:N_states) = CI_energy(1:N_states)
|
2016-10-07 12:27:30 +02:00
|
|
|
call ZMQ_selection(0, pt2)
|
2016-09-25 22:14:17 +02:00
|
|
|
print *, 'Final step'
|
|
|
|
print *, 'N_det = ', N_det
|
|
|
|
print *, 'N_states = ', N_states
|
|
|
|
do k=1,N_states
|
|
|
|
print *, 'State', k
|
|
|
|
print *, 'PT2 = ', pt2
|
|
|
|
print *, 'E = ', E_CI_before
|
|
|
|
print *, 'E+PT2 = ', E_CI_before+pt2
|
|
|
|
print *, '-----'
|
|
|
|
enddo
|
2016-11-30 17:33:34 +01:00
|
|
|
call ezfio_set_full_ci_zmq_energy_pt2(E_CI_before(1)+pt2(1))
|
2016-09-25 22:14:17 +02:00
|
|
|
endif
|
|
|
|
call save_wavefunction
|
2016-11-30 17:33:34 +01:00
|
|
|
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
|
|
|
|
call ezfio_set_full_ci_zmq_energy_pt2(E_CI_before(1)+pt2(1))
|
2016-07-19 10:15:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-19 15:00:20 +02:00
|
|
|
|
2016-10-07 12:27:30 +02:00
|
|
|
subroutine ZMQ_selection(N_in, pt2)
|
2016-07-11 12:36:58 +02:00
|
|
|
use f77_zmq
|
2016-07-19 15:00:20 +02:00
|
|
|
use selection_types
|
|
|
|
|
2016-07-11 12:36:58 +02:00
|
|
|
implicit none
|
2016-07-13 18:12:25 +02:00
|
|
|
|
2016-07-19 15:00:20 +02:00
|
|
|
character*(512) :: task
|
|
|
|
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
|
2016-10-07 12:27:30 +02:00
|
|
|
integer, intent(in) :: N_in
|
2016-07-19 15:00:20 +02:00
|
|
|
type(selection_buffer) :: b
|
2016-10-07 12:27:30 +02:00
|
|
|
integer :: i, N
|
2016-07-19 15:00:20 +02:00
|
|
|
integer, external :: omp_get_thread_num
|
2016-07-21 13:24:25 +02:00
|
|
|
double precision, intent(out) :: pt2(N_states)
|
2016-07-19 15:00:20 +02:00
|
|
|
|
2016-08-01 16:05:40 +02:00
|
|
|
|
2016-11-08 10:24:36 +01:00
|
|
|
if (.True.) then
|
2016-11-11 23:07:58 +01:00
|
|
|
PROVIDE pt2_e0_denominator
|
2016-11-08 10:24:36 +01:00
|
|
|
N = max(N_in,1)
|
|
|
|
provide nproc
|
|
|
|
call new_parallel_job(zmq_to_qp_run_socket,"selection")
|
2016-11-11 23:07:58 +01:00
|
|
|
call zmq_put_psi(zmq_to_qp_run_socket,1,pt2_e0_denominator,size(pt2_e0_denominator))
|
2016-11-08 10:24:36 +01:00
|
|
|
call zmq_set_running(zmq_to_qp_run_socket)
|
|
|
|
call create_selection_buffer(N, N*2, b)
|
|
|
|
endif
|
2016-08-03 00:18:53 +02:00
|
|
|
|
|
|
|
integer :: i_generator, i_generator_start, i_generator_max, step
|
|
|
|
! step = int(max(1.,10*elec_num/mo_tot_num)
|
|
|
|
|
2016-10-05 11:27:35 +02:00
|
|
|
step = int(5000000.d0 / dble(N_int * N_states * elec_num * elec_num * mo_tot_num * mo_tot_num ))
|
2016-08-03 00:18:53 +02:00
|
|
|
step = max(1,step)
|
2016-11-16 13:59:24 +01:00
|
|
|
do i= 1, N_det_generators,step
|
|
|
|
i_generator_start = i
|
|
|
|
i_generator_max = min(i+step-1,N_det_generators)
|
2016-08-03 00:18:53 +02:00
|
|
|
write(task,*) i_generator_start, i_generator_max, 1, N
|
2016-07-19 15:00:20 +02:00
|
|
|
call add_task_to_taskserver(zmq_to_qp_run_socket,task)
|
|
|
|
end do
|
|
|
|
|
2016-11-11 23:07:58 +01:00
|
|
|
!$OMP PARALLEL DEFAULT(shared) SHARED(b, pt2) PRIVATE(i) NUM_THREADS(nproc+1)
|
|
|
|
i = omp_get_thread_num()
|
|
|
|
if (i==0) then
|
|
|
|
call selection_collector(b, pt2)
|
|
|
|
else
|
|
|
|
call selection_slave_inproc(i)
|
|
|
|
endif
|
2016-07-19 15:00:20 +02:00
|
|
|
!$OMP END PARALLEL
|
2016-11-11 23:07:58 +01:00
|
|
|
call end_parallel_job(zmq_to_qp_run_socket, 'selection')
|
2016-10-07 12:27:30 +02:00
|
|
|
if (N_in > 0) then
|
|
|
|
call fill_H_apply_buffer_no_selection(b%cur,b%det,N_int,0) !!! PAS DE ROBIN
|
|
|
|
call copy_H_apply_buffer_to_wf()
|
2016-11-11 23:07:58 +01:00
|
|
|
if (s2_eig) then
|
|
|
|
call make_s2_eigenfunction
|
|
|
|
endif
|
2016-10-07 12:27:30 +02:00
|
|
|
endif
|
2016-07-19 15:00:20 +02:00
|
|
|
end subroutine
|
|
|
|
|
|
|
|
|
2016-10-07 12:27:30 +02:00
|
|
|
subroutine selection_slave_inproc(i)
|
2016-07-19 15:00:20 +02:00
|
|
|
implicit none
|
|
|
|
integer, intent(in) :: i
|
|
|
|
|
2016-11-11 23:07:58 +01:00
|
|
|
call run_selection_slave(1,i,pt2_e0_denominator)
|
2016-07-19 15:00:20 +02:00
|
|
|
end
|
|
|
|
|
2016-09-01 14:43:13 +02:00
|
|
|
subroutine selection_collector(b, pt2)
|
|
|
|
use f77_zmq
|
|
|
|
use selection_types
|
|
|
|
use bitmasks
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
|
|
|
|
type(selection_buffer), intent(inout) :: b
|
|
|
|
double precision, intent(out) :: pt2(N_states)
|
|
|
|
double precision :: pt2_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(ZMQ_PTR) :: zmq_socket_pull
|
|
|
|
|
|
|
|
integer :: msg_size, rc, more
|
|
|
|
integer :: acc, i, j, robin, N, ntask
|
|
|
|
double precision, allocatable :: val(:)
|
|
|
|
integer(bit_kind), allocatable :: det(:,:,:)
|
|
|
|
integer, allocatable :: task_id(:)
|
|
|
|
integer :: done
|
|
|
|
real :: time, time0
|
|
|
|
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
|
|
|
|
zmq_socket_pull = new_zmq_pull_socket()
|
|
|
|
allocate(val(b%N), det(N_int, 2, b%N), task_id(N_det))
|
|
|
|
done = 0
|
|
|
|
more = 1
|
|
|
|
pt2(:) = 0d0
|
|
|
|
call CPU_TIME(time0)
|
|
|
|
do while (more == 1)
|
|
|
|
call pull_selection_results(zmq_socket_pull, pt2_mwen, val(1), det(1,1,1), N, task_id, ntask)
|
|
|
|
pt2 += pt2_mwen
|
|
|
|
do i=1, N
|
|
|
|
call add_to_selection_buffer(b, det(1,1,i), val(i))
|
|
|
|
end do
|
|
|
|
|
|
|
|
do i=1, ntask
|
|
|
|
if(task_id(i) == 0) then
|
|
|
|
print *, "Error in collector"
|
|
|
|
endif
|
|
|
|
call zmq_delete_task(zmq_to_qp_run_socket,zmq_socket_pull,task_id(i),more)
|
|
|
|
end do
|
|
|
|
done += ntask
|
|
|
|
call CPU_TIME(time)
|
|
|
|
! print *, "DONE" , done, time - time0
|
|
|
|
end do
|
|
|
|
|
|
|
|
|
|
|
|
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
|
|
|
|
call end_zmq_pull_socket(zmq_socket_pull)
|
|
|
|
call sort_selection_buffer(b)
|
|
|
|
end subroutine
|
|
|
|
|