Index: palm/trunk/SOURCE/poismg_mod.f90
===================================================================
--- palm/trunk/SOURCE/poismg_mod.f90	(revision 4831)
+++ palm/trunk/SOURCE/poismg_mod.f90	(revision 4832)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! bugfix in redblack algorithm: lower i,j indices need to start alternatively with even or odd
+! value on the coarsest grid level, if the subdomain has an uneven number of gridpoints along x/y
+!
+! 4828 2021-01-05 11:21:41Z Giersch
 ! File re-formatted to follow the PALM coding standard
 !
@@ -742,7 +746,11 @@
     INTEGER(iwp) ::  l      !< grid level
     INTEGER(iwp) ::  n      !< loop variable GauÃ-Seidel iterations
-
-
-    LOGICAL ::  unroll  !< flag indicating whether loop unrolling is possible
+    INTEGER(iwp) ::  save_nxl_mg  !< to save nxl_mg on coarsest level 1
+    INTEGER(iwp) ::  save_nys_mg  !< to save nys_mg on coarsest level 1
+
+
+    LOGICAL ::  adjust_lower_i_index  !< adjust lower limit of i loop in case of odd number of grid points
+    LOGICAL ::  adjust_lower_j_index  !< adjust lower limit of j loop in case of odd number of grid points
+    LOGICAL ::  unroll                !< flag indicating whether loop unrolling is possible
 
     REAL(wp), DIMENSION(nzb:nzt_mg(grid_level)+1,nys_mg(grid_level)-1:nyn_mg(grid_level)+1,        &
@@ -751,8 +759,27 @@
                         nxl_mg(grid_level)-1:nxr_mg(grid_level)+1) ::  p_mg  !< perturbation pressure
 
+
     l = grid_level
 
     unroll = ( MOD( nyn_mg(l)-nys_mg(l)+1, 4 ) == 0  .AND.  MOD( nxr_mg(l)-nxl_mg(l)+1, 2 ) == 0 )
 
+!
+!-- The red/black decomposition requires that on the lower i,j indices need to start alternatively with an
+!-- even or odd value on the coarsest grid level, depending on the core-id, and if the subdomain has an
+!-- uneven number of gridpoints along x/y. Set the respective steering switches here.
+    IF ( l == 1  .AND.  MOD( myidx, 2 ) /= 0  .AND.  MOD( nxl_mg(l) - nxr_mg(l), 2 ) == 0 )  THEN
+       adjust_lower_i_index = .TRUE.
+       save_nxl_mg = nxl_mg(1)
+    ELSE
+       adjust_lower_i_index = .FALSE.
+    ENDIF
+    IF ( l == 1  .AND.  MOD( myidy, 2 ) /= 0  .AND.  MOD( nyn_mg(l) - nys_mg(l), 2 ) == 0 )  THEN
+       adjust_lower_j_index = .TRUE.
+       save_nys_mg = nys_mg(l)
+    ELSE
+       adjust_lower_j_index = .FALSE.
+    ENDIF
+
+
     DO  n = 1, ngsrb
 
@@ -762,4 +789,16 @@
 
              CALL cpu_log( log_point_s(36), 'redblack_no_unroll_f', 'start' )
+
+             IF ( adjust_lower_i_index )  THEN
+                nxl_mg(l) = save_nxl_mg + 1
+             ENDIF
+
+             IF ( adjust_lower_j_index )  THEN
+                IF ( color == 1 )  THEN
+                  nys_mg(l) = save_nys_mg - 1
+                ELSE
+                  nys_mg(l) = save_nys_mg + 1
+                ENDIF
+             ENDIF
 !
 !--          Without unrolling of loops, no cache optimization
@@ -784,4 +823,16 @@
              ENDDO
 
+             IF ( adjust_lower_i_index )  THEN
+                nxl_mg(l) = save_nxl_mg - 1
+             ENDIF
+
+             IF ( adjust_lower_j_index )  THEN
+                IF ( color == 1 )  THEN
+                  nys_mg(l) = save_nys_mg + 1
+                ELSE
+                  nys_mg(l) = save_nys_mg - 1
+                ENDIF
+             ENDIF
+
              !$OMP DO
              DO  i = nxl_mg(l)+1, nxr_mg(l), 2
@@ -803,4 +854,16 @@
              ENDDO
 
