Index: palm/trunk/SOURCE/pmc_parent_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_server_mod.f90	(revision 1901)
+++ palm/trunk/SOURCE/pmc_parent_mod.f90	(revision 1933)
@@ -1,5 +1,5 @@
- MODULE pmc_server
-
-!--------------------------------------------------------------------------------!
+ MODULE pmc_parent
+
+!-------------------------------------------------------------------------------!
 ! This file is part of PALM.
 !
@@ -16,13 +16,16 @@
 !
 ! Copyright 1997-2016 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! ------------------
 ! 
-!
+! 
 ! Former revisions:
 ! -----------------
 ! $Id$
+!
+! 1901 2016-05-04 15:39:38Z raasch
+! Module renamed. Code clean up. The words server/client changed to parent/child. 
 !
 ! 1900 2016-05-04 15:27:53Z raasch
@@ -47,6 +50,6 @@
 !
 ! 1786 2016-03-08 05:49:27Z raasch
-! change in client-server data transfer: server now gets data from client
-! instead that client put's it to the server
+! change in child-parent data transfer: parent now gets data from child
+! instead that child put's it to the parent
 !
 ! 1779 2016-03-03 08:01:28Z raasch
@@ -68,6 +71,6 @@
 ! ------------
 !
-! Server part of Palm Model Coupler
-!------------------------------------------------------------------------------!
+! Parent part of Palm Model Coupler
+!-------------------------------------------------------------------------------!
 
 #if defined( __parallel )
@@ -80,13 +83,13 @@
 #endif
     USE kinds
-    USE pmc_general,                                                           &
-        ONLY: arraydef, clientdef, da_namedef, da_namelen, pedef,              &
+    USE pmc_general,                                                            &
+        ONLY: arraydef, childdef, da_namedef, da_namelen, pedef,                &
               pmc_g_setname, pmc_max_array, pmc_max_models, pmc_sort
 
-    USE pmc_handle_communicator,                                               &
-        ONLY: m_model_comm,m_model_rank,m_model_npes, m_to_client_comm,        &
-              m_world_rank, pmc_server_for_client
-
-    USE pmc_mpi_wrapper,                                                       &
+    USE pmc_handle_communicator,                                                &
+        ONLY: m_model_comm,m_model_rank,m_model_npes, m_to_child_comm,          &
+              m_world_rank, pmc_parent_for_child
+
+    USE pmc_mpi_wrapper,                                                        &
         ONLY: pmc_alloc_mem, pmc_bcast, pmc_time
 
@@ -96,21 +99,21 @@
    SAVE
 
-   TYPE clientindexdef
+   TYPE childindexdef
       INTEGER                              ::  nrpoints       !<
       INTEGER, DIMENSION(:,:), ALLOCATABLE ::  index_list_2d  !<
-   END TYPE clientindexdef
-
-   TYPE(clientdef), DIMENSION(pmc_max_models)      ::  clients     !<
-   TYPE(clientindexdef), DIMENSION(pmc_max_models) ::  indclients  !<
+   END TYPE childindexdef
+
+   TYPE(childdef), DIMENSION(pmc_max_models)       ::  children     !<
+   TYPE(childindexdef), DIMENSION(pmc_max_models)  ::  indchildren  !<
 
    INTEGER ::  next_array_in_list = 0  !<
 
 
-   PUBLIC pmc_server_for_client
-
-
-   INTERFACE pmc_serverinit
-      MODULE PROCEDURE  pmc_serverinit
-   END INTERFACE pmc_serverinit
+   PUBLIC pmc_parent_for_child
+
+
+   INTERFACE pmc_parentinit
+      MODULE PROCEDURE  pmc_parentinit
+   END INTERFACE pmc_parentinit
 
     INTERFACE pmc_s_set_2d_index_list
@@ -147,7 +150,7 @@
     END INTERFACE pmc_s_set_active_data_array
 
-    PUBLIC pmc_serverinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,      &
-           pmc_s_getdata_from_buffer, pmc_s_getnextarray,                      &
-           pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,             &
+    PUBLIC pmc_parentinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,       &
+           pmc_s_getdata_from_buffer, pmc_s_getnextarray,                       &
+           pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,              &
            pmc_s_set_dataarray, pmc_s_set_2d_index_list
 
@@ -155,9 +158,9 @@
 
 
- SUBROUTINE pmc_serverinit
+ SUBROUTINE pmc_parentinit
 
     IMPLICIT NONE
 
-    INTEGER ::  clientid  !<
+    INTEGER ::  childid   !<
     INTEGER ::  i         !<
     INTEGER ::  j         !<
