Ejemplo n.º 1
0
def getData(exename, launcher, path=None, batchFile = "", \
            inputDecks=[], usesMPI=False, \
            usesOpenMP=False, usesPthreads=False, appname=None, format="old",CNLfixUp=False, ptDataDir="",exportEnvAtLaunch=False):

    uname_res = os.uname()
    run_OS_name = uname_res[0]
    run_OS_release_type = uname_res[2]
    run_OS_release_version = uname_res[3]
    globals()["OS_name"] = run_OS_name

    #what user is running this command
    userName = os.getenv('USER')

    # things we are expecting to get from parsing the launch command
    # or batch file:
    # machine name
    # number of processes, number of threads, processes per node,
    # partition job run on
    sub = Submission()
    okay = sub.getInfo(launcher,batchFile)
    if not okay:
       print "parsing of submission information failed"
       sys.exit(0)

    run_machine = sub.getRunMachine()
    numberOfProcesses = sub.getNumberOfProcesses()
    processesPerNode = sub.getProcessesPerNode()
    numberOfThreads = sub.getNumberOfThreads()
    numberOfNodes  = sub.getNumberOfNodes()
    if numberOfThreads == -1 and usesOpenMP == True:
       # default OMP_NUM_THREADS is number of cpus per node
       numberOfThreads = sub.getCpusPerNode() 
    elif numberOfThreads == -1:
       numberOfThreads = 1
       
       

    #print "runmachine="+str(run_machine)+ " usesMPI="+str(usesMPI) +" usesOpenMP="+ str(usesOpenMP) + " usesPthreads="+ str(usesPthreads) +" numberOfProcesses=" +str(numberOfProcesses) + " numberOfThreads="+ str(numberOfThreads) 

    #print "runmachine="+str(run_machine)
    #print " usesMPI="+str(usesMPI) 
    #print " usesOpenMP="+ str(usesOpenMP) 
    #print  " usesPthreads="+ str(usesPthreads) 
    #print " numberOfProcesses=" +str(numberOfProcesses) 
    #print  " numberOfThreads="+ str(numberOfThreads) 
           

    # Grab env vars to put in DB => runEnv
    (result, output) = commands.getstatusoutput('env')
    if (result != 0):
        print  'environment (\'env\') command failed with error: ' + str(result)
        print output
        sys.exit(2)
    # for simplicity, runEnvVars is a string of (envVar=value) separated by
    # '@@@'  e.g. envVar1=value1@@@envVar2=value2@@@envVar3=value3
    runEnvVars = output.replace("\n","@@@")

    page_size = os.sysconf('SC_PAGESIZE') #TODO double check this size has consistent units across platforms.
    if(path): 
       dynLibs = getDynamicLibs([path])
    else:
       dynLibs = getDynamicLibs([exename])


    # this gets file system information
    fs = fsInfo() 
    fs.getInfo()


    # if we're running on a Cray XT machine, the compute nodes may be running
    # compute node linux, while the login nodes are running regular  linux
    # we want to add some commands to the batch file to get some data 
    # directly from the compute nodes
    if(CNLfixUp):
       tmpBatch = "%s.ptBatch" % batchFile
       cmds = ""
       cmds += "aprun -n 1 uname -s > %s/out.uname ;" % ptDataDir
       cmds += "aprun -n 1 uname -r >> %s/out.uname ;" % ptDataDir
       cmds += "aprun -n 1 uname -v >> %s/out.uname ;" % ptDataDir
       cmds += "aprun -n 1 env > %s/out.env ;" % ptDataDir
       cmds += "ptCNLfix.py %s" % ptDataDir
       #sedcmd = "'s/PERFTRACK_CMDS/%s/g' %s > %s" % (cmds,batchFile,tmpBatch)
       my_exec2("cp %s %s" % (batchFile,tmpBatch), "")
       my_exec2('echo "%s" >>' % cmds, tmpBatch)
       batchFile = tmpBatch


    # get the current date and time in ISO format 
    launchTime = string.split(str(datetime.datetime.isoformat( \
                                     datetime.datetime.now())), '.')[0]


    # get input deck information
    # TODO fix this so that we can get the relevant information out from
    # the input decks - somehow. perhaps provide an interface to enter
    # name, value pairs for important input information, such as x=192 or 
    # weather=cloudy
    # for now, we are just recording the names of the files and their 
    # modification date.
    # oh, and we expect the input files to exist in the current working 
    # directory , or be given a complete path to the file
    
    iDecks= getInputDecks(inputDecks)

    # launch the job
    if launcher == "lcrm":
      (out, err, retval) = my_exec2("psub", batchFile)
      print out
      print err
    elif launcher == "pbs":
      #print "NOT LAUNCHING"
      if (CNLfixUp or exportEnvAtLaunch):
        (out, err, retval) = my_exec2("qsub -V", batchFile)
      else:
        (out, err, retval) = my_exec2("qsub", batchFile)
      print out
      print err 

    elif launcher == "mpirun":
      mpirunArgs = sub.getLauncherArgs()
      (out, err, retval) = my_exec2("mpirun", mpirunArgs)
      print out
      print err 
        

    # output data 
    if format == "PERIxml":
        filename = "perftrack_run_" + exename + "_" \
               + launchTime.replace(" ","") + "." + run_machine+ ".xml"

        if path:
           exeName = path
        else:
           exeName = exename
        printInPERIformat(filename,launchTime, userName, appname, exeName,run_machine, run_OS_name, run_OS_release_version, run_OS_release_type, runEnvVars, page_size, str(numberOfNodes), str(numberOfProcesses), str(processesPerNode), str(numberOfThreads), str(usesMPI), str(usesOpenMP), str(usesPthreads), sub, fs, dynLibs, iDecks ) 
        return filename

    if(exename == None):
       print "no exeName specified. Error"  
       sys.exit(1)
    filename = "perftrack_run_" + exename + "_" + launchTime.replace(" ","") \
               + "." + run_machine+ ".txt"
    file = open(filename,'w')
    file.write("RunDataBegin\n")
    file.write("LaunchDateTime=" + launchTime +"\n") 
    file.write("UserName="******"\n")
    if appname:
       file.write("ApplicationName=" + appname + "\n")
    if path:
       file.write("ExecutableName=" + path + "\n")
    else:
       file.write("ExecutableName=" + exename + "\n")
    file.write("RunMachine=" + run_machine + "\n")
    file.write("RunOSName=" + run_OS_name + "\n")
    file.write("RunOSReleaseVersion=" + run_OS_release_version + "\n" )
    file.write("RunOSReleaseType=" + run_OS_release_type + "\n")
    file.write("RunEnv="+ runEnvVars + "\n") 
    file.write("PageSize=" + str(page_size) + "\n") 
    if numberOfNodes != -1:
      file.write("NumberOfNodes=" + str(numberOfNodes) + "\n")
    if numberOfProcesses != -1:
      file.write("NumberOfProcesses=" + str(numberOfProcesses) + "\n")
    if processesPerNode != -1: # sometimes we can't figure it out
      file.write("ProcessesPerNode=" + str(processesPerNode) + "\n")
    if (usesOpenMP or usesPthreads) and numberOfThreads != -1:
      file.write("ThreadsPerProcess=" + str(numberOfThreads) + "\n")
    file.write("UsesMPI=" + str(usesMPI) +"\n")
    file.write("UsesOpenMP=" + str(usesOpenMP) + "\n")
    file.write("UsesPthreads=" + str(usesPthreads) +"\n")
    file.write(sub.printData())
    file.write(fs.printData())
    for l in dynLibs:
       file.write(l.printData())
    for (f,mt) in iDecks:
       file.write("InputDeckBegin\n")
       file.write("InputDeckName=" + f + "\n")
       file.write("InputDeckModTime=" + mt + "\n")
       file.write("InputDeckEnd\n")
    file.write("RunDataEnd\n")
    file.close()

 
    return filename
