#!/usr/bin/env python import os import sys import datetime # subroutine that runs a shell command def execute_command(shell_command): print(shell_command) status = os.system(shell_command) # subroutine that returns the time since 1970 in seconds to high precision def TimestampSec(): return (datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).total_seconds() def help_me(args, nargs): for arg in args: if (arg.find("-help")!=-1) or (arg.find("--help")!=-1) or (nargs>2): print() print("USAGE options for "+args[0]+":") print(" "+args[0]+" (specify the number of threads; default 1)") print() quit() ########### MAIN program ############ # get arguments args = sys.argv nargs = len(sys.argv) # call a help-me function to print USAGE is necessary help_me(args, nargs) # parse the number of parallel threads n_threads = 1 if nargs == 2: n_threads = args[1] # get start time start_time = TimestampSec() # run parallel program execute_command('export OMP_NUM_THREADS='+str(n_threads)+'; ./omp_test') # get end time and compute total runtime end_time = TimestampSec() print('Runtime: ', end_time - start_time, 's')