Index: BOL/LMDZ_Setup_amaury/lmdz_env.sh
===================================================================
--- BOL/LMDZ_Setup_amaury/lmdz_env.sh	(revision 5046)
+++ BOL/LMDZ_Setup_amaury/lmdz_env.sh	(revision 5052)
@@ -73,5 +73,5 @@
       module purge
       module load PrgEnv-gnu  # we need to load the env because lmdz links some shared libraries
-      module load gcc/12.1.0  # required, see https://dci.dci-gitlab.cines.fr/webextranet/user_support/index.html#prgenv-and-compilers
+      module load gcc/13.2.0  # required, see https://dci.dci-gitlab.cines.fr/webextranet/user_support/index.html#prgenv-and-compilers
 
       function cdo {  # cdo is available as a spack cmd which requires a specific, incompatible env
@@ -103,9 +103,9 @@
       NB_OMP_MAX=200
       NB_CORE_PER_NODE_MAX=192
-      N_HYPERTHREADING=2
+      N_HYPERTHREADING=1  # Adastra has SMT=2 enabled, but we found no actual performance improvement for the latlon model. Maybe useful for Dynamico ?
       MPICMD="srun -n"
 #      RUNBASHCMD="srun --label --account=$account --constraint=GENOA --ntasks-per-node=1 -n 1 --time=00:15:00 -c"
       RUNBASHCMD="bash"  # On Adastra the docs says we can use login nodes for compilation
-      SUBMITCMD="env $(env | grep -E "SLURM_|SBATCH_|SRUN_" | cut -d= -f1 | awk '{print "-u " $0}' | tr '\n' ' ' ) sbatch --constraint=GENOA --account=$account"  # we need to remove the existing SLURM variables otherwise they lay be unexpectedly inherited by the submitted script
+      SUBMITCMD="env $(env | grep -E "SLURM_|SBATCH_|SRUN_" | cut -d= -f1 | awk '{print "-u " $0}' | tr '\n' ' ' ) sbatch --constraint=GENOA --account=$account"  # we need to remove the existing SLURM variables otherwise they may be unexpectedly inherited by the submitted script
       ;;
     *) echo "WARNING: RUNNING THIS SCRIPT ON A LOCAL COMPUTER IS DISCOURAGED (lackluster cpus and memory)"
Index: BOL/LMDZ_Setup_amaury/script_SIMU
===================================================================
--- BOL/LMDZ_Setup_amaury/script_SIMU	(revision 5046)
+++ BOL/LMDZ_Setup_amaury/script_SIMU	(revision 5052)
@@ -84,5 +84,7 @@
 SCRIPTDIR=$SCRATCHD/$MAINDIR
 
-cp $STORED/$MAINDIR/lmdz_env.sh . ; . lmdz_env.sh
+cp "$STORED/$MAINDIR/lmdz_env.sh" .; . lmdz_env.sh
+cp "$STORED/$MAINDIR/slurm_set_cpu_binding.sh" .
+
 ERADIR=$STORED/$MAINDIR/GUIDE
 if [ "$aerosols" = "spla" ] ; then ERA10mDIR=$STORED/$MAINDIR/ERA10m ; fi
@@ -320,5 +322,10 @@
 echo '##################################################################'
 
+#@ADS if 1; then
 time $MPICMD $ntasks ./gcm.e > listing
+#@ADS else
+#@ADS srun --cpu-bind=none --mem-bind=none -- ./slurm_set_cpu_binding.sh ./gcm.e > listing
+#@ADS fi
+
 if [ ! -f restartphy.nc ] ; then
 echo PROBLEME PAS DE FICHIER RESTARTPHY
