From d74522ba65f5d0e33c210d4fb2f18919793bdad6 Mon Sep 17 00:00:00 2001 From: Yannick Augenstein Date: Mon, 6 Mar 2023 09:21:18 +0100 Subject: [PATCH 1/2] Add MEEP_VERBOSITY_LEVEL and MPB_VERBOSITY_LEVEL environment variables to set default verbosity level at initialization --- python/meep.i | 5 +++-- python/mpb.i | 3 ++- python/simulation.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/python/meep.i b/python/meep.i index 2a9da2bd8..663f9e99d 100644 --- a/python/meep.i +++ b/python/meep.i @@ -1870,8 +1870,9 @@ PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where comm = MPI.COMM_WORLD if am_master(): Procs=comm.Get_size() - (Major,Minor)=MPI.Get_version(); - print('Using MPI version {}.{}, {} processes'.format(Major, Minor, Procs)); + (Major,Minor)=MPI.Get_version() + if verbosity.meep > 0: + print('Using MPI version {}.{}, {} processes'.format(Major, Minor, Procs)) if not am_master(): import os diff --git a/python/mpb.i b/python/mpb.i index fcab607ea..2e33769dd 100644 --- a/python/mpb.i +++ b/python/mpb.i @@ -356,8 +356,9 @@ const int MPB_VERSION_PATCH; %pythoncode %{ __version__ = (_mpb.cvar.MPB_VERSION_MAJOR, _mpb.cvar.MPB_VERSION_MINOR, _mpb.cvar.MPB_VERSION_PATCH) + import os from meep.verbosity_mgr import Verbosity - verbosity = Verbosity(_mpb.cvar, 'mpb', 1) + verbosity = Verbosity(_mpb.cvar, 'mpb', int(os.getenv("MPB_VERBOSITY_LEVEL", 1))) from .solver import ( MPBArray, diff --git a/python/simulation.py b/python/simulation.py index e693cd7d7..19483bb9d 100644 --- a/python/simulation.py +++ b/python/simulation.py @@ -43,7 +43,7 @@ from matplotlib.axes import Axes -verbosity = Verbosity(mp.cvar, "meep", 1) +verbosity = Verbosity(mp.cvar, "meep", int(os.getenv("MEEP_VERBOSITY_LEVEL", 1))) mp.setup() From 1d6d416d5431ee2fad43310c7e8f3fe3dc0056f5 Mon Sep 17 00:00:00 2001 From: Yannick Augenstein Date: Mon, 6 Mar 2023 09:35:09 +0100 Subject: [PATCH 2/2] Add MEEP_MPI_SILENCE_WORKERS environment variable to optionally enable stdout from all meep workers --- python/meep.i | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/python/meep.i b/python/meep.i index 663f9e99d..07606f49d 100644 --- a/python/meep.i +++ b/python/meep.i @@ -1866,20 +1866,19 @@ PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where print('\n**\n** failed to load python MPI module (mpi4py)\n**', e, '\n**\n') pass else: - # this variable reference is needed for lazy initialization of MPI - comm = MPI.COMM_WORLD - if am_master(): - Procs=comm.Get_size() - (Major,Minor)=MPI.Get_version() - if verbosity.meep > 0: - print('Using MPI version {}.{}, {} processes'.format(Major, Minor, Procs)) - - if not am_master(): - import os + import os + if not am_master() and os.getenv("MEEP_MPI_SILENCE_WORKERS", "true").lower() in ("true", "1"): import sys saved_stdout = sys.stdout sys.stdout = open(os.devnull, 'w') + # this variable reference is needed for lazy initialization of MPI + comm = MPI.COMM_WORLD + Procs = comm.Get_size() + Major, Minor = MPI.Get_version() + if verbosity.meep > 0: + print('Using MPI version {}.{}, {} processes'.format(Major, Minor, Procs)) + vacuum = Medium(epsilon=1) air = Medium(epsilon=1) metal = Medium(epsilon=-inf)