|
| 1 | +# Airconds and Advection examples to get partition results using classic partitioners. |
| 2 | + |
| 3 | +# General configuration to access qss-sover methods (the solver needs to be installed first). |
| 4 | +# libconf is needded as an external dep, run: `pip install libconf` first.` |
| 5 | + |
| 6 | +import argparse |
| 7 | +import os |
| 8 | +import sys |
| 9 | + |
| 10 | +MMOC_SRC = os.environ['MMOC_SRC'] |
| 11 | +MMOC_OUTPUT = os.environ['MMOC_OUTPUT'] |
| 12 | +sys.path.append(MMOC_SRC+'/python') |
| 13 | +sys.path.append(MMOC_SRC+'/python/qss_solver') |
| 14 | + |
| 15 | +import qss_solver |
| 16 | +import qss_solver.results as solver_results |
| 17 | +import qss_solver.model as solver_model |
| 18 | +import qss_solver.simulate as solver_sim |
| 19 | + |
| 20 | +def run_experiments(path, model_name): |
| 21 | + # Model constants size. |
| 22 | + model_size = [1000, 10000, 100000, 1000000, 10000000] |
| 23 | + |
| 24 | + # Partitioners |
| 25 | + model_partitioners = ['Metis', 'Scotch'] |
| 26 | + print(path) |
| 27 | + |
| 28 | + model_full_path = path+'/'+model_name+'.mo' |
| 29 | + |
| 30 | + for s in model_size: |
| 31 | + for p in model_partitioners: |
| 32 | + # The parameter should be the full path name if not stored in the solver default folders. |
| 33 | + model_constant = solver_model.constants(model_full_path) |
| 34 | + model_constant['N'] = s |
| 35 | + |
| 36 | + solver_model.set_constants(model_full_path, model_constant) |
| 37 | + model_annotations = solver_model.annotations(model_full_path) |
| 38 | + model_annotations['MMO_PartitionMethod'] = p |
| 39 | + # Store the number of LPS (partitions) we are using. |
| 40 | + lps = model_annotations['MMO_LPS'] |
| 41 | + solver_model.set_annotations(model_full_path, model_annotations) |
| 42 | + |
| 43 | + # Compile the model to generate the excecutabe ini file. |
| 44 | + solver_sim.compile_model(model_full_path) |
| 45 | + |
| 46 | + # Now update the ini file to set the 'partitionOnly' flag to avoid running the simulation. |
| 47 | + model_config = solver_model.config(model_name) |
| 48 | + model_config['partitionOnly'] = 1 |
| 49 | + solver_model.set_config(model_name, model_config) |
| 50 | + |
| 51 | + # Now go ahead and execute the model. |
| 52 | + solver_sim.execute_model(model_full_path) |
| 53 | + |
| 54 | + # Finally, get the partitioner stats into a dict. |
| 55 | + # Full size of the advection model. |
| 56 | + model_full_size = s |
| 57 | + if model_name == 'airconds': |
| 58 | + # Update full size for airconds model. |
| 59 | + model_full_size = s*4 |
| 60 | + partitioner_log_file = model_name+'-'+str(model_full_size)+'-'+lps+'-partition-stats.log' |
| 61 | + partition_log = solver_results.simulation_log(MMOC_OUTPUT+'/'+model_name+'/'+partitioner_log_file) |
| 62 | + print('Partition method: '+ p) |
| 63 | + print('Model size: ' + str(s)) |
| 64 | + print('Results') |
| 65 | + print(partition_log) |
| 66 | + |
| 67 | + |
| 68 | +# Example usage: python3 ./airconds_experimets.py /home/joaquin/work/sbg-partitioner/src/external_tools/experiments/airconds airconds |
| 69 | + |
| 70 | +def main(): |
| 71 | + parser = argparse.ArgumentParser(description='Run experiments for classic partitioners.') |
| 72 | + parser.add_argument('path', type=str, help='Full path to the folder where the airconds model .mo file is located.') |
| 73 | + parser.add_argument('model_name', type=str, help='Model name whitout .mo extension. It should be one of \'advection\' or \'airconds\'') |
| 74 | + |
| 75 | + args = parser.parse_args() |
| 76 | + |
| 77 | + run_experiments(args.path, args.model_name) |
| 78 | + |
| 79 | +if __name__ == '__main__': |
| 80 | + main() |
0 commit comments