Index: palm/trunk/SOURCE/cpulog_mod.f90
===================================================================
--- palm/trunk/SOURCE/cpulog_mod.f90	(revision 4548)
+++ palm/trunk/SOURCE/cpulog_mod.f90	(revision 4549)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! bugfix for r4539: values for min/max/rms stored in separate arrays
+! 
+! 4539 2020-05-18 14:05:17Z raasch
 ! code re-structured,
 ! cpu time per grid point and timestep does not included initialization and spinup any more
@@ -280,10 +283,16 @@
        REAL(dp)       ::  average_cputime  !<
        REAL(dp), SAVE ::  norm = 1.0_dp    !<
-       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_max        !<
-       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_min        !<
-       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_rms        !<
-       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_tmp        !<
-       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  sum           !<
-       REAL(dp), DIMENSION(:,:), ALLOCATABLE ::  pe_log_points !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_max          !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_max_s        !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_min          !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_min_s        !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_rms          !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_rms_s        !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_tmp          !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  pe_tmp_s        !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  sum             !<
+       REAL(dp), DIMENSION(:),   ALLOCATABLE ::  sum_s           !<
+       REAL(dp), DIMENSION(:,:), ALLOCATABLE ::  pe_log_points   !<
+       REAL(dp), DIMENSION(:,:), ALLOCATABLE ::  pe_log_points_s !<
 
 
@@ -372,8 +381,11 @@
        IF ( myid == 0 )  THEN
 !
-!--       Initialize temporary arrays needed for statistics
-          pe_min = log_point_s%sum
-          pe_max = log_point_s%sum    ! need to be set in case of 1 PE
-          pe_rms = 0.0_dp
+!--       Allocate and initialize temporary arrays needed for statistics
+          ALLOCATE( pe_max_s( SIZE( log_point_s ) ), pe_min_s( SIZE( log_point_s ) ),              &
+                    pe_rms_s( SIZE( log_point_s ) ), pe_tmp_s( SIZE( log_point_s ) ),              &
+                    pe_log_points_s( SIZE( log_point_s ), 0:numprocs-1 ) )
+          pe_min_s = log_point_s%sum
+          pe_max_s = log_point_s%sum    ! need to be set in case of 1 PE
+          pe_rms_s = 0.0_dp
 
 #if defined( __parallel )
@@ -381,18 +393,18 @@
 !--       Receive data from all PEs
           DO  i = 1, numprocs-1
-             CALL MPI_RECV( pe_tmp(1), SIZE( log_point ), MPI_DOUBLE_PRECISION, MPI_ANY_SOURCE,    &
-                            MPI_ANY_TAG, comm2d, status, ierr )
+             CALL MPI_RECV( pe_tmp_s(1), SIZE( log_point_s ), MPI_DOUBLE_PRECISION,                &
+                            MPI_ANY_SOURCE, MPI_ANY_TAG, comm2d, status, ierr )
              sender = status(MPI_SOURCE)
-             pe_log_points(:,sender) = pe_tmp
+             pe_log_points_s(:,sender) = pe_tmp_s
           ENDDO
-          pe_log_points(:,0) = log_point_s%sum   ! Results from PE0
+          pe_log_points_s(:,0) = log_point_s%sum   ! Results from PE0
 !
 !--       Calculate mean of all PEs, store it on log_point_s%sum
 !--       and find minimum and maximum
-          DO  iii = 1, SIZE( log_point )
+          DO  iii = 1, SIZE( log_point_s )
              DO  i = 1, numprocs-1
-                log_point_s(iii)%sum = log_point_s(iii)%sum + pe_log_points(iii,i)
-                pe_min(iii) = MIN( pe_min(iii), pe_log_points(iii,i) )
-                pe_max(iii) = MAX( pe_max(iii), pe_log_points(iii,i) )
+                log_point_s(iii)%sum = log_point_s(iii)%sum + pe_log_points_s(iii,i)
+                pe_min_s(iii) = MIN( pe_min_s(iii), pe_log_points_s(iii,i) )
+                pe_max_s(iii) = MAX( pe_max_s(iii), pe_log_points_s(iii,i) )
              ENDDO
              log_point_s(iii)%sum = log_point_s(iii)%sum / numprocs
@@ -400,7 +412,7 @@
 !--          Calculate rms
              DO  i = 0, numprocs-1
-                pe_rms(iii) = pe_rms(iii) + ( pe_log_points(iii,i) - log_point_s(iii)%sum )**2
+                pe_rms_s(iii) = pe_rms_s(iii) + ( pe_log_points_s(iii,i) - log_point_s(iii)%sum )**2
              ENDDO
-             pe_rms(iii) = SQRT( pe_rms(iii) / numprocs )
+             pe_rms_s(iii) = SQRT( pe_rms_s(iii) / numprocs )
           ENDDO
        ELSE
@@ -408,6 +420,8 @@
 !--       Send data to PE0 (pe_max is used as temporary storage to send
 !--       the data in order to avoid sending the data type log)
-          pe_max = log_point_s%sum
-          CALL MPI_SEND( pe_max(1), SIZE( log_point ), MPI_DOUBLE_PRECISION, 0, 0, comm2d, ierr )
+          ALLOCATE( pe_max_s( SIZE( log_point_s ) ) )
+          pe_max_s = log_point_s%sum
+          CALL MPI_SEND( pe_max_s(1), SIZE( log_point_s ), MPI_DOUBLE_PRECISION, 0, 0, comm2d,     &
+                         ierr )
 #endif
 
@@ -470,8 +484,9 @@
 !
 !--       Re-store sums
+          ALLOCATE( sum_s( SIZE( log_point_s ) ) )
           WHERE ( log_point_s%counts /= 0 )
-             sum = log_point_s%sum
+             sum_s = log_point_s%sum
           ELSEWHERE
-             sum = -1.0_dp
+             sum_s = -1.0_dp
           ENDWHERE
 
@@ -480,11 +495,11 @@
           WRITE ( 18, 101 )
           DO
-             ii = MAXLOC( sum )
+             ii = MAXLOC( sum_s )
              i = ii(1)
-             IF ( sum(i) /= -1.0_dp )  THEN
+             IF ( sum_s(i) /= -1.0_dp )  THEN
                 WRITE ( 18, 102 )  log_point_s(i)%place, log_point_s(i)%sum,                       &
                                    log_point_s(i)%sum / log_point(1)%sum * 100.0_dp,               &
-                                   log_point_s(i)%counts, pe_min(i), pe_max(i), pe_rms(i)
-                sum(i) = -1.0_dp
+                                   log_point_s(i)%counts, pe_min_s(i), pe_max_s(i), pe_rms_s(i)
+                sum_s(i) = -1.0_dp
              ELSE
                 EXIT
