Index: palm/trunk/SOURCE/pres.f90
===================================================================
--- palm/trunk/SOURCE/pres.f90	(revision 1112)
+++ palm/trunk/SOURCE/pres.f90	(revision 1113)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! GPU-porting of several loops, some loops rearranged
 !
 ! Former revisions:
@@ -403,5 +403,5 @@
 !--       Solver for 2d-decomposition
           CALL poisfft( d, tend )
-          !$acc update host( d )
+
        ELSEIF ( psolver == 'poisfft_hybrid' )  THEN 
 !
@@ -410,4 +410,5 @@
 !--       are some optimization problems in poisfft
           CALL poisfft_hybrid( d )
+
        ENDIF
 
@@ -416,6 +417,9 @@
 !--    z-direction
        !$OMP PARALLEL DO
+       !$acc kernels present( d, tend )
+       !$acc loop
        DO  i = nxl, nxr
           DO  j = nys, nyn
+             !$acc loop vector( 32 )
              DO  k = nzb+1, nzt
                 tend(k,j,i) = d(k,j,i)
@@ -423,4 +427,5 @@
           ENDDO
        ENDDO
+       !$acc end kernels
 
 !
@@ -432,4 +437,5 @@
 !--       Neumann (dp/dz = 0)
           !$OMP PARALLEL DO
+          !$acc kernels present( nzb_s_inner, tend )
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
@@ -437,4 +443,5 @@
              ENDDO
           ENDDO
+          !$acc end kernels
 
        ELSE
@@ -442,4 +449,5 @@
 !--       Dirichlet
           !$OMP PARALLEL DO
+          !$acc kernels present( tend )
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
@@ -447,4 +455,5 @@
              ENDDO
           ENDDO
+          !$acc end kernels
 
        ENDIF
@@ -456,4 +465,5 @@
 !--       Neumann
           !$OMP PARALLEL DO
+          !$acc kernels present( tend )
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
@@ -461,4 +471,5 @@
              ENDDO
           ENDDO
+          !$acc end kernels
 
        ELSE
@@ -466,4 +477,5 @@
 !--       Dirichlet
           !$OMP PARALLEL DO
+          !$acc kernels present( tend )
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
@@ -471,4 +483,5 @@
              ENDDO
           ENDDO
+          !$acc end kernels
 
        ENDIF
@@ -476,5 +489,15 @@
 !
 !--    Exchange boundaries for p
+       IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
+          on_device = .TRUE.         ! to be removed after complete porting
+       ELSE                          ! of ghost point exchange
+          !$acc update host( tend )
+       ENDIF
        CALL exchange_horiz( tend, nbgp )
+       IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
+          on_device = .FALSE.        ! to be removed after complete porting
+       ELSE                          ! of ghost point exchange
+          !$acc update device( tend )
+       ENDIF
       
     ELSEIF ( psolver == 'sor' )  THEN
@@ -531,6 +554,9 @@
        !$OMP PARALLEL PRIVATE (i,j,k)
        !$OMP DO
+       !$acc kernels present( p, tend, weight_substep )
+       !$acc loop
        DO  i = nxl-1, nxr+1
           DO  j = nys-1, nyn+1
+             !$acc loop vector( 32 )
              DO  k = nzb, nzt+1
                 p(k,j,i) = tend(k,j,i) * &
@@ -539,4 +565,5 @@
           ENDDO
        ENDDO
+       !$acc end kernels
        !$OMP END PARALLEL
 
@@ -544,6 +571,9 @@
        !$OMP PARALLEL PRIVATE (i,j,k)
        !$OMP DO
+       !$acc kernels present( p, tend, weight_substep )
+       !$acc loop
        DO  i = nxl-1, nxr+1
           DO  j = nys-1, nyn+1
+             !$acc loop vector( 32 )
              DO  k = nzb, nzt+1
                 p(k,j,i) = p(k,j,i) + tend(k,j,i) * &
@@ -552,4 +582,5 @@
           ENDDO
        ENDDO
+       !$acc end kernels
        !$OMP END PARALLEL
 
@@ -571,43 +602,71 @@
     !$OMP PARALLEL PRIVATE (i,j,k)
     !$OMP DO
+    !$acc kernels present( ddzu, nzb_u_inner, nzb_v_inner, nzb_w_inner, tend, u, v, w, weight_pres )
+    !$acc loop
     DO  i = nxl, nxr   
        DO  j = nys, nyn
-          DO  k = nzb_w_inner(j,i)+1, nzt
-             w(k,j,i) = w(k,j,i) - dt_3d *                                 &
-                        ( tend(k+1,j,i) - tend(k,j,i) ) * ddzu(k+1) *      &
-                        weight_pres(intermediate_timestep_count)
-          ENDDO
-          DO  k = nzb_u_inner(j,i)+1, nzt
-             u(k,j,i) = u(k,j,i) - dt_3d *                                 &
-                        ( tend(k,j,i) - tend(k,j,i-1) ) * ddx *            &
-                        weight_pres(intermediate_timestep_count)
-          ENDDO
-          DO  k = nzb_v_inner(j,i)+1, nzt
-             v(k,j,i) = v(k,j,i) - dt_3d *                                 &
-                        ( tend(k,j,i) - tend(k,j-1,i) ) * ddy *            &
-                        weight_pres(intermediate_timestep_count)
+          !$acc loop vector( 32 )
+          DO  k = 1, nzt
+             IF ( k > nzb_w_inner(j,i) )  THEN
+                w(k,j,i) = w(k,j,i) - dt_3d *                                 &
+                           ( tend(k+1,j,i) - tend(k,j,i) ) * ddzu(k+1) *      &
+                           weight_pres(intermediate_timestep_count)
+             ENDIF
+          ENDDO
+          !$acc loop vector( 32 )
+          DO  k = 1, nzt
+             IF ( k > nzb_u_inner(j,i) )  THEN
+                u(k,j,i) = u(k,j,i) - dt_3d *                                 &
+                           ( tend(k,j,i) - tend(k,j,i-1) ) * ddx *            &
+                           weight_pres(intermediate_timestep_count)
+             ENDIF
+          ENDDO
+          !$acc loop vector( 32 )
+          DO  k = 1, nzt
+             IF ( k > nzb_v_inner(j,i) )  THEN
+                v(k,j,i) = v(k,j,i) - dt_3d *                                 &
+                           ( tend(k,j,i) - tend(k,j-1,i) ) * ddy *            &
+                           weight_pres(intermediate_timestep_count)
+             ENDIF
           ENDDO                                                         
