Index: palm/trunk/SOURCE/pmc_parent_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_parent_mod.f90	(revision 2101)
+++ palm/trunk/SOURCE/pmc_parent_mod.f90	(revision 2599)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Some cleanup and commenting improvements only.
+! 
+! 2101 2017-01-05 16:42:31Z suehring
 !
 ! 2000 2016-08-20 18:09:15Z knoop
@@ -192,5 +195,5 @@
 
 !
-!--    Intra communicater is used for MPI_GET
+!--    Intra communicator is used for MPI_GET
        CALL MPI_INTERCOMM_MERGE( children(childid)%inter_comm, .FALSE.,         &
                                  children(childid)%intra_comm, istat )
@@ -232,27 +235,20 @@
 
      IF ( m_model_rank == 0 )  THEN
-
-!
-!--     Sort to ascending parent PE order
+!
+!--     Sort to ascending parent process order
         CALL pmc_sort( index_list, 6 )
-
         is = 1
         DO  ip = 0, m_model_npes-1
-
-!
-!--        Split into parent PEs
+!
+!--        Split into parent processes
            ie = is - 1
-
-!
-!--        There may be no entry for this PE
+!
+!--        There may be no entry for this process
            IF ( is <= SIZE( index_list,2 )  .AND.  ie >= 0 )  THEN
-
               DO WHILE ( index_list(6,ie+1 ) == ip )
                  ie = ie + 1
                  IF ( ie == SIZE( index_list,2 ) )  EXIT
               ENDDO
-
               ian = ie - is + 1
-
            ELSE
               is  = -1
@@ -260,7 +256,6 @@
               ian =  0
            ENDIF
-
-!
-!--        Send data to other parent PEs
+!
+!--        Send data to other parent processes
            IF ( ip == 0 )  THEN
               indchildren(childid)%nrpoints = ian
@@ -279,13 +274,9 @@
            ENDIF
            is = ie + 1
-
         ENDDO
-
      ELSE
-
         CALL MPI_RECV( indchildren(childid)%nrpoints, 1, MPI_INTEGER, 0, 1000,  &
                        m_model_comm, MPI_STATUS_IGNORE, istat )
         ian = indchildren(childid)%nrpoints
-
         IF ( ian > 0 )  THEN
            ALLOCATE( indchildren(childid)%index_list_2d(6,ian) )
@@ -294,7 +285,5 @@
                           MPI_STATUS_IGNORE, istat)
         ENDIF
-
      ENDIF
-
      CALL set_pe_index_list( childid, children(childid),                        &
                              indchildren(childid)%index_list_2d,                &
@@ -328,11 +317,10 @@
 
     next_array_in_list = next_array_in_list + 1
-
-!
-!-- Array names are the same on all children PEs, so take first PE to get the name
+!
+!-- Array names are the same on all children processes, so take first
+!-- process to get the name
     ape => children(childid)%pes(1)
 
     IF ( next_array_in_list > ape%nr_arrays )  THEN
-
 !
 !--    All arrays are done
@@ -343,5 +331,4 @@
     ar => ape%array_list(next_array_in_list)
     myname = ar%name
-
 !
 !-- Return true if legal array
@@ -413,5 +400,4 @@
 
     array_adr = C_LOC(array)
-
 !
 !-- In PALM's pointer version, two indices have to be stored internally.
@@ -469,5 +455,4 @@
     rcount  = 0
     bufsize = 8
-
 !
 !-- First stride: compute size and set index
@@ -493,8 +478,7 @@
           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 mean?
+!--       TODO: what does this limit mean? Does outstanding mean pending?
           IF ( rcount == 1024 )  THEN
              CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
@@ -505,5 +489,4 @@
           bufsize = bufsize + arlen
           ar%sendsize = arlen
-
        ENDDO
 
@@ -513,5 +496,4 @@
 
     ENDDO
-
 !
 !-- Create RMA (One Sided Communication) window for data buffer parent to
@@ -530,9 +512,7 @@
                          children(childid)%intra_comm,                          &
                          children(childid)%win_parent_child, ierr )
