Commit 5eb55990 authored by Matthieu Tristram's avatar Matthieu Tristram
Browse files

Version used for Mnu

parent 54519e79
#!/bin/bash
nargs=$#
if ! [ $nargs -eq 2 -o $nargs -eq 3 ]; then
echo "***************************************************"
echo ">>>> Usage: `basename $0` parfile scanfile (range)"
echo "***************************************************"
echo "* \"scanfile\" must be provided as a text file with the name and values of the profiled parameter."
echo "For instance var=\"omega_b\" && val=(0.02 0.025 0.030)"
echo "* The optional \"range\" parameter can be used to specify different starting points "
echo "It must be given in the form: begin-end (eg. 1-5 for jobs 1 to 5)"
echo "Job 1 corresponding to not changing the parFile starting values, while other values"
echo "will send jobs shuffling the parameters randomly within the min-max bounds of the parFile"
exit 1
fi
parFile=$1
scanFile=$2
range="1-1"
if [ $nargs -eq 3 ] ; then
range="$3"
fi
HERE=$PWD
#check environment
if [ -z "${CAMELROOT}" ] ; then
echo "CAMELROOT undefined: did you sourced camel_setup.sh?"
exit
fi
if ! [ -f $CAMELROOT/$CMTCONFIG/Minimize ] ; then
echo "missing Minimize executable: rum make exec in cmt/"
fi
if [ ! -f "$parFile" ] ; then
echo "Missing parfile=$parFile"
exit
fi
if [ ! -f "$scanFile" ] ; then
echo "Missing scanfile=$scanFile"
exit
fi
##############define the scanned variable###############
source $scanFile
if [ -z "$var" ] ; then
echo "missing profile variable name: define var=\"...\" in the scan file"
fi
if [ -z "$val" ] ; then
echo "missing profile variable values: define val=( v1 v2 ...) in the scan file"
fi
######################################################
echo "Profile variable= $var"
echo "values=${val[*]}"
#fix number of cores for openMP
#default is running on 8 cores.
#if you wish to change it, set the environment variable NCORES to another value.
if [ -z "$NCORES" ] ; then
NCORES=8
fi
#default QSUB command (if not overriden by user)
if [ -z "${QSUB_CMD}" ] ; then
QSUB_CMD="qsub -P P_$GROUP -pe multicores $NCORES -q mc_long -l sps=1"
fi
echo "About to run ${#val[@]} array-jobs (each with range=$range)"
echo "QSUB command will be: ${QSUB_CMD} -t $range"
echo "Is this OK? [y/n]"
read answer
if [ $answer != 'y' ] ; then
echo "exiting"
exit 1
fi
######################################
file=$(readlink -e $parFile)
parbase=$(basename $file)
dirout=$PWD/${parbase%".par"}_prof_"$var"
if [ -d "$dirout" ] ; then
echo "Output directory $dirout already exists: still want to run? (y/n)"
read answer
if [ $answer != 'y' ] ; then
echo "exiting"
exit 1
fi
else
mkdir $dirout
fi
#cp $scanFile $dirout/
cp $parFile $dirout/
##########LOOP################################
for i in $(seq 0 $((${#val[@]}-1))) ; do
zeval=${val[$i]}
OUTDIR=$dirout/"$var"_${zeval}
mkdir $OUTDIR
cd $OUTDIR
jobname=${parbase%".par"}_prof_"$var"_${zeval}
########################################################
cat > camelrun_$zeval <<EOBATCH
#!/bin/env bash
#$ -N ${jobname}
#$ -R y
#$ -j y
#$ -o $PWD
#$ -e $PWD
cd \$TMPDIR
uname -a
echo "NSLOTS=\$NSLOTS"
export OMP_NUM_THREADS=$NCORES
export PYTHONPATH=${PICO_CODE}
# copies locales
cp $CAMELROOT/$CMTCONFIG/Minimize .
cp $CAMELROOT/work/tools/awk/genrand.awk .
#
#input file: rm variable from it
#need to escape the * for grep command
awk '{if ((\$1 == "par" || \$1 == "fix" || \$1 == "class") && \$2 == "${var/\*/\\*}") print ""; else print \$0}' ${dirout}/${parbase} > parfile_in
#grep -v "${var/\*/\\*}" $file > parfile_in
#compute var: here no escape
echo "fix $var cosmo $zeval" >> parfile_in
#special case of degenerate neutrinos (need to decrement Neff by 1 when mass=0)
if [ "$var" == "m_ncdm" ] ; then
grep -v ncdm parfile_in | grep -v N_eff > tmp
if [ "$zeval" == "0" ] ; then
echo "fix N_ncdm cosmo 0" >> tmp
echo "class N_eff 3.046" >> tmp
else
echo "class N_ncdm 1" >> tmp
echo "fix m_ncdm cosmo $zeval" >> tmp
echo "class N_eff 2.046" >> tmp
fi
cp -f tmp parfile_in
fi
#force Profile parameters
grep -v nitermax parfile_in | grep -v set_tol | grep -v remove_cosmo_limits | grep -v doHesse > tmp
echo "nitermax=100000" >> tmp
echo "set_tol=0.0001" >> tmp
echo "remove_cosmo_limits=true" >> tmp
echo "doHesse=false" >> tmp
cp -f tmp parfile_in
echo "init par:"
cat parfile_in
#================================
#randomize si id ne 1
#================================
echo "***************************************************************"
if [ \${SGE_TASK_ID} -eq 1 ] ; then
cp parfile_in parfile
else
RANDOM=\${SGE_TASK_ID}
awk -v seed=\$RANDOM -f genrand.awk parfile_in > parfile
fi
cp parfile "$OUTDIR"/camel\${SGE_TASK_ID}.par
echo "***************************************************************"
#================================
# Camel run
#================================
#PICO RUN
./Minimize parfile best_fit #covmat
cp -f best_fit "$OUTDIR"/best_fit\${SGE_TASK_ID}
#cp -f covmat "$OUTDIR"/covmat\${SGE_TASK_ID}
EOBATCH
###################################################################
#submit an array job for this scanned value
jobsub="${QSUB_CMD} -t $range camelrun_$zeval"
eval $jobsub
##################################################################
done
echo ">>>> Outputs in: $dirout"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment