Index: trunk/LMDZ.GENERIC/README
===================================================================
--- trunk/LMDZ.GENERIC/README	(revision 1516)
+++ trunk/LMDZ.GENERIC/README	(revision 1520)
@@ -1121,2 +1121,7 @@
 - Added tests to ensure that soil model settings are adequate to resolve
   sub-surface diurnal and annual thermal waves.
+
+== 24/03/2016 == EM
+- Some fixes/adjustments to run using OpenMP (in the physics, best practice is to always have "save" variables,
+  this of course includes all module variables, as "threadprivate").
+
Index: trunk/LMDZ.GENERIC/libf/phystd/callkeys_mod.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/callkeys_mod.F90	(revision 1516)
+++ trunk/LMDZ.GENERIC/libf/phystd/callkeys_mod.F90	(revision 1520)
@@ -2,82 +2,106 @@
 IMPLICIT NONE  
 
-      logical callrad,corrk,calldifv,UseTurbDiff                        &
-     &   , calladj,co2cond,callsoil                                     &
-     &   , season,diurnal,tlocked,rings_shadow,lwrite                   &
-     &   , callstats,calleofdump                                        &
-     &   , callgasvis,continuum,H2Ocont_simple,graybody                 &
-     &   , strictboundcorrk                                     
+      logical,save :: callrad,corrk,calldifv,UseTurbDiff
+!$OMP THREADPRIVATE(callrad,corrk,calldifv,UseTurbDiff)
+      logical,save :: calladj,co2cond,callsoil
+!$OMP THREADPRIVATE(calladj,co2cond,callsoil)
+      logical,save :: season,diurnal,tlocked,rings_shadow,lwrite
+!$OMP THREADPRIVATE(season,diurnal,tlocked,rings_shadow,lwrite)
+      logical,save :: callstats,calleofdump
+!$OMP THREADPRIVATE(callstats,calleofdump)
+      logical,save :: callgasvis,continuum,H2Ocont_simple,graybody
+!$OMP THREADPRIVATE(callgasvis,continuum,H2Ocont_simple,graybody)
+      logical,save :: strictboundcorrk                                     
+!$OMP THREADPRIVATE(strictboundcorrk)
 
-      logical enertest
-      logical nonideal
-      logical meanOLR
-      logical specOLR
-      logical kastprof
-      logical newtonian
-      logical check_cpp_match
-      logical force_cpp
-      logical testradtimes
-      logical rayleigh
-      logical stelbbody
-      logical ozone
-      logical nearco2cond
-      logical tracer
-      logical mass_redistrib
-      logical varactive
-      logical varfixed
-      logical radfixed
-      logical sedimentation
-      logical water,watercond,waterrain
-      logical aeroco2,aeroh2o,aeroh2so4,aeroback2lay
-      logical aerofixco2,aerofixh2o
-      logical hydrology
-      logical sourceevol
-      logical CLFvarying
-      logical nosurf
-      logical oblate
-      logical ok_slab_ocean
-      logical ok_slab_sic
-      logical ok_slab_heat_transp
-      logical albedo_spectral_mode
+      logical,save :: enertest
+      logical,save :: nonideal
+      logical,save :: meanOLR
+      logical,save :: specOLR
+      logical,save :: kastprof
+!$OMP THREADPRIVATE(enertest,nonideal,meanOLR,kastprof)
+      logical,save :: newtonian
+      logical,save :: check_cpp_match
+      logical,save :: force_cpp
+      logical,save :: testradtimes
+      logical,save :: rayleigh
+!$OMP THREADPRIVATE(newtonian,check_cpp_match,force_cpp,testradtimes,rayleigh)
+      logical,save :: stelbbody
+      logical,save :: ozone
+      logical,save :: nearco2cond
+      logical,save :: tracer
+      logical,save :: mass_redistrib
+!$OMP THREADPRIVATE(stelbbody,ozone,nearco2cond,tracer,mass_redistrib)
+      logical,save :: varactive
+      logical,save :: varfixed
+      logical,save :: radfixed
+      logical,save :: sedimentation
+!$OMP THREADPRIVATE(varactive,varfixed,radfixed,sedimentation)
+      logical,save :: water,watercond,waterrain
+!$OMP THREADPRIVATE(water,watercond,waterrain)
+      logical,save :: aeroco2,aeroh2o,aeroh2so4,aeroback2lay
+!$OMP THREADPRIVATE(aeroco2,aeroh2o,aeroh2so4,aeroback2lay)
+      logical,save :: aerofixco2,aerofixh2o
+!$OMP THREADPRIVATE(aerofixco2,aerofixh2o)
+      logical,save :: hydrology
+      logical,save :: sourceevol
+      logical,save :: CLFvarying
+      logical,save :: nosurf
+      logical,save :: oblate
+!$OMP THREADPRIVATE(hydrology,sourceevol,CLFvarying,nosurf,oblate)
+      logical,save :: ok_slab_ocean
+      logical,save :: ok_slab_sic
+      logical,save :: ok_slab_heat_transp
+      logical,save :: albedo_spectral_mode
+!$OMP THREADPRIVATE(ok_slab_ocean,ok_slab_sic,ok_slab_heat_transp,albedo_spectral_mode)
 