@@ -165,46 +168,49 @@
 
 
-    DO  i = 1, SIZE( pmc_server_for_client )-1
-
-       clientid = pmc_server_for_client( i )
-
-       clients(clientid)%model_comm = m_model_comm
-       clients(clientid)%inter_comm = m_to_client_comm(clientid)
+    DO  i = 1, SIZE( pmc_parent_for_child )-1
+
+       childid = pmc_parent_for_child( i )
+
+       children(childid)%model_comm = m_model_comm
+       children(childid)%inter_comm = m_to_child_comm(childid)
+
 !
 !--    Get rank and size
-       CALL MPI_COMM_RANK( clients(clientid)%model_comm,                       &
-                           clients(clientid)%model_rank, istat )
-       CALL MPI_COMM_SIZE( clients(clientid)%model_comm,                       &
-                           clients(clientid)%model_npes, istat )
-       CALL MPI_COMM_REMOTE_SIZE( clients(clientid)%inter_comm,                &
-                                  clients(clientid)%inter_npes, istat )
+       CALL MPI_COMM_RANK( children(childid)%model_comm,                        &
+                           children(childid)%model_rank, istat )
+       CALL MPI_COMM_SIZE( children(childid)%model_comm,                        &
+                           children(childid)%model_npes, istat )
+       CALL MPI_COMM_REMOTE_SIZE( children(childid)%inter_comm,                 &
+                                  children(childid)%inter_npes, istat )
+
 !
 !--    Intra communicater is used for MPI_GET
-       CALL MPI_INTERCOMM_MERGE( clients(clientid)%inter_comm, .FALSE.,        &
-                                 clients(clientid)%intra_comm, istat )
-       CALL MPI_COMM_RANK( clients(clientid)%intra_comm,                       &
-                           clients(clientid)%intra_rank, istat )
-
-       ALLOCATE( clients(clientid)%pes(clients(clientid)%inter_npes))
-!
-!--    Allocate array of TYPE arraydef for all client PEs to store information
+       CALL MPI_INTERCOMM_MERGE( children(childid)%inter_comm, .FALSE.,         &
+                                 children(childid)%intra_comm, istat )
+       CALL MPI_COMM_RANK( children(childid)%intra_comm,                        &
+                           children(childid)%intra_rank, istat )
+
+       ALLOCATE( children(childid)%pes(children(childid)%inter_npes))
+
+!
+!--    Allocate array of TYPE arraydef for all child PEs to store information
 !--    of the transfer array
-       DO  j = 1, clients(clientid)%inter_npes
-         ALLOCATE( clients(clientid)%pes(j)%array_list(pmc_max_array) )
+       DO  j = 1, children(childid)%inter_npes
+         ALLOCATE( children(childid)%pes(j)%array_list(pmc_max_array) )
        ENDDO
 
-       CALL get_da_names_from_client (clientid)
-
-    ENDDO
-
- END SUBROUTINE pmc_serverinit
-
-
-
- SUBROUTINE pmc_s_set_2d_index_list( clientid, index_list )
+       CALL get_da_names_from_child (childid)
+
+    ENDDO
+
+ END SUBROUTINE pmc_parentinit
+
+
+
+ SUBROUTINE pmc_s_set_2d_index_list( childid, index_list )
 
      IMPLICIT NONE
 
-     INTEGER, INTENT(IN)                    :: clientid    !<
+     INTEGER, INTENT(IN)                    :: childid     !<
      INTEGER, DIMENSION(:,:), INTENT(INOUT) :: index_list  !<
 
@@ -219,13 +225,16 @@
 
      IF ( m_model_rank == 0 )  THEN
-!
-!--     Sort to ascending server PE
+
+!
+!--     Sort to ascending parent PE order
         CALL pmc_sort( index_list, 6 )
 
         is = 1
         DO  ip = 0, m_model_npes-1
-!
-!--        Split into server PEs
+
+!
+!--        Split into parent PEs
            ie = is - 1
+
 !
 !--        There may be no entry for this PE
@@ -244,18 +253,19 @@
               ian =  0
            ENDIF
-!
-!--        Send data to other server PEs
+
+!
+!--        Send data to other parent PEs
            IF ( ip == 0 )  THEN
-              indclients(clientid)%nrpoints = ian
+              indchildren(childid)%nrpoints = ian
               IF ( ian > 0)  THEN
-                  ALLOCATE( indclients(clientid)%index_list_2d(6,ian) )
-                  indclients(clientid)%index_list_2d(:,1:ian) =                &
+                  ALLOCATE( indchildren(childid)%index_list_2d(6,ian) )
+                  indchildren(childid)%index_list_2d(:,1:ian) =                 &
                                                              index_list(:,is:ie)
               ENDIF
            ELSE
