Index: LMDZ4/trunk/libf/cosp/cosp.F90
===================================================================
--- LMDZ4/trunk/libf/cosp/cosp.F90	(revision 1279)
+++ LMDZ4/trunk/libf/cosp/cosp.F90	(revision 1327)
@@ -26,4 +26,6 @@
   USE MOD_COSP_TYPES
   USE MOD_COSP_SIMULATOR
+  USE mod_phys_lmdz_para
+  USE mod_grid_phy_lmdz
   IMPLICIT NONE
 
@@ -61,9 +63,11 @@
   real :: minv,maxv
   real :: maxp,minp
-  integer,dimension(:),allocatable :: & ! Dimensions nPoints
+  integer,dimension(:),save,  allocatable :: & ! Dimensions nPoints
                   seed    !  It is recommended that the seed is set to a different value for each model
                           !  gridbox it is called on, as it is possible that the choice of the same 
                           !  seed value every time may introduce some statistical bias in the results, 
                           !  particularly for low values of NCOL.
+!$OMP THREADPRIVATE(seed)
+  real,dimension(:),allocatable :: rseed    !  It is recommended that the seed is set to a different value for each model
   ! Types used in one iteration
   type(cosp_gridbox) :: gbx_it
@@ -76,4 +80,7 @@
   type(cosp_radarstats) :: stradar_it
   type(cosp_lidarstats) :: stlidar_it
+  
+  logical,save :: first_cosp=.TRUE.
+!$OMP THREADPRIVATE(first_cosp)
   
   !++++++++++ Dimensions ++++++++++++
@@ -162,15 +169,27 @@
   endif
 
-   
+  if (first_cosp) then   
    ! We base the seed in the decimal part of the surface pressure.
-   allocate(seed(Npoints))
-   seed = int(gbx%psfc) ! This is to avoid division by zero when Npoints = 1   
+     allocate(seed(Npoints))
+
+     allocate(rseed(klon_glo))
+     CALL gather(gbx%psfc,rseed)
+     call bcast(rseed)
+!   seed = int(gbx%psfc) ! This is to avoid division by zero when Npoints = 1   
       ! Roj Oct/2008 ... Note: seed value of 0 caused me some problems + I want to 
       ! randomize for each call to COSP even when Npoints ==1
-   minp = minval(gbx%psfc)
-   maxp = maxval(gbx%psfc)
-   if (Npoints .gt. 1) seed=int((gbx%psfc-minp)/(maxp-minp)*100000) + 1
-
-  
+     minp = minval(rseed)
+     maxp = maxval(rseed)
+   
+     if (Npoints .gt. 1) THEN
+       seed=int((gbx%psfc-minp)/(maxp-minp)*100000) + 1
+     else
+       seed=int(gbx%psfc-minp)
+     endif
+
+     deallocate(rseed)
+     first_cosp=.false.
+   endif
+    
    if (gbx%Npoints_it >= gbx%Npoints) then ! One iteration gbx%Npoints
         call cosp_iter(overlap,seed,cfg,vgrid,gbx,sgx,sgradar,sglidar,isccp,misr,stradar,stlidar)
@@ -273,5 +292,4 @@
         call free_cosp_lidarstats(stlidar_it)
    endif
-   deallocate(seed)
 
     
@@ -305,5 +323,6 @@
   integer :: i,j,k
   real,dimension(:,:),pointer :: column_frac_out ! Array with one column of frac_out
-  integer :: scops_debug=0    !  set to non-zero value to print out inputs for debugging in SCOPS
+  integer,parameter :: scops_debug=0    !  set to non-zero value to print out inputs for debugging in SCOPS
+  
   real,dimension(:, :),allocatable :: cca_scops,ls_p_rate,cv_p_rate, &
                      tca_scops ! Cloud cover in each model level (HORIZONTAL gridbox fraction) of total cloud.
Index: LMDZ4/trunk/libf/cosp/ini_histdayCOSP.h
===================================================================
--- LMDZ4/trunk/libf/cosp/ini_histdayCOSP.h	(revision 1279)
+++ LMDZ4/trunk/libf/cosp/ini_histdayCOSP.h	(revision 1327)
@@ -5,4 +5,5 @@
 ! sorties par jour
 !
+!$OMP MASTER
         zstoday = ecrit_day
         zout = freq_COSP
@@ -191,2 +192,4 @@
 
         CALL histend(nid_day_cosp)