+             IF ( adjust_lower_i_index )  THEN
+                nxl_mg(l) = save_nxl_mg + 1
+             ENDIF
+
+             IF ( adjust_lower_j_index )  THEN
+                IF ( color == 1 )  THEN
+                  nys_mg(l) = save_nys_mg + 1
+                ELSE
+                  nys_mg(l) = save_nys_mg - 1
+                ENDIF
+             ENDIF
+
              !$OMP DO
              DO  i = nxl_mg(l), nxr_mg(l), 2
@@ -821,4 +884,16 @@
                 ENDDO
              ENDDO
+
+             IF ( adjust_lower_i_index )  THEN
+                nxl_mg(l) = save_nxl_mg - 1
+             ENDIF
+
+             IF ( adjust_lower_j_index )  THEN
+                IF ( color == 1 )  THEN
+                  nys_mg(l) = save_nys_mg - 1
+                ELSE
+                  nys_mg(l) = save_nys_mg + 1
+                ENDIF
+             ENDIF
 
              !$OMP DO
@@ -1013,4 +1088,15 @@
     ENDDO
 
+!
+!-- Reset lower index limits to their standard values (may happen on coarsest levels only)
+    IF ( adjust_lower_i_index )  THEN
+       nxl_mg(l) = save_nxl_mg
+    ENDIF
+
+    IF ( adjust_lower_j_index )  THEN
+       nys_mg(l) = save_nys_mg
+    ENDIF
+
+
  END SUBROUTINE redblack
 
Index: palm/trunk/SOURCE/poismg_noopt_mod.f90
===================================================================
--- palm/trunk/SOURCE/poismg_noopt_mod.f90	(revision 4831)
+++ palm/trunk/SOURCE/poismg_noopt_mod.f90	(revision 4832)
@@ -25,6 +25,9 @@
 ! -----------------
 ! $Id$
+! bugfix in redblack algorithm: lower i,j indices need to start alternatively with even or odd
+! value on the coarsest grid level, if the subdomain has an uneven number of gridpoints along x/y
+!
+! 4828 2021-01-05 11:21:41Z Giersch
 ! File re-formatted to follow the PALM coding standard
-!
 !
 ! 4457 2020-03-11 14:20:43Z raasch
@@ -801,14 +804,18 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) :: color  !<
-    INTEGER(iwp) :: i      !<
-    INTEGER(iwp) :: ic     !<
-    INTEGER(iwp) :: j      !<
-    INTEGER(iwp) :: jc     !<
-    INTEGER(iwp) :: jj     !<
-    INTEGER(iwp) :: k      !<
-    INTEGER(iwp) :: l      !<
-    INTEGER(iwp) :: n      !<
-
+    INTEGER(iwp) ::  color  !<
+    INTEGER(iwp) ::  i      !<
+    INTEGER(iwp) ::  ic     !<
+    INTEGER(iwp) ::  j      !<
+    INTEGER(iwp) ::  jc     !<
+    INTEGER(iwp) ::  jj     !<
+    INTEGER(iwp) ::  k      !<
+    INTEGER(iwp) ::  l      !<
+    INTEGER(iwp) ::  n      !<
+    INTEGER(iwp) ::  save_nxl_mg  !< to save nxl_mg on coarsest level 1
+    INTEGER(iwp) ::  save_nys_mg  !< to save nys_mg on coarsest level 1
+
+    LOGICAL ::  adjust_lower_i_index  !< adjust lower limit of i loop in case of odd number of grid points
+    LOGICAL ::  adjust_lower_j_index  !< adjust lower limit of j loop in case of odd number of grid points
     LOGICAL ::  unroll  !<
 
@@ -855,4 +862,22 @@
                MOD( nxr_mg(l)-nxl_mg(l)+1, 2 ) == 0 )
 
+!
+!-- The red/black decomposition requires that on the lower i,j indices need to start alternatively with an
+!-- even or odd value on the coarsest grid level, depending on the core-id, and if the subdomain has an
+!-- uneven number of gridpoints along x/y. Set the respective steering switches here.
+    IF ( l == 1  .AND.  MOD( myidx, 2 ) /= 0  .AND.  MOD( nxl_mg(l) - nxr_mg(l), 2 ) == 0 )  THEN
+       adjust_lower_i_index = .TRUE.
+       save_nxl_mg = nxl_mg(1)
+    ELSE
+       adjust_lower_i_index = .FALSE.
+    ENDIF
+    IF ( l == 1  .AND.  MOD( myidy, 2 ) /= 0  .AND.  MOD( nyn_mg(l) - nys_mg(l), 2 ) == 0 )  THEN
+       adjust_lower_j_index = .TRUE.
+       save_nys_mg = nys_mg(l)
+    ELSE
+       adjust_lower_j_index = .FALSE.
+    ENDIF
+
+
     DO  n = 1, ngsrb
 