-              CALL MPI_SEND( ian, 1, MPI_INTEGER, ip, 1000, m_model_comm,      &
+              CALL MPI_SEND( ian, 1, MPI_INTEGER, ip, 1000, m_model_comm,       &
                              istat )
               IF ( ian > 0)  THEN
-                  CALL MPI_SEND( index_list(1,is), 6*ian, MPI_INTEGER, ip,  &
+                  CALL MPI_SEND( index_list(1,is), 6*ian, MPI_INTEGER, ip,      &
                                  1001, m_model_comm, istat )
               ENDIF
@@ -267,12 +277,12 @@
      ELSE
 
-        CALL MPI_RECV( indclients(clientid)%nrpoints, 1, MPI_INTEGER, 0, 1000, &
+        CALL MPI_RECV( indchildren(childid)%nrpoints, 1, MPI_INTEGER, 0, 1000,  &
                        m_model_comm, MPI_STATUS_IGNORE, istat )
-        ian = indclients(clientid)%nrpoints
+        ian = indchildren(childid)%nrpoints
 
         IF ( ian > 0 )  THEN
-           ALLOCATE( indclients(clientid)%index_list_2d(6,ian) )
-           CALL MPI_RECV( indclients(clientid)%index_list_2d, 6*ian,           &
-                          MPI_INTEGER, 0, 1001, m_model_comm,                  &
+           ALLOCATE( indchildren(childid)%index_list_2d(6,ian) )
+           CALL MPI_RECV( indchildren(childid)%index_list_2d, 6*ian,            &
+                          MPI_INTEGER, 0, 1001, m_model_comm,                   &
                           MPI_STATUS_IGNORE, istat)
         ENDIF
@@ -280,7 +290,7 @@
      ENDIF
 
-     CALL set_pe_index_list( clientid, clients(clientid),                      &
-                             indclients(clientid)%index_list_2d,               &
-                             indclients(clientid)%nrpoints )
+     CALL set_pe_index_list( childid, children(childid),                        &
+                             indchildren(childid)%index_list_2d,                &
+                             indchildren(childid)%nrpoints )
 
  END SUBROUTINE pmc_s_set_2d_index_list
@@ -298,5 +308,6 @@
 
 
- LOGICAL FUNCTION pmc_s_getnextarray( clientid, myname )
+ LOGICAL FUNCTION pmc_s_getnextarray( childid, myname )
+
 !
 !-- List handling is still required to get minimal interaction with
@@ -304,5 +315,5 @@
 !-- TODO: what does "still" mean? Is there a chance to change this!
     CHARACTER(LEN=*), INTENT(OUT) ::  myname    !<
-    INTEGER(iwp), INTENT(IN)      ::  clientid  !<
+    INTEGER(iwp), INTENT(IN)      ::  childid   !<
 
     TYPE(arraydef), POINTER :: ar
@@ -310,9 +321,11 @@
 
     next_array_in_list = next_array_in_list + 1
-!
-!-- Array names are the same on all client PEs, so take first PE to get the name
-    ape => clients(clientid)%pes(1)
+
+!
+!-- Array names are the same on all children PEs, so take first PE to get the name
+    ape => children(childid)%pes(1)
 
     IF ( next_array_in_list > ape%nr_arrays )  THEN
+
 !
 !--    All arrays are done
@@ -323,4 +336,5 @@
     ar => ape%array_list(next_array_in_list)
     myname = ar%name
+
 !
 !-- Return true if legal array
@@ -332,9 +346,9 @@
 
 
- SUBROUTINE pmc_s_set_dataarray_2d( clientid, array, array_2 )
+ SUBROUTINE pmc_s_set_dataarray_2d( childid, array, array_2 )
 
     IMPLICIT NONE
 
-    INTEGER,INTENT(IN) ::  clientid  !<
+    INTEGER,INTENT(IN) ::  childid   !<
 
     REAL(wp), INTENT(IN), DIMENSION(:,:), POINTER           ::  array    !<
@@ -355,8 +369,8 @@
     IF ( PRESENT( array_2 ) )  THEN
        second_adr = C_LOC(array_2)
-       CALL pmc_s_setarray( clientid, nrdims, dims, array_adr,                 &
+       CALL pmc_s_setarray( childid, nrdims, dims, array_adr,                   &
                             second_adr = second_adr)
     ELSE
-       CALL pmc_s_setarray( clientid, nrdims, dims, array_adr )
+       CALL pmc_s_setarray( childid, nrdims, dims, array_adr )
     ENDIF
 
@@ -365,9 +379,9 @@
 
 
- SUBROUTINE pmc_s_set_dataarray_3d( clientid, array, nz_cl, nz, array_2 )
+ SUBROUTINE pmc_s_set_dataarray_3d( childid, array, nz_cl, nz, array_2 )
 
     IMPLICIT NONE
 
-    INTEGER, INTENT(IN) ::  clientid  !<
+    INTEGER, INTENT(IN) ::  childid   !<
     INTEGER, INTENT(IN) ::  nz        !<
     INTEGER, INTENT(IN) ::  nz_cl     !<
@@ -381,4 +395,5 @@
     TYPE(C_PTR)           ::  second_adr  !<
 
+!
 !-- TODO: the next assignment seems to be obsolete. Please check!
     dims      = 1
@@ -397,8 +412,8 @@
     IF ( PRESENT( array_2 ) )  THEN
       second_adr = C_LOC( array_2 )
-      CALL pmc_s_setarray( clientid, nrdims, dims, array_adr,                  &
+      CALL pmc_s_setarray( childid, nrdims, dims, array_adr,                    &
                            second_adr = second_adr)
     ELSE
-       CALL pmc_s_setarray( clientid, nrdims, dims, array_adr )
+       CALL pmc_s_setarray( childid, nrdims, dims, array_adr )
     ENDIF
 
@@ -407,7 +422,7 @@
 
 
- SUBROUTINE pmc_s_setind_and_allocmem( clientid )
-
-    USE control_parameters,                                                    &
+ SUBROUTINE pmc_s_setind_and_allocmem( childid )
+
+    USE control_parameters,                                                     &
         ONLY:  message_string
 
@@ -415,9 +430,9 @@
 
 !
-!-- Naming convention for appendices:   _sc  -> server to client transfer
-!--                                     _cs  -> client to server transfer
-!--                                     send -> server to client transfer
-!--                                     recv -> client to server transfer
-    INTEGER, INTENT(IN) ::  clientid  !<
+!-- Naming convention for appendices:   _pc  -> parent to child transfer
+!--                                     _cp  -> child to parent transfer
+!--                                     send -> parent to child transfer
+!--                                     recv -> child to parent transfer
+    INTEGER, INTENT(IN) ::  childid   !<
 
     INTEGER                        ::  arlen    !<
@@ -439,9 +454,9 @@
     TYPE(arraydef), POINTER ::  ar        !<
 
-    REAL(wp),DIMENSION(:), POINTER, SAVE ::  base_array_sc  !< base array for server to client transfer
-    REAL(wp),DIMENSION(:), POINTER, SAVE ::  base_array_cs  !< base array for client to server transfer
-
-!
-!-- Server to client direction
+    REAL(wp),DIMENSION(:), POINTER, SAVE ::  base_array_pc  !< base array for parent to child transfer
+    REAL(wp),DIMENSION(:), POINTER, SAVE ::  base_array_cp  !< base array for child to parent transfer
+
+!
+!-- Parent to child direction
     myindex = 1
     rcount  = 0
@@ -450,7 +465,7 @@
 !
 !-- First stride: compute size and set index
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
        tag = 200
 
@@ -469,9 +484,10 @@
           tag    = tag + 1
           rcount = rcount + 1
-          CALL MPI_ISEND( myindex, 1, MPI_INTEGER, i-1, tag,                   &
-                          clients(clientid)%inter_comm, req(rcount), ierr )
+          CALL MPI_ISEND( myindex, 1, MPI_INTEGER, i-1, tag,                    &
+                          children(childid)%inter_comm, req(rcount), ierr )
+
 !
 !--       Maximum of 1024 outstanding requests
-!--       TODO: what does this limit means?
+!--       TODO: what does this limit mean?
           IF ( rcount == 1024 )  THEN
              CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
@@ -492,38 +508,41 @@
 
 !
-!-- Create RMA (One Sided Communication) window for data buffer server to
-!-- client transfer.
+!-- Create RMA (One Sided Communication) window for data buffer parent to
+!-- child transfer.
 !-- The buffer of MPI_GET (counterpart of transfer) can be PE-local, i.e.
 !-- it can but must not be part of the MPI RMA window. Only one RMA window is
 !-- required to prepare the data for
-!--                       server -> client transfer on the server side
+!--                       parent -> child transfer on the parent side
 !-- and for
-!--                       client -> server transfer on the client side
-    CALL pmc_alloc_mem( base_array_sc, bufsize )
-    clients(clientid)%totalbuffersize = bufsize * wp
+!--                       child -> parent transfer on the child side
+    CALL pmc_alloc_mem( base_array_pc, bufsize )
+    children(childid)%totalbuffersize = bufsize * wp
 
     winsize = bufsize * wp
-    CALL MPI_WIN_CREATE( base_array_sc, winsize, wp, MPI_INFO_NULL,            &
-                         clients(clientid)%intra_comm,                         &
-                         clients(clientid)%win_server_client, ierr )
+    CALL MPI_WIN_CREATE( base_array_pc, winsize, wp, MPI_INFO_NULL,             &
+                         children(childid)%intra_comm,                          &
+                         children(childid)%win_parent_child, ierr )
+
 !
 !-- Open window to set data
-    CALL MPI_WIN_FENCE( 0, clients(clientid)%win_server_client, ierr )
+    CALL MPI_WIN_FENCE( 0, children(childid)%win_parent_child, ierr )
+
 !
 !-- Second stride: set buffer pointer
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
 
        DO  j = 1, ape%nr_arrays
 
           ar => ape%array_list(j)
-          ar%sendbuf = C_LOC( base_array_sc(ar%sendindex) )
-
-!--       TODO: replace this by standard PALM error message using the message routine
-          IF ( ar%sendindex + ar%sendsize > bufsize )  THEN
-             write(0,'(a,i4,4i7,1x,a)') 'Server Buffer too small ',i,        &
-                ar%sendindex,ar%sendsize,ar%sendindex+ar%sendsize,bufsize,trim(ar%name)
-             CALL MPI_Abort (MPI_COMM_WORLD, istat, ierr)
+          ar%sendbuf = C_LOC( base_array_pc(ar%sendindex) )
+
+          IF ( ar%sendindex + ar%sendsize > bufsize )  THEN             
+             WRITE( message_string, '(a,i4,4i7,1x,a)' )                         &
+                    'Parent buffer too small ',i,                               &
+                    ar%sendindex,ar%sendsize,ar%sendindex+ar%sendsize,          &
+                    bufsize,trim(ar%name)
+             CALL message( 'pmc_s_setind_and_allocmem', 'PA0429', 3, 2, 0, 6, 0 )
           ENDIF
        ENDDO
@@ -531,11 +550,12 @@
 
 !
-!-- Client to server direction
+!-- Child to parent direction
     bufsize = 8
+
 !
 !-- First stride: compute size and set index
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
        tag = 300
 
@@ -543,9 +563,10 @@
 
           ar => ape%array_list(j)
-!
-!--       Receive index from client
+
+!
+!--       Receive index from child
           tag = tag + 1
-          CALL MPI_RECV( myindex, 1, MPI_INTEGER, i-1, tag,                    &
-                         clients(clientid)%inter_comm, MPI_STATUS_IGNORE, ierr )
+          CALL MPI_RECV( myindex, 1, MPI_INTEGER, i-1, tag,                     &
+                         children(childid)%inter_comm, MPI_STATUS_IGNORE, ierr )
 
           IF ( ar%nrdims == 3 )  THEN
@@ -564,13 +585,14 @@
 !-- The buffer for MPI_GET can be PE local, i.e. it can but must not be part of
 !-- the MPI RMA window
-    CALL pmc_alloc_mem( base_array_cs, bufsize, base_ptr )
-    clients(clientid)%totalbuffersize = bufsize * wp
-
-    CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
+    CALL pmc_alloc_mem( base_array_cp, bufsize, base_ptr )
+    children(childid)%totalbuffersize = bufsize * wp
+
+    CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
+
 !
 !-- Second stride: set buffer pointer
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
 
        DO  j = 1, ape%nr_arrays
@@ -585,9 +607,9 @@
 
 
- SUBROUTINE pmc_s_fillbuffer( clientid, waittime )
+ SUBROUTINE pmc_s_fillbuffer( childid, waittime )
 
     IMPLICIT NONE
 
-    INTEGER, INTENT(IN)             ::  clientid  !<
+    INTEGER, INTENT(IN)             ::  childid   !<
 
     REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
@@ -612,6 +634,6 @@
 
 !
-!-- Synchronization of the model is done in pmci_client_synchronize and
-!-- pmci_server_synchronize. Therefor the RMA window can be filled without
+!-- Synchronization of the model is done in pmci_synchronize.
+!-- Therefor the RMA window can be filled without
 !-- sychronization at this point and a barrier is not necessary.
 !-- Please note that waittime has to be set in pmc_s_fillbuffer AND
@@ -619,12 +641,12 @@
     IF ( PRESENT( waittime) )  THEN
       t1 = pmc_time()
-      CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
+      CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
       t2 = pmc_time()
       waittime = t2- t1
     ENDIF
 
-    DO  ip = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(ip)
+    DO  ip = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(ip)
 
        DO  j = 1, ape%nr_arrays
@@ -649,5 +671,5 @@
              CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3) )
              DO  ij = 1, ape%nrele
-                buf(myindex:myindex+ar%a_dim(4)-1) =                           &
+                buf(myindex:myindex+ar%a_dim(4)-1) =                            &
                         data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i)
                 myindex = myindex + ar%a_dim(4)
@@ -659,7 +681,8 @@
 
     ENDDO
+
 !
 !-- Buffer is filled
-    CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
+    CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
 
  END SUBROUTINE pmc_s_fillbuffer
@@ -667,22 +690,22 @@
 
 
- SUBROUTINE pmc_s_getdata_from_buffer( clientid, waittime )
+ SUBROUTINE pmc_s_getdata_from_buffer( childid, waittime )
 
     IMPLICIT NONE
 
-    INTEGER, INTENT(IN)             ::  clientid  !<
-    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
-
-    INTEGER                        ::  ierr         !<
-    INTEGER                        ::  ij           !<
-    INTEGER                        ::  ip           !<
-    INTEGER                        ::  istat        !<
-    INTEGER                        ::  j            !<
-    INTEGER                        ::  myindex      !<
-    INTEGER                        ::  nr           !<
-    INTEGER                        ::  target_pe    !<
-    INTEGER(kind=MPI_ADDRESS_KIND) ::  target_disp  !<
-
-    INTEGER, DIMENSION(1)          ::  buf_shape    !<
+    INTEGER, INTENT(IN)             ::  childid      !<
+    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime     !<
+
+    INTEGER                        ::  ierr          !<
+    INTEGER                        ::  ij            !<
+    INTEGER                        ::  ip            !<
+    INTEGER                        ::  istat         !<
+    INTEGER                        ::  j             !<
+    INTEGER                        ::  myindex       !<
+    INTEGER                        ::  nr            !<
+    INTEGER                        ::  target_pe     !<
+    INTEGER(kind=MPI_ADDRESS_KIND) ::  target_disp   !<
+
+    INTEGER, DIMENSION(1)          ::  buf_shape     !<
 
     REAL(wp)                            ::  t1       !<
@@ -697,18 +720,20 @@
 
     t1 = pmc_time()
-!
-!-- Wait for client to fill buffer
-    CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
+
+!
+!-- Wait for child to fill buffer
+    CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
     t2 = pmc_time() - t1
     IF ( PRESENT( waittime ) )  waittime = t2
+
 !
 !-- TODO: check next statement
 !-- Fence might do it, test later
-!-- CALL MPI_WIN_FENCE( 0, clients(clientid)%win_server_client, ierr)
-    CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
-
-    DO  ip = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(ip)
+!-- CALL MPI_WIN_FENCE( 0, children(childid)%win_parent_child, ierr)
+    CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
+
+    DO  ip = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(ip)
 
        DO  j = 1, ape%nr_arrays
@@ -731,13 +756,14 @@
           IF ( nr > 0 )  THEN
              target_disp = ar%recvindex - 1
-!
-!--          Client PEs are located behind server PEs
+
+!
+!--          Child PEs are located behind parent PEs
              target_pe = ip - 1 + m_model_npes
-             CALL MPI_WIN_LOCK( MPI_LOCK_SHARED, target_pe, 0,                 &
-                                clients(clientid)%win_server_client, ierr )
-             CALL MPI_GET( buf, nr, MPI_REAL, target_pe, target_disp, nr,      &
-                           MPI_REAL, clients(clientid)%win_server_client, ierr )
-             CALL MPI_WIN_UNLOCK( target_pe,                                   &
-                                  clients(clientid)%win_server_client, ierr )
+             CALL MPI_WIN_LOCK( MPI_LOCK_SHARED, target_pe, 0,                  &
+                                children(childid)%win_parent_child, ierr )
+             CALL MPI_GET( buf, nr, MPI_REAL, target_pe, target_disp, nr,       &
+                           MPI_REAL, children(childid)%win_parent_child, ierr )
+             CALL MPI_WIN_UNLOCK( target_pe,                                    &
+                                  children(childid)%win_parent_child, ierr )
           ENDIF
 
@@ -755,5 +781,5 @@
              CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3))
              DO  ij = 1, ape%nrele
-                data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i) =     &
+                data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i) =      &
                                               buf(myindex:myindex+ar%a_dim(4)-1)
                 myindex = myindex + ar%a_dim(4)