-      integer iddist
-      integer iaervar
-      integer iradia
-      integer startype
+      integer,save :: iddist
+      integer,save :: iaervar
+      integer,save :: iradia
+      integer,save :: startype
+!$OMP THREADPRIVATE(iddist,iaervar,iradia,startype)
 
-      real topdustref
-      real Nmix_co2
-      real dusttau
-      real Fat1AU
-      real stelTbb
-      real Tstrat
-      real tplanet
-      real obs_tau_col_tropo
-      real obs_tau_col_strato
-      real pres_bottom_tropo
-      real pres_top_tropo
-      real pres_bottom_strato
-      real pres_top_strato
-      real size_tropo
-      real size_strato
-      real satval
-      real CLFfixval
-      real n2mixratio
-      real co2supsat
-      real pceil
-      real albedosnow
-      real albedoco2ice
-      real maxicethick
-      real Tsaldiff
-      real tau_relax
-      real cloudlvl
-      real icetstep
-      real intheat
-      real flatten
-      real Rmean
-      real J2
-      real MassPlanet
-      
-      logical :: iscallphys=.false.!existence of callphys.def
+      real,save :: topdustref
+      real,save :: Nmix_co2
+      real,save :: dusttau
+      real,save :: Fat1AU
+      real,save :: stelTbb
+!$OMP THREADPRIVATE(topdustref,Nmix_co2,dusttau,Fat1AU,stelTbb)
+      real,save :: Tstrat
+      real,save :: tplanet
+      real,save :: obs_tau_col_tropo
+      real,save :: obs_tau_col_strato
+!$OMP THREADPRIVATE(Tstrat,tplanet,obs_tau_col_tropo,obs_tau_col_strato)
+      real,save :: pres_bottom_tropo
+      real,save :: pres_top_tropo
+      real,save :: pres_bottom_strato
+      real,save :: pres_top_strato
+!$OMP THREADPRIVATE(pres_bottom_tropo,pres_top_tropo,pres_bottom_strato,pres_top_strato)
+      real,save :: size_tropo
+      real,save :: size_strato
+      real,save :: satval
+      real,save :: CLFfixval
+      real,save :: n2mixratio
+!$OMP THREADPRIVATE(size_tropo,size_strato,satval,CLFfixval,n2mixratio)
+      real,save :: co2supsat
+      real,save :: pceil
+      real,save :: albedosnow
+      real,save :: albedoco2ice
+      real,save :: maxicethick
+!$OMP THREADPRIVATE(co2supsat,pceil,albedosnow,albedoco2ice,maxicethick)
+      real,save :: Tsaldiff
+      real,save :: tau_relax
+      real,save :: cloudlvl
+      real,save :: icetstep
+      real,save :: intheat
+!$OMP THREADPRIVATE(Tsaldiff,tau_relax,cloudlvl,icetstep,intheat)
+      real,save :: flatten
+      real,save :: Rmean
+      real,save :: J2
+      real,save :: MassPlanet
+!$OMP THREADPRIVATE(flatten,Rmean,J2,MassPlanet)
+
+      logical,save :: iscallphys=.false.!existence of callphys.def
+!$OMP THREADPRIVATE(iscallphys)
 
 END MODULE callkeys_mod
Index: trunk/LMDZ.GENERIC/libf/phystd/comcstfi_mod.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comcstfi_mod.F90	(revision 1516)
+++ trunk/LMDZ.GENERIC/libf/phystd/comcstfi_mod.F90	(revision 1520)
@@ -2,15 +2,16 @@
 IMPLICIT NONE
       
