#!/bin/bash
# usage : ./python.sh mode [n] script script_args
# mode is 'serial' or mpi
# if mode is 'mpi' then argument [n] specifies the number of MPI processes

# This script relies on ../.. being DYNAMICO_ROOT
# If you move it, set DYNAMICO_ROOT accordingly in the script or before calling the script

function cmd_serial()
{
    LD_PRELOAD=$PYTHON_PRELOAD python -u $*
}

function cmd_gdb()
{
    set -x
    LD_PRELOAD=$PYTHON_PRELOAD gdb --args python -u $*
}

function cmd_mpi()
{
    NB_MPI=$1
    shift
    rm -f xios_client*.*
    mpirun --mca mpi_warn_on_fork 0 -np $NB_MPI python -u $* 2>&1 | tee dynamico.log
}

TEST=$PWD
DYNAMICO_ROOT=$(cd -P $(dirname $0)/../.. ; pwd) # change/remove this line if you move this script

cd $DYNAMICO_ROOT

cp -i -u Python/dynamico/*.py lib/dynamico/
cp -i -u Python/dynamico/dev/*.py lib/dynamico/dev/

. arch.env
. arch.path
cd arch
. arch-${CURRENT_ARCH}.dev

cd $TEST

export OMP_STACKSIZE=128M
ulimit -s unlimited

CMD=$1
shift
cmd_$CMD $*
