Index: codes/icosagcm/trunk/src/timeloop_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 174)
+++ codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 186)
@@ -7,20 +7,22 @@
 
   INTEGER, PARAMETER :: euler=1, rk4=2, mlf=3
-  INTEGER  :: itau_sync=10
-
-  TYPE(t_message) :: req_ps0, req_mass0, req_theta_rhodz0, req_u0, req_q0
-
-  TYPE(t_field),POINTER :: f_q(:)
-  TYPE(t_field),POINTER :: f_rhodz(:), f_mass(:), f_massm1(:), f_massm2(:), f_dmass(:)
-  TYPE(t_field),POINTER :: f_phis(:), f_ps(:),f_psm1(:), f_psm2(:), f_dps(:)
-  TYPE(t_field),POINTER :: f_u(:),f_um1(:),f_um2(:), f_du(:)
-  TYPE(t_field),POINTER :: f_theta_rhodz(:),f_theta_rhodzm1(:),f_theta_rhodzm2(:), f_dtheta_rhodz(:)
-  TYPE(t_field),POINTER :: f_hflux(:), f_wflux(:), f_hfluxt(:), f_wfluxt(:)  
-
-  INTEGER :: nb_stage, matsuno_period, scheme    
+  INTEGER, PARAMETER :: itau_sync=10
+
+  TYPE(t_message),SAVE :: req_ps0, req_mass0, req_theta_rhodz0, req_u0, req_q0
+
+  TYPE(t_field),POINTER,SAVE :: f_q(:)
+  TYPE(t_field),POINTER,SAVE :: f_rhodz(:), f_mass(:), f_massm1(:), f_massm2(:), f_dmass(:)
+  TYPE(t_field),POINTER,SAVE :: f_phis(:), f_ps(:),f_psm1(:), f_psm2(:), f_dps(:)
+  TYPE(t_field),POINTER,SAVE :: f_u(:),f_um1(:),f_um2(:), f_du(:)
+  TYPE(t_field),POINTER,SAVE :: f_theta_rhodz(:),f_theta_rhodzm1(:),f_theta_rhodzm2(:), f_dtheta_rhodz(:)
+  TYPE(t_field),POINTER,SAVE :: f_hflux(:), f_wflux(:), f_hfluxt(:), f_wfluxt(:)  
+
+  INTEGER,SAVE :: nb_stage, matsuno_period, scheme    
+!$OMP THREADPRIVATE(nb_stage, matsuno_period, scheme)
 
   REAL(rstd),SAVE :: jD_cur, jH_cur
+!$OMP THREADPRIVATE(jD_cur, jH_cur)  
   REAL(rstd),SAVE :: start_time
-
+!$OMP THREADPRIVATE(start_time)
 CONTAINS
   
@@ -39,5 +41,4 @@
   USE transfert_mod
   USE check_conserve_mod
-  USE ioipsl
   USE output_field_mod
   USE write_field
@@ -47,57 +48,58 @@
 
 !----------------------------------------------------
-  IF (TRIM(time_style)=='lmd')  Then
-
-   day_step=180
-   CALL getin('day_step',day_step)
-
-   ndays=1
-   CALL getin('ndays',ndays)
-
-   dt = daysec/REAL(day_step)
-   itaumax = ndays*day_step
-
-   calend = 'earth_360d'
-   CALL getin('calend', calend)
-
-   day_ini = 0
-   CALL getin('day_ini',day_ini)
-
-   day_end = 0
-   CALL getin('day_end',day_end)
-
-   annee_ref = 1998
-   CALL getin('annee_ref',annee_ref)
-
-   start_time = 0
-   CALL getin('start_time',start_time) 
-
-   
-   write_period=0
-   CALL getin('write_period',write_period)
-      
-   write_period=write_period/scale_factor
-   itau_out=FLOOR(write_period/dt)
-   
-   PRINT *, 'Output frequency (scaled) set to ',write_period, ' : itau_out = ',itau_out 
-
-  mois = 1 ; heure = 0.
-  call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
-  jH_ref = jD_ref - int(jD_ref) 
-  jD_ref = int(jD_ref) 
-  
-  CALL ioconf_startdate(INT(jD_ref),jH_ref) 
-  write(*,*)'annee_ref, mois, day_ref, heure, jD_ref'
-  write(*,*)annee_ref, mois, day_ref, heure, jD_ref
-  write(*,*)"ndays,day_step,itaumax,dt======>"
-  write(*,*)ndays,day_step,itaumax,dt
-  call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
-  write(*,*)'jD_ref+jH_ref,an, mois, jour, heure'
-  write(*,*)jD_ref+jH_ref,an, mois, jour, heure
-  day_end = day_ini + ndays 
- END IF 
+!  IF (TRIM(time_style)=='lmd')  Then
+
+!   day_step=180
+!   CALL getin('day_step',day_step)
+
+!   ndays=1
+!   CALL getin('ndays',ndays)
+
+!   dt = daysec/REAL(day_step)
+!   itaumax = ndays*day_step
+
+!   calend = 'earth_360d'
+!   CALL getin('calend', calend)
+
+!   day_ini = 0
+!   CALL getin('day_ini',day_ini)
+
+!   day_end = 0
+!   CALL getin('day_end',day_end)
+
+!   annee_ref = 1998
+!   CALL getin('annee_ref',annee_ref)
+
+!   start_time = 0
+!   CALL getin('start_time',start_time) 
+
+!   
+!   write_period=0
+!   CALL getin('write_period',write_period)
+!      
+!   write_period=write_period/scale_factor
+!   itau_out=FLOOR(write_period/dt)
+!   
+!   PRINT *, 'Output frequency (scaled) set to ',write_period, ' : itau_out = ',itau_out 
+
+!  mois = 1 ; heure = 0.
+!  call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
+!  jH_ref = jD_ref - int(jD_ref) 
+!  jD_ref = int(jD_ref) 
+!  
+!  CALL ioconf_startdate(INT(jD_ref),jH_ref) 
+!  write(*,*)'annee_ref, mois, day_ref, heure, jD_ref'
+!  write(*,*)annee_ref, mois, day_ref, heure, jD_ref
+!  write(*,*)"ndays,day_step,itaumax,dt======>"
+!  write(*,*)ndays,day_step,itaumax,dt
+!  call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
+!  write(*,*)'jD_ref+jH_ref,an, mois, jour, heure'
+!  write(*,*)jD_ref+jH_ref,an, mois, jour, heure
+!  day_end = day_ini + ndays 
+! END IF 
 !----------------------------------------------------
 
    IF (xios_output) itau_out=1
+   IF (.NOT. enable_io) itau_out=HUGE(itau_out)
 
 ! Time-independant orography
@@ -178,4 +180,5 @@
     CALL init_check_conserve
     CALL init_physics
+
     CALL etat0(f_ps,f_mass,f_phis,f_theta_rhodz,f_u, f_q)
 
@@ -221,8 +224,11 @@
     LOGICAL :: fluxt_zero(ndomain) ! set to .TRUE. to start accumulating fluxes in time
     LOGICAL, PARAMETER :: check=.FALSE.
-
+    INTEGER :: start_clock
+    INTEGER :: stop_clock
+    INTEGER :: rate_clock
+    
     CALL caldyn_BC(f_phis, f_wflux) ! set constant values in first/last interfaces
 
-!$OMP BARRIER
+!!$OMP BARRIER
   DO ind=1,ndomain
      CALL swap_dimensions(ind)
@@ -237,4 +243,10 @@
   fluxt_zero=.TRUE.
 
+!$OMP MASTER
+  CALL SYSTEM_CLOCK(start_clock)
+!$OMP END MASTER   
+
+  CALL trace_on
+  
   DO it=0,itaumax
     
@@ -242,16 +254,24 @@
     IF (MOD(it,itau_sync)==0) THEN
       CALL send_message(f_ps,req_ps0)
+      CALL wait_message(req_ps0)
       CALL send_message(f_mass,req_mass0)
+      CALL wait_message(req_mass0)
       CALL send_message(f_theta_rhodz,req_theta_rhodz0) 
+      CALL wait_message(req_theta_rhodz0) 
       CALL send_message(f_u,req_u0)
+      CALL wait_message(req_u0)
       CALL send_message(f_q,req_q0) 
-      CALL wait_message(req_ps0)
-      CALL wait_message(req_mass0)
-      CALL wait_message(req_theta_rhodz0) 
-      CALL wait_message(req_u0)
       CALL wait_message(req_q0) 
+
+!      CALL wait_message(req_ps0)
+!      CALL wait_message(req_mass0)
+!      CALL wait_message(req_theta_rhodz0) 
+!      CALL wait_message(req_u0)
+!      CALL wait_message(req_q0) 
     ENDIF
-    
-!    IF (is_mpi_root) PRINT *,"It No :",It,"   t :",dt*It
+
+!$OMP MASTER    
+    IF (is_mpi_root) PRINT *,"It No :",It,"   t :",dt*It
+!$OMP END MASTER    
     IF (mod(it,itau_out)==0 ) THEN
       CALL update_time_counter(dt*it)
@@ -279,6 +299,10 @@
 
     IF (MOD(it+1,itau_dissip)==0) THEN
+!         CALL send_message(f_ps,req_ps)
+!         CALL wait_message(req_ps)  
+       
        IF(caldyn_eta==eta_mass) THEN
           DO ind=1,ndomain
+             IF (.NOT. assigned_domain(ind)) CYCLE
              CALL swap_dimensions(ind)
              CALL swap_geometry(ind)
@@ -287,5 +311,9 @@
           END DO
        ENDIF
+!       CALL send_message(f_mass,req_mass)
+!       CALL wait_message(req_mass)  
        CALL dissip(f_u,f_du,f_mass,f_phis, f_theta_rhodz,f_dtheta_rhodz)
+!       CALL send_message(f_mass,req_mass)
+!       CALL wait_message(req_mass)  
        CALL euler_scheme(.FALSE.)  ! update only u, theta
     END IF
@@ -299,4 +327,5 @@
        IF (check) THEN
          DO ind=1,ndomain
+            IF (.NOT. assigned_domain(ind)) CYCLE
             CALL swap_dimensions(ind)
             CALL swap_geometry(ind)
@@ -316,6 +345,17 @@
 !    jH_cur = jH_cur - int(jH_cur)
     CALL physics(it,jD_cur,jH_cur,f_phis, f_ps, f_theta_rhodz, f_u, f_q)
+
     ENDDO
 
+    CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,it)  
+
+!$OMP MASTER
+    CALL SYSTEM_CLOCK(stop_clock)
+    CALL SYSTEM_CLOCK(count_rate=rate_clock)
+    
+    IF (mpi_rank==0) THEN 
+      PRINT *,"Time elapsed : ",(stop_clock-start_clock)*1./rate_clock
+    ENDIF  
+!$OMP END MASTER 
  
   CONTAINS
@@ -329,4 +369,5 @@
 
     DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)) CYCLE
        CALL swap_dimensions(ind)
        CALL swap_geometry(ind)
@@ -390,4 +431,5 @@
 
             DO ind=1,ndomain
+               IF (.NOT. assigned_domain(ind)) CYCLE
                CALL swap_dimensions(ind)
                CALL swap_geometry(ind)
@@ -408,8 +450,11 @@
             ENDDO
          ENDIF
-         CALL send_message(f_ps,req_ps)
+!         CALL send_message(f_ps,req_ps)
+!ym no overlap for now         
+!         CALL wait_message(req_ps)  
       
       ELSE ! Lagrangian coordinate, deal with mass
          DO ind=1,ndomain
+            IF (.NOT. assigned_domain(ind)) CYCLE
             CALL swap_dimensions(ind)
             CALL swap_geometry(ind)
@@ -433,5 +478,7 @@
             ENDDO
          END DO
-         CALL send_message(f_mass,req_mass)
+!         CALL send_message(f_mass,req_mass)
+!ym no overlap for now         
+!         CALL wait_message(req_mass)  
 
       END IF
@@ -439,4 +486,5 @@
       ! now deal with other prognostic variables
       DO ind=1,ndomain
+         IF (.NOT. assigned_domain(ind)) CYCLE
          CALL swap_dimensions(ind)
          CALL swap_geometry(ind)
@@ -488,4 +536,5 @@
       tau = dt/nb_stage
       DO ind=1,ndomain
+        IF (.NOT. assigned_domain(ind)) CYCLE
         CALL swap_dimensions(ind)
         CALL swap_geometry(ind)
