Index: LMDZ4/trunk/libf/phylmd/phyredem.F
===================================================================
--- LMDZ4/trunk/libf/phylmd/phyredem.F	(revision 644)
+++ LMDZ4/trunk/libf/phylmd/phyredem.F	(revision 766)
@@ -4,14 +4,14 @@
 c
       SUBROUTINE phyredem (fichnom,dtime,radpas,
-     .           rlat,rlon, pctsrf,tsol,tsoil,
+     .           rlat_p,rlon_p, pctsrf_p,tsol_p,tsoil_p,
 cIM "slab" ocean
      .           tslab,seaice,
-     .           qsurf,qsol,snow,
-     .           albedo, alblw, evap, rain_fall, snow_fall,
-     .           solsw, sollw,fder,
-     .           radsol,frugs,agesno,
-     .           zmea,zstd,zsig,zgam,zthe,zpic,zval,rugsrel,
-     .           t_ancien, q_ancien, rnebcon, ratqs, clwcon,
-     .           run_off_lic_0)
+     .           qsurf_p,qsol_p,snow_p,albedo_p, alblw_p, evap_p,
+     .           rain_fall_p, snow_fall_p,solsw_p, sollw_p,fder_p,
+     .           radsol_p,frugs_p,agesno_p,zmea_p,zstd_p,zsig_p,
+     .           zgam_p,zthe_p,zpic_p,zval_p,rugsrel_p,
+     .           t_ancien_p, q_ancien_p, rnebcon_p, ratqs_p, clwcon_p,
+     .           run_off_lic_0_p)
+      USE dimphy
       IMPLICIT none
 c======================================================================
@@ -19,6 +19,6 @@
 c Objet: Ecriture de l'etat de redemarrage pour la physique
 c======================================================================
-#include "dimensions.h"
-#include "dimphy.h"
+cym#include "dimensions.h"
+cym#include "dimphy.h"
 #include "netcdf.inc"
 #include "indicesol.h"
@@ -31,37 +31,69 @@
       REAL dtime
       INTEGER radpas
-      REAL rlat(klon), rlon(klon)
-      REAL tsol(klon,nbsrf)
-      REAL tsoil(klon,nsoilmx,nbsrf)
+      REAL rlat_p(klon), rlon_p(klon)
+      REAL tsol_p(klon,nbsrf)
+      REAL tsoil_p(klon,nsoilmx,nbsrf)
 cIM "slab" ocean
-      REAL tslab(klon), seaice(klon)
-      REAL qsurf(klon,nbsrf)
-      REAL qsol(klon)
-      REAL snow(klon,nbsrf)
-      REAL albedo(klon,nbsrf)
+      REAL tslab_p(klon), seaice_p(klon)
+      REAL qsurf_p(klon,nbsrf)
+      REAL qsol_p(klon)
+      REAL snow_p(klon,nbsrf)
+      REAL albedo_p(klon,nbsrf)
 cIM BEG
-      REAL alblw(klon,nbsrf)
+      REAL alblw_p(klon,nbsrf)
 cIM END
