10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-07-03 18:05:59 +02:00
quantum_package/plugins/Full_CI_ZMQ/zmq_selection.irp.f
Anthony Scemama 4098b05202 Squashed commit of the following:
commit 96715abd7bc0645b994fc4fff1c764e7bec3042e
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Thu Sep 6 12:08:34 2018 +0200

    Tasks

commit e43b1e2faff5ad1ec4ecd2eb99e8d86e0000a9a2
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Thu Sep 6 11:47:02 2018 +0200

    Fixed print

commit c498c8944b5695b953909711a2e9a542e1bc6015
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Thu Sep 6 11:11:51 2018 +0200

    PT2 and shiftedBk fixed

commit 965cf0361d54df096c9bfca93f9d50ecd946c198
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Wed Sep 5 18:48:59 2018 +0200

    Shifted Bk multistate broken

commit 87ef641b65a122fa1256605cbe098c1a0de04bc0
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Wed Sep 5 17:23:38 2018 +0200

    PT2 fixed

commit a2adb533bcaf96191a24ff5fcef86cd14ac00697
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Wed Sep 5 16:55:05 2018 +0200

    Working on PT2 (broken)

commit 33f52991b65ac42ced5521ef0e713df765268860
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Wed Sep 5 12:13:23 2018 +0200

    Fixed missing argument

commit 712bf75f76421880299dc65b30acfda3d531f709
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Wed Sep 5 11:42:31 2018 +0200

    Fixed floating invalid in PT2

commit cf2412ebd99f9acf573a5180603611f1c3e35155
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Wed Sep 5 11:34:37 2018 +0200

    n_states_diag >= n_states

commit bb415435e4d9be72a285ec789c3d63046a9173e4
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Wed Sep 5 11:23:41 2018 +0200

    Fixed final print

commit f2d339cf7b
Merge: cfa8e1dc 52ca18c1
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 20:51:14 2018 +0200

    Merge branch 'thesis' of ssh://github.com/garniron/quantum_package into thesis

commit cfa8e1dc34
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 20:50:09 2018 +0200

    restored relative_error

commit bccad69c77
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 20:47:11 2018 +0200

    uninitialized variable

commit 52ca18c152
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 20:47:11 2018 +0200

    uninitialized variable

commit ba0094f5f8
Merge: 093e3fd0 68458296
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 20:07:15 2018 +0200

    merge with garniroy

commit 68458296dc
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Tue Sep 4 18:43:39 2018 +0200

    Almost working but still broken

commit 9ebb88cbf3
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Tue Sep 4 18:05:00 2018 +0200

    Cleaning