-      REAL :: pi ! something like 3.14159
-      REAL :: rad ! radius of the planet (m)
-      REAL :: g ! gravity (m/s2)
-      REAL :: r ! reduced gas constant (r=8.314511/(mugaz/1000.0))
-      REAL :: cpp ! Cp of the atmosphere
-      REAL :: rcp ! r/cpp
-      REAL :: dtphys ! physics time step (s)
-      REAL :: daysec ! length of day (s)
-      REAL :: mugaz ! molar mass of the atmosphere (g/mol)
-      REAL :: omeg ! planet rotation rate (rad/s)
-      REAL :: avocado ! something like 6.022e23
+      REAL,SAVE :: pi ! something like 3.14159
+      REAL,SAVE :: rad ! radius of the planet (m)
+      REAL,SAVE :: g ! gravity (m/s2)
+      REAL,SAVE :: r ! reduced gas constant (r=8.314511/(mugaz/1000.0))
+      REAL,SAVE :: cpp ! Cp of the atmosphere
+      REAL,SAVE :: rcp ! r/cpp
+      REAL,SAVE :: dtphys ! physics time step (s)
+      REAL,SAVE :: daysec ! length of day (s)
+      REAL,SAVE :: mugaz ! molar mass of the atmosphere (g/mol)
+      REAL,SAVE :: omeg ! planet rotation rate (rad/s)
+      REAL,SAVE :: avocado ! something like 6.022e23
+!$OMP THREADPRIVATE(pi,rad,g,r,cpp,rcp,dtphys,daysec,mugaz,omeg,avocado)
 
 END MODULE comcstfi_mod
Index: trunk/LMDZ.GENERIC/libf/phystd/comdiurn_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comdiurn_h.F90	(revision 1516)
+++ trunk/LMDZ.GENERIC/libf/phystd/comdiurn_h.F90	(revision 1520)
@@ -4,7 +4,6 @@
        implicit none
 
-       real, allocatable, dimension(:) :: sinlon, coslon, sinlat, coslat
-       logical :: ldiurn
-!$OMP THREADPRIVATE(sinlon,coslon,sinlat,coslat,ldiurn) !ldiurn is unused
+       real,allocatable,dimension(:),save :: sinlon, coslon, sinlat, coslat
+!$OMP THREADPRIVATE(sinlon,coslon,sinlat,coslat)
 
        end module comdiurn_h
Index: trunk/LMDZ.GENERIC/libf/phystd/comgeomfi_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/comgeomfi_h.F90	(revision 1516)
+++ trunk/LMDZ.GENERIC/libf/phystd/comgeomfi_h.F90	(revision 1520)
@@ -4,7 +4,7 @@
        implicit none
 
-       REAL,ALLOCATABLE,DIMENSION(:) :: long,lati,area
-       REAL :: totarea, totarea_planet
-!$OMP THREADPRIVATE(long,lati,area,totarea)
+       REAL,ALLOCATABLE,DIMENSION(:),SAVE :: long,lati,area
+       REAL,SAVE :: totarea, totarea_planet
+!$OMP THREADPRIVATE(long,lati,area,totarea,totarea_planet)
 
        end module comgeomfi_h
Index: trunk/LMDZ.GENERIC/libf/phystd/datafile_mod.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/datafile_mod.F90	(revision 1516)
+++ trunk/LMDZ.GENERIC/libf/phystd/datafile_mod.F90	(revision 1520)
@@ -10,5 +10,6 @@
 !      character(len=300) :: datadir='/san/home/rdword/gcm/datagcm'
       ! Default for LMD machines:
-      character(len=300) :: datadir='/u/lmdz/WWW/planets/LMDZ.GENERIC/datagcm'
+      character(len=300),save :: datadir='/u/lmdz/WWW/planets/LMDZ.GENERIC/datagcm'
+!$OMP THREADPRIVATE(datadir)
       
       ! Subdirectories of 'datadir':
Index: trunk/LMDZ.GENERIC/libf/phystd/inifis.F
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/inifis.F	(revision 1516)
+++ trunk/LMDZ.GENERIC/libf/phystd/inifis.F	(revision 1520)
@@ -52,7 +52,5 @@
 !   -------------
       use datafile_mod, only: datadir
-! to use  'getin'
-!      USE ioipsl_getincom 
-      USE ioipsl_getincom_p
+      USE ioipsl_getincom_p, only: getin_p
       IMPLICIT NONE
 
@@ -78,5 +76,4 @@
       real psurf,pN2 ! added by RW for Gliese 581d N2+CO2
 
-!$OMP MASTER
       rad=prad
       daysec=pdaysec
@@ -89,6 +86,4 @@
       avocado = 6.02214179e23   ! added by RW
 
-!$OMP END MASTER
-!$OMP BARRIER
 
       ! read in 'ecritphy' (frequency of calls to physics, in dynamical steps)
@@ -100,5 +95,4 @@
 ! --------------------------------------------------------------
      
