#!/bin/bash function write_nb6wrapper() { cat > $1 </dev/null if [ \$? -ne 0 ]; then echo "Uncompressing the source files failed" exit -1 fi echo "" } function compile() { echo "*****************************************************************************" echo "********************** Compile and Install **********************************" # make: Compiling and linking cd \$NBODY6_SRC_DIR echo Changed working directory to \$(pwd) if [ \$ENABLE_MPI = 'yes' ]; then CONFIGURE_CMD="./configure --enable-mpi --prefix=\${ORIGIN_WORKDIR}/\${EXEC_DIR} --bindir=\${ORIGIN_WORKDIR}/\${EXEC_DIR}" else CONFIGURE_CMD="./configure --prefix=\${ORIGIN_WORKDIR}/\${EXEC_DIR} --bindir=\${ORIGIN_WORKDIR}/\${EXEC_DIR}" fi echo \$CONFIGURE_CMD \$CONFIGURE_CMD if [ \$? -ne 0 ]; then echo "FALLBACK: Default compiler failed. Trying g77..." export F77=g77 \$CONFIGURE_CMD check_exit configure fi MAKE_CMD="make" echo \$MAKE_CMD \$MAKE_CMD check_exit make MAKE_INSTALL_CMD="make install" echo \$MAKE_INSTALL_CMD \$MAKE_INSTALL_CMD check_exit make install echo "" } # Executes the plugins # Parameters: #1 First parameter to the plugin function plugins_execution() { if [ -f nb6_plugin_*_${task_id} ]; then for i in nb6_plugin_*_${task_id}; do [ ! -x \$i ] && chmod +x \$i EXEC_PLUGIN="./\$i \$1" echo "****************************" echo "EXECUTING PLUGIN \$i" echo "****************************" \$EXEC_PLUGIN done fi } function execute() { echo "*****************************************************************************" echo "******************************* Execute *************************************" # These dummy files needs to be created # to prevent stage-out failures. for i in \$OUTPUT_FILES; do touch \${i}_${task_id} done cd \${ORIGIN_WORKDIR}/\${EXEC_DIR} plugins_execution pre_execution echo Creating dummy files: \$OUTPUT_FILES touch \$OUTPUT_FILES log "Executing NBODY6++..." NB6_STARTTIME=\$(date +%s) if [ x\$ENABLE_MPI = 'xyes' ]; then mpirun -np 4 ./\$EXECUTABLE < \$PARAM_FILE &> nbody6.out else ./\$EXECUTABLE < \$PARAM_FILE 2>&1 | tee nbody6.out fi NB6_STOPTIME=\$(date +%s) exitcode=\$? if [ \$exitcode -eq 0 ]; then log "NBODY6++ finished successfully" echo Execution walltime: \$((\$NB6_STOPTIME-\$NB6_STARTTIME)) seconds else log "NBODY6++ exited with error code \$?" fi echo "" plugins_execution post_execution } function post_execute() { echo "*****************************************************************************" echo "************************** Post-execute *************************************" # GridWay/GridGateWay workaround (full paths # are not supported at the moment so we have # to move the files from \$EXEC_DIR back to \$ORIGIN_WORKDIR echo Moving output files from \$EXEC_DIR to \$ORIGIN_WORKDIR for i in \$OUTPUT_FILES; do CMD="mv \$i \${ORIGIN_WORKDIR}/\${i}_${task_id}" echo \$CMD \$CMD done # Globus cleanup expects PARAM_FILE in ORIGIN_WORKDIR mv \$PARAM_FILE \$ORIGIN_WORKDIR # Globus cleanup expects EXECUTABLE in ORIGIN_WORKDIR mv \$EXECUTABLE \$ORIGIN_WORKDIR echo Changing working directory to \$ORIGIN_WORKDIR cd \$ORIGIN_WORKDIR echo Removing \$EXEC_DIR rm -r \$EXEC_DIR if [ -d \$EXEC_DIR ]; then echo "\$EXEC_DIR could not be removed. Please check this directory." fi log "Wrapper finished." exit \$exitcode } function deploy() { init print_environment print_configuration create_sandbox compile execute post_execute } #################### # MAIN #################### deploy EOF }