+!$OMP END MASTER
+!$OMP BARRIER
Index: LMDZ4/trunk/libf/cosp/ini_histhfCOSP.h
===================================================================
--- LMDZ4/trunk/libf/cosp/ini_histhfCOSP.h	(revision 1279)
+++ LMDZ4/trunk/libf/cosp/ini_histhfCOSP.h	(revision 1327)
@@ -5,4 +5,5 @@
 ! sorties par jour
 !
+!$OMP MASTER
         zstohf = ecrit_hf
         zout = freq_COSP
@@ -191,2 +192,4 @@
 
         CALL histend(nid_hf_cosp)
+!$OMP END MASTER
+!$OMP BARRIER
Index: LMDZ4/trunk/libf/cosp/ini_histmthCOSP.h
===================================================================
--- LMDZ4/trunk/libf/cosp/ini_histmthCOSP.h	(revision 1279)
+++ LMDZ4/trunk/libf/cosp/ini_histmthCOSP.h	(revision 1327)
@@ -5,4 +5,5 @@
 ! sorties par jour
 !
+!$OMP MASTER
         zstomth = ecrit_mth
         zout = freq_COSP
@@ -189,2 +190,4 @@
 
         CALL histend(nid_mth_cosp)
+!$OMP END MASTER
+!$OMP BARRIER
Index: LMDZ4/trunk/libf/cosp/phys_cosp.F90
===================================================================
--- LMDZ4/trunk/libf/cosp/phys_cosp.F90	(revision 1279)
+++ LMDZ4/trunk/libf/cosp/phys_cosp.F90	(revision 1327)
@@ -70,4 +70,5 @@
   USE MOD_COSP
   USE mod_phys_lmdz_para
+  USE mod_grid_phy_lmdz
   use ioipsl
   use iophy
@@ -76,6 +77,6 @@
 
   ! Local variables
-  character(len=64)  :: cosp_input_nl='cosp_input_nl.txt'
-  character(len=64)  :: cosp_output_nl='cosp_output_nl.txt'
+  character(len=64),PARAMETER  :: cosp_input_nl='cosp_input_nl.txt'
+  character(len=64),PARAMETER  :: cosp_output_nl='cosp_output_nl.txt'
   character(len=512), save :: finput ! Input file name
   character(len=512), save :: cmor_nl
@@ -84,4 +85,5 @@
   integer,parameter :: Ncollmdz=20
   integer, save :: Npoints      ! Number of gridpoints
+!$OMP THREADPRIVATE(Npoints)
   integer, save :: Nlevels      ! Number of levels
   Integer :: Nptslmdz,Nlevlmdz ! Nb de points issus de physiq.F
@@ -90,4 +92,5 @@
   integer :: i
   type(cosp_config),save :: cfg   ! Configuration options
+!$OMP THREADPRIVATE(cfg)
   type(cosp_gridbox) :: gbx ! Gridbox information. Input for COSP
   type(cosp_subgrid) :: sgx     ! Subgrid outputs
@@ -103,4 +106,5 @@
   integer :: Nlon,Nlat,geomode
   real,save :: radar_freq,k2,ZenAng,co2,ch4,n2o,co,emsfc_lw
+!$OMP THREADPRIVATE(emsfc_lw)
   integer,dimension(RTTOV_MAX_CHANNELS),save :: Channels
   real,dimension(RTTOV_MAX_CHANNELS),save :: Surfem
@@ -115,10 +119,13 @@
   integer :: nhori,nvert,nvertp,nvertisccp,nvertm,nvertcol
   integer, save :: nid_day_cosp,nid_mth_cosp,nid_hf_cosp
+!$OMP THREADPRIVATE(nid_day_cosp,nid_mth_cosp,nid_hf_cosp)
   logical, save :: debut_cosp=.true.
+!$OMP THREADPRIVATE(debut_cosp)
   integer :: itau_wcosp
