summaryrefslogtreecommitdiff
path: root/PyGan/rpython
diff options
context:
space:
mode:
authorstainer_t <thomas.stainer@oecd-nea.org>2025-09-08 13:48:49 +0200
committerstainer_t <thomas.stainer@oecd-nea.org>2025-09-08 13:48:49 +0200
commit7dfcc480ba1e19bd3232349fc733caef94034292 (patch)
tree03ee104eb8846d5cc1a981d267687a729185d3f3 /PyGan/rpython
Initial commit from Polytechnique Montreal
Diffstat (limited to 'PyGan/rpython')
-rwxr-xr-xPyGan/rpython187
1 files changed, 187 insertions, 0 deletions
diff --git a/PyGan/rpython b/PyGan/rpython
new file mode 100755
index 0000000..bf3e12a
--- /dev/null
+++ b/PyGan/rpython
@@ -0,0 +1,187 @@
+#!/bin/sh
+#
+# author : A. Hebert
+# use : rpython [-c:|-q|-w|-e|-p:|-i:] <file.py>
+# note : <file.py> must be located on directory ./data/
+# If <file.access> exists, it is executed.
+# -c name of compiler
+# -q quiet execution for regression testing
+# -w to execute in console (for debug purpose)
+# -e to use PIP extension modules for lifo, lcm and cle2000
+# -p number of parallel threads (=1 by default)
+# -i name of python dataset (by default, use the last argument)
+#
+if [ $# = 0 ]
+ then
+ echo "usage: rpython [-c:|-q|-w|-e|-p:|-i:] <file.py>" 1>&2
+ exit 1
+fi
+System=`uname -s`
+Sysx="`echo $System | cut -b -6`"
+if [ $Sysx = "CYGWIN" ]; then
+ export MACH=`uname -o`
+elif [ $Sysx = "AIX" ]; then
+ export MACH=`uname -s`
+else
+ export MACH=`uname -sm | sed 's/[ ]/_/'`
+fi
+
+for last; do : ; done
+mydata=${last}
+typ='custom'
+quiet=0
+term=0
+nomp=0
+pip=0
+
+while getopts ":c:qwei:p:" opt; do
+ case $opt in
+ c) typ="$OPTARG"
+ ;;
+ q) quiet=1
+ ;;
+ w) term=1
+ ;;
+ e) pip=1
+ ;;
+ p) nomp=$OPTARG
+ ;;
+ i) mydata=$OPTARG
+ ;;
+ \?) echo "Invalid option -$OPTARG" >&2
+ exit 1
+ ;;
+ esac
+
+ case $OPTARG in
+ -*) echo "Option $opt needs a valid argument"
+ exit 1
+ ;;
+ esac
+done
+
+xxx=`basename $mydata .py`
+Code=`basename "$PWD"`
+if [ $quiet = 0 ]; then
+ echo 'execute' $xxx 'with' $Code 'on system' $MACH 'with' $typ 'compiler'
+fi
+
+if [ -d "$MACH" ]; then
+ if [ $quiet = 0 ]; then
+ echo 'use the existing directory' $MACH
+ fi
+else
+ echo 'creation of directory' $MACH
+ mkdir "$MACH"
+fi
+CodeDir=$PWD
+
+if [ $Sysx = "AIX" ]; then
+ Tmpdir=/usr/tmp
+elif [ $Sysx = "SunOS" ]; then
+ Tmpdir=/var/tmp
+else
+ Tmpdir=/tmp
+fi
+inum=1
+while [ -d $Tmpdir/rundir$inum ]
+ do
+ inum=`expr $inum + 1 `
+done
+Rundir=$Tmpdir/rundir$inum
+mkdir $Rundir
+pyv=`echo $(python3 --version) | cut -d. -f2`
+if [ $quiet = 0 ]; then
+ echo "RunDirectory:" $Rundir
+ echo "Python version= 3."$pyv
+fi
+
+if [ $typ = 'intel' ]; then
+ export COMPILER=INTELTOOLS
+elif [ $typ = 'nvidia' ]; then
+ export COMPILER=NVTOOLS
+elif [ $typ = 'llvm' ]; then
+ export COMPILER=LLVMTOOLS
+else
+ export COMPILER=FORTRANPATH
+fi
+if [ $pip = 0 ]; then
+ export PYTHONPATH="$(python3 ../script/set_pythonpath.py)"
+fi
+if [ $quiet = 0 ]; then
+ echo "PythonPath=" $PYTHONPATH
+fi
+export PYTHONMALLOC=debug
+cd $Rundir
+cp "$CodeDir"/data/$mydata ./mydata
+
+export NO_STOP_MESSAGE=1
+if [ -d "$CodeDir"/data/`echo $xxx`_proc ]; then
+ cp "$CodeDir"/data/`echo $xxx`_proc/*.c2m . 2> /dev/null
+ cp "$CodeDir"/data/`echo $xxx`_proc/*.py . 2> /dev/null
+fi
+if [ -f "$CodeDir"/data/$xxx.access ]; then
+ if [ $quiet = 0 ]; then
+ "$CodeDir"/data/$xxx.access "$CodeDir"
+ else
+ "$CodeDir"/data/$xxx.access "$CodeDir" > /dev/null
+ fi
+fi
+if [ -f "$CodeDir"/data/assertS.py ]; then
+ cp "$CodeDir"/data/assertS.py .
+fi
+if [ -f "$CodeDir"/data/assertV.py ]; then
+ cp "$CodeDir"/data/assertV.py .
+fi
+if [ $quiet = 0 ]; then
+ ls -l
+fi
+before=$(date +%s)
+if [ $nomp != 0 ]; then
+ echo 'number of OpenMP threads=' $nomp
+ export OMP_NUM_THREADS=$nomp
+ if command -v numactl >&2; then
+ numactl --cpunodebind=0 --membind=0 2>/dev/null
+ echo "use NUMA memory policy"
+ fi
+else
+ export OMP_NUM_THREADS=1
+fi
+if [ $term = 0 ]; then
+ python3 mydata >$xxx.result
+elif [ $term = 1 ]; then
+ python3 mydata
+fi
+if [ $quiet = 0 ]; then
+ time=$(( $(date +%s) - before))
+ printf 'End of execution. Total execution time: %dh %dmin %ds\n' \
+ $(($time/3600)) $(($time%3600/60)) $(($time%60))
+fi
+if [ -f "$CodeDir"/data/$xxx.save ]; then
+ if [ $quiet = 0 ]; then
+ "$CodeDir"/data/$xxx.save "$CodeDir"
+ else
+ "$CodeDir"/data/$xxx.save "$CodeDir" > /dev/null
+ fi
+fi
+mv $xxx.result "$CodeDir"/"$MACH"
+if [ $quiet = 0 ]; then
+ echo 'the listing is located on ./'$MACH
+fi
+
+cd "$CodeDir"/"$MACH"
+if [ $quiet = 0 ] && [ $term = 0 ]; then
+ tail -15 $xxx.result
+elif [ $term = 0 ]; then
+ RED='\033[0;31m'
+ GREEN='\033[0;32m'
+ NC='\033[0m' # No Color
+ if tail $xxx.result | grep -q "completed" ; then
+ printf "${GREEN}[OK]${NC}\n"
+ else
+ printf "${RED}[FAILED]${NC}\n"
+ fi
+fi
+chmod -R 777 $Rundir
+/bin/rm -r -f $Rundir
+cd ..