-
 !
 !-- Open window to set data
     CALL MPI_WIN_FENCE( 0, children(childid)%win_parent_child, ierr )
-
 !
 !-- Second stride: set buffer pointer
@@ -555,20 +535,14 @@
        ENDDO
     ENDDO
-
 !
 !-- Child to parent direction
     bufsize = 8
-
 !
 !-- First stride: compute size and set index
     DO  i = 1, children(childid)%inter_npes
-
        ape => children(childid)%pes(i)
        tag = 300
-
        DO  j = 1, ape%nr_arrays
-
           ar => ape%array_list(j)
-
 !
 !--       Receive index from child
@@ -576,5 +550,4 @@
           CALL MPI_RECV( myindex, 1, MPI_INTEGER, i-1, tag,                     &
                          children(childid)%inter_comm, MPI_STATUS_IGNORE, ierr )
-
           IF ( ar%nrdims == 3 )  THEN
              bufsize = MAX( bufsize, ape%nrele * ar%a_dim(4) )
@@ -583,9 +556,6 @@
           ENDIF
           ar%recvindex = myindex
-
         ENDDO
-
-    ENDDO
-
+    ENDDO
 !
 !-- Create RMA (one sided communication) data buffer.
@@ -596,16 +566,12 @@
 
     CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
-
 !
 !-- Second stride: set buffer pointer
     DO  i = 1, children(childid)%inter_npes
-
        ape => children(childid)%pes(i)
-
        DO  j = 1, ape%nr_arrays
           ar => ape%array_list(j)
           ar%recvbuf = base_ptr
        ENDDO
-
     ENDDO
 
@@ -654,14 +620,9 @@
 
     DO  ip = 1, children(childid)%inter_npes
-
        ape => children(childid)%pes(ip)
-
        DO  j = 1, ape%nr_arrays
-
           ar => ape%array_list(j)
           myindex = 1
-
           IF ( ar%nrdims == 2 )  THEN
-
              buf_shape(1) = ape%nrele
              CALL C_F_POINTER( ar%sendbuf, buf, buf_shape )
@@ -671,7 +632,5 @@
                 myindex = myindex + 1
              ENDDO
-
           ELSEIF ( ar%nrdims == 3 )  THEN
-
              buf_shape(1) = ape%nrele*ar%a_dim(4)
              CALL C_F_POINTER( ar%sendbuf, buf, buf_shape )
@@ -682,11 +641,7 @@
                 myindex = myindex + ar%a_dim(4)
              ENDDO
-
           ENDIF
-
         ENDDO
-
-    ENDDO
-
+    ENDDO
 !
 !-- Buffer is filled
@@ -727,5 +682,4 @@
 
     t1 = pmc_time()
-
 !
 !-- Wait for child to fill buffer
@@ -733,5 +687,4 @@
     t2 = pmc_time() - t1
     IF ( PRESENT( waittime ) )  waittime = t2
-
 !
 !-- TODO: check next statement
@@ -741,11 +694,8 @@
 
     DO  ip = 1, children(childid)%inter_npes
-
        ape => children(childid)%pes(ip)
-
        DO  j = 1, ape%nr_arrays
-
           ar => ape%array_list(j)
-
+          
           IF ( ar%recvindex < 0 )  CYCLE
 
@@ -755,15 +705,12 @@
              nr = ape%nrele * ar%a_dim(4)
           ENDIF
-
           buf_shape(1) = nr
           CALL C_F_POINTER( ar%recvbuf, buf, buf_shape )
-
 !
 !--       MPI passive target RMA
           IF ( nr > 0 )  THEN
              target_disp = ar%recvindex - 1
-
-!
-!--          Child PEs are located behind parent PEs
+!
+!--          Child processes are located behind parent process
              target_pe = ip - 1 + m_model_npes
              CALL MPI_WIN_LOCK( MPI_LOCK_SHARED, target_pe, 0,                  &
@@ -774,8 +721,6 @@
                                   children(childid)%win_parent_child, ierr )
           ENDIF