-!
-!--       Sum up the volume flow through the right and north boundary
-          IF ( conserve_volume_flow  .AND.  bc_lr_cyc  .AND.  bc_ns_cyc  .AND. &
-               i == nx )  THEN
-             !$OMP CRITICAL
-             DO  k = nzb_2d(j,i) + 1, nzt
-                volume_flow_l(1) = volume_flow_l(1) + u(k,j,i) * dzw(k)
-             ENDDO
-             !$OMP END CRITICAL
-          ENDIF
-          IF ( conserve_volume_flow  .AND.  bc_ns_cyc  .AND.  bc_lr_cyc  .AND. &
-               j == ny )  THEN
-             !$OMP CRITICAL
-             DO  k = nzb_2d(j,i) + 1, nzt
-                volume_flow_l(2) = volume_flow_l(2) + v(k,j,i) * dzw(k)
-             ENDDO
-             !$OMP END CRITICAL
-          ENDIF
 
        ENDDO
     ENDDO
+    !$acc end kernels
     !$OMP END PARALLEL
+
+!
+!-- Sum up the volume flow through the right and north boundary
+    IF ( conserve_volume_flow  .AND.  bc_lr_cyc  .AND.  bc_ns_cyc  .AND.  &
+         nxr == nx )  THEN
+
+       !$OMP PARALLEL PRIVATE (j,k)
+       !$OMP DO
+       DO  j = nys, nyn
+          !$OMP CRITICAL
+          DO  k = nzb_2d(j,nx) + 1, nzt
+             volume_flow_l(1) = volume_flow_l(1) + u(k,j,nx) * dzw(k)
+          ENDDO
+          !$OMP END CRITICAL
+       ENDDO
+       !$OMP END PARALLEL
+
+    ENDIF
+
+    IF ( conserve_volume_flow  .AND.  bc_ns_cyc  .AND.  bc_lr_cyc  .AND.  &
+         nyn == ny )  THEN
+
+       !$OMP PARALLEL PRIVATE (i,k)
+       !$OMP DO
+       DO  i = nxl, nxr
+          !$OMP CRITICAL
+          DO  k = nzb_2d(ny,i) + 1, nzt
+             volume_flow_l(2) = volume_flow_l(2) + v(k,ny,i) * dzw(k)
+           ENDDO
+          !$OMP END CRITICAL
+       ENDDO
+       !$OMP END PARALLEL
+
+    ENDIF
     
 !
@@ -645,7 +704,17 @@
 !
 !-- Exchange of boundaries for the velocities
+    IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
+       on_device = .TRUE.         ! to be removed after complete porting
+    ELSE                          ! of ghost point exchange
+       !$acc update host( u, v, w )
+    ENDIF
     CALL exchange_horiz( u, nbgp )
     CALL exchange_horiz( v, nbgp )
     CALL exchange_horiz( w, nbgp )
+    IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
+       on_device = .FALSE.        ! to be removed after complete porting
+    ELSE                          ! of ghost point exchange
+       !$acc update device( u, v, w )
+    ENDIF
 
 !
@@ -679,10 +748,26 @@
     ENDDO
 #else
+    !$acc kernels present( d, ddzw, nzb_s_inner, u, v, w )
+    !$acc loop
     DO  i = nxl, nxr
        DO  j = nys, nyn
+          !$acc loop vector( 32 )
+          DO  k = 1, nzt
+             IF ( k > nzb_s_inner(j,i) )  THEN
+                d(k,j,i) = ( u(k,j,i+1) - u(k,j,i) ) * ddx + &
+                           ( v(k,j+1,i) - v(k,j,i) ) * ddy + &
+                           ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k)
+             ENDIF
+          ENDDO
+       ENDDO
+    ENDDO
+    !$acc end kernels
+!
+!-- Compute possible PE-sum of divergences for flow_statistics
+    !$OMP PARALLEL PRIVATE (i,j,k) FIRSTPRIVATE(threadsum) REDUCTION(+:localsum)
+    !$OMP DO SCHEDULE( STATIC )
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
           DO  k = nzb_s_inner(j,i)+1, nzt
-             d(k,j,i) = ( u(k,j,i+1) - u(k,j,i) ) * ddx + &
-                        ( v(k,j+1,i) - v(k,j,i) ) * ddy + &
-                        ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k)
              threadsum = threadsum + ABS( d(k,j,i) )
           ENDDO
@@ -701,8 +786,5 @@
     CALL cpu_log( log_point_s(1), 'divergence', 'stop' )
 
-    !$acc update device( u, v, w )
-
     CALL cpu_log( log_point(8), 'pres', 'stop' )
-    
 
 
