Advertisement
Guest User

Untitled

a guest
May 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from subprocess import call
  3. import os
  4. import sys
  5. import time
  6. from argparse import ArgumentParser
  7. from textwrap import dedent
  8.  
  9. CYCLUS_SCRIPT = \
  10. """
  11. #!/bin/bash
  12. cyclus %(in_dir)s/$ALPS_APP_PE.json -o \
  13. %(out_dir)s/$ALPS_APP_PE.%(out_type)s \
  14. > %(log_dir)s/out_$ALPS_APP_PE.log
  15. """
  16.  
  17. PBS_SCRIPT = \
  18. """
  19. #!/bin/bash
  20. #PBS -l gres=shifter
  21. #PBS -v UDI=adityapb/cyclus:bw
  22. #PBS -l nodes=%(nodes)s:ppn=%(ppn)s:xe
  23. #PBS -l walltime=%(walltime)s
  24. export CRAY_ROOTFS=UDI
  25. export LD_LIBRARY_PATH="/usr/lib/lapack:/usr/lib/libblas:$LD_LIBRARY_PATH"
  26. cd $PBS_O_WORKDIR
  27. aprun -n %(n)s -N %(N)s -d 1 -b cyclus_script.sh
  28. """
  29.  
  30. def render_cyclus_script(out_type="sqlite", in_dir=".", out_dir=".",
  31. log_dir="."):
  32. rendered_cyclus_script = dedent(CYCLUS_SCRIPT) % {"in_dir" : in_dir,
  33. "out_dir" : out_dir, "out_type" : out_type,
  34. "log_dir" : log_dir}
  35.  
  36. return rendered_cyclus_script.strip()
  37.  
  38. def render_pbs_script(nodes, ppn, walltime):
  39. rendered_pbs_script = dedent(PBS_SCRIPT) % {"nodes" : str(nodes), "ppn" : str(ppn),
  40. "walltime" : walltime, "n" : str(nodes*ppn), "N" : str(ppn)}
  41.  
  42. return rendered_pbs_script.strip()
  43.  
  44. def write_to_files(cyclus_script, pbs_script):
  45. with open("cyclus_script.sh", "w+") as f:
  46. f.write(cyclus_script)
  47.  
  48. with open("pbs_script.pbs", "w+") as f:
  49. f.write(pbs_script)
  50.  
  51. if __name__ == "__main__":
  52. parser = ArgumentParser()
  53. parser.add_argument('--nodes', dest='nodes', type=int,
  54. help='Number of nodes', default=1)
  55. parser.add_argument('--ppn', dest='ppn', type=int,
  56. help='Number of processors per node', default=1)
  57. parser.add_argument('--walltime', dest="walltime", type=str,
  58. help='Wall time', default='00:01:00')
  59. parser.add_argument('-o', dest='out_type', type=str,
  60. help='Output type', choices=['sqlite', 'h5'],
  61. default='sqlite')
  62. parser.add_argument('--in-dir', dest="in_dir", type=str,
  63. help='Inputs directory', default='.')
  64. parser.add_argument('--out-dir', dest="out_dir", type=str,
  65. help='Outputs directory', default='.')
  66. parser.add_argument('--log-dir', dest="log_dir", type=str,
  67. help='Logs directory', default='.')
  68.  
  69.  
  70. args = parser.parse_args()
  71.  
  72. cyclus_script = render_cyclus_script(out_type=args.out_type,
  73. in_dir=args.in_dir, out_dir=args.out_dir, log_dir=args.log_dir)
  74.  
  75. pbs_script = render_pbs_script(args.nodes, args.ppn, args.walltime)
  76.  
  77. write_to_files(cyclus_script, pbs_script)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement