Skip to content

Commit

Permalink
docs: Use switchconfig with extra condition
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Apr 18, 2024
1 parent 8e6ab03 commit 240b750
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
18 changes: 9 additions & 9 deletions devito/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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())
Expand Down
15 changes: 8 additions & 7 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,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

Expand Down Expand Up @@ -913,9 +917,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

Expand Down

0 comments on commit 240b750

Please sign in to comment.