#!/bin/bash

#----------------------------- split_XXX ----------------------------

function split_serial_40() {
    setvar nbp 41 nsplit_i 2 nsplit_j 2
}
function split_mpi_40() {
    setvar nbp 41 nsplit_i 2 nsplit_j 2
}
function split_mpi_80() {
    setvar nbp 81 nsplit_i 4 nsplit_j 2
}

#------------------------------ job_XXX -----------------------------

function job_serial() { # EXP_NAME
    job_X64_CURIE $1 1 "" 
}
function job_serial_40() { # EXP_NAME
    job_serial $1
}

function job_mpi() { #EXP_NAME NB_MPI
    job_X64_CURIE $1 $2 ccc_mprun
}
function job_mpi_40() { # EXP_NAME
    job_mpi $1 40
}
function job_mpi_80() { # EXP_NAME
    job_mpi $1 80
}

function job_X64_CURIE() { # EXP_NAME MPI_TASKS MPIRUN
    cat <<EOF
#!/bin/bash
## Request name
#MSUB -r $1
#MSUB -q standard 
#MSUB -A gen7548
#MSUB -x
## Number of tasks (=MPI processes) to use
#MSUB -n $2
## Elapsed time limit in seconds
#MSUB -T 600
## Quality of Service required (long [3 days], normal [1 day], test [30 min])
#MSUB -Q test

export OMP_NUM_THREADS=1
cd \${BRIDGE_MSUB_PWD} 

module purge
module load licsrv/intel
module load c/intel/14.0.3.174
module load c++/intel/14.0.3.174
module load fortran/intel/14.0.3.174
module load mkl/14.0.3.174
module load idb/14.0.3.174
module load intel/14.0.3.174
module load mpi/bullxmpi/1.2.8.4
module load netcdf/4.3.3.1_hdf5_parallel

rm -rf gcm.log logs *.nc netcdf
date > gcm.log
ulimit -s unlimited
$3 ./gcm.exe >> gcm.log
date >> gcm.log

mkdir -p netcdf
cp gcm.log *.def netcdf
mv *.nc netcdf

mkdir -p logs
cp *.xml logs
mv xios_client_*.err xios_client_*.out gcm.log logs

EOF
}
