10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-06-17 02:35:26 +02:00
quantum_package/src/ZMQ/put_get.irp.f

100 lines
2.6 KiB
Fortran
Raw Normal View History

2017-11-29 13:52:52 +01:00
integer function zmq_put_dvector(zmq_to_qp_run_socket, worker_id, name, x, size_x)
2017-11-27 10:58:32 +01:00
use f77_zmq
implicit none
BEGIN_DOC
! Put the X vector on the qp_run scheduler
END_DOC
integer(ZMQ_PTR), intent(in) :: zmq_to_qp_run_socket
integer, intent(in) :: worker_id
character*(*) :: name
integer, intent(in) :: size_x
double precision, intent(out) :: x(size_x)
integer :: rc
character*(256) :: msg
2017-11-29 15:15:10 +01:00
zmq_put_dvector = 0
2017-11-27 10:58:32 +01:00
2017-11-29 13:52:52 +01:00
write(msg,'(A,1X,I8,1X,A200)') 'put_data '//trim(zmq_state), worker_id, name
2017-11-27 10:58:32 +01:00
rc = f77_zmq_send(zmq_to_qp_run_socket,trim(msg),len(trim(msg)),ZMQ_SNDMORE)
if (rc /= len(trim(msg))) then
2017-11-29 15:15:10 +01:00
zmq_put_dvector = -1
2017-11-29 13:52:52 +01:00
return
2017-11-27 10:58:32 +01:00
endif
rc = f77_zmq_send(zmq_to_qp_run_socket,x,size_x*8,0)
if (rc /= size_x*8) then
2017-11-29 15:15:10 +01:00
zmq_put_dvector = -1
2017-11-29 13:52:52 +01:00
return
2017-11-27 10:58:32 +01:00
endif
rc = f77_zmq_recv(zmq_to_qp_run_socket,msg,len(msg),0)
if (msg(1:rc) /= 'put_data_reply ok') then
2017-11-29 15:15:10 +01:00
zmq_put_dvector = -1
2017-11-29 13:52:52 +01:00
return
2017-11-27 10:58:32 +01:00
endif
end
2017-11-29 13:52:52 +01:00
integer function zmq_get_dvector(zmq_to_qp_run_socket, worker_id, name, x, size_x)
2017-11-27 10:58:32 +01:00
use f77_zmq
implicit none
BEGIN_DOC
! Get psi_coef from the qp_run scheduler
END_DOC
integer(ZMQ_PTR), intent(in) :: zmq_to_qp_run_socket
integer, intent(in) :: worker_id
integer, intent(in) :: size_x
character*(*), intent(in) :: name
double precision, intent(out) :: x(size_x)
integer :: rc
integer*8 :: rc8
2017-11-27 23:38:48 +01:00
character*(256) :: msg
2017-11-27 10:58:32 +01:00
2018-01-05 15:12:27 +01:00
PROVIDE zmq_state
2017-11-29 13:52:52 +01:00
! Success
zmq_get_dvector = 0
2017-11-29 15:15:10 +01:00
if (mpi_master) then
write(msg,'(A,1X,I8,1X,A200)') 'get_data '//trim(zmq_state), worker_id, name
rc = f77_zmq_send(zmq_to_qp_run_socket,trim(msg),len(trim(msg)),0)
2017-11-29 19:10:27 +01:00
if (rc /= len(trim(msg))) then
zmq_get_dvector = -1
go to 10
endif
2017-11-27 10:58:32 +01:00
2017-11-29 15:15:10 +01:00
rc = f77_zmq_recv(zmq_to_qp_run_socket,msg,len(msg),0)
2017-11-29 19:10:27 +01:00
if (msg(1:14) /= 'get_data_reply') then
zmq_get_dvector = -1
go to 10
endif
2017-11-27 10:58:32 +01:00
2017-11-29 15:15:10 +01:00
rc = f77_zmq_recv(zmq_to_qp_run_socket,x,size_x*8,0)
2017-11-29 19:10:27 +01:00
if (rc /= size_x*8) then
zmq_get_dvector = -1
go to 10
endif
2017-11-27 10:58:32 +01:00
endif
2017-11-28 14:20:17 +01:00
2017-11-29 19:10:27 +01:00
10 continue
2017-11-29 13:52:52 +01:00
2017-11-28 14:20:17 +01:00
IRP_IF MPI
integer :: ierr
include 'mpif.h'
2017-11-29 13:52:52 +01:00
call MPI_BCAST (zmq_get_dvector, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
if (ierr /= MPI_SUCCESS) then
print *, irp_here//': Unable to broadcast zmq_get_dvector'
stop -1
endif
2017-11-29 19:10:27 +01:00
call MPI_BCAST (x, size_x, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)
2017-11-28 14:20:17 +01:00
if (ierr /= MPI_SUCCESS) then
2017-11-29 19:10:27 +01:00
print *, irp_here//': Unable to broadcast dvector'
2017-11-28 14:20:17 +01:00
stop -1
endif
IRP_ENDIF
2017-11-29 19:10:27 +01:00
2017-11-27 10:58:32 +01:00
end