Index: LMDZ4/branches/LMDZ4_V3_patches/libf/dyn3dpar/leapfrog_p.F
===================================================================
--- LMDZ4/branches/LMDZ4_V3_patches/libf/dyn3dpar/leapfrog_p.F	(revision 844)
+++ LMDZ4/branches/LMDZ4_V3_patches/libf/dyn3dpar/leapfrog_p.F	(revision 916)
@@ -6,5 +6,5 @@
 #define IO_DEBUG
 
-!#undef CPP_IOIPSL
+c#undef CPP_IOIPSL
 
       SUBROUTINE leapfrog_p(ucov,vcov,teta,ps,masse,phis,nq,q,clesphy0,
@@ -481,4 +481,6 @@
 c$OMP MASTER
        call VTb(VThallo)
+c$OMP END MASTER
+
        call Register_Hallo(ucov,ip1jmp1,llm,1,1,1,1,TestRequest)
        call Register_Hallo(vcov,ip1jm,llm,1,1,1,1,TestRequest)
@@ -496,7 +498,11 @@
 
        call SendRequest(TestRequest)
+c$OMP BARRIER
        call WaitRequest(TestRequest)
+
+c$OMP MASTER
        call VTe(VThallo)
-
+c$OMP END MASTER
+c$OMP BARRIER
       
       if (debug) then	
@@ -514,7 +520,7 @@
      .                reshape(q(:,:,j),(/iip1,jmp1,llm/)))
         enddo        
+c$OMP BARRIER
       endif
-c$OMP END MASTER 
-c$OMP BARRIER
+
       
       True_itau=True_itau+1
@@ -531,23 +537,19 @@
       call VTb(VTcaldyn)
 c$OMP END MASTER
-c$OMP BARRIER
       var_time=time+iday-day_ini
-cc$OMP PARALLEL DEFAULT(SHARED)
-cc$OMP+         PRIVATE(rdaym_ini,rdayvrai,ijb,ije,
-cc$OMP+                 tppn,tpn,tpps,tps)
-
-cc$OMP+         SHARED(itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
-cc$OMP+                phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, 
-cc$OMP+                time, iday,day_ini,forward,leapf, iapptrac,
-cc$OMP+                q,dq,p,VTcaldyn,offline,dtvr,itau)      
-
+
+c$OMP BARRIER
+!      CALL FTRACE_REGION_BEGIN("caldyn")
       CALL caldyn_p 
      $  ( itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
      $    phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, time+iday-day_ini )
 
-ccc$OMP END PARALLEL      
+!      CALL FTRACE_REGION_END("caldyn")
 c$OMP MASTER
       call VTe(VTcaldyn)
 c$OMP END MASTER      
+
+cc$OMP BARRIER
+cc$OMP MASTER
 c      call WriteField_p('du',reshape(du,(/iip1,jmp1,llm/)))
 c      call WriteField_p('dv',reshape(dv,(/iip1,jjm,llm/)))
@@ -557,4 +559,8 @@
 c      call WriteField_p('pbaru',reshape(pbaru,(/iip1,jmp1,llm/)))
 c      call WriteField_p('pbarv',reshape(pbarv,(/iip1,jjm,llm/)))
+c      call WriteField_p('p',reshape(p,(/iip1,jmp1,llmp1/)))
+c      call WriteField_p('masse',reshape(masse,(/iip1,jmp1,llm/)))
+c      call WriteField_p('pk',reshape(pk,(/iip1,jmp1,llm/)))
+cc$OMP END MASTER
 
 c-----------------------------------------------------------------------
@@ -587,7 +593,7 @@
        IF (offline) THEN
 Cmaf stokage du flux de masse pour traceurs OFF-LINE
-#undef CPP_IOIPSL
+
 #ifdef CPP_IOIPSL
-           CALL fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
+           CALL fluxstokenc_p(pbaru,pbarv,masse,teta,phi,phis,
      .   dtvr, itau)
 #endif
@@ -662,8 +668,10 @@
 c$OMP END MASTER
 
-c$OMP BARRIER
          CALL pression_p (  ip1jmp1, ap, bp, ps,  p      )
 
+c$OMP BARRIER
+
          CALL exner_hyb_p(  ip1jmp1, ps, p,alpha,beta,pks, pk, pkf )
+c$OMP BARRIER
            rdaym_ini  = itau * dtvr / daysec
            rdayvrai   = rdaym_ini  + day_ini