@@ -863,4 +888,15 @@
              CALL cpu_log( log_point_s(36), 'redblack_no_unroll_noopt', 'start' )
 
+             IF ( adjust_lower_i_index )  THEN
+                nxl_mg(l) = save_nxl_mg + 1
+             ENDIF
+
+             IF ( adjust_lower_j_index )  THEN
+                IF ( color == 1 )  THEN
+                  nys_mg(l) = save_nys_mg - 1
+                ELSE
+                  nys_mg(l) = save_nys_mg + 1
+                ENDIF
+             ENDIF
 !
 !--          Without unrolling of loops, no cache optimization
@@ -897,4 +933,16 @@
                 ENDDO
              ENDDO
+
+             IF ( adjust_lower_i_index )  THEN
+                nxl_mg(l) = save_nxl_mg - 1
+             ENDIF
+
+             IF ( adjust_lower_j_index )  THEN
+                IF ( color == 1 )  THEN
+                  nys_mg(l) = save_nys_mg + 1
+                ELSE
+                  nys_mg(l) = save_nys_mg - 1
+                ENDIF
+             ENDIF
 
              DO  i = nxl_mg(l)+1, nxr_mg(l), 2
@@ -924,4 +972,16 @@
              ENDDO
 
+             IF ( adjust_lower_i_index )  THEN
+                nxl_mg(l) = save_nxl_mg + 1
+             ENDIF
+
+             IF ( adjust_lower_j_index )  THEN
+                IF ( color == 1 )  THEN
+                  nys_mg(l) = save_nys_mg + 1
+                ELSE
+                  nys_mg(l) = save_nys_mg - 1
+                ENDIF
+             ENDIF
+
              DO  i = nxl_mg(l), nxr_mg(l), 2
                 DO  j = nys_mg(l) + (color-1), nyn_mg(l), 2
@@ -949,4 +1009,16 @@
                 ENDDO
              ENDDO
+
+             IF ( adjust_lower_i_index )  THEN
+                nxl_mg(l) = save_nxl_mg - 1
+             ENDIF
+
+             IF ( adjust_lower_j_index )  THEN
+                IF ( color == 1 )  THEN
+                  nys_mg(l) = save_nys_mg - 1
+                ELSE
+                  nys_mg(l) = save_nys_mg + 1
+                ENDIF
+             ENDIF
 
              DO  i = nxl_mg(l)+1, nxr_mg(l), 2
@@ -1215,5 +1287,15 @@
 
 !
-!--    Set pressure within topography and at the topography surfaces
+!-- Reset lower index limits to their standard values (may happen on coarsest levels only)
+    IF ( adjust_lower_i_index )  THEN
+       nxl_mg(l) = save_nxl_mg
+    ENDIF
+
+    IF ( adjust_lower_j_index )  THEN
+       nys_mg(l) = save_nys_mg
+    ENDIF
+
+!
+!-- Set pressure within topography and at the topography surfaces
 !$OMP PARALLEL PRIVATE (i,j,k,wall_left,wall_north,wall_right,wall_south,wall_top,wall_total)
 !$OMP DO
Index: palm/trunk/SOURCE/restart_data_mpi_io_mod.f90
===================================================================
--- palm/trunk/SOURCE/restart_data_mpi_io_mod.f90	(revision 4831)
+++ palm/trunk/SOURCE/restart_data_mpi_io_mod.f90	(revision 4832)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! some debug output flushed
+!
+! 4828 2021-01-05 11:21:41Z Giersch
 ! interface for 3d logical arrays added
 !
@@ -2355,5 +2358,8 @@
                                       INT( (iog%nx+1), KIND = rd_offset_kind ) * wp
 
-    write(9,*) 'array_position real3d ',trim(name),' ',array_position
+    IF ( debug_output )  THEN
+       WRITE (9,*) 'array_position real3d ', TRIM( name ), ' ', array_position
+       FLUSH( 9 )
+    ENDIF
 
  END SUBROUTINE wrd_mpi_io_real_3d