@@ -770,37 +796,39 @@
 
 
- SUBROUTINE get_da_names_from_client( clientid )
-!
-!-- Get data array description and name from client
+ SUBROUTINE get_da_names_from_child( childid )
+
+!
+!-- Get data array description and name from child
     IMPLICIT NONE
 
-    INTEGER, INTENT(IN) ::  clientid  !<
+    INTEGER, INTENT(IN) ::  childid  !<
 
     TYPE(da_namedef) ::  myname  !<
 
     DO
-       CALL pmc_bcast( myname%couple_index, 0, comm=m_to_client_comm(clientid) )
+       CALL pmc_bcast( myname%couple_index, 0, comm=m_to_child_comm(childid) )
        IF ( myname%couple_index == -1 )  EXIT
-       CALL pmc_bcast( myname%serverdesc,   0, comm=m_to_client_comm(clientid) )
-       CALL pmc_bcast( myname%nameonserver, 0, comm=m_to_client_comm(clientid) )
-       CALL pmc_bcast( myname%clientdesc,   0, comm=m_to_client_comm(clientid) )
-       CALL pmc_bcast( myname%nameonclient, 0, comm=m_to_client_comm(clientid) )
-
-       CALL pmc_g_setname( clients(clientid), myname%couple_index,             &
-                           myname%nameonserver )
+       CALL pmc_bcast( myname%parentdesc,   0, comm=m_to_child_comm(childid) )
+       CALL pmc_bcast( myname%nameonparent, 0, comm=m_to_child_comm(childid) )
+       CALL pmc_bcast( myname%childdesc,    0, comm=m_to_child_comm(childid) )
+       CALL pmc_bcast( myname%nameonchild,  0, comm=m_to_child_comm(childid) )
+
+       CALL pmc_g_setname( children(childid), myname%couple_index,              &
+                           myname%nameonparent )
    ENDDO
 
