Index: palm/trunk/SOURCE/exchange_horiz.f90
===================================================================
--- palm/trunk/SOURCE/exchange_horiz.f90	(revision 484)
+++ palm/trunk/SOURCE/exchange_horiz.f90	(revision 667)
@@ -1,8 +1,13 @@
- SUBROUTINE exchange_horiz( ar )
+ SUBROUTINE exchange_horiz( ar, nbgp_local)
 
 !------------------------------------------------------------------------------!
 ! Current revisions:
 ! -----------------
-! 
+! Dynamic exchange of ghost points with nbgp_local to ensure that no useless 
+! ghost points exchanged in case of multigrid. type_yz(0) and type_xz(0)
+! used for normal grid, the remaining types used for the several grid levels.
+! Exchange is done via MPI-Vectors with a dynamic value of ghost points which
+! depend on the advection scheme. Exchange of left and right PEs is 10% faster 
+! with MPI-Vectors than without. 
 !
 ! Former revisions:
@@ -41,10 +46,15 @@
     INTEGER, DIMENSION(MPI_STATUS_SIZE,4) ::  wait_stat
 #endif
-
-    REAL ::  ar(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1)
-
+    INTEGER :: i,nbgp_local
+    REAL, DIMENSION(nzb:nzt+1,nys-nbgp_local:nyn+nbgp_local, &
+                    nxl-nbgp_local:nxr+nbgp_local) ::  ar
 
     CALL cpu_log( log_point_s(2), 'exchange_horiz', 'start' )
 
+    IF ( exchange_mg == .TRUE. ) THEN
+      i = grid_level
+    ELSE
+      i = 0
+    END IF
 #if defined( __parallel )
 
@@ -56,6 +66,6 @@
 !--    within the PE memory
        IF ( bc_lr == 'cyclic' )  THEN
-          ar(:,nys:nyn,nxl-1) = ar(:,nys:nyn,nxr)
-          ar(:,nys:nyn,nxr+1) = ar(:,nys:nyn,nxl)
+          ar(:,:,nxl-nbgp_local:nxl-1) = ar(:,:,nxr-nbgp_local+1:nxr)
+          ar(:,:,nxr+1:nxr+nbgp_local) = ar(:,:,nxl:nxl+nbgp_local-1)
        ENDIF
 
@@ -65,18 +75,17 @@
 !
 !--    Send left boundary, receive right one
-       CALL MPI_ISEND(                                                     &
-               ar(nzb,nys-1,nxl), ngp_yz(grid_level), MPI_REAL, pleft,  0, &
-                          comm2d, req(1), ierr )
-       CALL MPI_IRECV(                                                       &
-               ar(nzb,nys-1,nxr+1), ngp_yz(grid_level), MPI_REAL, pright, 0, &
-                          comm2d, req(2), ierr )
+       CALL MPI_ISEND(ar(nzb,nys-nbgp_local,nxl),1,type_yz(i),pleft,0,comm2d,&
+                      req(1),ierr)
+       CALL MPI_IRECV(ar(nzb,nys-nbgp_local,nxr+1),1,type_yz(i),pright,0,&
+                     comm2d,req(2),ierr)
 !
 !--    Send right boundary, receive left one
-       CALL MPI_ISEND(                                                     &
-               ar(nzb,nys-1,nxr), ngp_yz(grid_level), MPI_REAL, pright, 1, &
-                          comm2d, req(3), ierr )
-       CALL MPI_IRECV(                                                       &
-               ar(nzb,nys-1,nxl-1), ngp_yz(grid_level), MPI_REAL, pleft,  1, &
-                          comm2d, req(4), ierr )
+
+
+       CALL MPI_ISEND(ar(nzb,nys-nbgp_local,nxr+1-nbgp_local),1,type_yz(i),pright, 1,  &
+                      comm2d, req(3), ierr )
+       CALL MPI_IRECV(ar(nzb,nys-nbgp_local,nxl-nbgp_local),1,type_yz(i),pleft,1,&
+                      comm2d,req(4), ierr)
+
        CALL MPI_WAITALL( 4, req, wait_stat, ierr )
 
@@ -89,6 +98,6 @@
 !--    within the PE memory
        IF ( bc_ns == 'cyclic' )  THEN
-          ar(:,nys-1,:) = ar(:,nyn,:)
-          ar(:,nyn+1,:) = ar(:,nys,:)
+          ar(:,nys-nbgp_local:nys-1,:) = ar(:,nyn-nbgp_local+1:nyn,:)
+          ar(:,nyn+1:nyn+nbgp_local,:) = ar(:,nys:nys+nbgp_local-1,:)
        ENDIF
 
@@ -98,18 +107,19 @@
 !
 !--    Send front boundary, receive rear one
-       CALL MPI_ISEND( ar(nzb,nys,nxl-1),   1, type_xz(grid_level), psouth, 0, &
+!--    MPI_ISEND initial send adress changed, type_xz() is sendet nbgp times
+
+       CALL MPI_ISEND( ar(nzb,nys,nxl-nbgp_local),1, type_xz(i), psouth, 0, &
                        comm2d, req(1), ierr )
-       CALL MPI_IRECV( ar(nzb,nyn+1,nxl-1), 1, type_xz(grid_level), pnorth, 0, &
+       CALL MPI_IRECV( ar(nzb,nyn+1,nxl-nbgp_local),1, type_xz(i), pnorth, 0, &
                        comm2d, req(2), ierr )
 !
 !--    Send rear boundary, receive front one
-       CALL MPI_ISEND( ar(nzb,nyn,nxl-1),   1, type_xz(grid_level), pnorth, 1, &
+       CALL MPI_ISEND( ar(nzb,nyn-nbgp_local+1,nxl-nbgp_local),1, type_xz(i), pnorth, 1, &
                        comm2d, req(3), ierr )
-       CALL MPI_IRECV( ar(nzb,nys-1,nxl-1), 1, type_xz(grid_level), psouth, 1, &
+       CALL MPI_IRECV( ar(nzb,nys-nbgp_local,nxl-nbgp_local),1, type_xz(i), psouth, 1, &
                        comm2d, req(4), ierr )
        call MPI_WAITALL( 4, req, wait_stat, ierr )
 
     ENDIF
-
 
 #else
@@ -118,16 +128,16 @@
 !-- Lateral boundary conditions in the non-parallel case
     IF ( bc_lr == 'cyclic' )  THEN
-       ar(:,nys:nyn,nxl-1) = ar(:,nys:nyn,nxr)
-       ar(:,nys:nyn,nxr+1) = ar(:,nys:nyn,nxl)
+        ar(:,:,nxl-nbgp_local:nxl-1) = ar(:,:,nxr-nbgp_local+1:nxr)
+        ar(:,:,nxr+1:nxr+nbgp_local) = ar(:,:,nxl:nxl+nbgp_local-1)
     ENDIF
 
     IF ( bc_ns == 'cyclic' )  THEN
-       ar(:,nys-1,:) = ar(:,nyn,:)
-       ar(:,nyn+1,:) = ar(:,nys,:)
+        ar(:,nys-nbgp_local:nys-1,:) = ar(:,nyn-nbgp_local+1:nyn,:)
+        ar(:,nyn+1:nyn+nbgp_local,:) = ar(:,nys:nys+nbgp_local-1,:)
     ENDIF
 
 #endif
-
     CALL cpu_log( log_point_s(2), 'exchange_horiz', 'stop' )
 
+
  END SUBROUTINE exchange_horiz
