9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-07 04:03:29 +01:00
qp2/src/cipsi/zmq_selection.irp.f

235 lines
7.4 KiB
Fortran
Raw Normal View History

2020-08-28 00:10:46 +02:00
subroutine ZMQ_selection(N_in, pt2_data)
2019-01-25 11:39:31 +01:00
use f77_zmq
use selection_types
implicit none
integer(ZMQ_PTR) :: zmq_to_qp_run_socket , zmq_socket_pull
integer, intent(in) :: N_in
type(selection_buffer) :: b
2020-08-31 22:39:40 +02:00
integer :: i, l, N
2019-01-25 11:39:31 +01:00
integer, external :: omp_get_thread_num
2020-08-28 00:10:46 +02:00
type(pt2_type), intent(inout) :: pt2_data
2019-01-25 11:39:31 +01:00
! PROVIDE psi_det psi_coef N_det qp_max_mem N_states pt2_F s2_eig N_det_generators
N = max(N_in,1)
N = min(N, (elec_alpha_num * (mo_num-elec_alpha_num))**2)
2019-01-25 11:39:31 +01:00
if (.True.) then
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 selection_weight pseudo_sym
2021-06-25 00:11:57 +02:00
PROVIDE n_act_orb n_inact_orb n_core_orb n_virt_orb n_del_orb seniority_max
PROVIDE excitation_beta_max excitation_alpha_max excitation_max
2019-06-04 18:12:55 +02:00
2019-01-25 11:39:31 +01:00
call new_parallel_job(zmq_to_qp_run_socket,zmq_socket_pull,'selection')
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
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
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'
2019-06-05 17:34:36 +02:00
endif
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'selection_weight',selection_weight,N_states) == -1) then
stop 'Unable to put selection_weight on ZMQ server'
2019-01-25 11:39:31 +01:00
endif
2021-03-12 14:44:27 +01:00
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'threshold_generators',(/threshold_generators/),1) == -1) then
2019-01-25 11:39:31 +01:00
stop 'Unable to put threshold_generators on ZMQ server'
endif
call create_selection_buffer(N, N*2, b)
endif
integer, external :: add_task_to_taskserver
character(len=100000) :: task
integer :: j,k,ipos
ipos=1
task = ' '
do i= 1, N_det_generators
do j=1,pt2_F(i)
write(task(ipos:ipos+30),'(I9,1X,I9,1X,I9,''|'')') j, i, N
ipos += 30
if (ipos > 100000-30) 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
stop 'Unable to add task to task server'
endif
endif
N = max(N_in,1)
2019-01-25 11:39:31 +01:00
ASSERT (associated(b%det))
ASSERT (associated(b%val))
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
integer :: nproc_target
2019-06-04 11:42:55 +02:00
if (N_det < 3*nproc) then
nproc_target = N_det/4
2019-06-04 11:42:55 +02:00
else
nproc_target = nproc
endif
2019-01-25 11:39:31 +01:00
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)/(0.1d0 + mem)))
2019-01-25 11:39:31 +01:00
nproc_target = min(nproc_target,nproc)
endif
f(:) = 1.d0
if (.not.do_pt2) then
2020-08-28 15:39:01 +02:00
double precision :: f(N_states), u_dot_u
2019-01-25 11:39:31 +01:00
do k=1,min(N_det,N_states)
f(k) = 1.d0 / u_dot_u(psi_selectors_coef(1,k), N_det_selectors)
enddo
endif
2020-08-28 00:10:46 +02:00
!$OMP PARALLEL DEFAULT(shared) SHARED(b, pt2_data) PRIVATE(i) NUM_THREADS(nproc_target+1)
2019-01-25 11:39:31 +01:00
i = omp_get_thread_num()
if (i==0) then
2020-08-28 15:39:01 +02:00
call selection_collector(zmq_socket_pull, b, N, pt2_data)
2019-01-25 11:39:31 +01:00
else
call selection_slave_inproc(i)
endif
!$OMP END PARALLEL
2020-08-28 15:39:01 +02:00
2019-01-25 11:39:31 +01:00
call end_parallel_job(zmq_to_qp_run_socket, zmq_socket_pull, 'selection')
if (N_in > 0) then
if (s2_eig) then
call make_selection_buffer_s2(b)
endif
call fill_H_apply_buffer_no_selection(b%cur,b%det,N_int,0)
endif
call delete_selection_buffer(b)
2020-08-28 15:39:01 +02:00
2020-08-28 16:05:53 +02:00
do k=1,N_states
2020-08-30 22:16:39 +02:00
pt2_data % pt2(k) = pt2_data % pt2(k) * f(k)
pt2_data % variance(k) = pt2_data % variance(k) * f(k)
2020-08-31 22:39:40 +02:00
do l=1,N_states
pt2_data % overlap(k,l) = pt2_data % overlap(k,l) * dsqrt(f(k)*f(l))
pt2_data % overlap(l,k) = pt2_data % overlap(l,k) * dsqrt(f(k)*f(l))
enddo
2020-08-28 16:05:53 +02:00
2020-08-30 22:16:39 +02:00
pt2_data % rpt2(k) = &
2020-08-31 22:39:40 +02:00
pt2_data % pt2(k)/(1.d0 + pt2_data % overlap(k,k))
2020-08-28 16:05:53 +02:00
enddo
2019-01-25 11:39:31 +01:00
2020-08-31 23:04:34 +02:00
pt2_overlap(:,:) = pt2_data % overlap(:,:)
2020-09-03 17:13:26 +02:00
print *, 'Overlap of perturbed states:'
do l=1,N_states
print *, pt2_overlap(l,:)
enddo
print *, '-------'
2020-08-31 23:04:34 +02:00
SOFT_TOUCH pt2_overlap
2020-08-28 00:10:46 +02:00
call update_pt2_and_variance_weights(pt2_data, N_states)
2019-05-15 12:29:39 +02:00
2019-01-25 11:39:31 +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
2020-08-28 15:39:01 +02:00
subroutine selection_collector(zmq_socket_pull, b, N, pt2_data)
2019-01-25 11:39:31 +01:00
use f77_zmq
use selection_types
use bitmasks
implicit none
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
type(selection_buffer), intent(inout) :: b
integer, intent(in) :: N
2020-08-28 15:39:01 +02:00
type(pt2_type), intent(inout) :: pt2_data
2020-08-30 22:16:39 +02:00
type(pt2_type) :: pt2_data_tmp
2020-08-28 15:39:01 +02:00
double precision :: pt2_mwen(N_states)
double precision :: variance_mwen(N_states)
double precision :: norm2_mwen(N_states)
2019-01-25 11:39:31 +01:00
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
integer :: acc, i, j, robin, ntask
double precision, pointer :: val(:)
integer(bit_kind), pointer :: det(:,:,:)
integer, allocatable :: task_id(:)
type(selection_buffer) :: b2
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
call create_selection_buffer(N, N*2, b2)
2020-08-31 22:39:40 +02:00
integer :: k
2019-01-25 11:39:31 +01:00
double precision :: rss
double precision, external :: memory_of_int
rss = memory_of_int(N_det_generators)
call check_mem(rss,irp_here)
allocate(task_id(N_det_generators))
more = 1
2020-08-28 15:39:01 +02:00
pt2_data % pt2(:) = 0d0
pt2_data % variance(:) = 0.d0
2020-08-31 22:39:40 +02:00
pt2_data % overlap(:,:) = 0.d0
2020-08-30 22:16:39 +02:00
call pt2_alloc(pt2_data_tmp,N_states)
2019-01-25 11:39:31 +01:00
do while (more == 1)
2020-08-30 22:16:39 +02:00
call pull_selection_results(zmq_socket_pull, pt2_data_tmp, b2%val(1), b2%det(1,1,1), b2%cur, task_id, ntask)
2019-01-25 11:39:31 +01:00
2020-08-30 22:16:39 +02:00
call pt2_add(pt2_data, 1.d0, pt2_data_tmp)
2019-01-25 11:39:31 +01: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
do i=1, ntask
if(task_id(i) == 0) then
print *, "Error in collector"
endif
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
end do
end do
2020-08-30 22:16:39 +02:00
call pt2_dealloc(pt2_data_tmp)
2019-01-25 11:39:31 +01:00
call delete_selection_buffer(b2)
call sort_selection_buffer(b)
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
end subroutine