-      REAL evap(klon,nbsrf)
-      REAL rain_fall(klon)
-      REAL snow_fall(klon)
-      real solsw(klon)
-      real sollw(klon)
-      real fder(klon)
-      REAL radsol(klon)
-      REAL frugs(klon,nbsrf)
-      REAL agesno(klon,nbsrf)
-      REAL zmea(klon)
-      REAL zstd(klon)
-      REAL zsig(klon)
-      REAL zgam(klon)
-      REAL zthe(klon)
-      REAL zpic(klon)
-      REAL zval(klon)
-      REAL rugsrel(klon)
-      REAL pctsrf(klon, nbsrf)
-      REAL t_ancien(klon,klev), q_ancien(klon,klev)
-      real clwcon(klon,klev),rnebcon(klon,klev),ratqs(klon,klev)
-      REAL run_off_lic_0(klon)
+      REAL evap_p(klon,nbsrf)
+      REAL rain_fall_p(klon)
+      REAL snow_fall_p(klon)
+      real solsw_p(klon)
+      real sollw_p(klon)
+      real fder_p(klon)
+      REAL radsol_p(klon)
+      REAL frugs_p(klon,nbsrf)
+      REAL agesno_p(klon,nbsrf)
+      REAL zmea_p(klon)
+      REAL zstd_p(klon)
+      REAL zsig_p(klon)
+      REAL zgam_p(klon)
+      REAL zthe_p(klon)
+      REAL zpic_p(klon)
+      REAL zval_p(klon)
+      REAL rugsrel_p(klon)
+      REAL pctsrf_p(klon, nbsrf)
+      REAL t_ancien_p(klon,klev), q_ancien_p(klon,klev)
+      real clwcon_p(klon,klev),rnebcon_p(klon,klev),ratqs_p(klon,klev)
+      REAL run_off_lic_0_p(klon)
+      
+      REAL rlat(klon2), rlon(klon2)
+      REAL tsol(klon2,nbsrf)
+      REAL tsoil(klon2,nsoilmx,nbsrf)
+      REAL tslab(klon2), seaice(klon2)
+      REAL qsurf(klon2,nbsrf)
+      REAL qsol(klon2)
+      REAL snow(klon2,nbsrf)
+      REAL albedo(klon2,nbsrf)
+      REAL alblw(klon2,nbsrf)
+      REAL evap(klon2,nbsrf)
+      REAL rain_fall(klon2)
+      REAL snow_fall(klon2)
+      real solsw(klon2)
+      real sollw(klon2)
+      real fder(klon2)
+      REAL radsol(klon2)
+      REAL frugs(klon2,nbsrf)
+      REAL agesno(klon2,nbsrf)
+      REAL zmea(klon2)
+      REAL zstd(klon2)
+      REAL zsig(klon2)
+      REAL zgam(klon2)
+      REAL zthe(klon2)
+      REAL zpic(klon2)
+      REAL zval(klon2)
+      REAL rugsrel(klon2)
+      REAL pctsrf(klon2, nbsrf)
+      REAL t_ancien(klon2,klev), q_ancien(klon2,klev)
+      real clwcon(klon2,klev),rnebcon(klon2,klev),ratqs(klon2,klev)
+      REAL run_off_lic_0(klon2)
+      REAL masq(klon2)
 c
       INTEGER nid, nvarid, idim1, idim2, idim3
@@ -75,4 +107,188 @@
       CHARACTER*2 str2
 c