- END SUBROUTINE get_da_names_from_client
-
-
-
- SUBROUTINE pmc_s_setarray(clientid, nrdims, dims, array_adr, second_adr )
-!
-!-- Set array for client interPE 0
+ END SUBROUTINE get_da_names_from_child
+
+
+
+ SUBROUTINE pmc_s_setarray(childid, nrdims, dims, array_adr, second_adr )
+
+!
+!-- Set array for child inter PE 0
     IMPLICIT NONE
 
-    INTEGER, INTENT(IN)               ::  clientid  !<
-    INTEGER, INTENT(IN)               ::  nrdims    !<
-    INTEGER, INTENT(IN), DIMENSION(:) ::  dims      !<
+    INTEGER, INTENT(IN)               ::  childid    !<
+    INTEGER, INTENT(IN)               ::  nrdims     !<
+    INTEGER, INTENT(IN), DIMENSION(:) ::  dims       !<
 
     TYPE(C_PTR), INTENT(IN)           :: array_adr   !<
@@ -813,7 +841,7 @@
 
 
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
        ar  => ape%array_list(next_array_in_list)
        ar%nrdims = nrdims
@@ -835,9 +863,9 @@
 
 
- SUBROUTINE pmc_s_set_active_data_array( clientid, iactive )
+ SUBROUTINE pmc_s_set_active_data_array( childid, iactive )
 
     IMPLICIT NONE
 
