Index: /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh	(revision 1295)
+++ /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh	(revision 1296)
@@ -145,8 +145,4 @@
 #- set PackDefault to true on ada
 PackDefault=true
-
-#====================================================
-#- Number of core per node (max number of OpenMP task)
-NUM_COREPERNODE=8
 
 #====================================================
@@ -1255,5 +1251,17 @@
 #D-
 function IGCM_sys_ListJobInQueue {
-  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
+  IGCM_debug   cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
+    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
+    IGCM_debug_PopStack "IGCM_sys_atlas"
+    return 1
+  else
+    IGCM_debug_PopStack "IGCM_sys_atlas"
+    return 0
+  fi
+
+  IGCM_debug_PopStack "IGCM_sys_atlas"
+}
+
+_PushStack "IGCM_sys_ListJobInQueue"
   if ( $DEBUG_sys ) ; then
     echo "IGCM_sys_ListJobInQueue"
@@ -1290,14 +1298,3 @@
   if [ ${status} -gt 0 ] ; then
     echo "IGCM_sys_atlas : error code ${status}"
-    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
-    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
-    IGCM_debug_PopStack "IGCM_sys_atlas"
-    return 1
-  else
-    IGCM_debug_PopStack "IGCM_sys_atlas"
-    return 0
-  fi
-
-  IGCM_debug_PopStack "IGCM_sys_atlas"
-}
-
+ 
Index: /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ciclad.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ciclad.ksh	(revision 1295)
+++ /trunk/libIGCM/libIGCM_sys/libIGCM_sys_ciclad.ksh	(revision 1296)
@@ -62,5 +62,5 @@
 
 #=====================================================
-# Host and user names
+# Host user names project maxCpuTime
 # $hostname ou hostname
 typeset HOST=${HOST:=$( hostname )}
@@ -156,12 +156,8 @@
 
 #====================================================
-#- Number of core per node (max number of OpenMP task)
-NUM_COREPERNODE=4
-
-#====================================================
 #- Default number of MPI task for IPSL coupled model
 #- required for backward compatibility
 #-