Index: BOL/LMDZ_Setup_amaury/slurm_set_cpu_binding.sh
===================================================================
--- BOL/LMDZ_Setup_amaury/slurm_set_cpu_binding.sh	(revision 5052)
+++ BOL/LMDZ_Setup_amaury/slurm_set_cpu_binding.sh	(revision 5052)
@@ -0,0 +1,61 @@
+#!/bin/bash
+# Adapted A. Barral 07/2024 from https://dci.dci-gitlab.cines.fr/webextranet/porting_optimization/detailed_binding_script.html#porting-optimization-detailed-binding-script
+# Used within exclusive nodes as srun --cpu-bind=none --mem-bind=none -- ./set_binding.sh <executable> <args>
+# Note: On Adastra, OMP_PLACES & OMP_PROC_BIND seems to have no effect (probably the default assignment is the same), but I left it there just in case for other configurations.
+
+set -eu
+
+function create_affinity_numactl() {
+    local num_tasks=$1  # Number of MPI tasks
+    local num_threads=$2  # Number of OMP threads per task
+
+    AFFINITY_NUMACTL=()
+    OMP_PLACES_ARR=()
+    local start_cpu=0
+    local total_strands thread_per_core
+    total_strands=392  # "$(lscpu | grep "^CPU(s):" | awk '{print $2}')"  # Total physical threads in the system
+    thread_per_core="$(lscpu | grep "^Thread(s) per core:" | awk '{print $4}')"
+    local total_cpus=$(( total_strands / thread_per_core ))  # Total physical cores in the system
+    num_smt_used=$(( (num_tasks*num_threads+total_cpus-1)/total_cpus ))  # ceil(total_threads_required/total_cpus)
+
+    # Parameter range check
+    if [[ $(( num_tasks * num_threads )) -gt $(( total_strands )) ]]; then
+        echo "STOP: requesting more CPUs than available on the system!"; exit 1
+    fi
+    if [[ $(( num_threads % num_smt_used )) -ne 0 ]]; then
+        echo "STOP: OMP threads number ($num_threads) must be a multiple of $num_smt_used (using $num_smt_used out of $thread_per_core SMT threads per core)."; exit 1
+    fi
+
+    for (( task=0; task<num_tasks; task++ )); do
+        local range=""
+        local range_omp=""
+        for (( i_smt=0; i_smt<num_smt_used; i_smt++ )); do
+            local smt_start_cpu=$((start_cpu + total_cpus * i_smt))
+            local smt_end_cpu=$((smt_start_cpu + num_threads / num_smt_used - 1))
+            range+=",${smt_start_cpu}-${smt_end_cpu}"
+            range_omp+=",{${smt_start_cpu}}:$((num_threads / num_smt_used)):1"
+        done
+        range=$(echo "$range" | cut -c 2-)
+        range_omp=$(echo "$range_omp" | cut -c 2-)
+        AFFINITY_NUMACTL+=("$range")
+        OMP_PLACES_ARR+=("$range_omp")
+        start_cpu=$((start_cpu + num_threads / num_smt_used))
+    done
+}
+
+create_affinity_numactl "$SLURM_NTASKS_PER_NODE" "$OMP_NUM_THREADS" ""
+
+# Modulo arithmetic eases some corner use cases.
+LOCAL_RANK_INDEX="${SLURM_LOCALID}"
+CPU_SET="${AFFINITY_NUMACTL[$((LOCAL_RANK_INDEX % ${#AFFINITY_NUMACTL[@]}))]}"
+OMP_PLACES="${OMP_PLACES_ARR[$((LOCAL_RANK_INDEX % ${#OMP_PLACES_ARR[@]}))]}"
+
+if [[ $LOCAL_RANK_INDEX = 0 ]]; then
+  echo "[$(hostname)] Number of used SMT: $num_smt_used"
+  echo "[$(hostname)] AFFINITY_NUMACTL:" "${AFFINITY_NUMACTL[@]}"
+  echo "[$(hostname)] OMP_PLACES:" "${OMP_PLACES_ARR[@]}"
+fi
+export OMP_PLACES="$OMP_PLACES"
+export OMP_PROC_BIND=CLOSE
+echo "[$(hostname)] Starting local rank ${LOCAL_RANK_INDEX} with: 'numactl --localalloc --physcpubind=${CPU_SET} --' | OMP_PLACES=$OMP_PLACES"
+exec numactl --localalloc --physcpubind="${CPU_SET}" -- "${@}"
