Index: codes/icosagcm/trunk/src/dissip_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/dissip_gcm.f90	(revision 286)
+++ codes/icosagcm/trunk/src/dissip_gcm.f90	(revision 295)
@@ -71,4 +71,5 @@
   USE time_mod
   USE transfert_omp_mod
+  USE omp_para
   IMPLICIT NONE
   
@@ -100,15 +101,15 @@
    CASE('none')
       rayleigh_friction_type=0
-      IF (is_mpi_root) PRINT *, 'No Rayleigh friction'
+      IF (is_master) PRINT *, 'No Rayleigh friction'
    CASE('dcmip2_schaer_noshear')
       rayleigh_friction_type=1
       rayleigh_shear=0
-      IF (is_mpi_root) PRINT *, 'Rayleigh friction : Schaer-like mountain without shear DCMIP2.1'
+      IF (is_master) PRINT *, 'Rayleigh friction : Schaer-like mountain without shear DCMIP2.1'
    CASE('dcmip2_schaer_shear')
       rayleigh_shear=1
       rayleigh_friction_type=2
-      IF (is_mpi_root) PRINT *, 'Rayleigh friction : Schaer-like mountain with shear DCMIP2.2'
+      IF (is_master) PRINT *, 'Rayleigh friction : Schaer-like mountain with shear DCMIP2.2'
    CASE DEFAULT
-      IF (is_mpi_root) PRINT *, 'Bad selector : rayleigh_friction_type =', TRIM(rayleigh_friction_key), ' in dissip_gcm.f90/init_dissip'
+      IF (is_master) PRINT *, 'Bad selector : rayleigh_friction_type =', TRIM(rayleigh_friction_key), ' in dissip_gcm.f90/init_dissip'
       STOP
    END SELECT
@@ -119,5 +120,5 @@
       rayleigh_tau = rayleigh_tau / scale_factor
       IF(rayleigh_tau<=0) THEN
-         IF (is_mpi_root) PRINT *, 'Forbidden : negative value for rayleigh_friction_tau =',rayleigh_tau
+         IF (is_master) PRINT *, 'Forbidden : negative value for rayleigh_friction_tau =',rayleigh_tau
          STOP
       END IF
@@ -156,7 +157,8 @@
     cdivgrad=-1
     cgradrot=-1
-    
+
+!$OMP BARRIER
+!$OMP MASTER
     DO ind=1,ndomain
-      IF (.NOT. assigned_domain(ind)) CYCLE
       CALL swap_dimensions(ind)
       CALL swap_geometry(ind)
@@ -175,6 +177,6 @@
       ENDDO        
     ENDDO
-  
-
+!$OMP END MASTER  
+!$OMP BARRIER
 
     DO it=1,20
@@ -184,5 +186,5 @@
         CALL transfert_request(f_u,req_e1_vect)
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind)) CYCLE
+          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
           CALL swap_dimensions(ind)
           CALL swap_geometry(ind)
@@ -197,5 +199,5 @@
       
       DO ind=1,ndomain
-        IF (.NOT. assigned_domain(ind)) CYCLE
+        IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
         CALL swap_dimensions(ind)
         CALL swap_geometry(ind)
@@ -214,5 +216,5 @@
 
       IF (using_mpi) THEN 
-        CALL reduce_sum_omp(dumax,dumax1)
+        CALL reduce_max_omp(dumax,dumax1)
 !$OMP MASTER        
         CALL MPI_ALLREDUCE(dumax1,dumax,1,MPI_REAL8,MPI_MAX,comm_icosa,ierr)
@@ -220,10 +222,10 @@
         CALL bcast_omp(dumax)  
       ELSE
-        CALL allreduce_sum_omp(dumax,dumax1)
+        CALL allreduce_max_omp(dumax,dumax1)
         dumax=dumax1
       ENDIF  
 			
       DO ind=1,ndomain
-        IF (.NOT. assigned_domain(ind)) CYCLE
+        IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
         CALL swap_dimensions(ind)
         CALL swap_geometry(ind)
@@ -232,18 +234,19 @@
         u=du/dumax
       ENDDO
-      IF (is_mpi_root) PRINT *,"gradiv : it :",it ,": dumax",dumax
+      IF (is_master) PRINT *,"gradiv : it :",it ,": dumax",dumax
 
     ENDDO 
-    IF (is_mpi_root) PRINT *,"gradiv : dumax",dumax
-    IF (is_mpi_root) PRINT *, 'mean T-cell edge size (km)', 1.45*radius/iim_glo/1000., &
+    IF (is_master) PRINT *,"gradiv : dumax",dumax
+    IF (is_master) PRINT *, 'mean T-cell edge size (km)', 1.45*radius/iim_glo/1000., &
                               'effective T-cell half-edge size (km)', dumax**(-.5/nitergdiv)/1000
-    IF (is_mpi_root)  PRINT *, 'Max. time step assuming c=340 m/s and Courant number=2.8 :', &
+    IF (is_master)  PRINT *, 'Max. time step assuming c=340 m/s and Courant number=2.8 :', &
                                2.8/340.*dumax**(-.5/nitergdiv)
 
     cgraddiv=dumax**(-1./nitergdiv)
-    IF (is_mpi_root) PRINT *,"cgraddiv : ",cgraddiv
-
+    IF (is_master) PRINT *,"cgraddiv : ",cgraddiv
+
+!$OMP BARRIER
+!$OMP MASTER
     DO ind=1,ndomain
-      IF (.NOT. assigned_domain(ind)) CYCLE
       CALL swap_dimensions(ind)
       CALL swap_geometry(ind)
@@ -262,4 +265,6 @@
       ENDDO        
     ENDDO
