Cluster Grid

Font Size

SCREEN

Layout

Menu Style

Cpanel

How to submit and view the output of jobs from a Makefile

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:

  1. [heri@fep mpi]$ make run_fep
  2. mpicc -o hello_sun hello_world.c
  3. Running job: 52526
  4. Job queued: .............................................
  5. Running. Job started: Tue Dec 30 18:33:24 EET 2008
  6. Job ended: Tue Dec 30 18:34:11 EET 2008
  7. ==> hello_sun.10514.e <==
  8.  
  9. ==> hello_sun.10514.o <==
  10. Hello world from process 4 of 12
  11. Hello world from process 3 of 12
  12. Hello world from process 1 of 12
  13. Hello world from process 5 of 12
  14. Hello world from process 6 of 12
  15. Hello world from process 11 of 12
  16. Hello world from process 9 of 12
  17. Hello world from process 8 of 12
  18. Hello world from process 10 of 12
  19. Hello world from process 7 of 12

 

The makefile looks like this:

 

  1. #Author: Heri
  2. #Date: 30dec08
  3.  
  4. PROG_NAME := hello_sun
  5. NPROCS := 12
  6. TMPFILE := ${PROG_NAME}.${shell echo $$RANDOM}
  7. JID := ${shell set `qsub -q ibm-quad -pe ibm-quad ${NPROCS} -cwd -N
  8. ${PROG_NAME} \
  9. -e ${TMPFILE}.e -o ${TMPFILE}.o -b y \
  10. "/opt/openmpi/default/bin/mpirun -np ${NPROCS} ./${PROG_NAME}"` ;
  11. echo $$3}
  12.  
  13. all:
  14. @echo "Usage: make run_fep"
  15. compile:
  16. mpicc -o ${PROG_NAME} hello_world.c
  17. run_fep: compile
  18. @echo "Running job: ${JID}"
  19. @sleep 2
  20. @echo -ne "Job queued: "
  21. @JSTATUS=`qstat | grep ${JID}` ; while [ `echo $$JSTATUS | wc -l`
  22. -gt 0 ] ; do set $$JSTATUS ; \
  23. case $$5 in \
  24. *q*) echo -ne "." ; sleep 1 ;; \
  25. E*) echo "Sheduling error" ; exit 2 ;; \
  26. r|t) echo "" ; echo "Running. Job started: `date`" ; break ;; esac
  27. ; \
  28. JSTATUS=`qstat | grep ${JID}` ; done
  29. @while [ `qstat | grep ${JID} | wc -l` -gt 0 ] ; do sleep 1 ;
  30. done
  31. @echo "Job ended: `date`"
  32. @tail --retry ${TMPFILE}.e ${TMPFILE}.o 2>/dev/null
  33. @rm ${TMPFILE}.e ${TMPFILE}.o
  34. clean:
  35. rm ${PROG_NAME}