@@ -690,4 +698,6 @@
 c$OMP MASTER
         call VTb(VThallo)
+c$OMP END MASTER
+
         call SetTag(Request_physic,800)
 	
@@ -726,11 +736,13 @@
      *                               jj_Nb_physic,2,2,Request_physic)
 #endif
+	
+        call SendRequest(Request_Physic)
+c$OMP BARRIER
+        call WaitRequest(Request_Physic)       
+
+c$OMP BARRIER
+c$OMP MASTER
         call SetDistrib(jj_nb_Physic)
-	
-        call SendRequest(Request_Physic)
-        call WaitRequest(Request_Physic)       
-	
 	call VTe(VThallo)
-	
 	call VTb(VTphysiq)
 c$OMP END MASTER
@@ -773,6 +785,7 @@
 c$OMP MASTER
 	call SetDistrib(jj_nb_Physic_bis)
-
         call VTb(VThallo)
+c$OMP END MASTER
+c$OMP BARRIER
  
         call Register_Hallo(dufi,ip1jmp1,llm,
@@ -794,12 +807,15 @@
         
         call SendRequest(Request_Physic)
+c$OMP BARRIER
         call WaitRequest(Request_Physic)
              
+c$OMP BARRIER
+c$OMP MASTER
         call VTe(VThallo)
- 
         call SetDistrib(jj_nb_Physic)
 c$OMP END MASTER
 c$OMP BARRIER	
-	        ijb=ij_begin
+	
+        ijb=ij_begin
 	if (.not. pole_nord) then
 	
@@ -842,6 +858,6 @@
 c$OMP MASTER
         call VTe(VTphysiq)
-
         call VTb(VThallo)
+c$OMP END MASTER
 
         call SetTag(Request_physic,800)
@@ -878,9 +894,11 @@
 
         call SendRequest(Request_Physic)
+c$OMP BARRIER
         call WaitRequest(Request_Physic)     
 
-        call VTe(VThallo)
-
-        call SetDistrib(jj_Nb_caldyn)
+c$OMP BARRIER
+c$OMP MASTER
+       call VTe(VThallo)
+       call SetDistrib(jj_Nb_caldyn)
 c$OMP END MASTER
 c$OMP BARRIER
@@ -931,6 +949,8 @@
        ENDIF
 
-c$OMP BARRIER
         CALL pression_p ( ip1jmp1, ap, bp, ps, p                  )
+c$OMP BARRIER
+
+
         CALL exner_hyb_p( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
 c$OMP BARRIER
@@ -956,5 +976,5 @@
 
 c$OMP BARRIER
-c$OMP MASTER
+
         call Register_SwapFieldHallo(ucov,ucov,ip1jmp1,llm,
      *                          jj_Nb_dissip,1,1,Request_dissip)
@@ -973,11 +993,12 @@
 
         call SendRequest(Request_dissip)       
+c$OMP BARRIER
         call WaitRequest(Request_dissip)       
+
+c$OMP BARRIER
+c$OMP MASTER
         call SetDistrib(jj_Nb_dissip)
-        
-	call VTe(VThallo)
-
+        call VTe(VThallo)
         call VTb(VTdissipation)
-        
 	call start_timer(timer_dissip)
 c$OMP END MASTER
@@ -1016,9 +1037,11 @@
             call suspend_timer(timer_dissip)
 	    call VTb(VThallo)
-
+c$OMP END MASTER
             call Register_Hallo(ucov,ip1jmp1,llm,1,1,1,1,Request_Dissip)
             call Register_Hallo(vcov,ip1jm,llm,1,1,1,1,Request_Dissip)
             call SendRequest(Request_Dissip)
+c$OMP BARRIER
             call WaitRequest(Request_Dissip)
+c$OMP MASTER
             call VTe(VThallo)
             call resume_timer(timer_dissip)
@@ -1115,9 +1138,7 @@
 c$OMP MASTER
         call VTe(VTdissipation)
-
         call stop_timer(timer_dissip)
-	
         call VTb(VThallo)
-
+c$OMP END MASTER
         call Register_SwapField(ucov,ucov,ip1jmp1,llm,
      *                          jj_Nb_caldyn,Request_dissip)
@@ -1136,5 +1157,9 @@
 
         call SendRequest(Request_dissip)       
+c$OMP BARRIER
         call WaitRequest(Request_dissip)       
+
+c$OMP BARRIER
+c$OMP MASTER
         call SetDistrib(jj_Nb_caldyn)
         call VTe(VThallo)
@@ -1142,4 +1167,5 @@
 	print *,'fin dissipation'
 c$OMP END MASTER
+c$OMP BARRIER
       END IF
 
@@ -1211,4 +1237,5 @@
         call finalize_parallel
 c$OMP END MASTER
+c$OMP BARRIER
 	RETURN
       ENDIF
@@ -1244,5 +1271,4 @@
             IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
 c$OMP BARRIER
-c$OMP MASTER
                IF(itau.EQ.itaufin) THEN
                   iav=1
@@ -1250,15 +1276,16 @@
                   iav=0
                ENDIF
-#ifdef CPP_IOIPSL
-             call Register_Hallo(vcov,ip1jm,llm,1,0,0,1,TestRequest)
-              call SendRequest(TestRequest)
-              call WaitRequest(TestRequest)
-
-              CALL writedynav_p(histaveid, nqmx, itau,vcov ,
-     ,                          ucov,teta,pk,phi,q,masse,ps,phis)
+c#ifdef CPP_IOIPSL
+c             call Register_Hallo(vcov,ip1jm,llm,1,0,0,1,TestRequest)
+c             call SendRequest(TestRequest)
+cc$OMP BARRIER
+c              call WaitRequest(TestRequest)
+cc$OMP MASTER
+c              CALL writedynav_p(histaveid, nqmx, itau,vcov ,
+c     ,                          ucov,teta,pk,phi,q,masse,ps,phis)
+cc$OMP END MASTER
 c               call bilan_dyn_p(2,dtvr*iperiod,dtvr*day_step*periodav,
 c     ,           ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
-#endif
-c$OMP END MASTER
+c#endif
             ENDIF
 
@@ -1302,8 +1329,8 @@
         enddo
 	
-#ifdef CPP_IOIPSL
+c#ifdef CPP_IOIPSL
  
-        CALL writehist_p(histid,histvid, nqmx,itau,vcov, 
-     s                       ucov,teta,phi,q,masse,ps,phis)
+c        CALL writehist_p(histid,histvid, nqmx,itau,vcov, 
+c     s                       ucov,teta,phi,q,masse,ps,phis)
 c#else
 c       call Gather_Field(unat,ip1jmp1,llm,0)
@@ -1318,5 +1345,5 @@
 c#include "write_grads_dyn.h"
 c       endif
-#endif
+c#endif
 c$OMP END MASTER
            ENDIF
@@ -1402,18 +1429,19 @@
                   iav=0
                ENDIF
-#ifdef CPP_IOIPSL
-c$OMP BARRIER
-c$OMP MASTER
-
-              call Register_Hallo(vcov,ip1jm,llm,1,0,0,1,TestRequest)
-              call SendRequest(TestRequest)
-              call WaitRequest(TestRequest)
-
-              CALL writedynav_p(histaveid, nqmx, itau,vcov ,
-     ,                          ucov,teta,pk,phi,q,masse,ps,phis)
+c#ifdef CPP_IOIPSL
+cc$OMP BARRIER
+
+c              call Register_Hallo(vcov,ip1jm,llm,1,0,0,1,TestRequest)
+c              call SendRequest(TestRequest)
+cc$OMP BARRIER
+c              call WaitRequest(TestRequest)
+
+cc$OMP MASTER
+c              CALL writedynav_p(histaveid, nqmx, itau,vcov ,
+c     ,                          ucov,teta,pk,phi,q,masse,ps,phis)
 c               call bilan_dyn_p (2,dtvr*iperiod,dtvr*day_step*periodav,
 c     ,           ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
-c$OMP END MASTER
-#endif
+cc$OMP END MASTER
+c#endif
             ENDIF
 
@@ -1451,8 +1479,8 @@
         enddo
 
-#ifdef CPP_IOIPSL
-
-       CALL writehist_p( histid, histvid, nqmx, itau,vcov , 
-     ,                           ucov,teta,phi,q,masse,ps,phis)
+c#ifdef CPP_IOIPSL
+
+c       CALL writehist_p( histid, histvid, nqmx, itau,vcov , 
+c     ,                           ucov,teta,phi,q,masse,ps,phis)
 c#else
 c      call Gather_Field(unat,ip1jmp1,llm,0)
@@ -1467,5 +1495,5 @@
 c#include "write_grads_dyn.h"
 c      endif
-#endif
+c#endif
 
 c$OMP END MASTER
