/scheduler/simulations/run_DetailedNetworkSim.py

https://gitlab.com/pranith/sst-elements · Python · 112 lines · 82 code · 16 blank · 14 comment · 5 complexity · 5c5fa60a4536822a9421e129715cd622 MD5 · raw file

  1. #!/usr/bin/env python
  2. '''
  3. Date : 08/04/2015
  4. Created by : Fulya Kaplan
  5. Description : This main python script runs scheduler and ember simulations successively until completion.
  6. '''
  7. import os, sys
  8. from xml.dom.minidom import parse
  9. import xml.dom.minidom
  10. from optparse import OptionParser
  11. import math
  12. import numpy as np
  13. # Function to run linux commands
  14. def run(cmd):
  15. #print(cmd)
  16. os.system(cmd)
  17. def clear_files(options):
  18. erFile = open(options.emberRunningFile, 'w')
  19. ecFile = open(options.emberCompletedFile, 'w')
  20. erFile.close()
  21. ecFile.close()
  22. def delete_logs():
  23. cmd = "rm motif*.log"
  24. run(cmd)
  25. def run_sim (options):
  26. # Run scheduler for the first time and create the first snapshot
  27. init_cmd = "sst ./%s" %(options.schedPythonFile)
  28. run(init_cmd)
  29. # Do the following in a loop until the simulation is completed
  30. # Parse scheduler snapshot->run ember->Parse ember output->run scheduler->...
  31. while( is_not_empty(options.xmlFile) ):
  32. ember_cmd = "./%s --xml %s > %s" %(options.sched_parser, options.xmlFile, options.emberOutFile)
  33. run(ember_cmd)
  34. sched_cmd = "./%s --xml %s --emberOut %s --schedPy %s --ember_completed %s --ember_running %s " %(options.ember_parser, options.xmlFile, options.emberOutFile, options.schedPythonFile, options.emberCompletedFile, options.emberRunningFile)
  35. run(sched_cmd)
  36. delete_logs()
  37. def is_not_empty(fileName):
  38. try:
  39. if os.stat(fileName).st_size > 0:
  40. return True
  41. else:
  42. return False
  43. except OSError:
  44. print "No file"
  45. '''
  46. def set_path_emberLoad(options):
  47. emberpath="/home/fkaplan/SST/scratch/src/sst-simulator/sst/elements/ember/test"
  48. cmd = "sed -i \"s|PATH|%s|g\" emberLoad.py" %(emberpath)
  49. print cmd
  50. run(cmd)
  51. '''
  52. def grep_set_fileNames(options):
  53. # Parser script names are defined by default
  54. options.sched_parser = "snapshotParser_sched.py"
  55. options.ember_parser = "snapshotParser_ember.py"
  56. # Grep other file names from the scheduler input configuration file
  57. traceFile = open(options.schedPythonFile, 'r')
  58. for line in traceFile:
  59. if "traceName" in line:
  60. temp = line.split(':')[1]
  61. temp = temp.split('\"')[1]
  62. options.xmlFile = temp + ".snapshot.xml"
  63. elif "completedJobsTrace" in line:
  64. temp = line.split(':')[1]
  65. temp = temp.split('\"')[1]
  66. options.emberCompletedFile = temp
  67. elif "runningJobsTrace" in line:
  68. temp = line.split(':')[1]
  69. temp = temp.split('\"')[1]
  70. options.emberRunningFile = temp
  71. traceFile.close()
  72. return (options)
  73. def main():
  74. parser = OptionParser(usage="usage: %prog [options]")
  75. parser.add_option("--emberOut", action='store', dest="emberOutFile", help="Name of the ember output file.")
  76. parser.add_option("--schedPy", action='store', dest="schedPythonFile", help="Name of the python file that holds the scheduler parameters.")
  77. (options, args) = parser.parse_args()
  78. options = grep_set_fileNames(options)
  79. clear_files(options)
  80. #set_path_emberLoad(options)
  81. run_sim(options)
  82. if __name__ == '__main__':
  83. main()