Ejemplo n.º 2
0
def getData(exename, launcher, path=None, batchFile = "", \
            inputDecks=[], usesMPI=False, \
            usesOpenMP=False, usesPthreads=False, appname=None, format="old",CNLfixUp=False, ptDataDir="",exportEnvAtLaunch=False):

    uname_res = os.uname()
    run_OS_name = uname_res[0]
    run_OS_release_type = uname_res[2]
    run_OS_release_version = uname_res[3]
    globals()["OS_name"] = run_OS_name

    #what user is running this command
    userName = os.getenv('USER')

    # things we are expecting to get from parsing the launch command
    # or batch file:
    # machine name
    # number of processes, number of threads, processes per node,
    # partition job run on
    sub = Submission()
    okay = sub.getInfo(launcher, batchFile)
    if not okay:
        print "parsing of submission information failed"
        sys.exit(0)

    run_machine = sub.getRunMachine()
    numberOfProcesses = sub.getNumberOfProcesses()
    processesPerNode = sub.getProcessesPerNode()
    numberOfThreads = sub.getNumberOfThreads()
    numberOfNodes = sub.getNumberOfNodes()
    if numberOfThreads == -1 and usesOpenMP == True:
        # default OMP_NUM_THREADS is number of cpus per node
        numberOfThreads = sub.getCpusPerNode()
    elif numberOfThreads == -1:
        numberOfThreads = 1

    #print "runmachine="+str(run_machine)+ " usesMPI="+str(usesMPI) +" usesOpenMP="+ str(usesOpenMP) + " usesPthreads="+ str(usesPthreads) +" numberOfProcesses=" +str(numberOfProcesses) + " numberOfThreads="+ str(numberOfThreads)

    #print "runmachine="+str(run_machine)
    #print " usesMPI="+str(usesMPI)
    #print " usesOpenMP="+ str(usesOpenMP)
    #print  " usesPthreads="+ str(usesPthreads)
    #print " numberOfProcesses=" +str(numberOfProcesses)
    #print  " numberOfThreads="+ str(numberOfThreads)

    # Grab env vars to put in DB => runEnv
    (result, output) = commands.getstatusoutput('env')
    if (result != 0):
        print 'environment (\'env\') command failed with error: ' + str(result)
        print output
        sys.exit(2)
    # for simplicity, runEnvVars is a string of (envVar=value) separated by
    # '@@@'  e.g. envVar1=value1@@@envVar2=value2@@@envVar3=value3
    runEnvVars = output.replace("\n", "@@@")

    page_size = os.sysconf(
        'SC_PAGESIZE'
    )  #TODO double check this size has consistent units across platforms.
    if (path):
        dynLibs = getDynamicLibs([path])
    else:
        dynLibs = getDynamicLibs([exename])

    # this gets file system information
    fs = fsInfo()
    fs.getInfo()

    # if we're running on a Cray XT machine, the compute nodes may be running
    # compute node linux, while the login nodes are running regular  linux
    # we want to add some commands to the batch file to get some data
    # directly from the compute nodes
    if (CNLfixUp):
        tmpBatch = "%s.ptBatch" % batchFile
        cmds = ""
        cmds += "aprun -n 1 uname -s > %s/out.uname ;" % ptDataDir
        cmds += "aprun -n 1 uname -r >> %s/out.uname ;" % ptDataDir
        cmds += "aprun -n 1 uname -v >> %s/out.uname ;" % ptDataDir
        cmds += "aprun -n 1 env > %s/out.env ;" % ptDataDir
        cmds += "ptCNLfix.py %s" % ptDataDir
        #sedcmd = "'s/PERFTRACK_CMDS/%s/g' %s > %s" % (cmds,batchFile,tmpBatch)
        my_exec2("cp %s %s" % (batchFile, tmpBatch), "")
        my_exec2('echo "%s" >>' % cmds, tmpBatch)
        batchFile = tmpBatch

    # get the current date and time in ISO format
    launchTime = string.split(str(datetime.datetime.isoformat( \
                                     datetime.datetime.now())), '.')[0]

    # get input deck information
    # TODO fix this so that we can get the relevant information out from
    # the input decks - somehow. perhaps provide an interface to enter
    # name, value pairs for important input information, such as x=192 or
    # weather=cloudy
    # for now, we are just recording the names of the files and their
    # modification date.
    # oh, and we expect the input files to exist in the current working
    # directory , or be given a complete path to the file

    iDecks = getInputDecks(inputDecks)

    # launch the job
    if launcher == "lcrm":
        (out, err, retval) = my_exec2("psub", batchFile)
        print out
        print err
    elif launcher == "pbs":
        #print "NOT LAUNCHING"
        if (CNLfixUp or exportEnvAtLaunch):
            (out, err, retval) = my_exec2("qsub -V", batchFile)
        else:
            (out, err, retval) = my_exec2("qsub", batchFile)
        print out
        print err

    elif launcher == "mpirun":
        mpirunArgs = sub.getLauncherArgs()
        (out, err, retval) = my_exec2("mpirun", mpirunArgs)
        print out
        print err

    # output data
    if format == "PERIxml":
        filename = "perftrack_run_" + exename + "_" \
               + launchTime.replace(" ","") + "." + run_machine+ ".xml"

        if path:
            exeName = path
        else:
            exeName = exename
        printInPERIformat(filename, launchTime, userName, appname, exeName,
                          run_machine, run_OS_name, run_OS_release_version,
                          run_OS_release_type, runEnvVars, page_size,
                          str(numberOfNodes), str(numberOfProcesses),
                          str(processesPerNode), str(numberOfThreads),
                          str(usesMPI), str(usesOpenMP), str(usesPthreads),
                          sub, fs, dynLibs, iDecks)
        return filename

    if (exename == None):
        print "no exeName specified. Error"
        sys.exit(1)
    filename = "perftrack_run_" + exename + "_" + launchTime.replace(" ","") \
               + "." + run_machine+ ".txt"
    file = open(filename, 'w')
    file.write("RunDataBegin\n")
    file.write("LaunchDateTime=" + launchTime + "\n")
    file.write("UserName="******"\n")
    if appname:
        file.write("ApplicationName=" + appname + "\n")
    if path:
        file.write("ExecutableName=" + path + "\n")
    else:
        file.write("ExecutableName=" + exename + "\n")
    file.write("RunMachine=" + run_machine + "\n")
    file.write("RunOSName=" + run_OS_name + "\n")
    file.write("RunOSReleaseVersion=" + run_OS_release_version + "\n")
    file.write("RunOSReleaseType=" + run_OS_release_type + "\n")
    file.write("RunEnv=" + runEnvVars + "\n")
    file.write("PageSize=" + str(page_size) + "\n")
    if numberOfNodes != -1:
        file.write("NumberOfNodes=" + str(numberOfNodes) + "\n")
    if numberOfProcesses != -1:
        file.write("NumberOfProcesses=" + str(numberOfProcesses) + "\n")
    if processesPerNode != -1:  # sometimes we can't figure it out
        file.write("ProcessesPerNode=" + str(processesPerNode) + "\n")
    if (usesOpenMP or usesPthreads) and numberOfThreads != -1:
        file.write("ThreadsPerProcess=" + str(numberOfThreads) + "\n")
    file.write("UsesMPI=" + str(usesMPI) + "\n")
    file.write("UsesOpenMP=" + str(usesOpenMP) + "\n")
    file.write("UsesPthreads=" + str(usesPthreads) + "\n")
    file.write(sub.printData())
    file.write(fs.printData())
    for l in dynLibs:
        file.write(l.printData())
    for (f, mt) in iDecks:
        file.write("InputDeckBegin\n")
        file.write("InputDeckName=" + f + "\n")
        file.write("InputDeckModTime=" + mt + "\n")
        file.write("InputDeckEnd\n")
    file.write("RunDataEnd\n")
    file.close()

    return filename