-DEFAULT_NUM_PROC_OCE=1
+DEFAULT_NUM_PROC_OCE=5
 DEFAULT_NUM_PROC_CPL=1
 (( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
@@ -350,5 +346,5 @@
   fi
 
-  \tree -f $@
+  \ls -lR ${@}
 
   IGCM_debug_PopStack "IGCM_sys_Tree"
@@ -728,5 +724,5 @@
 #D-#==================================================
 #D-function IGCM_sys_sync
-#D-* Purpose: flush buffer on disk (dummy function on Ada)
+#D-* Purpose: flush buffer on disk (dummy function on Ciclad)
 #D-* Examples:
 #D-
@@ -859,7 +855,5 @@
 #D-
 function IGCM_sys_build_run_file {
-
   IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
-
 }
 
@@ -879,24 +873,66 @@
   fi
 
-  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
-  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
-  typeset num_corempi nombre_restant_node nombre_restant_comp
-
+  EXECUTION=${HOST_MPIRUN_COMMAND}
+
+  # MPMD mode
   if ( ${OK_PARA_MPMD} ) ; then
 
-    if [ -f run_file ] ; then
-      IGCM_sys_Rm -f run_file
-    fi
-    touch run_file
-
-    if ( ${OK_PARA_OMP} ) ; then
+    # Only MPI (MPMD)
+    if  ( ! ${OK_PARA_OMP} ) ; then
+
+      if [ -f run_file ] ; then
+        IGCM_sys_Rm -f run_file
+      fi
+      touch run_file
+
+      # Build run_file
+
+      # First loop on the components for the coupler ie oasis (only if oasis3)
+      # the coupler ie oasis3 must be the first one
+      for comp in ${config_ListOfComponents[*]} ; do
+
+        eval ExeNameIn=\${config_Executable_${comp}[0]}
+        eval ExeNameOut=\${config_Executable_${comp}[1]}
+
+        # for CPL component only
+        if [ "X${comp}" = "XCPL" ]  && [ "X${ExeNameOut}" != X\"\" ] ; then
+          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
+          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
+          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
+        fi
+      done
+
+      # Then second loop on the components
+      for comp in ${config_ListOfComponents[*]} ; do
+
+        eval ExeNameIn=\${config_Executable_${comp}[0]}
+        eval ExeNameOut=\${config_Executable_${comp}[1]}
+
+        # Only if we really have an executable for the component and not the coupler ie oasis:
+        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
+
+          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
+          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
+          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
+        fi
+      done
+
+      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
+
+      IGCM_sys_Chmod u+x run_file
+      if ( $DEBUG_sys ) ; then
+        echo "run_file contains : "
+        cat run_file
+      fi
+ 
+    # MPI-OpenMP (MPMD)
+    else
 
       #  Hosts treatment
-
       ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
 
       i=0
       rm -f hosts
-      IGCM_debug_Print 1 "sys Ciclad, Hosts avaible :"
+      IGCM_debug_Print 1 "sys Ciclad, Hosts available :"
       for nodes in `cat hosts.tmp` ; do
         host[$i]=$nodes
@@ -912,183 +948,95 @@
 
       # Initialisation
-
-      init_node=y
-      node_num_current=0
-      start_num=0
+      rank=0
+      current_core=0
+      core_per_node=8
       init_exec=n
 
-      # Build run_file
-
-      # First loop on the components for the coupler ie oasis (only if oasis3)
-      # the coupler ie oasis3 must be the first one
+      # Loop on the components
       for comp in ${config_ListOfComponents[*]} ; do
 
-        if [ "X${comp}" = "XCPL" ]  ; then
-
-          eval ExeNameIn=\${config_Executable_${comp}[0]}
-          eval ExeNameOut=\${config_Executable_${comp}[1]}
+        eval ExeNameIn=\${config_Executable_${comp}[0]}
+        eval ExeNameOut=\${config_Executable_${comp}[1]}
+
+        # Not possible if oasis has an executable (i.e old version of oasis3)
+        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
+          IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
+          IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
+          IGCM_debug_Verif_Exit
+        fi
+
+        # Only if we really have an executable for the component :
+        if [ "X${ExeNameOut}" != X\"\" ] ; then
+
+          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
+          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
 
           echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
           echo ""  >> script_${ExeNameOut}.ksh
-          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
-          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
-          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
-          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
+          if [ ${comp_proc_omp_loc} -gt 1 ] ; then
+
+            # Check if the number of threads is correct
+            case ${comp_proc_omp_loc} in
+            2|4)
+              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
+              ;;
+            *)
+              IGCM_debug_Exit "ERROR with OMP parameters !"
+              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
+              IGCM_debug_Print 2 "Only 2,4 as number of OMP threads are possible "
+              IGCM_debug_Verif_Exit
+              ;;
+            esac
+            #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
+            #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
+            #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
+            echo "export OMP_STACKSIZE=200M" >> script_${ExeNameOut}.ksh 
+            echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
+          fi
+          #echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
+          #echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
+          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
           IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
 
-          init_node=n
-
-          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
-          node_num_current=0
-          node_current=${host[${node_num_current}]}
-
-          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
-
-          init_exec=y
-          start_num=1
-
-        fi
-
-      done
-
-      # Then loop on the components (except for oasis)
-
-      for comp in ${config_ListOfComponents[*]} ; do
-
-        eval ExeNameIn=\${config_Executable_${comp}[0]}
-        eval ExeNameOut=\${config_Executable_${comp}[1]}
-
-        # Only if we really have an executable for the component :
-        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
-
-          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
-          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
-
-          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
-          # echo "set -vx" >> script_${ExeNameOut}.ksh
-          echo ""  >> script_${ExeNameOut}.ksh
-          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
-          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
-          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
-          echo "export OMP_STACKSIZE=200M" >> script_${ExeNameOut}.ksh 
-          echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
-          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
-          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
-          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
-
-          node_num=0
-
-          # We define the number of MPI process to be assigned for the component
-
-          nombre_restant_comp=${comp_proc_mpi_loc}
-
-          # Loop on the allocated nodes
-
-          for node in ${listnodes} ; do
-
-            # We go to the current node
-            if [ ${node_num} = ${node_num_current} ] ; then
-
-              node_current=${host[${node_num_current}]}
-
-              # If first time on the node : initialisation
-
-              if [ ${init_node} = y ] ; then
-                nombre_restant_node=${NUM_COREPERNODE}
-              fi
-
-              # Test on the number of OMP threads
-
-              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
-                (( node_num = node_num + 1 ))
-                node_num_current=${node_num}
-                init_node=y
-                continue
-              fi
-
-              # Number of MPI process to assign
-
-              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
-
-              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
-                num_corempi=${nombre_restant_comp}
-              fi
-
-              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
-              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
-
-              if [ ${init_exec} = y ] ; then
-                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
-              else
-                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
-                init_exec=y
-              fi
-
-              ((  start_num = num_corempi + start_num ))
-
-            else
-
-              (( node_num = node_num + 1 ))
-              continue
-            fi
-
-            # Test on the number of core/process remaining on the node/component
-
-            if [ ${nombre_restant_node} = 0 ] ; then
-              (( node_num = node_num + 1 ))
-              node_num_current=${node_num}
-              init_node=y
-
-              if [ ${nombre_restant_comp} = 0 ] ; then
-                break 1
-              fi
-            else
-
-              node_num_current=${node_num}
-              init_node=n
-
-              if [ ${nombre_restant_comp} = 0 ] ; then
-                break 1
-              fi
-            fi
+          if [ ${init_exec} = y ] ; then
+            EXECUTION="${EXECUTION} : -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
+          else
+            EXECUTION="${EXECUTION} -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
+            init_exec=y
+          fi
+
+          # Build rankfile : method used to assign cores and nodes for the MPI process
+          # Ex :
+          #rank 0=curie5296 slot=0,1,2,3
+          #rank 1=curie5296 slot=4,5,6,7
+          # Example of final command :
+          # mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
+          # with script_lmdz.x.ksh :
+          # #!/bin/ksh
+          #export OMP_STACKSIZE=200M
+          #export OMP_NUM_THREADS=4
+          #./lmdz.x
+
+          for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do
+            (( index_host = current_core / core_per_node ))
+            host_value=${host[${index_host}]}
+            (( slot =  current_core % core_per_node ))
+            virg=","
+            string_final=""
+            for index in `seq $slot $(($slot+$comp_proc_omp_loc-1))`; do
+              string=$index$virg
+              string_final=$string_final$string
+            done
+            string_final=$( echo $string_final | sed "s/.$//" )
+            echo "rank $rank=$host_value slot=$string_final" >> rankfile
+            (( rank = rank + 1 ))
+            (( current_core = current_core + comp_proc_omp_loc ))
           done
         fi
       done
-
-    else
-
-      # Then first loop on the components for the coupler ie oasis
-
-      ## the coupler ie oasis must be the first one
-      for comp in ${config_ListOfComponents[*]} ; do
-
-        eval ExeNameOut=\${config_Executable_${comp}[1]}
-
-        # for CPL component only
-        if [ "X${comp}" = "XCPL" ] ; then
-          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
-          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
-        fi
-      done
-
-      # Then second loop on the components
-
-      for comp in ${config_ListOfComponents[*]} ; do
-
-        eval ExeNameOut=\${config_Executable_${comp}[1]}
-
-        # Only if we really have an executable for the component and not the coupler ie oasis:
-        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
-          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
-          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
-        fi
-      done
-      IGCM_sys_Chmod u+x run_file
-
-      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
-
     fi
 
-  else # Only one executable. launch it.
+  # Only one executable (SPMD mode).
+  else
 
     for comp in ${config_ListOfComponents[*]} ; do
Index: /trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh
===================================================================
--- /trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh	(revision 1295)
+++ /trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh	(revision 1296)
@@ -181,8 +181,4 @@
 #- set PackDefault to true on curie
 PackDefault=true
-
-#====================================================
-#- Number of core per node (max number of OpenMP task)
-NUM_COREPERNODE=8
 
 #====================================================
@@ -1317,18 +1313,17 @@
           fi
 
-# Build rankfile : method used to assign cores and nodes for the MPI process
-# Ex :
-#rank 0=curie5296 slot=0,1,2,3
-#rank 1=curie5296 slot=4,5,6,7
-# Example of final command :
-# mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
-# with script_lmdz.x.ksh :
-# #!/bin/ksh
-#export KMP_STACKSIZE=3g
-#export KMP_LIBRARY=turnaround
-#export MKL_SERIAL=YES
-#OMP_NUM_THREADS=4
-#./lmdz.x
-#
+          # Build rankfile : method used to assign cores and nodes for the MPI process
+          # Ex :
+          #rank 0=curie5296 slot=0,1,2,3
+          #rank 1=curie5296 slot=4,5,6,7
+          # Example of final command :
+          # mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
+          # with script_lmdz.x.ksh :
+          # #!/bin/ksh
+          #export KMP_STACKSIZE=3g
+          #export KMP_LIBRARY=turnaround
+          #export MKL_SERIAL=YES
+          #OMP_NUM_THREADS=4
+          #./lmdz.x
 
           for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do
@@ -1348,5 +1343,4 @@
           done
         fi
-
       done
     fi
