How to submit and view the output of jobs from a Makefile
- Details Hits: 9175
Usually this little bit of code should be handy. You can submit a job, say hello_world from the makefile,and you can also track the job and see its output.
This code is available on fep.grid.pub.ro in /srv/ncitCluster/examples/BasicMPI_Makefile.
Output example:
[heri@fep mpi]$ make run_fep mpicc -o hello_sun hello_world.c Running job: 52526 Job queued: ............................................. Running. Job started: Tue Dec 30 18:33:24 EET 2008 Job ended: Tue Dec 30 18:34:11 EET 2008 ==> hello_sun.10514.e <== ==> hello_sun.10514.o <== Hello world from process 4 of 12 Hello world from process 3 of 12 Hello world from process 1 of 12 Hello world from process 5 of 12 Hello world from process 6 of 12 Hello world from process 11 of 12 Hello world from process 9 of 12 Hello world from process 8 of 12 Hello world from process 10 of 12 Hello world from process 7 of 12
The makefile looks like this:
#Author: Heri #Date: 30dec08 PROG_NAME := hello_sun NPROCS := 12 TMPFILE := ${PROG_NAME}.${shell echo $$RANDOM} JID := ${shell set `qsub -q ibm-quad -pe ibm-quad ${NPROCS} -cwd -N ${PROG_NAME} \ -e ${TMPFILE}.e -o ${TMPFILE}.o -b y \ "/opt/openmpi/default/bin/mpirun -np ${NPROCS} ./${PROG_NAME}"` ; echo $$3} all: @echo "Usage: make run_fep" compile: mpicc -o ${PROG_NAME} hello_world.c run_fep: compile @echo "Running job: ${JID}" @sleep 2 @echo -ne "Job queued: " @JSTATUS=`qstat | grep ${JID}` ; while [ `echo $$JSTATUS | wc -l` -gt 0 ] ; do set $$JSTATUS ; \ case $$5 in \ *q*) echo -ne "." ; sleep 1 ;; \ E*) echo "Sheduling error" ; exit 2 ;; \ r|t) echo "" ; echo "Running. Job started: `date`" ; break ;; esac ; \ JSTATUS=`qstat | grep ${JID}` ; done @while [ `qstat | grep ${JID} | wc -l` -gt 0 ] ; do sleep 1 ; done @echo "Job ended: `date`" @tail --retry ${TMPFILE}.e ${TMPFILE}.o 2>/dev/null @rm ${TMPFILE}.e ${TMPFILE}.o clean: rm ${PROG_NAME}