-  character(len=10),dimension(Ncollmdz) :: chcol=(/'c01','c02','c03','c04','c05','c06','c07','c08','c09','c10', &
+  character(len=10),dimension(Ncollmdz),parameter :: chcol=(/'c01','c02','c03','c04','c05','c06','c07','c08','c09','c10', &
                                                    'c11','c12','c13','c14','c15','c16','c17','c18','c19','c20'/)
   real,dimension(Ncollmdz) :: column_ax
   integer, save :: Nlevout
+!$OMP THREADPRIVATE(Nlevout)
 
   include "dimensions.h"
@@ -139,5 +146,5 @@
 !
    namelist/COSP_INPUT/cmor_nl,overlap,isccp_topheight,isccp_topheight_direction, &
-              npoints,npoints_it,ncolumns,nlevels,use_vgrid,nlr,csat_vgrid,finput, &
+              npoints_it,ncolumns,nlevels,use_vgrid,nlr,csat_vgrid,finput, &
               radar_freq,surface_radar,use_mie_tables, &
               use_gas_abs,do_ray,melt_lay,k2,Nprmts_max_hydro,Naero,Nprmts_max_aero, &
@@ -154,12 +161,12 @@
 
  if (debut_cosp) then
+  NPoints=Nptslmdz
 ! Lecture du namelist input 
-  open(10,file=cosp_input_nl,status='old')
-  read(10,nml=cosp_input)
-  close(10)
+  CALL read_cosp_input
+
 ! Clefs Outputs 
   call read_cosp_output_nl(cosp_output_nl,cfg)
 
-    if ( (Ncollmdz.ne.Ncolumns).or.(Nptslmdz.ne.Npoints).or.(Nlevlmdz.ne.Nlevels) ) then
+    if ( (Ncollmdz.ne.Ncolumns).or. (Nlevlmdz.ne.Nlevels) ) then
        print*,'Nb points Horiz, Vert, Sub-col passes par physiq.F = ', &
                Nptslmdz, Nlevlmdz, Ncollmdz
@@ -169,5 +176,5 @@
        call abort
     endif
-
+    
     if (overlaplmdz.ne.overlap) then
        print*,'Attention overlaplmdz different de overlap lu dans namelist '
@@ -194,5 +201,5 @@
         print *, 'Allocating memory for gridbox type...'
 
-        call construct_cosp_gridbox(float(itap),radar_freq,surface_radar,use_mie_tables,use_gas_abs,do_ray,melt_lay,k2, &
+        call construct_cosp_gridbox(dble(itap),radar_freq,surface_radar,use_mie_tables,use_gas_abs,do_ray,melt_lay,k2, &
                                     Npoints,Nlevels,Ncolumns,N_HYDRO,Nprmts_max_hydro,Naero,Nprmts_max_aero,Npoints_it, &
                                     lidar_ice_type,isccp_topheight,isccp_topheight_direction,overlap,emsfc_lw, &
@@ -316,5 +323,5 @@
    
         do ii=1,Ncolumns
-          column_ax(ii) = float(ii)
+          column_ax(ii) = real(ii)
         enddo
 
@@ -462,4 +469,51 @@
 !  call system_clock(t1,count_rate,count_max)
 !  print *,(t1-t0)*1.0/count_rate
+ 
+  CONTAINS 
+  
+  SUBROUTINE read_cosp_input
     
+    IF (is_master) THEN
+      OPEN(10,file=cosp_input_nl,status='old')
+      READ(10,nml=cosp_input)
+      CLOSE(10)
+    ENDIF
+    CALL bcast(cmor_nl)
+    CALL bcast(overlap)
+    CALL bcast(isccp_topheight)
+    CALL bcast(isccp_topheight_direction)
+    CALL bcast(npoints_it)
+    CALL bcast(ncolumns)
+    CALL bcast(nlevels)
+    CALL bcast(use_vgrid)
+    CALL bcast(nlr)
+    CALL bcast(csat_vgrid)
+    CALL bcast(finput)
+    CALL bcast(radar_freq)
+    CALL bcast(surface_radar)
+    CALL bcast(use_mie_tables)
+    CALL bcast(use_gas_abs)
+    CALL bcast(do_ray)
+    CALL bcast(melt_lay)
+    CALL bcast(k2)
+    CALL bcast(Nprmts_max_hydro)
+    CALL bcast(Naero)
+    CALL bcast(Nprmts_max_aero)
+    CALL bcast(lidar_ice_type)
+    CALL bcast(use_precipitation_fluxes)
+    CALL bcast(use_reff)
+    CALL bcast(platform)
+    CALL bcast(satellite)
+    CALL bcast(Instrument)
+    CALL bcast(Nchannels)
+    CALL bcast(Channels)
+    CALL bcast(Surfem)
+    CALL bcast(ZenAng)
+    CALL bcast(co2)
+    CALL bcast(ch4)
+    CALL bcast(n2o)
+    CALL bcast(co)
+!$OMP BARRIER  
+  END SUBROUTINE read_cosp_input 
+
 end subroutine phys_cosp
Index: LMDZ4/trunk/libf/cosp/radar_simulator_types.F90
===================================================================
--- LMDZ4/trunk/libf/cosp/radar_simulator_types.F90	(revision 1279)
+++ LMDZ4/trunk/libf/cosp/radar_simulator_types.F90	(revision 1327)
@@ -42,12 +42,14 @@
   end type mie
 
-  real*8, dimension(:), allocatable :: &
+  real*8, dimension(:), save, allocatable :: &
     mt_ttl, &			! liquid temperatures (C)
     mt_tti, &			! ice temperatures (C)
     mt_qext, mt_qbsca		! extincion/backscatter efficiency
+!$OMP THREADPRIVATE(mt_ttl,mt_tti,mt_qext, mt_qbsca)
 
-  integer*4 :: &
+  integer*4,save :: &
     cnt_liq, &			! liquid temperature count
     cnt_ice			! ice temperature count
+!$OMP THREADPRIVATE(cnt_liq,cnt_ice)
 
   end module radar_simulator_types
Index: LMDZ4/trunk/libf/cosp/read_cosp_output_nl.F90
===================================================================
--- LMDZ4/trunk/libf/cosp/read_cosp_output_nl.F90	(revision 1279)
+++ LMDZ4/trunk/libf/cosp/read_cosp_output_nl.F90	(revision 1327)
@@ -5,4 +5,5 @@
   USE MOD_COSP_CONSTANTS
   USE MOD_COSP_TYPES
+  USE mod_phys_lmdz_para
   character(len=*),intent(in) :: cosp_nl
   type(cosp_config),intent(out) :: cfg
@@ -16,4 +17,5 @@
              Llongitude,Llatitude,Lparasol_refl,LclMISR,Lmeantbisccp,Lmeantbclrisccp, &
              Lfrac_out,Lbeta_mol532,Ltbrttov
+
   namelist/COSP_OUTPUT/Lradar_sim,Llidar_sim,Lisccp_sim,Lmisr_sim,Lrttov_sim, &
              Lalbisccp,Latb532,Lboxptopisccp,Lboxtauisccp,Lcfad_dbze94, &
@@ -26,7 +28,44 @@
     cfg%out_list(i)=''
   enddo
-  open(10,file=cosp_nl,status='old')
-  read(10,nml=cosp_output)
-  close(10)
+  
+  IF (is_master) THEN
+    open(10,file=cosp_nl,status='old')
+    read(10,nml=cosp_output)
+    close(10)
+  ENDIF
+  
+  CALL bcast(Lradar_sim)
+  CALL bcast(Llidar_sim)
+  CALL bcast(Lisccp_sim)
+  CALL bcast(Lmisr_sim)
+  CALL bcast(Lrttov_sim)
+  CALL bcast(Lalbisccp)
+  CALL bcast(Latb532)
+  CALL bcast(Lboxptopisccp)
+  CALL bcast(Lboxtauisccp)
+  CALL bcast(Lcfad_dbze94)
+  CALL bcast(Lcfad_lidarsr532)
+  CALL bcast(Lclcalipso2)
+  CALL bcast(Lclcalipso)
+  CALL bcast(Lclhcalipso)
+  CALL bcast(Lclisccp2)
+  CALL bcast(Lcllcalipso)
+  CALL bcast(Lclmcalipso)
+  CALL bcast(Lcltcalipso)
+  CALL bcast(Lcltlidarradar)
+  CALL bcast(Lctpisccp)
+  CALL bcast(Ldbze94)
+  CALL bcast(Ltauisccp)
+  CALL bcast(Ltclisccp)
+  CALL bcast(Llongitude)
+  CALL bcast(Llatitude)
+  CALL bcast(Lparasol_refl)
+  CALL bcast(LclMISR)
+  CALL bcast(Lmeantbisccp)
+  CALL bcast(Lmeantbclrisccp)
+  CALL bcast(Lfrac_out)
+  CALL bcast(Lbeta_mol532)
+  CALL bcast(Ltbrttov)
+!$OMP BARRIER
 
 !  print*,' Cles sorties cosp :'
Index: LMDZ4/trunk/libf/cosp/scops.F
===================================================================
--- LMDZ4/trunk/libf/cosp/scops.F	(revision 1279)
+++ LMDZ4/trunk/libf/cosp/scops.F	(revision 1327)
@@ -39,4 +39,7 @@
 ! *****************************COPYRIGHT*******************************
 
+      USE mod_phys_lmdz_para
+      USE mod_grid_phy_lmdz
+
       implicit none
 
@@ -175,5 +178,6 @@
           ELSE
               DO ibox=1,ncol
-                include 'congvec.h'
+!                include 'congvec_para.h'
+                 include 'congvec.h'
                 ! select random pixels from the non-convective
                 ! part the gridbox ( some will be converted into