commit 873035e016
Author: Anthony Scemama <scemama@irsamc.ups-tlse.fr>
Date:   Tue Sep 4 17:31:45 2018 +0200

    Squashed commit of the following:

    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

    commit 093e3fd021
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Tue Sep 4 16:13:00 2018 +0200

        removed ungodly hack

    commit 8529a0f3f6
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Tue Sep 4 14:57:19 2018 +0200

        reduced prints in pt2_stoch

    commit 03b8f353bd
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Tue Sep 4 14:41:46 2018 +0200

        teeth building check for pt2_stoch

    commit 0d91b9310a
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Tue Sep 4 14:35:04 2018 +0200

        timestamp of first pull

    commit 34d9fa0165
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Tue Sep 4 14:27:10 2018 +0200

        potential numerical precision bug

    commit 9a0f900d8c
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Tue Sep 4 14:09:51 2018 +0200

        tests if teeth can be built

    commit dda0dc34df
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Mon Sep 3 17:48:04 2018 +0200

        corrected pt2_find_sample

    commit a521f0cb82
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Mon Sep 3 16:08:02 2018 +0200

        tasks get by batches of Nproc

    commit 997a5a1265
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Mon Sep 3 14:18:04 2018 +0200

        buffered task_id send

    commit 99ea7948e0
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Mon Sep 3 12:29:12 2018 +0200

        unbalanced fragmentation

    commit abb3b7e08b
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Sun Sep 2 17:18:44 2018 +0200

        overflow of pt2_J

    commit 8df49f394b
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Sun Sep 2 15:58:48 2018 +0200

        removed useless computation of intermediate checkpoints

    commit 4ba5b79eb3
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Sun Sep 2 15:50:14 2018 +0200

        dressing only sent for chosen checkpoint

    commit a4a6a69459
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Sat Sep 1 17:01:56 2018 +0200

        cumulative dot_F

    commit 6a7f04cb79
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Sat Sep 1 16:58:07 2018 +0200

        simpler purge

    commit 168ca2f2e2
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Fri Aug 31 21:07:01 2018 +0200

        task list optimized

    commit de4a0d0caf
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Fri Aug 31 18:57:03 2018 +0200

        removed print

    commit fee31d4e3e
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Fri Aug 31 18:56:23 2018 +0200

        dress fragmentation

    commit 02893a419d
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Fri Aug 31 15:52:16 2018 +0200

        bug in blocked search - replaced with thesis version

    commit bb6e073cf1
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Thu Aug 30 21:24:45 2018 +0200

        ungodly hack to prevent double providing

    commit 0609e8c627
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Thu Aug 30 20:52:05 2018 +0200

        debugging

    commit a254fdd7cf
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Thu Aug 30 15:24:07 2018 +0200

        parallel bug

    commit 2a6c1941d4
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Thu Aug 30 11:43:11 2018 +0200

        corrected when relative_error=0d0

    commit bac039bdf1
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Thu Aug 30 10:58:17 2018 +0200

        relative error 1d-5

    commit aae9d203ec
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Thu Aug 30 10:07:02 2018 +0200

        potential fragmentation bug

    commit ad69f39f99
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Wed Aug 29 20:54:58 2018 +0200

        dress_zmq re-implemented

    commit d78f64732a
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Wed Aug 29 11:30:19 2018 +0200

        pt2_stoch re-implemented

    commit 4b9b54e19a
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Tue Aug 28 10:24:38 2018 +0200

        removed test for phase_mask_bit

    commit 3abccca5e3
    Author: Yann Garniron <yann.garniron@yahoo.fr>
    Date:   Fri Aug 3 23:44:05 2018 +0200

        phasemask_bit

commit 093e3fd021
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 16:13:00 2018 +0200

    removed ungodly hack

commit 8529a0f3f6
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 14:57:19 2018 +0200

    reduced prints in pt2_stoch

commit 03b8f353bd
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 14:41:46 2018 +0200

    teeth building check for pt2_stoch

commit 0d91b9310a
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 14:35:04 2018 +0200

    timestamp of first pull

commit 34d9fa0165
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 14:27:10 2018 +0200

    potential numerical precision bug

commit 9a0f900d8c
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Sep 4 14:09:51 2018 +0200

    tests if teeth can be built

commit dda0dc34df
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Mon Sep 3 17:48:04 2018 +0200

    corrected pt2_find_sample

commit a521f0cb82
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Mon Sep 3 16:08:02 2018 +0200

    tasks get by batches of Nproc

commit 997a5a1265
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Mon Sep 3 14:18:04 2018 +0200

    buffered task_id send

commit 99ea7948e0
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Mon Sep 3 12:29:12 2018 +0200

    unbalanced fragmentation

commit abb3b7e08b
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Sun Sep 2 17:18:44 2018 +0200

    overflow of pt2_J

commit 8df49f394b
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Sun Sep 2 15:58:48 2018 +0200

    removed useless computation of intermediate checkpoints

commit 4ba5b79eb3
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Sun Sep 2 15:50:14 2018 +0200

    dressing only sent for chosen checkpoint

commit a4a6a69459
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Sat Sep 1 17:01:56 2018 +0200

    cumulative dot_F

commit 6a7f04cb79
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Sat Sep 1 16:58:07 2018 +0200

    simpler purge

commit 168ca2f2e2
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Fri Aug 31 21:07:01 2018 +0200

    task list optimized

commit de4a0d0caf
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Fri Aug 31 18:57:03 2018 +0200

    removed print

