#!/bin/bash # # determine the root directory of the LAP Tree, assuming this script resides # in its designated sub-directory in the tree. # if [ -z "${LAPTREE}" ]; then path=$(dirname ${0}) if [ "${path#./}" != "${path}" ]; then path="$(pwd)/${path#./}" fi if [ "${path#/}" = "${path}" ]; then if [ "${path}" = "." ]; then path="$(pwd)"; else path="$(pwd)/${path}" fi fi LAPTREE="${path%/etc}"; export LAPTREE; fi # # include a shared set of shell functions and global parameters, including the # architecture identifier .LAPOS. # . ${LAPTREE}/etc/library.bash; # # _fix_me_ # at this point, we plan to do more option parsing, e.g. to see which revision # to run; in principle, a request for an older revision can lead to checking # out (parts of) a back-dated copy of the LAP Tree and Library, which we shall # then use for tool execution. to make this work over time, we will need to # version the Library (and possibly the underlying database schema, seeing as # there may be more frequent library revisions than schema revisions, such that # in theory different library version can inter-operate with each other, as # long as their database records are mutually compatible) and record compatible # versions with each tool revision. # while [ $# -gt 0 -a "${1#==}" != "$1" ]; do case ${1} in ==tool) tool=$2; shift 2; ;; ==process) process=$2; shift 2; ;; ==revision) revision=$2; shift 2; ;; ==user) export LAPUSER=$2; shift 2; ;; ==cores) export LAPCORES=$2; shift 2; ;; ==memory) export LAPMEMORY=$2; shift 2; ;; ==test) test=$2; shift 2; ;; *) echo "driver: invalid option \`${1}'; exit."; exit 1; ;; esac done # # _fix_me_ # make sure the universe is set up properly to run earlier SVN revisions # if [ -n "${revision}" ]; then cd ${LAPTREE%%/trunk}; if [ ! -d "${revision}" ]; then /bin/mkdir "${revision}"; cd "${revision}"; svn co -r "${revision}" http://svn.emmtee.net/lap/trunk/tree; if [ $? -ne 0 ]; then error \ "driver: error getting LAP Tree revision ‘${revision}’; exit." \ 1; fi svn co -r "${revision}" http://svn.emmtee.net/lap/trunk/library; if [ $? -ne 0 ]; then error \ "driver: error getting LAP Library revision ‘${revision}’; exit." \ 1; fi fi LAPTREE=${LAPTREE%%/trunk}/${revision}/tree; LAPLIBRARY=${LAPTREE%%/trunk}/${revision}/library; fi # # determine the location of the LAP Library code (currently for Python only). # if [ -z "${LAPLIBRARY}" ]; then if [ -d ${LAPTREE%/tree}/library ]; then LAPLIBRARY=${LAPTREE%/tree}/library; else LAPLIBRARY=/projects/lap/development/trunk/library; fi fi export LAPLIBRARY; # # canonicalize (and abstract from potentially different queue environments) a # couple of job parameters, communicated to tool wrappers in the environment. # if [ -z "${LAPCORES}" ]; then LAPCORES=${SLURM_CPUS_ON_NODE:-1}; fi export LAPCORES; if [ -z "${LAPMEMORY}" ]; then LAPMEMORY=$[${SLURM_MEM_PER_CPU:-1024} * ${LAPCORES}]; fi export LAPMEMORY; # # in ‘==test’ mode, no actual tool is invoked, but rather our run-time # environment is inspected. # if [ -n "${test}" ]; then { echo "${0} [$(date "+%y-%m-%d (%H:%m)") on ${HOSTNAME}]"; echo; env | egrep '^LAP' | sort; echo; env | egrep '^SLURM' | sort; echo; echo "=== ulimit -Sa ==="; ulimit -Sa; echo; echo "=== ulimit -Ha ==="; ulimit -Ha; echo; echo; } > ${test} exit 0; fi # # confirm we have a valid wrapper for the tool and process that are requested # if [ -z "${tool}" ]; then error \ "driver: missing ‘==tool’ specification; exit." \ 1; else if [ -n "${process}" ]; then wrapper=${LAPTREE}/${tool}/lap/${process}.py; else wrapper=${LAPTREE}/${tool}/lap/wrapper.py; fi if [ ! -f ${wrapper} ]; then error \ "driver: unable to locate ‘${tool}’ (‘${process}’) wrapper; exit." 1; fi fi # # make sure that (non-core) shared libraries from the build environment are # available for dynamic loading (including on request, by add-one modules). # if [ -z "${LD_LIBRARY_PATH}" ]; then LD_LIBRARY_PATH=${LAPTREE}/python/lib; else LD_LIBRARY_PATH=${LAPTREE}/python/lib:${LD_LIBRARY_PATH}; fi export LD_LIBRARY_PATH; # # leave ourselves some traces about the execution environment. # log=${LAPLOG}/driver.log if [ ! -w ${log} ]; then log=/dev/null; fi { echo "${0} [$(date "+%y-%m-%d (%H:%m)") on ${HOSTNAME}]"; echo; env | egrep '^LAP' | sort; echo; env | egrep '^SLURM' | sort; echo; echo "=== ulimit -Sa ==="; ulimit -Sa; echo; echo "=== ulimit -Ha ==="; ulimit -Ha; echo; echo; } >> ${log} # # allow Python to find its own code from the LAP Tree and that of the Library # export PYTHONPATH=${LAPTREE}/python:${LAPLIBRARY}/python:${PYTHONPATH}; export NLTK_DATA=${LAPTREE}/python/nltk_data; exec ${LAPTREE}/python/lap/python ${wrapper} "$@";