+!$OMP END MASTER  
+!$OMP BARRIER
 
 
@@ -270,5 +275,5 @@
         CALL transfert_request(f_u,req_e1_vect)
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind)) CYCLE
+          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
           CALL swap_dimensions(ind)
           CALL swap_geometry(ind)
@@ -283,5 +288,5 @@
       
       DO ind=1,ndomain
-        IF (.NOT. assigned_domain(ind)) CYCLE
+        IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
         CALL swap_dimensions(ind)
         CALL swap_geometry(ind)
@@ -300,5 +305,5 @@
 
       IF (using_mpi) THEN 
-        CALL reduce_sum_omp(dumax,dumax1)
+        CALL reduce_max_omp(dumax,dumax1)
 !$OMP MASTER        
         CALL MPI_ALLREDUCE(dumax1,dumax,1,MPI_REAL8,MPI_MAX,comm_icosa,ierr)
@@ -306,5 +311,5 @@
         CALL bcast_omp(dumax)  
       ELSE
-        CALL allreduce_sum_omp(dumax,dumax1)
+        CALL allreduce_max_omp(dumax,dumax1)
         dumax=dumax1
       ENDIF  
@@ -312,5 +317,5 @@
       
       DO ind=1,ndomain
-        IF (.NOT. assigned_domain(ind)) CYCLE
+        IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
         CALL swap_dimensions(ind)
         CALL swap_geometry(ind)
@@ -320,16 +325,17 @@
       ENDDO
       
-      IF (is_mpi_root) PRINT *,"gradrot : it :",it ,": dumax",dumax
+      IF (is_master) PRINT *,"gradrot : it :",it ,": dumax",dumax
 
     ENDDO 
-    IF (is_mpi_root) PRINT *,"gradrot : dumax",dumax
+    IF (is_master) PRINT *,"gradrot : dumax",dumax
   
     cgradrot=dumax**(-1./nitergrot) 
-    IF (is_mpi_root) PRINT *,"cgradrot : ",cgradrot
+    IF (is_master) PRINT *,"cgradrot : ",cgradrot
    
 
 
+!$OMP BARRIER
+!$OMP MASTER
     DO ind=1,ndomain
-      IF (.NOT. assigned_domain(ind)) CYCLE
       CALL swap_dimensions(ind)
       CALL swap_geometry(ind)
@@ -344,4 +350,6 @@
       ENDDO  
     ENDDO
+!$OMP END MASTER
+!$OMP BARRIER
 
     DO it=1,20
@@ -351,5 +359,5 @@
         CALL transfert_request(f_theta,req_i1)
         DO ind=1,ndomain
-          IF (.NOT. assigned_domain(ind)) CYCLE
+          IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
           CALL swap_dimensions(ind)
           CALL swap_geometry(ind)
@@ -364,5 +372,5 @@
       
       DO ind=1,ndomain
-        IF (.NOT. assigned_domain(ind)) CYCLE
+        IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
         CALL swap_dimensions(ind)
         CALL swap_geometry(ind)
@@ -379,5 +387,5 @@
 
       IF (using_mpi) THEN 
-        CALL reduce_sum_omp(dthetamax ,dthetamax1)
+        CALL reduce_max_omp(dthetamax ,dthetamax1)
 !$OMP MASTER        
         CALL MPI_ALLREDUCE(dthetamax1,dthetamax,1,MPI_REAL8,MPI_MAX,comm_icosa,ierr)
@@ -385,12 +393,12 @@
         CALL bcast_omp(dthetamax)  
       ELSE
-        CALL allreduce_sum_omp(dthetamax,dthetamax1)
+        CALL allreduce_max_omp(dthetamax,dthetamax1)
         dumax=dumax1
       ENDIF  
       
-      IF (is_mpi_root) PRINT *,"divgrad : it :",it ,": dthetamax",dthetamax
+      IF (is_master) PRINT *,"divgrad : it :",it ,": dthetamax",dthetamax
 
       DO ind=1,ndomain
-        IF (.NOT. assigned_domain(ind)) CYCLE
+        IF (.NOT. assigned_domain(ind) .OR. .NOT. is_omp_level_master) CYCLE
         CALL swap_dimensions(ind)
         CALL swap_geometry(ind)
@@ -401,8 +409,8 @@
     ENDDO 
 
-    IF (is_mpi_root) PRINT *,"divgrad : divgrad",dthetamax
+    IF (is_master) PRINT *,"divgrad : divgrad",dthetamax
   
     cdivgrad=dthetamax**(-1./niterdivgrad) 
-    IF (is_mpi_root) PRINT *,"cdivgrad : ",cdivgrad
+    IF (is_master) PRINT *,"cdivgrad : ",cdivgrad
 
      
@@ -431,9 +439,9 @@
        dtdissip=itau_dissip*dt
     ELSE
-       IF (is_mpi_root) PRINT *,"No dissipation time set, setting itau_dissip to 1000000000"
+       IF (is_master) PRINT *,"No dissipation time set, setting itau_dissip to 1000000000"
        itau_dissip=100000000
     END IF
     itau_dissip=MAX(1,itau_dissip)
-    IF (is_mpi_root) PRINT *,"mintau ",mintau,"itau_dissip",itau_dissip," dtdissip ",dtdissip
+    IF (is_master) PRINT *,"mintau ",mintau,"itau_dissip",itau_dissip," dtdissip ",dtdissip
 
   END SUBROUTINE init_dissip 
@@ -713,5 +721,5 @@
 
     CALL trace_start("divgrad")
-       
+
     DO ind=1,ndomain
       IF (.NOT. assigned_domain(ind)) CYCLE
