2016-02-19 00:20:28 +01:00
|
|
|
subroutine $subroutine($params_main)
|
|
|
|
implicit none
|
|
|
|
use omp_lib
|
|
|
|
use bitmasks
|
|
|
|
use f77_zmq
|
|
|
|
BEGIN_DOC
|
|
|
|
! Calls H_apply on the HF determinant and selects all connected single and double
|
|
|
|
! excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script.
|
|
|
|
END_DOC
|
|
|
|
|
|
|
|
$decls_main
|
|
|
|
|
2016-05-04 16:14:59 +02:00
|
|
|
integer :: i
|
2016-02-19 00:20:28 +01:00
|
|
|
integer :: i_generator
|
|
|
|
double precision :: wall_0, wall_1
|
|
|
|
integer(bit_kind), allocatable :: mask(:,:,:)
|
|
|
|
integer :: ispin, k
|
|
|
|
integer :: rc
|
|
|
|
character*(512) :: task
|
|
|
|
double precision, allocatable :: fock_diag_tmp(:,:)
|
|
|
|
|
|
|
|
$initialization
|
2017-04-20 08:45:56 +02:00
|
|
|
PROVIDE H_apply_buffer_allocated mo_bielec_integrals_in_map psi_det_generators psi_coef_generators
|
2016-02-19 00:20:28 +01:00
|
|
|
|
2017-12-08 10:48:09 +01:00
|
|
|
integer(ZMQ_PTR), external :: new_zmq_pair_socket
|
|
|
|
integer(ZMQ_PTR) :: zmq_socket_pair, zmq_socket_pull
|
2016-02-19 00:20:28 +01:00
|
|
|
|
|
|
|
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
|
2016-05-29 23:24:18 +02:00
|
|
|
double precision, allocatable :: pt2_generators(:,:), norm_pert_generators(:,:)
|
|
|
|
double precision, allocatable :: H_pert_diag_generators(:,:)
|
2016-07-28 18:53:24 +02:00
|
|
|
double precision :: energy(N_st)
|
2016-05-29 23:24:18 +02:00
|
|
|
|
2017-11-27 23:18:18 +01:00
|
|
|
call new_parallel_job(zmq_to_qp_run_socket,zmq_socket_pull,'$subroutine')
|
2016-02-22 20:17:48 +01:00
|
|
|
zmq_socket_pair = new_zmq_pair_socket(.True.)
|
2016-02-19 00:20:28 +01:00
|
|
|
|
2017-11-29 15:15:10 +01:00
|
|
|
integer, external :: zmq_put_psi
|
|
|
|
integer, external :: zmq_put_N_det_generators
|
|
|
|
integer, external :: zmq_put_N_det_selectors
|
|
|
|
integer, external :: zmq_put_dvector
|
|
|
|
|
|
|
|
if (zmq_put_psi(zmq_to_qp_run_socket,1) == -1) then
|
|
|
|
stop 'Unable to put psi on ZMQ server'
|
|
|
|
endif
|
2017-12-08 10:48:09 +01:00
|
|
|
if (zmq_put_N_det_generators(zmq_to_qp_run_socket, 1) == -1) then
|
2017-11-29 15:15:10 +01:00
|
|
|
stop 'Unable to put N_det_generators on ZMQ server'
|
|
|
|
endif
|
2017-12-08 10:48:09 +01:00
|
|
|
if (zmq_put_N_det_selectors(zmq_to_qp_run_socket, 1) == -1) then
|
2017-11-29 15:15:10 +01:00
|
|
|
stop 'Unable to put N_det_selectors on ZMQ server'
|
|
|
|
endif
|
2017-11-29 13:52:52 +01:00
|
|
|
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'energy',energy,size(energy)) == -1) then
|
|
|
|
stop 'Unable to put energy on ZMQ server'
|
|
|
|
endif
|
2016-02-19 00:20:28 +01:00
|
|
|
|
2016-10-18 13:38:45 +02:00
|
|
|
do i_generator=1,N_det_generators
|
2016-02-19 00:20:28 +01:00
|
|
|
$skip
|
|
|
|
write(task,*) i_generator
|
2017-11-29 15:15:10 +01:00
|
|
|
integer, external :: add_task_to_taskserver
|
|
|
|
if (add_task_to_taskserver(zmq_to_qp_run_socket,trim(task)) == -1) then
|
|
|
|
stop 'Unable to add task to taskserver'
|
|
|
|
endif
|
2016-02-19 00:20:28 +01:00
|
|
|
enddo
|
|
|
|
|
2016-05-29 23:24:18 +02:00
|
|
|
allocate ( pt2_generators(N_states,N_det_generators), &
|
|
|
|
norm_pert_generators(N_states,N_det_generators), &
|
|
|
|
H_pert_diag_generators(N_states,N_det_generators) )
|
|
|
|
|
2016-05-10 23:21:38 +02:00
|
|
|
PROVIDE nproc N_states
|
2016-05-04 16:14:59 +02:00
|
|
|
!$OMP PARALLEL DEFAULT(NONE) &
|
2016-05-10 23:21:38 +02:00
|
|
|
!$OMP PRIVATE(i) &
|
2017-12-08 10:48:09 +01:00
|
|
|
!$OMP SHARED(zmq_socket_pair,N_states, pt2_generators, norm_pert_generators, H_pert_diag_generators, n, task_id, i_generator,zmq_socket_pull) &
|
2016-05-04 16:14:59 +02:00
|
|
|
!$OMP num_threads(nproc+1)
|
|
|
|
i = omp_get_thread_num()
|
|
|
|
if (i == 0) then
|
2017-11-27 23:18:18 +01:00
|
|
|
call $subroutine_collector(zmq_socket_pull)
|
2016-05-04 16:14:59 +02:00
|
|
|
integer :: n, task_id
|
2016-05-29 23:24:18 +02:00
|
|
|
call pull_pt2(zmq_socket_pair, pt2_generators, norm_pert_generators, H_pert_diag_generators, i_generator, size(pt2_generators), n, task_id)
|
2016-05-04 16:14:59 +02:00
|
|
|
else
|
|
|
|
call $subroutine_slave_inproc(i)
|
|
|
|
endif
|
2016-02-19 00:20:28 +01:00
|
|
|
!$OMP END PARALLEL
|
|
|
|
|
|
|
|
|
2016-02-22 20:17:48 +01:00
|
|
|
call end_zmq_pair_socket(zmq_socket_pair)
|
2017-11-27 23:18:18 +01:00
|
|
|
call end_parallel_job(zmq_to_qp_run_socket,zmq_socket_pull,'$subroutine')
|
2016-02-19 00:20:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
$copy_buffer
|
|
|
|
$generate_psi_guess
|
|
|
|
|
2016-05-29 23:24:18 +02:00
|
|
|
deallocate ( pt2_generators, norm_pert_generators, H_pert_diag_generators)
|
2016-02-19 00:20:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
subroutine $subroutine_slave_tcp(iproc)
|
|
|
|
implicit none
|
|
|
|
integer, intent(in) :: iproc
|
|
|
|
BEGIN_DOC
|
|
|
|
! Computes a buffer over the network
|
|
|
|
END_DOC
|
|
|
|
call $subroutine_slave(0,iproc)
|
|
|
|
end
|
|
|
|
|
|
|
|
subroutine $subroutine_slave_inproc(iproc)
|
|
|
|
implicit none
|
|
|
|
integer, intent(in) :: iproc
|
|
|
|
BEGIN_DOC
|
|
|
|
! Computes a buffer using threads
|
|
|
|
END_DOC
|
|
|
|
call $subroutine_slave(1,iproc)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
subroutine $subroutine_slave(thread, iproc)
|
|
|
|
implicit none
|
|
|
|
use omp_lib
|
|
|
|
use bitmasks
|
|
|
|
use f77_zmq
|
|
|
|
integer, intent(in) :: thread
|
|
|
|
BEGIN_DOC
|
|
|
|
! Calls H_apply on the HF determinant and selects all connected single and double
|
|
|
|
! excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script.
|
|
|
|
END_DOC
|
|
|
|
|
|
|
|
integer, intent(in) :: iproc
|
|
|
|
integer :: i_generator
|
|
|
|
double precision :: wall_0, wall_1
|
|
|
|
integer(bit_kind), allocatable :: mask(:,:,:)
|
|
|
|
integer :: ispin, k
|
|
|
|
double precision, allocatable :: fock_diag_tmp(:,:)
|
|
|
|
double precision, allocatable :: pt2(:), norm_pert(:), H_pert_diag(:)
|
|
|
|
|
|
|
|
integer :: worker_id, task_id, rc, N_st
|
|
|
|
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
|
|
|
|
|
|
|
|
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
|
|
|
|
|
2017-11-29 15:15:10 +01:00
|
|
|
integer, external :: connect_to_taskserver
|
|
|
|
if (connect_to_taskserver(zmq_to_qp_run_socket,worker_id,thread) == -1) then
|
|
|
|
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
zmq_socket_push = new_zmq_push_socket(thread)
|
2016-02-19 00:20:28 +01:00
|
|
|
|
|
|
|
N_st = N_states
|
|
|
|
allocate( pt2(N_st), norm_pert(N_st), H_pert_diag(N_st), &
|
|
|
|
mask(N_int,2,6), fock_diag_tmp(2,mo_tot_num+1) )
|
|
|
|
|
|
|
|
do
|
2017-11-29 15:15:10 +01:00
|
|
|
integer, external :: get_task_from_taskserver
|
|
|
|
if (get_task_from_taskserver(zmq_to_qp_run_socket,worker_id, task_id, task) == -1) then
|
|
|
|
exit
|
|
|
|
endif
|
2016-02-19 00:20:28 +01:00
|
|
|
if (task_id == 0) exit
|
|
|
|
read(task,*) i_generator
|
|
|
|
|
|
|
|
! Compute diagonal of the Fock matrix
|
|
|
|
call build_fock_tmp(fock_diag_tmp,psi_det_generators(1,1,i_generator),N_int)
|
|
|
|
|
|
|
|
pt2 = 0.d0
|
|
|
|
norm_pert = 0.d0
|
2016-08-01 16:05:40 +02:00
|
|
|
H_pert_diag = 0.d0
|
2016-02-19 00:20:28 +01:00
|
|
|
|
|
|
|
! Create bit masks for holes and particles
|
|
|
|
do ispin=1,2
|
|
|
|
do k=1,N_int
|
|
|
|
mask(k,ispin,s_hole) = &
|
|
|
|
iand(generators_bitmask(k,ispin,s_hole,i_bitmask_gen), &
|
|
|
|
psi_det_generators(k,ispin,i_generator) )
|
|
|
|
mask(k,ispin,s_part) = &
|
|
|
|
iand(generators_bitmask(k,ispin,s_part,i_bitmask_gen), &
|
|
|
|
not(psi_det_generators(k,ispin,i_generator)) )
|
|
|
|
mask(k,ispin,d_hole1) = &
|
|
|
|
iand(generators_bitmask(k,ispin,d_hole1,i_bitmask_gen), &
|
|
|
|
psi_det_generators(k,ispin,i_generator) )
|
|
|
|
mask(k,ispin,d_part1) = &
|
|
|
|
iand(generators_bitmask(k,ispin,d_part1,i_bitmask_gen), &
|
|
|
|
not(psi_det_generators(k,ispin,i_generator)) )
|
|
|
|
mask(k,ispin,d_hole2) = &
|
|
|
|
iand(generators_bitmask(k,ispin,d_hole2,i_bitmask_gen), &
|
|
|
|
psi_det_generators(k,ispin,i_generator) )
|
|
|
|
mask(k,ispin,d_part2) = &
|
|
|
|
iand(generators_bitmask(k,ispin,d_part2,i_bitmask_gen), &
|
|
|
|
not (psi_det_generators(k,ispin,i_generator)) )
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
|
|
|
|
if($do_double_excitations)then
|
|
|
|
call $subroutine_diexc(psi_det_generators(1,1,i_generator), &
|
|
|
|
psi_det_generators(1,1,1), &
|
|
|
|
mask(1,1,d_hole1), mask(1,1,d_part1), &
|
|
|
|
mask(1,1,d_hole2), mask(1,1,d_part2), &
|
|
|
|
fock_diag_tmp, i_generator, iproc $params_post)
|
|
|
|
endif
|
|
|
|
if($do_mono_excitations)then
|
|
|
|
call $subroutine_monoexc(psi_det_generators(1,1,i_generator), &
|
|
|
|
mask(1,1,s_hole ), mask(1,1,s_part ), &
|
|
|
|
fock_diag_tmp, i_generator, iproc $params_post)
|
|
|
|
endif
|
|
|
|
|
2017-11-29 15:15:10 +01:00
|
|
|
integer, external :: task_done_to_taskserver
|
|
|
|
if (task_done_to_taskserver(zmq_to_qp_run_socket, worker_id, task_id) == -1) then
|
|
|
|
print *, irp_here, ': Unable to send task_done'
|
|
|
|
endif
|
2016-05-29 22:38:06 +02:00
|
|
|
call push_pt2(zmq_socket_push,pt2,norm_pert,H_pert_diag,i_generator,N_st,task_id)
|
2016-02-19 00:20:28 +01:00
|
|
|
|
|
|
|
enddo
|
|
|
|
|
|
|
|
deallocate( mask, fock_diag_tmp, pt2, norm_pert, H_pert_diag )
|
|
|
|
|
2017-11-29 15:15:10 +01:00
|
|
|
|
|
|
|
integer, external :: disconnect_from_taskserver
|
2017-12-05 18:54:10 +01:00
|
|
|
if (disconnect_from_taskserver(zmq_to_qp_run_socket,worker_id) == -1) then
|
2017-11-29 15:15:10 +01:00
|
|
|
continue
|
|
|
|
endif
|
2016-02-19 00:20:28 +01:00
|
|
|
call end_zmq_push_socket(zmq_socket_push,thread)
|
2016-02-22 20:17:48 +01:00
|
|
|
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
|
2016-02-19 00:20:28 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-11-27 23:18:18 +01:00
|
|
|
subroutine $subroutine_collector(zmq_socket_pull)
|
2016-02-19 00:20:28 +01:00
|
|
|
use f77_zmq
|
|
|
|
implicit none
|
|
|
|
BEGIN_DOC
|
2016-05-29 23:24:18 +02:00
|
|
|
! Collects results from the selection in an array of generators
|
2016-02-19 00:20:28 +01:00
|
|
|
END_DOC
|
|
|
|
|
|
|
|
integer :: k, rc
|
|
|
|
|
|
|
|
integer(ZMQ_PTR), external :: new_zmq_pull_socket
|
2017-11-27 23:18:18 +01:00
|
|
|
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
|
2016-02-19 00:20:28 +01:00
|
|
|
integer*8 :: control, accu
|
2016-05-29 22:38:06 +02:00
|
|
|
integer :: n, more, task_id, i_generator
|
2016-02-19 00:20:28 +01:00
|
|
|
|
|
|
|
integer(ZMQ_PTR),external :: new_zmq_to_qp_run_socket
|
|
|
|
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
|
|
|
|
|
|
|
|
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
|
|
|
|
|
2016-05-29 23:24:18 +02:00
|
|
|
double precision, allocatable :: pt2(:), norm_pert(:), H_pert_diag(:)
|
|
|
|
double precision, allocatable :: pt2_result(:,:), norm_pert_result(:,:), H_pert_diag_result(:,:)
|
|
|
|
allocate (pt2(N_states), norm_pert(N_states), H_pert_diag(N_states))
|
|
|
|
allocate (pt2_result(N_states,N_det_generators), norm_pert_result(N_states,N_det_generators), &
|
|
|
|
H_pert_diag_result(N_states,N_det_generators))
|
2016-02-19 00:20:28 +01:00
|
|
|
|
2016-05-29 23:24:18 +02:00
|
|
|
pt2_result = 0.d0
|
|
|
|
norm_pert_result = 0.d0
|
|
|
|
H_pert_diag_result = 0.d0
|
2016-02-19 00:20:28 +01:00
|
|
|
accu = 0_8
|
|
|
|
more = 1
|
|
|
|
do while (more == 1)
|
|
|
|
|
2016-05-29 22:38:06 +02:00
|
|
|
call pull_pt2(zmq_socket_pull, pt2, norm_pert, H_pert_diag, i_generator, N_states, n, task_id)
|
2016-02-19 00:20:28 +01:00
|
|
|
if (n > 0) then
|
|
|
|
do k=1,N_states
|
2016-05-29 23:24:18 +02:00
|
|
|
pt2_result(k,i_generator) = pt2(k)
|
|
|
|
norm_pert_result(k,i_generator) = norm_pert(k)
|
|
|
|
H_pert_diag_result(k,i_generator) = H_pert_diag(k)
|
2016-02-19 00:20:28 +01:00
|
|
|
enddo
|
|
|
|
accu = accu + 1_8
|
2017-11-29 15:15:10 +01:00
|
|
|
integer, external :: zmq_delete_task
|
|
|
|
if (zmq_delete_task(zmq_to_qp_run_socket,zmq_socket_pull,task_id,more) == -1) then
|
|
|
|
stop 'Unable to delete task'
|
|
|
|
endif
|
2016-02-19 00:20:28 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
enddo
|
|
|
|
|
|
|
|
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
|
|
|
|
|
|
|
|
|
|
|
|
integer(ZMQ_PTR), external :: new_zmq_pair_socket
|
|
|
|
integer(ZMQ_PTR) :: socket_result
|
|
|
|
|
|
|
|
socket_result = new_zmq_pair_socket(.False.)
|
|
|
|
|
2016-05-29 23:24:18 +02:00
|
|
|
call push_pt2(socket_result, pt2_result, norm_pert_result, H_pert_diag_result, i_generator, &
|
|
|
|
N_states*N_det_generators,0)
|
2016-02-19 00:20:28 +01:00
|
|
|
|
2016-05-29 23:24:18 +02:00
|
|
|
deallocate (pt2, norm_pert, H_pert_diag, pt2_result, norm_pert_result, H_pert_diag_result)
|
2016-02-19 00:20:28 +01:00
|
|
|
|
|
|
|
call end_zmq_pair_socket(socket_result)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|