Ignore:
Timestamp:
Mar 8, 2016 5:49:27 AM (8 years ago)
Author:
raasch
Message:

pmc-change in server-client get-put, spectra-directives removed, spectra-package modularized

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/pmc_server.f90

    r1780 r1786  
    2020! Current revisions:
    2121! ------------------
    22 !
     22! change in client-server data transfer: server now gets data from client
     23! instead that client put's it to the server
    2324!
    2425! Former revisions:
     
    336337      IMPLICIT none
    337338
     339!
     340!--   Naming convention for appendices:   _sc  -> server to client transfer
     341!--                                       _cs  -> client to server transfer
     342!--                                       Send -> Server to client transfer
     343!--                                       Recv -> client to server transfer
    338344      INTEGER,INTENT(IN)                      :: ClientId
    339345
     
    347353      INTEGER,DIMENSION(1024)                 :: req
    348354      Type(c_ptr)                             :: base_ptr
    349       REAL(kind=wp),DIMENSION(:),POINTER      :: base_array
     355      REAL(wp),DIMENSION(:),POINTER,SAVE :: base_array_sc  !Base array for server to client transfer
     356      REAL(wp),DIMENSION(:),POINTER,SAVE :: base_array_cs  !Base array for client to server transfer
    350357      INTEGER(KIND=MPI_ADDRESS_KIND)          :: WinSize
    351358
     359!
     360!--   Server to client direction
    352361      myIndex = 1
    353362      rCount  = 0
    354363      bufsize = 8
    355364
    356       ! First stride, Compute size and set index
    357 
     365!
     366!--   First stride: Compute size and set index
    358367      do i=1,Clients(ClientId)%inter_npes
    359368         aPE => Clients(ClientId)%PEs(i)
     
    362371            ar  => aPE%array_list(j)
    363372            if(ar%NrDims == 2) then
    364                arlen     = aPE%NrEle;                             ! 2D
     373               arlen     = aPE%NrEle                              ! 2D
    365374            else if(ar%NrDims == 3) then
    366                arlen     = aPE%NrEle * ar%A_dim(4);               ! PALM 3D
     375               arlen     = aPE%NrEle * ar%A_dim(4);               ! 3D
    367376            else
    368377               arlen     = -1
    369378            end if
    370             ar%BufIndex = myIndex
     379            ar%SendIndex = myIndex
    371380
    372381            tag    = tag+1
     
    381390            myIndex = myIndex+arlen
    382391            bufsize = bufsize+arlen
    383             ar%BufSize = arlen
     392            ar%SendSize = arlen
    384393
    385394         end do
    386          if(rCount > 0) then                                          ! Wait for all send completed
     395         if(rCount > 0) then                       ! Wait for all send completed
    387396            CALL MPI_Waitall (rCount, req, MPI_STATUSES_IGNORE, ierr)
    388397         end if
    389398      end do
    390399
    391       ! Create RMA (One Sided Communication) window for data buffer
    392 
    393       CALL PMC_Alloc_mem (base_array, bufsize, base_ptr)
    394       Clients(ClientId)%TotalBufferSize = bufsize*wp       !Total buffer size in Byte
     400!
     401!--   Create RMA (One Sided Communication) window for data buffer server to
     402!--   client transfer.
     403!--   The buffer of MPI_Get (counter part of transfer) can be PE-local, i.e.
     404!--   it can but must not be part of the MPI RMA window.
     405!--   Only one RMA window is required to prepare the data
     406!--   for server -> client transfer on the server side and
     407!--   for client -> server transfer on the client side
     408      CALL PMC_Alloc_mem (base_array_sc, bufsize)
     409      Clients(ClientId)%TotalBufferSize = bufsize*wp   !Total buffer size in Byte
    395410
    396411      WinSize = bufsize*wp
    397 !      write(9,*) 'PMC_S_SetInd_and_Mem ',m_model_rank,Clients(ClientId)%inter_npes,WinSize,bufsize
    398       CALL MPI_Win_create (base_array, WinSize, wp, MPI_INFO_NULL, Clients(ClientId)%intra_comm, Clients(ClientId)%BufWin, ierr);
    399       CALL MPI_Win_fence (0, Clients(ClientId)%BufWin, ierr);                    !  Open Window to set data
    400       CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr)
    401 
    402       ! Second stride, Set Buffer pointer
    403 
     412      CALL MPI_Win_create (base_array_sc, WinSize, wp, MPI_INFO_NULL,          &
     413                  Clients(ClientId)%intra_comm,  Clients(ClientId)%win_server_client, ierr)
     414      CALL MPI_Win_fence (0, Clients(ClientId)%win_server_client, ierr);        !  Open Window to set data
     415!
     416!--   Second stride: Set Buffer pointer
    404417      do i=1,Clients(ClientId)%inter_npes
    405418         aPE => Clients(ClientId)%PEs(i)
    406419         do j=1,aPE%Nr_arrays
    407420            ar  => aPE%array_list(j)
    408 !--         TO_DO:  Adressrechnung ueberlegen?
    409             ar%SendBuf = c_loc(base_array(ar%BufIndex))                         !kk Adressrechnung ueberlegen
    410             if(ar%BufIndex+ar%BufSize > bufsize) then
    411 !--            TO_DO: can this error really happen, and what can be the reason?
    412                write(0,'(a,i4,4i7,1x,a)') 'Buffer too small ',i,ar%BufIndex,ar%BufSize,ar%BufIndex+ar%BufSize,bufsize,trim(ar%name)
     421            ar%SendBuf = c_loc(base_array_sc(ar%SendIndex))
     422            if(ar%SendIndex+ar%SendSize > bufsize) then
     423               write(0,'(a,i4,4i7,1x,a)') 'Server Buffer too small ',i,ar%SendIndex,ar%SendSize,ar%SendIndex+ar%SendSize,bufsize,trim(ar%name)
    413424               CALL MPI_Abort (MPI_COMM_WORLD, istat, ierr)
    414425            end if
     426         end do
     427      end do
     428
     429!--   Client to server direction
     430
     431      bufsize  = 8
     432
     433!--   First stride, Compute size and set index
     434
     435      do i=1,Clients(ClientId)%inter_npes
     436         aPE => Clients(ClientId)%PEs(i)
     437         tag = 300
     438
     439         do j=1,aPE%Nr_arrays
     440            ar  => aPE%array_list(j)
     441
     442            ! Receive Index from client
     443            tag = tag+1
     444            CALL MPI_Recv (myIndex, 1, MPI_INTEGER, i-1, tag, Clients(ClientId)%inter_comm, MPI_STATUS_IGNORE, ierr)
     445
     446            if(ar%NrDims == 3) then
     447               bufsize = max(bufsize,aPE%NrEle * ar%A_dim(4))               ! 3D
     448            else
     449               bufsize = max(bufsize,aPE%NrEle)                             ! 2D
     450            end if
     451            ar%RecvIndex = myIndex
     452          end do
     453
     454      end do
     455
     456!--   Create RMA (One Sided Communication) data buffer
     457!--   The buffer for MPI_Get can be PE local, i.e. it can but must not be part of the MPI RMA window
     458
     459      CALL PMC_Alloc_mem (base_array_cs, bufsize, base_ptr)
     460      Clients(ClientId)%TotalBufferSize = bufsize*wp       !Total buffer size in Byte
     461
     462      CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr)
     463
     464!--   Second stride, Set Buffer pointer
     465
     466      do i=1,Clients(ClientId)%inter_npes
     467         aPE => Clients(ClientId)%PEs(i)
     468
     469         do j=1,aPE%Nr_arrays
     470            ar  => aPE%array_list(j)
     471            ar%RecvBuf = base_ptr
    415472         end do
    416473      end do
     
    465522      end do
    466523
    467       CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr)    ! buffer is full
     524      CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr)    ! buffer is filled
    468525
    469526      return
     
    480537      INTEGER                             ::  ip,ij,istat,ierr,j
    481538      INTEGER                             ::  myIndex
     539      INTEGER                             ::  nr
    482540      REAL(wp)                            ::  t1,t2
    483541      TYPE(PeDef),POINTER                 ::  aPE
     
    488546      REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d
    489547      REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d
     548      INTEGER                             ::  target_pe
     549      INTEGER(kind=MPI_ADDRESS_KIND)      ::  target_disp
    490550
    491551      t1 = PMC_Time()
    492       CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr)              ! Wait for MPI_Put from client
    493       t2 = PMC_Time()
    494       if(present(WaitTime)) WaitTime = t2-t1
     552      CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr)                         ! Wait for client to fill buffer
     553      t2 = PMC_Time()-t1
     554      if(present(WaitTime)) WaitTime = t2
     555
     556!      CALL MPI_Win_fence (0, Clients(ClientId)%win_server_client, ierr)            ! Fence might do it, test later
     557      CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr)                         ! Wait for buffer is filled
    495558
    496559      do ip=1,Clients(ClientId)%inter_npes
     
    498561         do j=1,aPE%Nr_arrays
    499562            ar  => aPE%array_list(j)
     563
     564            if(ar%RecvIndex < 0)  CYCLE
     565
     566            if(ar%NrDims == 2) then
     567               nr = aPE%NrEle
     568            else if(ar%NrDims == 3) then
     569               nr = aPE%NrEle*ar%A_dim(4)
     570            end if
     571
     572            buf_shape(1) = nr
     573            CALL c_f_pointer(ar%RecvBuf, buf, buf_shape)
     574!
     575!--         MPI passive target RMA
     576
     577            if(nr > 0)   then
     578               target_disp = ar%RecvIndex-1
     579               target_pe = ip-1+m_model_npes                         ! client PEs are located behind server PEs
     580               CALL MPI_Win_lock (MPI_LOCK_SHARED , target_pe, 0, Clients(ClientId)%win_server_client, ierr)
     581               CALL MPI_Get (buf, nr, MPI_REAL, target_pe, target_disp, nr, MPI_REAL, Clients(ClientId)%win_server_client, ierr)
     582               CALL MPI_Win_unlock (target_pe, Clients(ClientId)%win_server_client, ierr)
     583            end if
     584
    500585            myIndex=1
    501586            if(ar%NrDims == 2) then
    502                buf_shape(1) = aPE%NrEle
    503                CALL c_f_pointer(ar%SendBuf, buf, buf_shape)
    504587               CALL c_f_pointer(ar%data, data_2d, ar%A_dim(1:2))
    505588               do ij=1,aPE%NrEle
     
    508591               end do
    509592            else if(ar%NrDims == 3) then
    510                buf_shape(1) = aPE%NrEle*ar%A_dim(4)
    511                CALL c_f_pointer(ar%SendBuf, buf, buf_shape)
    512593               CALL c_f_pointer(ar%data, data_3d, ar%A_dim(1:3))
    513594               do ij=1,aPE%NrEle
     
    519600      end do
    520601
    521       CALL MPI_Barrier(Clients(ClientId)%intra_comm, ierr)              ! data copy finished, buffer is free for use agein
    522 
    523         return
    524602   END SUBROUTINE PMC_S_GetData_from_Buffer
    525603
Note: See TracChangeset for help on using the changeset viewer.