PySDM_examples.Arabas_et_al_2015.example_benchmark
1import importlib 2 3from matplotlib import pyplot as plt 4from PySDM_examples.Arabas_et_al_2015 import Settings 5from PySDM_examples.Szumowski_et_al_1998 import Simulation, Storage 6 7import PySDM.backends.impl_numba.conf 8from PySDM import Formulae 9from PySDM.backends import CPU, GPU 10from PySDM.products import WallTime 11 12 13def reload_cpu_backend(): 14 importlib.reload(PySDM.backends.impl_numba.methods.collisions_methods) 15 importlib.reload(PySDM.backends.impl_numba.methods.displacement_methods) 16 importlib.reload(PySDM.backends.impl_numba.methods.moments_methods) 17 importlib.reload(PySDM.backends.impl_numba.methods.index_methods) 18 importlib.reload(PySDM.backends.impl_numba.methods.pair_methods) 19 importlib.reload(PySDM.backends.impl_numba.methods.physics_methods) 20 importlib.reload(PySDM.backends.impl_numba.methods.chemistry_methods) 21 importlib.reload(PySDM.backends.impl_numba.storage_impl) 22 importlib.reload(PySDM.backends.impl_numba.atomic_operations) 23 importlib.reload(PySDM.backends) 24 25 26def main(): 27 settings = Settings(Formulae()) 28 29 settings.grid = (25, 25) 30 settings.simulation_time = settings.dt * 100 31 settings.output_interval = settings.dt * 10 32 settings.processes = { 33 "particle advection": True, 34 "fluid advection": True, 35 "coalescence": True, 36 "condensation": False, 37 "sedimentation": True, 38 "freezing": False, 39 "breakup": False, 40 } 41 42 n_sd = range(14, 16, 1) 43 44 times = {} 45 backends = [(CPU, "sync"), (CPU, "async")] 46 if GPU.ENABLE: 47 backends.append((GPU, "async")) 48 for backend, mode in backends: 49 if backend is CPU: 50 PySDM.backends.impl_numba.conf.NUMBA_PARALLEL = mode 51 reload_cpu_backend() 52 key = f"{backend} (mode={mode})" 53 times[key] = [] 54 for sd in n_sd: 55 settings.n_sd_per_gridbox = sd 56 storage = Storage() 57 simulation = Simulation(settings, storage, None, backend) 58 simulation.reinit(products=[WallTime()]) 59 simulation.run() 60 times[key].append(storage.load("wall time")[-1]) 61 62 for parallelization, t in times.items(): 63 plt.plot(n_sd, t, label=parallelization) 64 plt.legend() 65 plt.loglog() 66 plt.savefig("benchmark.pdf", format="pdf") 67 68 69if __name__ == "__main__": 70 main()
def
reload_cpu_backend():
14def reload_cpu_backend(): 15 importlib.reload(PySDM.backends.impl_numba.methods.collisions_methods) 16 importlib.reload(PySDM.backends.impl_numba.methods.displacement_methods) 17 importlib.reload(PySDM.backends.impl_numba.methods.moments_methods) 18 importlib.reload(PySDM.backends.impl_numba.methods.index_methods) 19 importlib.reload(PySDM.backends.impl_numba.methods.pair_methods) 20 importlib.reload(PySDM.backends.impl_numba.methods.physics_methods) 21 importlib.reload(PySDM.backends.impl_numba.methods.chemistry_methods) 22 importlib.reload(PySDM.backends.impl_numba.storage_impl) 23 importlib.reload(PySDM.backends.impl_numba.atomic_operations) 24 importlib.reload(PySDM.backends)
def
main():
27def main(): 28 settings = Settings(Formulae()) 29 30 settings.grid = (25, 25) 31 settings.simulation_time = settings.dt * 100 32 settings.output_interval = settings.dt * 10 33 settings.processes = { 34 "particle advection": True, 35 "fluid advection": True, 36 "coalescence": True, 37 "condensation": False, 38 "sedimentation": True, 39 "freezing": False, 40 "breakup": False, 41 } 42 43 n_sd = range(14, 16, 1) 44 45 times = {} 46 backends = [(CPU, "sync"), (CPU, "async")] 47 if GPU.ENABLE: 48 backends.append((GPU, "async")) 49 for backend, mode in backends: 50 if backend is CPU: 51 PySDM.backends.impl_numba.conf.NUMBA_PARALLEL = mode 52 reload_cpu_backend() 53 key = f"{backend} (mode={mode})" 54 times[key] = [] 55 for sd in n_sd: 56 settings.n_sd_per_gridbox = sd 57 storage = Storage() 58 simulation = Simulation(settings, storage, None, backend) 59 simulation.reinit(products=[WallTime()]) 60 simulation.run() 61 times[key].append(storage.load("wall time")[-1]) 62 63 for parallelization, t in times.items(): 64 plt.plot(n_sd, t, label=parallelization) 65 plt.legend() 66 plt.loglog() 67 plt.savefig("benchmark.pdf", format="pdf")