-    INTEGER, INTENT(IN) ::  clientid  !<
+    INTEGER, INTENT(IN) ::  childid   !<
     INTEGER, INTENT(IN) ::  iactive   !<
 
@@ -849,7 +877,7 @@
     TYPE(arraydef), POINTER ::  ar   !<
 
-    DO  ip = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(ip)
+    DO  ip = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(ip)
 
        DO  j = 1, ape%nr_arrays
@@ -868,13 +896,13 @@
 
 
- SUBROUTINE set_pe_index_list( clientid, myclient, index_list, nrp )
+ SUBROUTINE set_pe_index_list( childid, mychild, index_list, nrp )
 
     IMPLICIT NONE
 
-    INTEGER, INTENT(IN)                 ::  clientid    !<
+    INTEGER, INTENT(IN)                 ::  childid     !<
     INTEGER, INTENT(IN), DIMENSION(:,:) ::  index_list  !<
     INTEGER, INTENT(IN)                 ::  nrp         !<
 
-    TYPE(clientdef), INTENT(INOUT) ::  myclient  !<
+    TYPE(childdef), INTENT(INOUT)       ::  mychild     !<
 
     INTEGER                                 :: i        !<
@@ -888,5 +916,5 @@
     INTEGER(KIND=MPI_ADDRESS_KIND)          :: winsize  !<
 