+      REAL,SAVE,ALLOCATABLE :: rlat_mpi(:), rlon_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: tsol_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: tsoil_mpi(:,:,:)
+      REAL,SAVE,ALLOCATABLE :: tslab_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: seaice_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: qsurf_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: qsol_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: snow_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: albedo_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: alblw_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: evap_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: rain_fall_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: snow_fall_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: solsw_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: sollw_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: fder_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: radsol_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: frugs_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: agesno_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: zmea_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: zstd_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: zsig_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: zgam_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: zthe_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: zpic_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: zval_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: rugsrel_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: pctsrf_mpi(:, :)
+      REAL,SAVE,ALLOCATABLE :: t_ancien_mpi(:,:), q_ancien_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: clwcon_mpi(:,:),rnebcon_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: ratqs_mpi(:,:)
+      REAL,SAVE,ALLOCATABLE :: run_off_lic_0_mpi(:)
+      REAL,SAVE,ALLOCATABLE :: masq_mpi(:)
+      
+c$OMP MASTER
+      ALLOCATE( rlat_mpi(klon_mpi), rlon_mpi(klon_mpi))
+      ALLOCATE( tsol_mpi(klon_mpi,nbsrf))
+      ALLOCATE( tsoil_mpi(klon_mpi,nsoilmx,nbsrf))
+      ALLOCATE( tslab_mpi(klon_mpi))
+      ALLOCATE( seaice_mpi(klon_mpi))
+      ALLOCATE( qsurf_mpi(klon_mpi,nbsrf))
+      ALLOCATE( qsol_mpi(klon_mpi))
+      ALLOCATE( snow_mpi(klon_mpi,nbsrf))
+      ALLOCATE( albedo_mpi(klon_mpi,nbsrf))
+      ALLOCATE( alblw_mpi(klon_mpi,nbsrf))
+      ALLOCATE( evap_mpi(klon_mpi,nbsrf))
+      ALLOCATE( rain_fall_mpi(klon_mpi))
+      ALLOCATE( snow_fall_mpi(klon_mpi))
+      ALLOCATE( solsw_mpi(klon_mpi))
+      ALLOCATE( sollw_mpi(klon_mpi))
+      ALLOCATE( fder_mpi(klon_mpi))
+      ALLOCATE( radsol_mpi(klon_mpi))
+      ALLOCATE( frugs_mpi(klon_mpi,nbsrf))
+      ALLOCATE( agesno_mpi(klon_mpi,nbsrf))
+      ALLOCATE( zmea_mpi(klon_mpi))
+      ALLOCATE( zstd_mpi(klon_mpi))
+      ALLOCATE( zsig_mpi(klon_mpi))
+      ALLOCATE( zgam_mpi(klon_mpi))
+      ALLOCATE( zthe_mpi(klon_mpi))
+      ALLOCATE( zpic_mpi(klon_mpi))
+      ALLOCATE( zval_mpi(klon_mpi))
+      ALLOCATE( rugsrel_mpi(klon_mpi))
+      ALLOCATE( pctsrf_mpi(klon_mpi, nbsrf))
+      ALLOCATE( t_ancien_mpi(klon_mpi,klev))
+      ALLOCATE( q_ancien_mpi(klon_mpi,klev))
+      ALLOCATE( clwcon_mpi(klon_mpi,klev),rnebcon_mpi(klon_mpi,klev))
+      ALLOCATE( ratqs_mpi(klon_mpi,klev))
+      ALLOCATE( run_off_lic_0_mpi(klon_mpi))
+      ALLOCATE( masq_mpi(klon_mpi))
+c$OMP END MASTER
+c$OMP BARRIER      
+
+      call GatherField_omp( rlat_p,rlat_mpi,1)
+      call GatherField_omp( rlon_p,rlon_mpi,1)
+      call GatherField_omp( tsol_p,tsol_mpi,nbsrf)
+      call GatherField_omp( tsoil_p,tsoil_mpi,nsoilmx*nbsrf)
+      call GatherField_omp( tslab_p,tslab_mpi,1)
+      call GatherField_omp( seaice_p,seaice_mpi,1)
+      call GatherField_omp( qsurf_p,qsurf_mpi,nbsrf)
+      call GatherField_omp( qsol_p,qsol_mpi,1)
+      call GatherField_omp( snow_p,snow_mpi,nbsrf)
+      call GatherField_omp( albedo_p,albedo_mpi,nbsrf)
+      call GatherField_omp( alblw_p,alblw_mpi,nbsrf)
+      call GatherField_omp( evap_p,evap_mpi,nbsrf)
+      call GatherField_omp( radsol_p,radsol_mpi,1)
+      call GatherField_omp( rain_fall_p,rain_fall_mpi,1)
+      call GatherField_omp( snow_fall_p,snow_fall_mpi,1)
+      call GatherField_omp( sollw_p,sollw_mpi,1)
+      call GatherField_omp( solsw_p,solsw_mpi,1)
+      call GatherField_omp( fder_p,fder_mpi,1)
+      call GatherField_omp( frugs_p,frugs_mpi,nbsrf)
+      call GatherField_omp( agesno_p,agesno_mpi,nbsrf)
+      call GatherField_omp( zmea_p,zmea_mpi,1)
+      call GatherField_omp( zstd_p,zstd_mpi,1)
+      call GatherField_omp( zsig_p,zsig_mpi,1)
+      call GatherField_omp( zgam_p,zgam_mpi,1)
+      call GatherField_omp( zthe_p,zthe_mpi,1)
+      call GatherField_omp( zpic_p,zpic_mpi,1)
+      call GatherField_omp( zval_p,zval_mpi,1)
+      call GatherField_omp( rugsrel_p,rugsrel_mpi,1)
+      call GatherField_omp( pctsrf_p,pctsrf_mpi, nbsrf)
+      call GatherField_omp( run_off_lic_0_p,run_off_lic_0_mpi,1)
+      call GatherField_omp( t_ancien_p,t_ancien_mpi,klev)
+      call GatherField_omp( q_ancien_p,q_ancien_mpi,klev)
+      call GatherField_omp( rnebcon_p,rnebcon_mpi,klev)
+      call GatherField_omp( clwcon_p,clwcon_mpi,klev)
+      call GatherField_omp( ratqs_p,ratqs_mpi,klev)
+      call GatherField_omp( zmasq,masq_mpi,1)
+
+c$OMP MASTER      
+      call GatherField( rlat_mpi,rlat,1)
+      call GatherField( rlon_mpi,rlon,1)
+      call GatherField( tsol_mpi,tsol,nbsrf)
+      call GatherField( tsoil_mpi,tsoil,nsoilmx*nbsrf)
+      call GatherField( tslab_mpi,tslab,1)
+      call GatherField( seaice_mpi,seaice,1)
+      call GatherField( qsurf_mpi,qsurf,nbsrf)
+      call GatherField( qsol_mpi,qsol,1)
+      call GatherField( snow_mpi,snow,nbsrf)
+      call GatherField( albedo_mpi,albedo,nbsrf)
+      call GatherField( alblw_mpi,alblw,nbsrf)
+      call GatherField( evap_mpi,evap,nbsrf)
+      call GatherField( radsol_mpi,radsol,1)
+      call GatherField( rain_fall_mpi,rain_fall,1)
+      call GatherField( snow_fall_mpi,snow_fall,1)
+      call GatherField( sollw_mpi,sollw,1)
+      call GatherField( solsw_mpi,solsw,1)
+      call GatherField( fder_mpi,fder,1)
+      call GatherField( frugs_mpi,frugs,nbsrf)
+      call GatherField( agesno_mpi,agesno,nbsrf)
+      call GatherField( zmea_mpi,zmea,1)
+      call GatherField( zstd_mpi,zstd,1)
+      call GatherField( zsig_mpi,zsig,1)
+      call GatherField( zgam_mpi,zgam,1)
+      call GatherField( zthe_mpi,zthe,1)
+      call GatherField( zpic_mpi,zpic,1)
+      call GatherField( zval_mpi,zval,1)
+      call GatherField( rugsrel_mpi,rugsrel,1)
+      call GatherField( pctsrf_mpi,pctsrf, nbsrf)
+      call GatherField( run_off_lic_0_mpi,run_off_lic_0,1)
+      call GatherField( t_ancien_mpi,t_ancien,klev)
+      call GatherField( q_ancien_mpi,q_ancien,klev)
+      call GatherField( rnebcon_mpi,rnebcon,klev)
+      call GatherField( clwcon_mpi,clwcon,klev)
+      call GatherField( ratqs_mpi,ratqs,klev)
+      call GatherField( masq_mpi,masq,1)
+      
+      DEALLOCATE( rlat_mpi, rlon_mpi)
+      DEALLOCATE( tsol_mpi)
+      DEALLOCATE( tsoil_mpi)
+      DEALLOCATE( tslab_mpi)
+      DEALLOCATE( seaice_mpi)
+      DEALLOCATE( qsurf_mpi)
+      DEALLOCATE( qsol_mpi)
+      DEALLOCATE( snow_mpi)
+      DEALLOCATE( albedo_mpi)
+      DEALLOCATE( alblw_mpi)
+      DEALLOCATE( evap_mpi)
+      DEALLOCATE( rain_fall_mpi)
+      DEALLOCATE( snow_fall_mpi)
+      DEALLOCATE( solsw_mpi)
+      DEALLOCATE( sollw_mpi)
+      DEALLOCATE( fder_mpi)
+      DEALLOCATE( radsol_mpi)
+      DEALLOCATE( frugs_mpi)
+      DEALLOCATE( agesno_mpi)
+      DEALLOCATE( zmea_mpi)
+      DEALLOCATE( zstd_mpi)
+      DEALLOCATE( zsig_mpi)
+      DEALLOCATE( zgam_mpi)
+      DEALLOCATE( zthe_mpi)
+      DEALLOCATE( zpic_mpi)
+      DEALLOCATE( zval_mpi)
+      DEALLOCATE( rugsrel_mpi)
+      DEALLOCATE( pctsrf_mpi)
+      DEALLOCATE( t_ancien_mpi)
+      DEALLOCATE( q_ancien_mpi)
+      DEALLOCATE( clwcon_mpi,rnebcon_mpi)
+      DEALLOCATE( ratqs_mpi)
+      DEALLOCATE( run_off_lic_0_mpi)
+      DEALLOCATE( masq_mpi)
+
+      if (phy_rank==0) then
+      
       ierr = NF_CREATE(fichnom, NF_CLOBBER, nid)
       IF (ierr.NE.NF_NOERR) THEN