commit fee31d4e3e
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Fri Aug 31 18:56:23 2018 +0200

    dress fragmentation

commit 02893a419d
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Fri Aug 31 15:52:16 2018 +0200

    bug in blocked search - replaced with thesis version

commit bb6e073cf1
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Thu Aug 30 21:24:45 2018 +0200

    ungodly hack to prevent double providing

commit 0609e8c627
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Thu Aug 30 20:52:05 2018 +0200

    debugging

commit a254fdd7cf
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Thu Aug 30 15:24:07 2018 +0200

    parallel bug

commit 2a6c1941d4
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Thu Aug 30 11:43:11 2018 +0200

    corrected when relative_error=0d0

commit bac039bdf1
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Thu Aug 30 10:58:17 2018 +0200

    relative error 1d-5

commit aae9d203ec
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Thu Aug 30 10:07:02 2018 +0200

    potential fragmentation bug

commit ad69f39f99
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Wed Aug 29 20:54:58 2018 +0200

    dress_zmq re-implemented

commit d78f64732a
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Wed Aug 29 11:30:19 2018 +0200

    pt2_stoch re-implemented

commit 4b9b54e19a
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Tue Aug 28 10:24:38 2018 +0200

    removed test for phase_mask_bit

commit 3abccca5e3
Author: Yann Garniron <yann.garniron@yahoo.fr>
Date:   Fri Aug 3 23:44:05 2018 +0200

    phasemask_bit
2018-09-06 15:19:51 +02:00

188 lines
5.8 KiB
Fortran

subroutine ZMQ_selection(N_in, pt2)
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
integer :: i, N
integer, external :: omp_get_thread_num
double precision, intent(out) :: pt2(N_states)
N = max(N_in,1)
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
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,'threshold_selectors',threshold_selectors,1) == -1) then
stop 'Unable to put threshold_selectors 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'
endif
if (zmq_put_dvector(zmq_to_qp_run_socket,1,'threshold_generators',threshold_generators,1) == -1) then
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=64000) :: task
integer :: j,k,ipos
ipos=1
task = ' '
do i= 1, N_det_generators
do j=1,pt2_F(pt2_J(i))
write(task(ipos:ipos+30),'(I9,1X,I9,1X,I9,''|'')') j, pt2_J(i), N
ipos += 30
if (ipos > 63970) 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
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
nproc_target = nproc
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)/mem))
nproc_target = min(nproc_target,nproc)
endif
!$OMP PARALLEL DEFAULT(shared) SHARED(b, pt2) PRIVATE(i) NUM_THREADS(nproc_target+1)
i = omp_get_thread_num()
if (i==0) then
call selection_collector(zmq_socket_pull, b, N, pt2)
else
call selection_slave_inproc(i)
endif
!$OMP END PARALLEL
call end_parallel_job(zmq_to_qp_run_socket, zmq_socket_pull, 'selection')
do i=N_det+1,N_states
pt2(i) = 0.d0
enddo
if (N_in > 0) then
call fill_H_apply_buffer_no_selection(b%cur,b%det,N_int,0)
call copy_H_apply_buffer_to_wf()
if (s2_eig.or.(N_states > 1) ) then
call make_s2_eigenfunction
endif
call save_wavefunction
endif
call delete_selection_buffer(b)
end subroutine
subroutine selection_slave_inproc(i)
implicit none
integer, intent(in) :: i
call run_selection_slave(1,i,pt2_e0_denominator)
end
subroutine selection_collector(zmq_socket_pull, b, N, pt2)
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
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
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)
allocate(task_id(N_det_generators))
more = 1
pt2(:) = 0d0
pt2_mwen(:) = 0.d0
do while (more == 1)
call pull_selection_results(zmq_socket_pull, pt2_mwen, b2%val(1), b2%det(1,1,1), b2%cur, task_id, ntask)
pt2(:) += pt2_mwen(:)
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
call delete_selection_buffer(b2)
call sort_selection_buffer(b)
call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
end subroutine