-    INTEGER, DIMENSION(myclient%inter_npes) :: remind   !<
+    INTEGER, DIMENSION(mychild%inter_npes)  :: remind   !<
 
     INTEGER, DIMENSION(:), POINTER          :: remindw  !<
@@ -896,19 +924,20 @@
 
 !
-!-- First, count entries for every remote client PE
-    DO  i = 1, myclient%inter_npes
-       ape => myclient%pes(i)
+!-- First, count entries for every remote child PE
+    DO  i = 1, mychild%inter_npes
+       ape => mychild%pes(i)
        ape%nrele = 0
     ENDDO
+
 !
 !-- Loop over number of coarse grid cells
     DO  j = 1, nrp
        rempe = index_list(5,j) + 1   ! PE number on remote PE
-       ape => myclient%pes(rempe)
-       ape%nrele = ape%nrele + 1 ! Increment number of elements for this client PE
-    ENDDO
-
-    DO  i = 1, myclient%inter_npes
-       ape => myclient%pes(i)
+       ape => mychild%pes(rempe)
+       ape%nrele = ape%nrele + 1     ! Increment number of elements for this child PE
+    ENDDO
+
+    DO  i = 1, mychild%inter_npes
+       ape => mychild%pes(i)
        ALLOCATE( ape%locind(ape%nrele) )
     ENDDO
