|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# Author : Albert Akhriev, albert_akhriev@ie.ibm.com |
| 3 | +# Copyright : IBM Research Ireland, 2017-2018 |
| 4 | +# ----------------------------------------------------------------------------- |
| 5 | + |
| 6 | +""" This script runs several simulations with increasing problem size |
| 7 | + utilizing all available CPUs. It saves the execution time of each |
| 8 | + simulation in a file that can be used to plot the scalability profile. |
| 9 | + Essential parameters, listed in the first lines, include the set of |
| 10 | + problem sizes and integration period. |
| 11 | + Each simulation is twofold. First, we run the Python forward solver that |
| 12 | + generates the ground-truth and observations ("ObservationsGenerator.py"). |
| 13 | + The Python code itself uses the C++ code running in the special mode for |
| 14 | + generating sensor locations (scenario "sensors"). Second, the C++ data |
| 15 | + assimilation application is launched (scenario "simulation") with |
| 16 | + observations generated by "ObservationsGenerator.py". |
| 17 | + The results of all the simulations are accumulated in the output |
| 18 | + directory and can be visualized later on by the script "Visualize.py". |
| 19 | + The configuration file "amdados.conf" is used in all the simulations with |
| 20 | + modification of three parameters: grid sizes (number of subdomains) in both |
| 21 | + dimensions and integration time. Other parameters remain intact. It is not |
| 22 | + recommended to tweak parameters unless their meaning is absolutely clear. |
| 23 | + If you had modified the parameters, please, consider to rerun this script |
| 24 | + because the results in the output directory a not valid any longer. |
| 25 | + The script was designed to fulfil the formal requirements of the |
| 26 | + Allscale project. |
| 27 | +""" |
| 28 | +print(__doc__) |
| 29 | + |
| 30 | +from timeit import default_timer as timer |
| 31 | +import os, cmd |
| 32 | +from RandObservationsGenerator import InitDependentParams, Amdados2D_quick |
| 33 | +from Utility import * |
| 34 | +import argparse |
| 35 | + |
| 36 | + |
| 37 | +# Get subdomain sizes as multiplier factors |
| 38 | + |
| 39 | +## read arguments describing filename, number of nodes and number of threads |
| 40 | +########################## |
| 41 | +# Arguments and settings # |
| 42 | +########################## |
| 43 | +parser = argparse.ArgumentParser() |
| 44 | +parser.add_argument('filename', type=str, help='filename to write scalability results to') |
| 45 | +parser.add_argument('nnodes', type=int, help='number of nodes to execute on') |
| 46 | +parser.add_argument('nthreads', type=int, help='number of threads per node') |
| 47 | +parser.add_argument('ndomains', type=int, help='number of subdomains') |
| 48 | +args = parser.parse_args() |
| 49 | + |
| 50 | +ResultsFileName = args.filename |
| 51 | +number_of_nodes = args.nnodes |
| 52 | +nthreads = args.nthreads |
| 53 | +grid = args.ndomains |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +# Integration period in seconds. |
| 58 | +IntegrationPeriod = 25 |
| 59 | +IntegrationNsteps = 50 |
| 60 | + |
| 61 | +# Configurations for Monitoring and resilience to test |
| 62 | +MONITORING = [0] |
| 63 | +RESILIENCE = [0] |
| 64 | + |
| 65 | + |
| 66 | +# Path to the C++ executable. |
| 67 | +AMDADOS_EXE = os.path.join(os.getcwd(),"targetcode/amdados_cc") |
| 68 | + |
| 69 | +print('filename = ', ResultsFileName) |
| 70 | +print('nnodes = ', number_of_nodes) |
| 71 | +print('nthreads = ', nthreads) |
| 72 | +print('ndomains = ', grid) |
| 73 | + |
| 74 | + |
| 75 | +execute_time = np.zeros([1, 7]) |
| 76 | + |
| 77 | +if __name__ == "__main__": |
| 78 | + try: |
| 79 | + # Read configuration file. |
| 80 | + conf = Configuration(os.path.join(os.getcwd(),"amdados.conf")) |
| 81 | + # Create the output directory, if it does not exist. |
| 82 | + conf.output_dir = os.path.join(os.getcwd(),conf.output_dir) |
| 83 | + if not os.path.isdir(conf.output_dir): |
| 84 | + os.mkdir(conf.output_dir) |
| 85 | + # Check existence of "amdados" application executable. |
| 86 | + assert os.path.isfile(AMDADOS_EXE), "amdados executable was not found" |
| 87 | + ## open scalability file and add header |
| 88 | +# HeaderTxt = ["ProblemSize,NNodes, NThreads, ALLSCALE_MONITOR, ALLSCALE_RESILIENCE, TotalRuntime, Throughput(Sdom/s)"] |
| 89 | + time_file = os.path.join(conf.output_dir, ResultsFileName) |
| 90 | + f = open(time_file, 'ab') |
| 91 | + i = 0 |
| 92 | + |
| 93 | + # Modify parameters given the current grid size. |
| 94 | + setattr(conf, "num_subdomains_x", int(grid)) |
| 95 | + setattr(conf, "num_subdomains_y", int(grid)) |
| 96 | + setattr(conf, "integration_period", int(IntegrationPeriod)) |
| 97 | + setattr(conf, "integration_nsteps", int(IntegrationNsteps)) |
| 98 | + InitDependentParams(conf) |
| 99 | + conf.PrintParameters() |
| 100 | + config_file = conf.WriteParameterFile(os.path.join(conf.output_dir,"scalability_test.conf")) |
| 101 | + os.sync() |
| 102 | + # Get the starting time. |
| 103 | + start_time = timer() |
| 104 | + |
| 105 | + # Run C++ data assimilation application. |
| 106 | + for MonitorFlag in MONITORING: |
| 107 | + for ResilienceFlag in RESILIENCE: |
| 108 | + print("##################################################") |
| 109 | + print("Testing Framework for AllScale project") |
| 110 | + print("Simulation by 'amdados' to check scalability and correctness") |
| 111 | + print("Testing Configuration Setup") |
| 112 | + print("GridSize =", grid, "ALLSCALE_MONITOR = ", MonitorFlag, |
| 113 | + "ALLSCALE_RESILIENCE = ", ResilienceFlag) |
| 114 | + print("##################################################") |
| 115 | + print(AMDADOS_EXE, config_file) |
| 116 | + output = subprocess.Popen(["aprun", "-n" +str(number_of_nodes), "-d" + str(nthreads), |
| 117 | + AMDADOS_EXE, "--scenario", "benchmark:" +str(grid),"--config", config_file, |
| 118 | + "--hpx:threads=" + str(nthreads), "--hpx:bind=none"], stdout=subprocess.PIPE, |
| 119 | + env=dict(os.environ, ALLSCALE_MONITOR=str(MonitorFlag), ALLSCALE_RESILIENCE=str(ResilienceFlag))) |
| 120 | + output.wait() |
| 121 | + # Strip the execution time from stdout, both total simulation time |
| 122 | + # and throughput (subdomain/s) |
| 123 | + strip_output = str(output.communicate()[0]).split('\\n') |
| 124 | + for line in strip_output: |
| 125 | + if re.search("Simulation", line): |
| 126 | + simtime_string = line |
| 127 | + if re.search("Throughput", line): |
| 128 | + throughput_string = line |
| 129 | + simtime_secs = float(simtime_string.split(' ')[2][:-1]) |
| 130 | + throughput_secs = float(throughput_string.split(' ')[1]) |
| 131 | + |
| 132 | + # Get the execution time and corresponding (global) problem size |
| 133 | + # and save the current scalability profile into the file. |
| 134 | + problem_size = ( conf.num_subdomains_x * conf.num_subdomains_y ) |
| 135 | + execute_time[0, :] = [problem_size, number_of_nodes, nthreads, MonitorFlag, ResilienceFlag, simtime_secs, throughput_secs] |
| 136 | + i += 1 |
| 137 | + np.savetxt(f, execute_time) |
| 138 | + f.close() |
| 139 | + except subprocess.CalledProcessError as error: |
| 140 | + traceback.print_exc() |
| 141 | + if error.output is not None: |
| 142 | + print("ERROR: " + str(error.output)) |
| 143 | + else: |
| 144 | + print("CalledProcessError") |
| 145 | + except AssertionError as error: |
| 146 | + traceback.print_exc() |
| 147 | + print("ERROR: " + str(error.args)) |
| 148 | + except ValueError as error: |
| 149 | + traceback.print_exc() |
| 150 | + print("ERROR: " + str(error.args)) |
| 151 | + except Exception as error: |
| 152 | + traceback.print_exc() |
| 153 | + print("ERROR: " + str(error.args)) |
| 154 | + |
0 commit comments