10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-26 06:14:43 +01:00
quantum_package/plugins/Full_CI_ZMQ/selection_davidson_slave.irp.f

199 lines
6.3 KiB
Fortran
Raw Normal View History

program selection_slave
implicit none
BEGIN_DOC
! Helper program to compute the PT2 in distributed mode.
END_DOC
read_wf = .False.
2017-05-17 22:49:15 +02:00
distributed_davidson = .False.
SOFT_TOUCH read_wf distributed_davidson
call provide_everything
call switch_qp_run_to_master
call run_wf
end
subroutine provide_everything
2017-11-28 14:20:17 +01:00
PROVIDE H_apply_buffer_allocated mo_bielec_integrals_in_map psi_det_generators psi_coef_generators psi_det_sorted_bit psi_selectors n_det_generators n_states generators_bitmask zmq_context n_states_diag
PROVIDE pt2_e0_denominator mo_tot_num N_int fragment_count ci_energy mpi_master zmq_state zmq_context
PROVIDE psi_det psi_coef
end
subroutine run_wf
use f77_zmq
2017-11-26 11:09:03 +01:00
implicit none
2017-11-27 16:31:00 +01:00
IRP_IF MPI
include 'mpif.h'
IRP_ENDIF
integer(ZMQ_PTR), external :: new_zmq_to_qp_run_socket
integer(ZMQ_PTR) :: zmq_to_qp_run_socket
2016-11-16 15:18:24 +01:00
double precision :: energy(N_states)
2017-11-29 12:49:26 +01:00
character*(64) :: states(3)
2018-06-07 16:15:26 +02:00
character*(64) :: old_state
2017-05-31 02:03:29 +02:00
integer :: rc, i, ierr
2017-11-28 14:20:17 +01:00
double precision :: t0, t1
2017-11-29 15:15:10 +01:00
integer, external :: zmq_get_dvector, zmq_get_N_det_generators
2018-06-05 17:51:10 +02:00
integer, external :: zmq_get_ivector
2017-11-29 15:15:10 +01:00
integer, external :: zmq_get_psi, zmq_get_N_det_selectors
integer, external :: zmq_get_N_states_diag
2017-11-29 13:52:52 +01:00
call provide_everything
zmq_context = f77_zmq_ctx_new ()
states(1) = 'selection'
states(2) = 'davidson'
2017-03-13 00:26:21 +01:00
states(3) = 'pt2'
2018-06-07 16:15:26 +02:00
old_state = 'Waiting'
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
do
2018-06-07 19:26:57 +02:00
if (mpi_master) then
call wait_for_states(states,zmq_state,size(states))
2018-06-08 01:11:30 +02:00
if (zmq_state(1:64) == old_state(1:64)) then
call sleep(1)
cycle
else
old_state(1:64) = zmq_state(1:64)
endif
print *, trim(zmq_state)
2018-06-07 19:26:57 +02:00
endif
IRP_IF MPI
call MPI_BCAST (zmq_state, 128, MPI_CHARACTER, 0, MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
print *, irp_here, 'error in broadcast of zmq_state'
endif
IRP_ENDIF
2017-11-29 12:49:26 +01:00
if(zmq_state(1:7) == 'Stopped') then
exit
2018-06-07 19:26:57 +02:00
endif
2018-06-07 19:26:57 +02:00
if (zmq_state(1:9) == 'selection') then
! Selection
! ---------
2017-11-28 14:20:17 +01:00
call wall_time(t0)
2017-11-29 15:15:10 +01:00
if (zmq_get_psi(zmq_to_qp_run_socket,1) == -1) cycle
2018-06-05 22:32:06 +02:00
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'threshold_generators',threshold_generators,1) == -1) cycle
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'threshold_selectors',threshold_selectors,1) == -1) cycle
2018-06-05 21:51:24 +02:00
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'energy',energy,N_states) == -1) cycle
2017-11-29 15:15:10 +01:00
if (zmq_get_N_det_generators (zmq_to_qp_run_socket, 1) == -1) cycle
if (zmq_get_N_det_selectors(zmq_to_qp_run_socket, 1) == -1) cycle
2018-06-05 22:32:06 +02:00
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'state_average_weight',state_average_weight,N_states) == -1) cycle
2018-05-22 17:09:12 +02:00
psi_energy(1:N_states) = energy(1:N_states)
2018-06-05 21:51:24 +02:00
TOUCH psi_energy state_average_weight threshold_selectors threshold_generators
2017-11-28 14:20:17 +01:00
2018-06-07 19:26:57 +02:00
if (mpi_master) then
print *, 'N_det', N_det
print *, 'N_det_generators', N_det_generators
print *, 'N_det_selectors', N_det_selectors
print *, 'psi_energy', psi_energy
print *, 'pt2_stoch_istate', pt2_stoch_istate
print *, 'state_average_weight', state_average_weight
endif
2017-11-28 14:20:17 +01:00
call wall_time(t1)
call write_double(6,(t1-t0),'Broadcast time')
!$OMP PARALLEL PRIVATE(i)
i = omp_get_thread_num()
2017-03-13 00:26:21 +01:00
call run_selection_slave(0,i,energy)
!$OMP END PARALLEL
print *, 'Selection done'
2018-06-08 01:11:30 +02:00
IRP_IF MPI
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
print *, irp_here, 'error in barrier'
endif
IRP_ENDIF
print *, 'All selection done'
2017-11-29 12:49:26 +01:00
else if (zmq_state(1:8) == 'davidson') then
! Davidson
! --------
2017-11-26 11:09:03 +01:00
call wall_time(t0)
2017-11-29 15:15:10 +01:00
if (zmq_get_psi(zmq_to_qp_run_socket,1) == -1) cycle
if (zmq_get_N_states_diag(zmq_to_qp_run_socket,1) == -1) cycle
2017-11-29 13:52:52 +01:00
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'energy',energy,N_states_diag) == -1) cycle
2017-11-28 14:20:17 +01:00
2017-11-26 11:09:03 +01:00
call wall_time(t1)
2018-06-07 19:26:57 +02:00
if (mpi_master) then
call write_double(6,(t1-t0),'Broadcast time')
endif
2017-11-26 11:09:03 +01:00
2017-05-16 09:17:16 +02:00
call omp_set_nested(.True.)
call davidson_slave_tcp(0)
call omp_set_nested(.False.)
print *, 'Davidson done'
2018-06-08 01:11:30 +02:00
IRP_IF MPI
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
print *, irp_here, 'error in barrier'
endif
IRP_ENDIF
print *, 'All Davidson done'
2017-11-26 11:09:03 +01:00
2017-11-29 12:49:26 +01:00
else if (zmq_state(1:3) == 'pt2') then
2017-03-13 00:26:21 +01:00
2017-03-13 00:30:14 +01:00
! PT2
! ---
2017-03-13 00:26:21 +01:00
2017-11-28 14:20:17 +01:00
call wall_time(t0)
2017-11-29 15:15:10 +01:00
if (zmq_get_psi(zmq_to_qp_run_socket,1) == -1) cycle
if (zmq_get_N_det_generators (zmq_to_qp_run_socket, 1) == -1) cycle
if (zmq_get_N_det_selectors(zmq_to_qp_run_socket, 1) == -1) cycle
2018-06-05 17:51:10 +02:00
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'threshold_generators',threshold_generators,1) == -1) cycle
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'threshold_selectors',threshold_selectors,1) == -1) cycle
2018-06-05 22:32:06 +02:00
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'energy',energy,N_states) == -1) cycle
if (zmq_get_ivector(zmq_to_qp_run_socket,1,'pt2_stoch_istate',pt2_stoch_istate,1) == -1) cycle
if (zmq_get_dvector(zmq_to_qp_run_socket,1,'state_average_weight',state_average_weight,N_states) == -1) cycle
2018-05-22 17:09:12 +02:00
psi_energy(1:N_states) = energy(1:N_states)
2018-06-05 17:51:10 +02:00
TOUCH psi_energy state_average_weight pt2_stoch_istate threshold_selectors threshold_generators
2018-06-07 19:26:57 +02:00
if (mpi_master) then
print *, 'N_det', N_det
print *, 'N_det_generators', N_det_generators
print *, 'N_det_selectors', N_det_selectors
print *, 'psi_energy', psi_energy
print *, 'pt2_stoch_istate', pt2_stoch_istate
print *, 'state_average_weight', state_average_weight
endif
2017-11-28 14:20:17 +01:00
call wall_time(t1)
call write_double(6,(t1-t0),'Broadcast time')
2017-03-13 00:30:14 +01:00
logical :: lstop
lstop = .False.
2017-03-13 00:26:21 +01:00
!$OMP PARALLEL PRIVATE(i)
i = omp_get_thread_num()
2018-06-05 17:51:10 +02:00
call run_pt2_slave(0,i,pt2_e0_denominator)
2017-03-13 00:26:21 +01:00
!$OMP END PARALLEL
print *, 'PT2 done'
2018-06-05 17:51:10 +02:00
FREE state_average_weight
2017-03-13 00:26:21 +01:00
2018-06-08 01:11:30 +02:00
IRP_IF MPI
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
print *, irp_here, 'error in barrier'
endif
IRP_ENDIF
print *, 'All PT2 done'
endif
end do
2017-11-23 12:17:47 +01:00
IRP_IF MPI
2018-06-08 01:11:30 +02:00
call MPI_finalize(ierr)
2017-11-23 12:17:47 +01:00
IRP_ENDIF
end