|
| 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 |
| 33 | +from Utility import * |
| 34 | + |
| 35 | + |
| 36 | +nthreads = np.arange(0,46,2) |
| 37 | +GridSizes = np.zeros([len(nthreads), 2]) |
| 38 | +nthreads[0] = 1 |
| 39 | +nthreads[1] = 3 |
| 40 | +GridSizes[0:13, :] = ([4,2], [6,4], [8,4], [8,6],[8,8], [10,8],[12, 8],[16,7], |
| 41 | + [16,8], [12,12], [20,8], [16,11], [16,12]) |
| 42 | +for i in range(13, len(GridSizes)): |
| 43 | + GridSizes[i, :] = [(i)*2, 8] |
| 44 | + problem_size= GridSizes[:,0]*GridSizes[:,1] |
| 45 | + |
| 46 | +execute_time = np.zeros([len(nthreads), 4]) |
| 47 | +# Integration period in seconds. |
| 48 | +IntegrationPeriod = 25 |
| 49 | +IntegrationNsteps = 50 |
| 50 | +# Path to the C++ executable. |
| 51 | +AMDADOS_EXE = "build/mpi_amdados" |
| 52 | + |
| 53 | + |
| 54 | +if __name__ == "__main__": |
| 55 | + try: |
| 56 | + # Read configuration file. |
| 57 | + conf = Configuration("amdados.conf") |
| 58 | + # Create the output directory, if it does not exist. |
| 59 | + if not os.path.isdir(conf.output_dir): |
| 60 | + os.mkdir(conf.output_dir) |
| 61 | + # Check existence of "amdados" application executable. |
| 62 | + assert os.path.isfile(AMDADOS_EXE), "amdados executable was not found" |
| 63 | + |
| 64 | + # For all the grid sizes in the list ... |
| 65 | + exe_time_profile = np.zeros((len(GridSizes),2)) |
| 66 | + for i in range(0, len(nthreads)): |
| 67 | + grid = GridSizes[i] |
| 68 | + Nproc = nthreads[i] |
| 69 | + # Modify parameters given the current grid size. |
| 70 | + setattr(conf, "num_subdomains_x", int(grid[0])) |
| 71 | + setattr(conf, "num_subdomains_y", int(grid[1])) |
| 72 | + setattr(conf, "integration_period", int(IntegrationPeriod)) |
| 73 | + setattr(conf, "integration_nsteps", int(IntegrationNsteps)) |
| 74 | + InitDependentParams(conf) |
| 75 | + conf.PrintParameters() |
| 76 | + config_file = conf.WriteParameterFile("scalability_test.conf") |
| 77 | + os.sync() |
| 78 | + # Python simulator generates the ground-truth and observations. |
| 79 | + Amdados2D(config_file, False) |
| 80 | + |
| 81 | + # Get the starting time. |
| 82 | + start_time = timer() |
| 83 | + |
| 84 | + # Run C++ data assimilation application. |
| 85 | + print("##################################################") |
| 86 | + print("Simulation by 'amdados' application for series of hpx threads") |
| 87 | + print("Initial simulations for Oceans paper") |
| 88 | + print("##################################################") |
| 89 | + print(AMDADOS_EXE, config_file) |
| 90 | + print("NPROC =", str(Nproc)) |
| 91 | + output = subprocess.Popen(["mpirun", "--allow-run-as-root", "-np", str(Nproc), |
| 92 | + "./build/mpi_amdados", "--scenario", "simulation", "--config", config_file], stdout=subprocess.PIPE) |
| 93 | + output.wait() |
| 94 | + assert output.returncode == 0, "amdados returned non-zero status" |
| 95 | + |
| 96 | + # Strip the execution time from stdout, both total simulation time |
| 97 | + # and throughput (subdomain/s) |
| 98 | + strip_output = str(output.communicate()[0]).split('\\n') |
| 99 | + for line in strip_output: |
| 100 | + if re.search("Simulation took", line): |
| 101 | + simtime_string = line |
| 102 | + if re.search("Throughput", line): |
| 103 | + throughput_string = line |
| 104 | + print('simtime read =', simtime_string) |
| 105 | + print('simtime string =', simtime_string.split(' ')[2][:-1]) |
| 106 | + print('throughput string =', throughput_string.split(' ')[1]) |
| 107 | + |
| 108 | + simtime_secs = float(simtime_string.split(' ')[2][:-1]) |
| 109 | + throughput_secs = float(throughput_string.split(' ')[1]) |
| 110 | + |
| 111 | + |
| 112 | + # Get the execution time and corresponding (global) problem size |
| 113 | + # and save the current scalability profile into the file. |
| 114 | + problem_size = ( conf.num_subdomains_x * conf.num_subdomains_y ) |
| 115 | + execute_time[i, :] = [problem_size, Nproc, simtime_secs, throughput_secs] |
| 116 | + np.savetxt(os.path.join(conf.output_dir, "scalability_performance_MPI.txt"), |
| 117 | + execute_time) |
| 118 | + |
| 119 | + except subprocess.CalledProcessError as error: |
| 120 | + traceback.print_exc() |
| 121 | + if error.output is not None: |
| 122 | + print("ERROR: " + str(error.output)) |
| 123 | + else: |
| 124 | + print("CalledProcessError") |
| 125 | + except AssertionError as error: |
| 126 | + traceback.print_exc() |
| 127 | + print("ERROR: " + str(error.args)) |
| 128 | + except ValueError as error: |
| 129 | + traceback.print_exc() |
| 130 | + print("ERROR: " + str(error.args)) |
| 131 | + except Exception as error: |
| 132 | + traceback.print_exc() |
| 133 | + print("ERROR: " + str(error.args)) |
| 134 | + |
0 commit comments