-
           myindex = 1
           IF ( ar%nrdims == 2 )  THEN
-
              CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) )
              DO  ij = 1, ape%nrele
@@ -783,7 +728,5 @@
                 myindex = myindex + 1
              ENDDO
-
           ELSEIF ( ar%nrdims == 3 )  THEN
-
              CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3))
              DO  ij = 1, ape%nrele
@@ -792,9 +735,6 @@
                 myindex = myindex + ar%a_dim(4)
              ENDDO
-
           ENDIF
-
        ENDDO
-
     ENDDO
 
@@ -832,5 +772,5 @@
 
 !
-!-- Set array for child inter PE 0
+!-- Set array for child inter process 0
     IMPLICIT NONE
 
@@ -849,5 +789,4 @@
 
     DO  i = 1, children(childid)%inter_npes
-
        ape => children(childid)%pes(i)
        ar  => ape%array_list(next_array_in_list)
@@ -855,5 +794,4 @@
        ar%a_dim  = dims
        ar%data   = array_adr
-
        IF ( PRESENT( second_adr ) )  THEN
           ar%po_data(1) = array_adr
@@ -863,5 +801,4 @@
           ar%po_data(2) = C_NULL_PTR
        ENDIF
-
     ENDDO
 
@@ -885,16 +822,11 @@
 
     DO  ip = 1, children(childid)%inter_npes
-
        ape => children(childid)%pes(ip)
-
        DO  j = 1, ape%nr_arrays
-
           ar => ape%array_list(j)
           IF ( iactive == 1  .OR.  iactive == 2 )  THEN
              ar%data = ar%po_data(iactive)
           ENDIF
-
        ENDDO
-
     ENDDO
 
@@ -931,16 +863,15 @@
 
 !
-!-- First, count entries for every remote child PE
+!-- First, count entries for every remote child process
     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
+       rempe = index_list(5,j) + 1   ! process number on remote process
        ape => mychild%pes(rempe)
-       ape%nrele = ape%nrele + 1     ! Increment number of elements for this child PE
+       ape%nrele = ape%nrele + 1     ! Increment number of elements for this child process
     ENDDO
 
@@ -951,5 +882,4 @@
 
     remind = 0
-
 !
 !-- Second, create lists
@@ -963,35 +893,29 @@
        ape%locind(ind)%j = index_list(2,j)
     ENDDO
-
-!
-!-- Prepare number of elements for children PEs
+!
+!-- Prepare number of elements for children processes
     CALL pmc_alloc_mem( rldef, mychild%inter_npes*2 )
-
-!
-!-- Number of child PEs * size of INTEGER (i just arbitrary INTEGER)
+!
+!-- Number of child processes * 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
     CALL MPI_WIN_FENCE( 0, indwin, ierr )
 
-    rldef(1) = 0            ! index on remote PE 0
-    rldef(2) = remind(1)    ! number of elements on remote PE 0
-
+    rldef(1) = 0            ! index on remote process 0
+    rldef(2) = remind(1)    ! number of elements on remote process 0
 !
 !-- Reserve buffer for index array
     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
-
+       rldef(i2)   = rldef(i2-2) + rldef(i2-1) * 2  ! index on remote process
+       rldef(i2+1) = remind(i)                      ! number of elements on remote process
+    ENDDO
 !
 !-- Close window to allow child to access data
     CALL MPI_WIN_FENCE( 0, indwin, ierr )
-
 !
 !-- Child has retrieved data
@@ -1000,5 +924,4 @@
     i2 = 2 * mychild%inter_npes - 1
     winsize = ( rldef(i2) + rldef(i2+1) ) * 2
-
 !
 !-- Make sure, MPI_ALLOC_MEM works
@@ -1013,9 +936,8 @@
 !-- 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
+       rempe = index_list(5,j) + 1    ! process number on remote process
        ape => mychild%pes(rempe)
        i2    = rempe * 2 - 1
@@ -1025,9 +947,7 @@
        rldef(i2)      = rldef(i2)+2
     ENDDO
-
 !
 !-- 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
