Skip to content

Commit

Permalink
docs: Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Apr 16, 2024
1 parent 8ad726e commit 3529090
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
23 changes: 22 additions & 1 deletion devito/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from contextlib import contextmanager

__all__ = ('set_log_level', 'set_log_noperf', 'is_log_enabled_for',
__all__ = ('set_log_level', 'set_log_noperf', 'is_log_enabled_for', 'switch_log_level',
'log', 'warning', 'error', 'perf', 'hint',
'RED', 'GREEN', 'BLUE')

Expand Down Expand Up @@ -86,6 +86,27 @@ def set_log_level(level, comm=None):
configuration['log-level'] = level


class switch_log_level(object):
"""
A context manager to temporarily change MPI logging.
"""

def __init__(self, comm):

from devito import configuration
self.level = configuration['log-level']
self.comm = comm

def __enter__(self):
# Limit logging to rank 0
set_log_level(self.level, self.comm)
return

def __exit__(self, *args):
set_log_level(self.level)
logger.addHandler(stream_handler)


def set_log_noperf():
"""Do not print performance-related messages."""
logger.setLevel(WARNING)
Expand Down
6 changes: 2 additions & 4 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from cached_property import cached_property
from sympy import sympify

from devito import switch_log_level
from devito.arch import compiler_registry, platform_registry
from devito.data import default_allocator
from devito.exceptions import InvalidOperator, ExecutionError
from devito.logger import debug, info, perf, warning, is_log_enabled_for
from devito.logger import debug, info, perf, warning, is_log_enabled_for, switch_log_level
from devito.ir.equations import LoweredEq, lower_exprs
from devito.ir.clusters import ClusterGroup, clusterize
from devito.ir.iet import (Callable, CInterface, EntryFunction, FindSymbols, MetaCall,
Expand Down Expand Up @@ -876,9 +875,8 @@ def apply(self, **kwargs):
with switch_log_level(comm=args.comm):
return self._emit_apply_profiling(args)

return self._emit_apply_profiling(args)

# Performance profiling

def _emit_build_profiling(self):
if not is_log_enabled_for('PERF'):
return
Expand Down
27 changes: 2 additions & 25 deletions devito/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from os import environ
from functools import wraps

from devito.logger import info, warning, logger, stream_handler, set_log_level
from devito.logger import info, warning
from devito.tools import Signer, filter_ordered

__all__ = ['configuration', 'init_configuration', 'print_defaults', 'print_state',
'switchconfig', 'switch_log_level']
'switchconfig']

# Be EXTREMELY careful when writing to a Parameters dictionary
# Read here for reference: http://wiki.c2.com/?GlobalVariablesAreBad
Expand Down Expand Up @@ -258,29 +258,6 @@ def wrapper(*args, **kwargs):
return wrapper


class switch_log_level(object):
"""
A context manager subclassing `switchconfig` to temporarily change
MPI logging.
"""

def __init__(self, comm):

self.level = configuration['log-level']
self.comm = comm

# Limit logging to rank 0
set_log_level(self.level, comm)

def __enter__(self):
return

def __exit__(self, exc_type, exc_val, exc_tb):
# Reinstate logging upon exit
set_log_level(self.level)
logger.addHandler(stream_handler)


def print_defaults():
"""Print the environment variables accepted by Devito, their default value,
as well as all of the accepted values."""
Expand Down

0 comments on commit 3529090

Please sign in to comment.