mirror of
https://github.com/LCPQ/quantum_package
synced 2024-12-25 13:53:49 +01:00
Anthony Scemama
873035e016
commit 4b9c435dce0f3b3078d573e66fd32b40fca26497 Merge:74e559c8
093e3fd0
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr> Date: Tue Sep 4 16:58:51 2018 +0200 Merge branch 'thesis' of git://github.com/garniron/quantum_package into garniron-thesis commit093e3fd021
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Tue Sep 4 16:13:00 2018 +0200 removed ungodly hack commit8529a0f3f6
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Tue Sep 4 14:57:19 2018 +0200 reduced prints in pt2_stoch commit03b8f353bd
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Tue Sep 4 14:41:46 2018 +0200 teeth building check for pt2_stoch commit0d91b9310a
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Tue Sep 4 14:35:04 2018 +0200 timestamp of first pull commit34d9fa0165
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Tue Sep 4 14:27:10 2018 +0200 potential numerical precision bug commit9a0f900d8c
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Tue Sep 4 14:09:51 2018 +0200 tests if teeth can be built commitdda0dc34df
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Mon Sep 3 17:48:04 2018 +0200 corrected pt2_find_sample commita521f0cb82
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Mon Sep 3 16:08:02 2018 +0200 tasks get by batches of Nproc commit997a5a1265
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Mon Sep 3 14:18:04 2018 +0200 buffered task_id send commit99ea7948e0
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Mon Sep 3 12:29:12 2018 +0200 unbalanced fragmentation commitabb3b7e08b
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Sun Sep 2 17:18:44 2018 +0200 overflow of pt2_J commit8df49f394b
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Sun Sep 2 15:58:48 2018 +0200 removed useless computation of intermediate checkpoints commit4ba5b79eb3
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Sun Sep 2 15:50:14 2018 +0200 dressing only sent for chosen checkpoint commita4a6a69459
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Sat Sep 1 17:01:56 2018 +0200 cumulative dot_F commit6a7f04cb79
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Sat Sep 1 16:58:07 2018 +0200 simpler purge commit168ca2f2e2
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Fri Aug 31 21:07:01 2018 +0200 task list optimized commitde4a0d0caf
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Fri Aug 31 18:57:03 2018 +0200 removed print commitfee31d4e3e
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Fri Aug 31 18:56:23 2018 +0200 dress fragmentation commit02893a419d
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Fri Aug 31 15:52:16 2018 +0200 bug in blocked search - replaced with thesis version commitbb6e073cf1
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Thu Aug 30 21:24:45 2018 +0200 ungodly hack to prevent double providing commit0609e8c627
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Thu Aug 30 20:52:05 2018 +0200 debugging commita254fdd7cf
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Thu Aug 30 15:24:07 2018 +0200 parallel bug commit2a6c1941d4
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Thu Aug 30 11:43:11 2018 +0200 corrected when relative_error=0d0 commitbac039bdf1
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Thu Aug 30 10:58:17 2018 +0200 relative error 1d-5 commitaae9d203ec
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Thu Aug 30 10:07:02 2018 +0200 potential fragmentation bug commitad69f39f99
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Wed Aug 29 20:54:58 2018 +0200 dress_zmq re-implemented commitd78f64732a
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Wed Aug 29 11:30:19 2018 +0200 pt2_stoch re-implemented commit4b9b54e19a
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Tue Aug 28 10:24:38 2018 +0200 removed test for phase_mask_bit commit3abccca5e3
Author: Yann Garniron <yann.garniron@yahoo.fr> Date: Fri Aug 3 23:44:05 2018 +0200 phasemask_bit
343 lines
10 KiB
Fortran
343 lines
10 KiB
Fortran
subroutine run_selection_slave(thread,iproc,energy)
|
|
implicit none
|
|
integer, intent(in) :: thread, iproc
|
|
double precision, intent(in) :: energy(N_states_diag)
|
|
call run_selection_slave_new(thread,iproc,energy)
|
|
end
|
|
|
|
subroutine run_selection_slave_new(thread,iproc,energy)
|
|
use f77_zmq
|
|
use selection_types
|
|
implicit none
|
|
|
|
integer, intent(in) :: thread, iproc
|
|
double precision, intent(in) :: energy(N_states_diag)
|
|
integer :: rc, i, N
|
|
logical :: buffer_ready
|
|
|
|
integer :: worker_id, ltask
|
|
character*(512), allocatable :: task(:)
|
|
integer, allocatable :: task_id(:)
|
|
|
|
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
|
|
|
|
type(selection_buffer) :: buf, buf2
|
|
logical :: done
|
|
|
|
double precision,allocatable :: pt2(:,:)
|
|
integer :: n_tasks, k, n_tasks_max
|
|
integer, allocatable :: i_generator(:), subset(:)
|
|
|
|
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
|
|
|
|
buffer_ready = .False.
|
|
n_tasks_max = N_det_generators/100+1
|
|
allocate(task_id(n_tasks_max), task(n_tasks_max))
|
|
allocate(pt2(N_states,n_tasks_max), i_generator(n_tasks_max), subset(n_tasks_max))
|
|
|
|
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
|
|
|
|
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)
|
|
|
|
buf%N = 0
|
|
n_tasks = 1
|
|
call create_selection_buffer(0, 0, buf)
|
|
done = .False.
|
|
do while (.not.done)
|
|
|
|
n_tasks = max(1,n_tasks)
|
|
n_tasks = min(n_tasks,n_tasks_max)
|
|
|
|
integer, external :: get_tasks_from_taskserver
|
|
if (get_tasks_from_taskserver(zmq_to_qp_run_socket,worker_id, task_id, task, n_tasks) == -1) then
|
|
exit
|
|
endif
|
|
done = task_id(n_tasks) == 0
|
|
if (done) n_tasks = n_tasks-1
|
|
if (n_tasks == 0) exit
|
|
|
|
do k=1,n_tasks
|
|
read (task(k),*) subset(k), i_generator(k), N
|
|
enddo
|
|
|
|
if(buf%N == 0) then
|
|
! Only first time
|
|
call create_selection_buffer(N, N*2, buf)
|
|
call create_selection_buffer(N, N*2, buf2)
|
|
buffer_ready = .True.
|
|
endif
|
|
|
|
double precision :: time0, time1
|
|
call wall_time(time0)
|
|
do k=1,n_tasks
|
|
pt2(:,k) = 0.d0
|
|
buf%cur = 0
|
|
call select_connected(i_generator(k),energy,pt2(1,k),buf,subset(k))
|
|
enddo
|
|
call wall_time(time1)
|
|
|
|
integer, external :: tasks_done_to_taskserver
|
|
if (tasks_done_to_taskserver(zmq_to_qp_run_socket,worker_id,task_id,n_tasks) == -1) then
|
|
done = .true.
|
|
endif
|
|
call sort_selection_buffer(buf)
|
|
call merge_selection_buffers(buf,buf2)
|
|
call push_selection_results(zmq_socket_push, pt2, buf, task_id, n_tasks)
|
|
buf%mini = buf2%mini
|
|
pt2(:,:) = 0d0
|
|
buf%cur = 0
|
|
|
|
! ! Try to adjust n_tasks around 5 second per job
|
|
! n_tasks = min(n_tasks,int( 5.d0 * dble(n_tasks) / (time1 - time0 + 1.d-9)))+1
|
|
n_tasks = n_tasks+1
|
|
end do
|
|
|
|
integer, external :: disconnect_from_taskserver
|
|
if (disconnect_from_taskserver(zmq_to_qp_run_socket,worker_id) == -1) then
|
|
continue
|
|
endif
|
|
|
|
call end_zmq_push_socket(zmq_socket_push,thread)
|
|
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
|
|
call delete_selection_buffer(buf)
|
|
|
|
end
|
|
|
|
subroutine run_selection_slave_old(thread,iproc,energy)
|
|
use f77_zmq
|
|
use selection_types
|
|
implicit none
|
|
|
|
double precision, intent(in) :: energy(N_states)
|
|
integer, intent(in) :: thread, iproc
|
|
integer :: rc, i
|
|
|
|
integer :: worker_id, task_id(1), ctask, ltask
|
|
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
|
|
|
|
type(selection_buffer) :: buf, buf2
|
|
logical :: done, buffer_ready
|
|
double precision :: pt2(N_states)
|
|
|
|
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
|
|
|
|
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
|
|
|
|
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)
|
|
|
|
buf%N = 0
|
|
buffer_ready = .False.
|
|
ctask = 1
|
|
pt2(:) = 0d0
|
|
|
|
do
|
|
integer, external :: get_task_from_taskserver
|
|
if (get_task_from_taskserver(zmq_to_qp_run_socket,worker_id, task_id(ctask), task) == -1) then
|
|
exit
|
|
endif
|
|
done = task_id(ctask) == 0
|
|
if (done) then
|
|
ctask = ctask - 1
|
|
else
|
|
integer :: i_generator, N, subset
|
|
read(task,*) subset, i_generator, N
|
|
if(buf%N == 0) then
|
|
! Only first time
|
|
call create_selection_buffer(N, N*2, buf)
|
|
call create_selection_buffer(N, N*2, buf2)
|
|
buffer_ready = .True.
|
|
else
|
|
ASSERT (N == buf%N)
|
|
end if
|
|
call select_connected(i_generator,energy,pt2,buf,subset,fragment_count)
|
|
endif
|
|
|
|
integer, external :: task_done_to_taskserver
|
|
|
|
if(done .or. ctask == size(task_id)) then
|
|
do i=1, ctask
|
|
if (task_done_to_taskserver(zmq_to_qp_run_socket,worker_id,task_id(i)) == -1) then
|
|
call sleep(1)
|
|
if (task_done_to_taskserver(zmq_to_qp_run_socket,worker_id,task_id(i)) == -1) then
|
|
ctask = 0
|
|
done = .true.
|
|
exit
|
|
endif
|
|
endif
|
|
end do
|
|
if(ctask > 0) then
|
|
call sort_selection_buffer(buf)
|
|
call merge_selection_buffers(buf,buf2)
|
|
call push_selection_results(zmq_socket_push, pt2, buf, task_id(1), ctask)
|
|
buf%mini = buf2%mini
|
|
pt2(:) = 0d0
|
|
buf%cur = 0
|
|
end if
|
|
ctask = 0
|
|
end if
|
|
|
|
if(done) exit
|
|
ctask = ctask + 1
|
|
end do
|
|
|
|
|
|
integer, external :: disconnect_from_taskserver
|
|
if (disconnect_from_taskserver(zmq_to_qp_run_socket,worker_id) == -1) then
|
|
continue
|
|
endif
|
|
|
|
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
|
|
call end_zmq_push_socket(zmq_socket_push,thread)
|
|
if (buffer_ready) then
|
|
call delete_selection_buffer(buf)
|
|
call delete_selection_buffer(buf2)
|
|
endif
|
|
end subroutine
|
|
|
|
|
|
subroutine push_selection_results(zmq_socket_push, pt2, b, task_id, ntask)
|
|
use f77_zmq
|
|
use selection_types
|
|
implicit none
|
|
|
|
integer(ZMQ_PTR), intent(in) :: zmq_socket_push
|
|
double precision, intent(in) :: pt2(N_states)
|
|
type(selection_buffer), intent(inout) :: b
|
|
integer, intent(in) :: ntask, task_id(*)
|
|
integer :: rc
|
|
|
|
rc = f77_zmq_send( zmq_socket_push, b%cur, 4, ZMQ_SNDMORE)
|
|
if(rc /= 4) then
|
|
print *, 'f77_zmq_send( zmq_socket_push, b%cur, 4, ZMQ_SNDMORE)'
|
|
endif
|
|
|
|
if (b%cur > 0) then
|
|
|
|
rc = f77_zmq_send( zmq_socket_push, pt2, 8*N_states, ZMQ_SNDMORE)
|
|
if(rc /= 8*N_states) then
|
|
print *, 'f77_zmq_send( zmq_socket_push, pt2, 8*N_states, ZMQ_SNDMORE)'
|
|
endif
|
|
|
|
rc = f77_zmq_send( zmq_socket_push, b%val(1), 8*b%cur, ZMQ_SNDMORE)
|
|
if(rc /= 8*b%cur) then
|
|
print *, 'f77_zmq_send( zmq_socket_push, b%val(1), 8*b%cur, ZMQ_SNDMORE)'
|
|
endif
|
|
|
|
rc = f77_zmq_send( zmq_socket_push, b%det(1,1,1), bit_kind*N_int*2*b%cur, ZMQ_SNDMORE)
|
|
if(rc /= bit_kind*N_int*2*b%cur) then
|
|
print *, 'f77_zmq_send( zmq_socket_push, b%det(1,1,1), bit_kind*N_int*2*b%cur, ZMQ_SNDMORE)'
|
|
endif
|
|
|
|
endif
|
|
|
|
rc = f77_zmq_send( zmq_socket_push, ntask, 4, ZMQ_SNDMORE)
|
|
if(rc /= 4) then
|
|
print *, 'f77_zmq_send( zmq_socket_push, ntask, 4, ZMQ_SNDMORE)'
|
|
endif
|
|
|
|
rc = f77_zmq_send( zmq_socket_push, task_id(1), ntask*4, 0)
|
|
if(rc /= 4*ntask) then
|
|
print *, 'f77_zmq_send( zmq_socket_push, task_id(1), ntask*4, 0)'
|
|
endif
|
|
|
|
! Activate is zmq_socket_push is a REQ
|
|
IRP_IF ZMQ_PUSH
|
|
IRP_ELSE
|
|
character*(2) :: ok
|
|
rc = f77_zmq_recv( zmq_socket_push, ok, 2, 0)
|
|
if ((rc /= 2).and.(ok(1:2) /= 'ok')) then
|
|
print *, irp_here//': error in receiving ok'
|
|
stop -1
|
|
endif
|
|
IRP_ENDIF
|
|
|
|
end subroutine
|
|
|
|
|
|
subroutine pull_selection_results(zmq_socket_pull, pt2, val, det, N, task_id, ntask)
|
|
use f77_zmq
|
|
use selection_types
|
|
implicit none
|
|
integer(ZMQ_PTR), intent(in) :: zmq_socket_pull
|
|
double precision, intent(inout) :: pt2(N_states)
|
|
double precision, intent(out) :: val(*)
|
|
integer(bit_kind), intent(out) :: det(N_int, 2, *)
|
|
integer, intent(out) :: N, ntask, task_id(*)
|
|
integer :: rc, rn, i
|
|
|
|
rc = f77_zmq_recv( zmq_socket_pull, N, 4, 0)
|
|
if(rc /= 4) then
|
|
print *, 'f77_zmq_recv( zmq_socket_pull, N, 4, 0)'
|
|
endif
|
|
|
|
if (N>0) then
|
|
rc = f77_zmq_recv( zmq_socket_pull, pt2, N_states*8, 0)
|
|
if(rc /= 8*N_states) then
|
|
print *, 'f77_zmq_recv( zmq_socket_pull, pt2, N_states*8, 0)'
|
|
endif
|
|
|
|
rc = f77_zmq_recv( zmq_socket_pull, val(1), 8*N, 0)
|
|
if(rc /= 8*N) then
|
|
print *, 'f77_zmq_recv( zmq_socket_pull, val(1), 8*N, 0)'
|
|
endif
|
|
|
|
rc = f77_zmq_recv( zmq_socket_pull, det(1,1,1), bit_kind*N_int*2*N, 0)
|
|
if(rc /= bit_kind*N_int*2*N) then
|
|
print *, 'f77_zmq_recv( zmq_socket_pull, det(1,1,1), bit_kind*N_int*2*N, 0)'
|
|
endif
|
|
else
|
|
pt2(:) = 0.d0
|
|
endif
|
|
|
|
rc = f77_zmq_recv( zmq_socket_pull, ntask, 4, 0)
|
|
if(rc /= 4) then
|
|
print *, 'f77_zmq_recv( zmq_socket_pull, ntask, 4, 0)'
|
|
endif
|
|
|
|
rc = f77_zmq_recv( zmq_socket_pull, task_id(1), ntask*4, 0)
|
|
if(rc /= 4*ntask) then
|
|
print *, 'f77_zmq_recv( zmq_socket_pull, task_id(1), ntask*4, 0)'
|
|
endif
|
|
|
|
! Activate is zmq_socket_pull is a REP
|
|
IRP_IF ZMQ_PUSH
|
|
IRP_ELSE
|
|
rc = f77_zmq_send( zmq_socket_pull, 'ok', 2, 0)
|
|
if (rc /= 2) then
|
|
print *, irp_here//': error in sending ok'
|
|
stop -1
|
|
endif
|
|
IRP_ENDIF
|
|
end subroutine
|
|
|
|
|
|
|