def run_experiment(ncores, codebase, diag, namelist, resolution, exp_name, codebase_name): """ Measure the time taken to complete the experiment :param ncores: Number of processor cores to be used :param codebase: One of: Held-Suarez, Grey-Mars :param diag: Diagnostics :param namelist: Namelist file :param resolution: Resolution of simulatin. One of: T21, T42, T85 :param exp_name: Name of the experiment :param codebase_name: Name of the codebase """ runs = 0 if codebase_name == constants.HELD_SUAREZ: runs = 13 elif codebase_name == constants.GREY_MARS: runs = 23 exp = Experiment(f'{exp_name}', codebase=codebase) exp.rm_datadir() exp.clear_rundir() exp.diag_table = diag exp.namelist = namelist.copy() exp.set_resolution(*resolution) start = time.time() print(exp.namelist) exp.run(1, use_restart=False, num_cores=ncores) end = time.time() time_delta = end - start data = [ncores, resolution[0], 1, time_delta] write_to_csvfile(f'{constants.GFDL_BENCH}/{exp_name}', data) for i in range( 2, runs ): # 13 as there are 12 months (12+1=13)(241 for grey_mars) / (13 for held_suarez) start = time.time() exp.run(i, num_cores=ncores) end = time.time() time_delta = end - start data = [ncores, resolution[0], i, time_delta] write_to_csvfile(f'{constants.GFDL_BENCH}/{exp_name}', data)
diag.add_field('dynamics', 'ps', time_avg=True) diag.add_field('dynamics', 'bk') diag.add_field('dynamics', 'pk') diag.add_field('atmosphere', 'precipitation', time_avg=True) diag.add_field('mixed_layer', 't_surf', time_avg=True) diag.add_field('dynamics', 'sphum', time_avg=True) diag.add_field('dynamics', 'ucomp', time_avg=True) diag.add_field('dynamics', 'vcomp', time_avg=True) diag.add_field('dynamics', 'temp', time_avg=True) diag.add_field('dynamics', 'vor', time_avg=True) diag.add_field('dynamics', 'div', time_avg=True) exp.diag_table = diag #Empty the run directory ready to run exp.clear_rundir() #Define values for the 'core' namelist exp.namelist = namelist = Namelist({ 'main_nml': { 'days': 30, 'hours': 0, 'minutes': 0, 'seconds': 0, 'dt_atmos': 720, 'current_date': [1, 1, 1, 0, 0, 0], 'calendar': 'thirty_day' }, 'idealized_moist_phys_nml': { 'do_damping': True, 'turb': True,