Index: codes/icosagcm/trunk/src/kernels/advect_horiz.k90
===================================================================
--- codes/icosagcm/trunk/src/kernels/advect_horiz.k90	(revision 899)
+++ codes/icosagcm/trunk/src/kernels/advect_horiz.k90	(revision 953)
@@ -1,52 +1,69 @@
    !--------------------------------------------------------------------------
    !---------------------------- advect_horiz ----------------------------------
+
+   !$acc data create(qflux(:,:)) present(qi(:,:), cc(:,:,:), gradq3d(:,:,:), mass(:,:), hfluxt(:,:), Ai(:), xyz_i(:,:)) async
+
    ! evaluate tracer field at point cc using piecewise linear reconstruction
    ! q(cc)= q0 + gradq.(cc-xyz_i) with xi centroid of hexagon
    ! sign*hfluxt>0 iff outgoing
+   !$acc parallel loop collapse(2) async
    DO l = ll_begin, ll_end
       !DIR$ SIMD
       DO ij=ij_begin_ext, ij_end_ext
          IF(ne_right*hfluxt(ij+u_right,l)>0.) THEN
-            qe = qi(ij,l)
-            qe = qe + (cc(ij+u_right,l,1)-xyz_i(ij,1))*gradq3d(ij,l,1)
-            qe = qe + (cc(ij+u_right,l,2)-xyz_i(ij,2))*gradq3d(ij,l,2)
-            qe = qe + (cc(ij+u_right,l,3)-xyz_i(ij,3))*gradq3d(ij,l,3)
+            ij_tmp = ij
          ELSE
-            qe = qi(ij+t_right,l)
-            qe = qe + (cc(ij+u_right,l,1)-xyz_i(ij+t_right,1))*gradq3d(ij+t_right,l,1)
-            qe = qe + (cc(ij+u_right,l,2)-xyz_i(ij+t_right,2))*gradq3d(ij+t_right,l,2)
-            qe = qe + (cc(ij+u_right,l,3)-xyz_i(ij+t_right,3))*gradq3d(ij+t_right,l,3)
+            ij_tmp = ij+t_right
          END IF
+
+         qe = qi(ij_tmp,l)
+         qe = qe + (cc(ij+u_right,l,1)-xyz_i(ij_tmp,1))*gradq3d(ij_tmp,l,1)
+         qe = qe + (cc(ij+u_right,l,2)-xyz_i(ij_tmp,2))*gradq3d(ij_tmp,l,2)
+         qe = qe + (cc(ij+u_right,l,3)-xyz_i(ij_tmp,3))*gradq3d(ij_tmp,l,3)
+
          qflux(ij+u_right,l) = hfluxt(ij+u_right,l)*qe
-         IF(diagflux_on) qfluxt(ij+u_right,l) = qfluxt(ij+u_right,l)+qflux(ij+u_right,l)
+
          IF(ne_lup*hfluxt(ij+u_lup,l)>0.) THEN
-            qe = qi(ij,l)
-            qe = qe + (cc(ij+u_lup,l,1)-xyz_i(ij,1))*gradq3d(ij,l,1)
-            qe = qe + (cc(ij+u_lup,l,2)-xyz_i(ij,2))*gradq3d(ij,l,2)
-            qe = qe + (cc(ij+u_lup,l,3)-xyz_i(ij,3))*gradq3d(ij,l,3)
+            ij_tmp = ij
          ELSE
-            qe = qi(ij+t_lup,l)
-            qe = qe + (cc(ij+u_lup,l,1)-xyz_i(ij+t_lup,1))*gradq3d(ij+t_lup,l,1)
-            qe = qe + (cc(ij+u_lup,l,2)-xyz_i(ij+t_lup,2))*gradq3d(ij+t_lup,l,2)
-            qe = qe + (cc(ij+u_lup,l,3)-xyz_i(ij+t_lup,3))*gradq3d(ij+t_lup,l,3)
+            ij_tmp = ij+t_lup
          END IF
+
+         qe = qi(ij_tmp,l)
+         qe = qe + (cc(ij+u_lup,l,1)-xyz_i(ij_tmp,1))*gradq3d(ij_tmp,l,1)
+         qe = qe + (cc(ij+u_lup,l,2)-xyz_i(ij_tmp,2))*gradq3d(ij_tmp,l,2)
+         qe = qe + (cc(ij+u_lup,l,3)-xyz_i(ij_tmp,3))*gradq3d(ij_tmp,l,3)
+
          qflux(ij+u_lup,l) = hfluxt(ij+u_lup,l)*qe
-         IF(diagflux_on) qfluxt(ij+u_lup,l) = qfluxt(ij+u_lup,l)+qflux(ij+u_lup,l)
+
          IF(ne_ldown*hfluxt(ij+u_ldown,l)>0.) THEN
-            qe = qi(ij,l)
-            qe = qe + (cc(ij+u_ldown,l,1)-xyz_i(ij,1))*gradq3d(ij,l,1)
-            qe = qe + (cc(ij+u_ldown,l,2)-xyz_i(ij,2))*gradq3d(ij,l,2)
-            qe = qe + (cc(ij+u_ldown,l,3)-xyz_i(ij,3))*gradq3d(ij,l,3)
+            ij_tmp = ij
          ELSE
-            qe = qi(ij+t_ldown,l)
-            qe = qe + (cc(ij+u_ldown,l,1)-xyz_i(ij+t_ldown,1))*gradq3d(ij+t_ldown,l,1)
-            qe = qe + (cc(ij+u_ldown,l,2)-xyz_i(ij+t_ldown,2))*gradq3d(ij+t_ldown,l,2)
-            qe = qe + (cc(ij+u_ldown,l,3)-xyz_i(ij+t_ldown,3))*gradq3d(ij+t_ldown,l,3)
+            ij_tmp = ij+t_ldown
          END IF
+
+         qe = qi(ij_tmp,l)
+         qe = qe + (cc(ij+u_ldown,l,1)-xyz_i(ij_tmp,1))*gradq3d(ij_tmp,l,1)
+         qe = qe + (cc(ij+u_ldown,l,2)-xyz_i(ij_tmp,2))*gradq3d(ij_tmp,l,2)
+         qe = qe + (cc(ij+u_ldown,l,3)-xyz_i(ij_tmp,3))*gradq3d(ij_tmp,l,3)
+
          qflux(ij+u_ldown,l) = hfluxt(ij+u_ldown,l)*qe
-         IF(diagflux_on) qfluxt(ij+u_ldown,l) = qfluxt(ij+u_ldown,l)+qflux(ij+u_ldown,l)
       END DO
    END DO
+
+   IF(diagflux_on) THEN
+     !$acc parallel loop collapse(2) copy(qfluxt(:,:)) async
+     DO l = ll_begin, ll_end
+        !DIR$ SIMD
+        DO ij=ij_begin_ext, ij_end_ext
+           qfluxt(ij+u_right,l) = qfluxt(ij+u_right,l)+qflux(ij+u_right,l)
+           qfluxt(ij+u_lup,l) = qfluxt(ij+u_lup,l)+qflux(ij+u_lup,l)
+           qfluxt(ij+u_ldown,l) = qfluxt(ij+u_ldown,l)+qflux(ij+u_ldown,l)
+        END DO
+     END DO
+   END IF
+
    ! update q and, if update_mass, update mass
+   !$acc parallel loop collapse(2) async
    DO l = ll_begin, ll_end
       !DIR$ SIMD
@@ -71,4 +88,7 @@
       END DO
    END DO
+   
+   !$acc end data
+
    !---------------------------- advect_horiz ----------------------------------
    !--------------------------------------------------------------------------