@@ -921,5 +950,5 @@
     DO  j = 1, nrp
        rempe = index_list(5,j) + 1
-       ape => myclient%pes(rempe)
+       ape => mychild%pes(rempe)
        remind(rempe)     = remind(rempe)+1
        ind               = remind(rempe)
@@ -927,13 +956,16 @@
        ape%locind(ind)%j = index_list(2,j)
     ENDDO
-!
-!-- Prepare number of elements for client PEs
-    CALL pmc_alloc_mem( rldef, myclient%inter_npes*2 )
-!
-!-- Number of client PEs * size of INTEGER (i just arbitrary INTEGER)
-    winsize = myclient%inter_npes*c_sizeof(i)*2
-
-    CALL MPI_WIN_CREATE( rldef, winsize, iwp, MPI_INFO_NULL,                   &
-                         myclient%intra_comm, indwin, ierr )
+
+!
+!-- Prepare number of elements for children PEs
+    CALL pmc_alloc_mem( rldef, mychild%inter_npes*2 )
+
+!
+!-- Number of child PEs * size of INTEGER (i just arbitrary INTEGER)
+    winsize = mychild%inter_npes*c_sizeof(i)*2
+
+    CALL MPI_WIN_CREATE( rldef, winsize, iwp, MPI_INFO_NULL,                    &
+                         mychild%intra_comm, indwin, ierr )
+
 !
 !-- Open window to set data
@@ -942,20 +974,24 @@
     rldef(1) = 0            ! index on remote PE 0
     rldef(2) = remind(1)    ! number of elements on remote PE 0
+
 !
 !-- Reserve buffer for index array
-    DO  i = 2, myclient%inter_npes
+    DO  i = 2, mychild%inter_npes
        i2          = (i-1) * 2 + 1
        rldef(i2)   = rldef(i2-2) + rldef(i2-1) * 2  ! index on remote PE
-       rldef(i2+1) = remind(i)                ! number of elements on remote PE
-    ENDDO
-!
-!-- Close window to allow client to access data
+       rldef(i2+1) = remind(i)                      ! number of elements on remote PE
+    ENDDO
+
+!
+!-- Close window to allow child to access data
     CALL MPI_WIN_FENCE( 0, indwin, ierr )
-!
-!-- Client has retrieved data
+
+!
+!-- Child has retrieved data
     CALL MPI_WIN_FENCE( 0, indwin, ierr )
 
-    i2 = 2 * myclient%inter_npes - 1
+    i2 = 2 * mychild%inter_npes - 1
     winsize = ( rldef(i2) + rldef(i2+1) ) * 2
+
 !
 !-- Make sure, MPI_ALLOC_MEM works
@@ -965,14 +1001,15 @@
 
     CALL MPI_BARRIER( m_model_comm, ierr )
-    CALL MPI_WIN_CREATE( remindw, winsize*c_sizeof(i), iwp, MPI_INFO_NULL,     &
-                         myclient%intra_comm, indwin2, ierr )
+    CALL MPI_WIN_CREATE( remindw, winsize*c_sizeof(i), iwp, MPI_INFO_NULL,      &
+                         mychild%intra_comm, indwin2, ierr )
 !
 !-- Open window to set data
     CALL MPI_WIN_FENCE( 0, indwin2, ierr )
+
 !
 !-- Create the 2D index list
     DO  j = 1, nrp
        rempe = index_list(5,j) + 1    ! PE number on remote PE
-       ape => myclient%pes(rempe)
+       ape => mychild%pes(rempe)
        i2    = rempe * 2 - 1
        ind   = rldef(i2) + 1
@@ -981,15 +1018,18 @@
        rldef(i2)      = rldef(i2)+2
     ENDDO
-!
-!-- All data areset
+
+!
+!-- All data are set
     CALL MPI_WIN_FENCE( 0, indwin2, ierr )
+
 !
 !-- Don't know why, but this barrier is necessary before windows can be freed
 !-- TODO: find out why this is required
-    CALL MPI_BARRIER( myclient%intra_comm, ierr )
+    CALL MPI_BARRIER( mychild%intra_comm, ierr )
 
     CALL MPI_WIN_FREE( indwin, ierr )
     CALL MPI_WIN_FREE( indwin2, ierr )
 
+!
 !-- TODO: check if the following idea needs to be done
 !-- Sollte funktionieren, Problem mit MPI implementation
@@ -1000,3 +1040,3 @@
 
 #endif
- END MODULE pmc_server
+ END MODULE pmc_parent
