10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-23 04:43:50 +01:00
quantum_package/plugins/Full_CI_ZMQ/zmq_selection.irp.f

166 lines
4.9 KiB
Fortran
Raw Normal View History

2016-12-26 17:11:44 +01:00
subroutine ZMQ_selection(N_in, pt2)
use f77_zmq
use selection_types
implicit none
2017-11-27 23:18:18 +01:00
integer(ZMQ_PTR) :: zmq_to_qp_run_socket , zmq_socket_pull
2016-12-26 17:11:44 +01:00
integer, intent(in) :: N_in
type(selection_buffer) :: b
integer :: i, N
integer, external :: omp_get_thread_num
double precision, intent(out) :: pt2(N_states)
2017-04-12 18:26:57 +02:00
integer, parameter :: maxtasks=10000
2016-12-26 17:11:44 +01:00
2017-02-12 09:37:00 +01:00
PROVIDE fragment_count
2017-04-12 18:26:57 +02:00
N = max(N_in,1)
2016-12-26 17:11:44 +01:00
if (.True.) then
2017-05-15 12:33:41 +02:00
PROVIDE pt2_e0_denominator nproc
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
2017-11-28 18:16:44 +01:00
call new_parallel_job(zmq_to_qp_run_socket,zmq_socket_pull,'selection')
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
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
2017-11-29 13:52:52 +01:00
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'energy',pt2_e0_denominator,size(pt2_e0_denominator)) == -1) then
stop 'Unable to put energy on ZMQ server'
endif
2016-12-26 17:11:44 +01:00
call create_selection_buffer(N, N*2, b)
endif
2017-11-29 15:15:10 +01:00
integer, external :: add_task_to_taskserver
2017-04-12 18:26:57 +02:00
character*(20*maxtasks) :: task
task = ' '
integer :: k
k=0
2017-03-03 12:02:21 +01:00
do i= 1, N_det_generators
2017-04-12 18:26:57 +02:00
k = k+1
2017-04-12 19:29:21 +02:00
write(task(20*(k-1)+1:20*k),'(I9,1X,I9,''|'')') i, N
2017-04-14 12:04:21 +02:00
if (k>=maxtasks) then
2017-04-12 18:26:57 +02:00
k=0
2017-11-29 15:15:10 +01:00
if (add_task_to_taskserver(zmq_to_qp_run_socket,task) == -1) then
stop 'Unable to add task to task server'
endif
2017-04-12 18:26:57 +02:00
endif
2016-12-26 17:11:44 +01:00
end do
2017-04-12 18:26:57 +02:00
if (k > 0) then
2017-11-29 15:15:10 +01:00
if (add_task_to_taskserver(zmq_to_qp_run_socket,task) == -1) then
stop 'Unable to add task to task server'
endif
2017-04-12 18:26:57 +02:00
endif
2016-12-26 17:11:44 +01:00
2017-11-27 13:43:05 +01:00
ASSERT (associated(b%det))
ASSERT (associated(b%val))
2017-11-26 11:09:03 +01:00
2017-12-01 13:27:34 +01:00
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
2016-12-26 17:11:44 +01:00
!$OMP PARALLEL DEFAULT(shared) SHARED(b, pt2) PRIVATE(i) NUM_THREADS(nproc+1)
i = omp_get_thread_num()
if (i==0) then
2017-11-27 23:18:18 +01:00
call selection_collector(zmq_socket_pull, b, N, pt2)
2016-12-26 17:11:44 +01:00
else
call selection_slave_inproc(i)
endif
!$OMP END PARALLEL
2017-11-27 23:18:18 +01:00
call end_parallel_job(zmq_to_qp_run_socket, zmq_socket_pull, 'selection')
2017-11-21 17:20:18 +01:00
do i=N_det+1,N_states
pt2(i) = 0.d0
enddo
2016-12-26 17:11:44 +01:00
if (N_in > 0) then
2017-03-03 12:02:21 +01:00
call fill_H_apply_buffer_no_selection(b%cur,b%det,N_int,0)
2016-12-26 17:11:44 +01:00
call copy_H_apply_buffer_to_wf()
2017-11-28 14:20:17 +01:00
if (s2_eig.or.(N_states > 1) ) then
2016-12-26 17:11:44 +01:00
call make_s2_eigenfunction
endif
2017-02-27 21:33:29 +01:00
call save_wavefunction
2016-12-26 17:11:44 +01:00
endif
2017-05-05 11:32:17 +02:00
call delete_selection_buffer(b)
2017-04-12 18:26:57 +02:00
2016-12-26 17:11:44 +01:00
end subroutine
subroutine selection_slave_inproc(i)
implicit none
integer, intent(in) :: i
call run_selection_slave(1,i,pt2_e0_denominator)
end
2017-11-27 23:18:18 +01:00
subroutine selection_collector(zmq_socket_pull, b, N, pt2)
2016-12-26 17:11:44 +01:00
use f77_zmq
use selection_types
use bitmasks
implicit none
2017-11-27 23:18:18 +01:00
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
2016-12-26 17:11:44 +01:00
type(selection_buffer), intent(inout) :: b
2017-05-05 11:32:17 +02:00
integer, intent(in) :: N
2016-12-26 17:11:44 +01:00
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 :: msg_size, rc, more
2017-05-05 11:32:17 +02:00
integer :: acc, i, j, robin, ntask
double precision, pointer :: val(:)
integer(bit_kind), pointer :: det(:,:,:)
2016-12-26 17:11:44 +01:00
integer, allocatable :: task_id(:)
2017-05-05 11:32:17 +02:00
type(selection_buffer) :: b2
2016-12-26 17:11:44 +01:00
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
2017-05-19 14:21:21 +02:00
call create_selection_buffer(N, N*2, b2)
2017-05-05 11:32:17 +02:00
allocate(task_id(N_det_generators))
2016-12-26 17:11:44 +01:00
more = 1
pt2(:) = 0d0
2017-11-23 10:35:13 +01:00
pt2_mwen(:) = 0.d0
2016-12-26 17:11:44 +01:00
do while (more == 1)
2017-05-05 11:32:17 +02:00
call pull_selection_results(zmq_socket_pull, pt2_mwen, b2%val(1), b2%det(1,1,1), b2%cur, task_id, ntask)
2017-11-23 10:35:13 +01:00
pt2(:) += pt2_mwen(:)
2017-05-10 20:42:14 +02:00
do i=1, b2%cur
call add_to_selection_buffer(b, b2%det(1,1,i), b2%val(i))
if (b2%val(i) > b%mini) exit
end do
2016-12-26 17:11:44 +01:00
do i=1, ntask
if(task_id(i) == 0) then
print *, "Error in collector"
endif
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(i),more) == -1) then
stop 'Unable to delete task'
endif
2016-12-26 17:11:44 +01:00
end do
end do
2017-05-05 11:32:17 +02:00
call delete_selection_buffer(b2)
2017-05-05 15:54:08 +02:00
call sort_selection_buffer(b)
2016-12-26 17:11:44 +01:00
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
end subroutine