-!$OMP MASTER     
       ! check that 'callphys.def' file is around
       OPEN(99,file='callphys.def',status='old',form='formatted'
@@ -106,6 +100,4 @@
       CLOSE(99)
       IF(ierr.EQ.0) iscallphys=.true. !iscallphys initialised as false in callkeys_mod module
-!$OMP END MASTER
-!$OMP BARRIER
       
 !!!      IF(ierr.EQ.0) THEN
@@ -721,8 +713,5 @@
       ENDDO
 
-!$OMP MASTER
       pi=2.*asin(1.) ! NB: pi is a common in comcstfi_mod
-!$OMP END MASTER
-!$OMP BARRIER
 
       ! allocate "comsoil_h" arrays
Index: trunk/LMDZ.GENERIC/libf/phystd/planete_mod.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/planete_mod.F90	(revision 1516)
+++ trunk/LMDZ.GENERIC/libf/phystd/planete_mod.F90	(revision 1520)
@@ -2,23 +2,27 @@
   IMPLICIT NONE
   
-  REAL :: apoastr ! maximum star-planet distance (AU)
-  REAL :: periastr ! minimum star-planet distance (AU)
-  REAL :: year_day ! length of year (sols)
-  REAL :: peri_day ! date of periastron (sols since N. spring)
-  REAL :: obliquit ! Obliquity of the planet (deg)
-  REAL :: nres ! tidal resonance ratio
-  REAL :: z0 ! surface roughness (m)
-  REAL :: lmixmin ! mixing length
-  REAL :: emin_turb ! minimal energy
-  REAL :: coefvis
-  REAL :: coefir
-  REAL :: timeperi
-  REAL :: e_elips
-  REAL :: p_elips
+  REAL,SAVE :: apoastr ! maximum star-planet distance (AU)
+  REAL,SAVE :: periastr ! minimum star-planet distance (AU)
+  REAL,SAVE :: year_day ! length of year (sols)
+  REAL,SAVE :: peri_day ! date of periastron (sols since N. spring)
+  REAL,SAVE :: obliquit ! Obliquity of the planet (deg)
+!$OMP THREADPRIVATE(apoastr,periastr,year_day,peri_day,obliquit)
+  REAL,SAVE :: nres ! tidal resonance ratio
+  REAL,SAVE :: z0 ! surface roughness (m)
+  REAL,SAVE :: lmixmin ! mixing length
+  REAL,SAVE :: emin_turb ! minimal energy
+!$OMP THREADPRIVATE(nres,z0,lmixmin,emin_turb)
+  REAL,SAVE :: coefvis
+  REAL,SAVE :: coefir
+  REAL,SAVE :: timeperi
+  REAL,SAVE :: e_elips
+  REAL,SAVE :: p_elips
+!$OMP THREADPRIVATE(coefvis,coefir,timeperi,e_elips,p_elips)
   
-  REAL :: preff ! reference surface pressure (Pa)	!read by master
-  REAL,ALLOCATABLE :: ap(:) ! hybrid coordinate at layer interface	!read by master
-  REAL,ALLOCATABLE :: bp(:) ! hybrid coordinate at layer interface 	!read by master
-  
+  REAL,SAVE :: preff ! reference surface pressure (Pa)	!read by master
+  REAL,SAVE,ALLOCATABLE :: ap(:) ! hybrid coordinate at layer interface	!read by master
+  REAL,SAVE,ALLOCATABLE :: bp(:) ! hybrid coordinate at layer interface 	!read by master
+!$OMP THREADPRIVATE(preff,ap,bp)
+
   CONTAINS
   
@@ -31,5 +35,4 @@
   real,intent(in) :: bp_dyn(nlayer+1) ! hybrid coordinate at interfaces
   
-!$OMP MASTER
   allocate(ap(nlayer+1))
   allocate(bp(nlayer+1))
@@ -38,6 +41,4 @@
   ap(:)=ap_dyn(:)
   bp(:)=bp_dyn(:)
-!$OMP END MASTER
-!$OMP BARRIER
   
   end subroutine ini_planete_mod
Index: trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90
===================================================================
--- trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90	(revision 1516)
+++ trunk/LMDZ.GENERIC/libf/phystd/radinc_h.F90	(revision 1520)
@@ -90,10 +90,8 @@
       integer, parameter :: nsizemax = 60
 
-      character (len=100) :: corrkdir
-      save corrkdir
+      character(len=100),save :: corrkdir
 !$OMP THREADPRIVATE(corrkdir)
 
-      character (len=100) :: banddir
-      save banddir
+      character(len=100),save :: banddir
 !$OMP THREADPRIVATE(banddir)
 
