From c67c473f0c2d0df5e56d4f0a105d69803ed2994a Mon Sep 17 00:00:00 2001 From: George BIsbas Date: Wed, 17 Jan 2024 15:57:13 +0200 Subject: [PATCH] docs: Use switchconfig with extra condition --- devito/logger.py | 18 +++++++++--------- devito/operator/operator.py | 15 ++++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/devito/logger.py b/devito/logger.py index edd87cc662..8bd0179958 100644 --- a/devito/logger.py +++ b/devito/logger.py @@ -13,13 +13,13 @@ stream_handler = logging.StreamHandler() logger.addHandler(stream_handler) -# Add extra logging levels (note: INFO has value=20, WARNING has value=30) -DEBUG = logging.DEBUG +# Add extra logging levels +DEBUG = logging.DEBUG # value=10 PERF = 19 -INFO = logging.INFO -WARNING = logging.WARNING -ERROR = logging.ERROR -CRITICAL = logging.CRITICAL +INFO = logging.INFO # value=20 +WARNING = logging.WARNING # value=30 +ERROR = logging.ERROR # value=40 +CRITICAL = logging.CRITICAL # value=50 logging.addLevelName(PERF, "PERF") @@ -71,13 +71,13 @@ def set_log_level(level, comm=None): comm : MPI communicator, optional An MPI communicator the logger should be collective over. If provided, only rank-0 on that communicator will write to the registered handlers, other - ranks will use a `logging.NullHandler`. By default, ``comm`` is set - to ``None``, so all ranks will use the default handlers. This could be + ranks will use a `logging.NullHandler`. By default, ``comm`` is set + to ``None``, so all ranks will use the default handlers. This could be used, for example, if one wants to log to one file per rank. """ from devito import configuration - if comm is not None and configuration['mpi']: + if comm is not None: if comm.rank != 0: logger.removeHandler(stream_handler) logger.addHandler(logging.NullHandler()) diff --git a/devito/operator/operator.py b/devito/operator/operator.py index 552885fea9..0a8198aac3 100644 --- a/devito/operator/operator.py +++ b/devito/operator/operator.py @@ -857,10 +857,14 @@ def apply(self, **kwargs): # Post-process runtime arguments self._postprocess_arguments(args, **kwargs) - # Output summary of performance achieved and - # temporarily drop MPI for printing arguments - with switchconfig(mpi=False): - return self._emit_apply_profiling(args) + # In case MPI is used restrict result logging to one rank only + if configuration['mpi']: + # Only temporarily change configuration + with switchconfig(mpi=True): + set_log_level('DEBUG', comm=args.comm) + return self._emit_apply_profiling(args) + + return self._emit_apply_profiling(args) # Performance profiling @@ -898,9 +902,6 @@ def _emit_timings(timings, indent=''): def _emit_apply_profiling(self, args): """Produce a performance summary of the profiled sections.""" - # In case MPI is used restrict result logging to one rank - set_log_level('DEBUG', comm=args.comm) - # Rounder to 2 decimal places fround = lambda i: ceil(i * 100) / 100