@@ -86,6 +302,6 @@
 c
       ierr = NF_DEF_DIM (nid, "index", length, idim1)
-      ierr = NF_DEF_DIM (nid, "points_physiques", klon, idim2)
-      ierr = NF_DEF_DIM (nid, "horizon_vertical", klon*klev, idim3)
+      ierr = NF_DEF_DIM (nid, "points_physiques", klon2, idim2)
+      ierr = NF_DEF_DIM (nid, "horizon_vertical", klon2*klev, idim3)
 c
       ierr = NF_ENDDEF(nid)
@@ -168,7 +384,7 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,zmasq)
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,zmasq)
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,masq)
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,masq)
 #endif      
 c BP ajout des fraction de chaque sous-surface
@@ -186,7 +402,7 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pctsrf(1 : klon, is_ter))
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,pctsrf(1 : klon, is_ter))
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pctsrf(1 : klon2, is_ter))
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,pctsrf(1 : klon2, is_ter))
 #endif
 C 
@@ -203,7 +419,7 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pctsrf(1 : klon,is_lic))
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,pctsrf(1 : klon, is_lic))
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pctsrf(1 : klon2,is_lic))
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,pctsrf(1 : klon2, is_lic))
 #endif
 C
@@ -220,7 +436,7 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pctsrf(1 : klon, is_oce))
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,pctsrf(1 : klon, is_oce))
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pctsrf(1 : klon2, is_oce))
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,pctsrf(1 : klon2, is_oce))
 #endif
 C
@@ -237,7 +453,7 @@
       ierr = NF_ENDDEF(nid)
 #ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pctsrf(1 : klon, is_sic))
-#else
-      ierr = NF_PUT_VAR_REAL (nid,nvarid,pctsrf(1 : klon, is_sic))
+      ierr = NF_PUT_VAR_DOUBLE (nid,nvarid,pctsrf(1 : klon2, is_sic))
+#else
+      ierr = NF_PUT_VAR_REAL (nid,nvarid,pctsrf(1 : klon2, is_sic))
 #endif
 C
@@ -547,4 +763,9 @@
 #endif
 c
+       endif
+c$OMP END MASTER
+cc ----> necessaire pour eviter bug openMP sur SX6
+c$OMP MASTER
+      if (phy_rank==0) then
       DO nsrf = 1, nbsrf
         IF (nsrf.LE.99) THEN
@@ -799,4 +1020,6 @@
       ierr = NF_CLOSE(nid)
 c
+      endif   ! phy_rank==0
+c$OMP END MASTER
       RETURN
       END
