Skip to content

Commit 91c91c3

Browse files
authored
Merge pull request #2626 from devitocodes/biharmonic
dsl/compiler: Fix&tidy PETSc mixed solver functionality
2 parents 6b6ad4f + ff4b2d7 commit 91c91c3

38 files changed

Lines changed: 2989 additions & 1154 deletions

.github/workflows/examples-mpi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ on:
1717
push:
1818
branches:
1919
- main
20-
- master
20+
- petsc
2121
pull_request:
2222
branches:
2323
- main
24-
- master
24+
- petsc
2525

2626
jobs:
2727
build:

.github/workflows/examples.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ on:
1010
push:
1111
branches:
1212
- main
13-
- master
13+
- petsc
1414
pull_request:
1515
branches:
1616
- main
17-
- master
17+
- petsc
1818

1919
jobs:
2020
tutorials:

.github/workflows/flake8.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ on:
1010
push:
1111
branches:
1212
- main
13-
- master
13+
- petsc
1414
pull_request:
1515
branches:
1616
- main
17-
- master
17+
- petsc
1818

1919
jobs:
2020
flake8:

.github/workflows/pytest-core-mpi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ on:
1010
push:
1111
branches:
1212
- main
13-
- master
13+
- petsc
1414
pull_request:
1515
branches:
1616
- main
17-
- master
17+
- petsc
1818

1919
jobs:
2020
test-mpi-basic:

.github/workflows/pytest-core-nompi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ on:
1010
push:
1111
branches:
1212
- main
13-
- master
13+
- petsc
1414
pull_request:
1515
branches:
1616
- main
17-
- master
17+
- petsc
1818

1919
jobs:
2020
pytest:

.github/workflows/pytest-petsc.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ on:
1010
push:
1111
branches:
1212
- main
13-
- master
13+
- petsc
14+
- biharmonic
1415
pull_request:
1516
branches:
1617
- main
17-
- master
18+
- petsc
19+
- biharmonic
1820

1921
jobs:
2022
pytest:
@@ -83,6 +85,7 @@ jobs:
8385
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/Poisson/03_poisson.py
8486
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/Poisson/04_poisson.py
8587
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/random/01_helmholtz.py
88+
${{ env.RUN_CMD }} mpiexec -n 1 python3 examples/petsc/random/02_biharmonic.py
8689
8790
- name: Upload coverage to Codecov
8891
if: "!contains(matrix.name, 'docker')"

.github/workflows/tutorials.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ on:
1010
push:
1111
branches:
1212
- main
13-
- master
13+
- petsc
1414
pull_request:
1515
branches:
1616
- main
17-
- master
17+
- petsc
1818

1919
jobs:
2020
tutorials:

devito/logger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ def set_log_level(level, comm=None):
7676
used, for example, if one wants to log to one file per rank.
7777
"""
7878
from devito import configuration
79+
from devito.mpi.distributed import MPI
7980

8081
if comm is not None and configuration['mpi']:
81-
if comm.rank != 0:
82+
if comm != MPI.COMM_NULL and comm.rank != 0:
8283
logger.removeHandler(stream_handler)
8384
logger.addHandler(logging.NullHandler())
8485
else:

devito/operator/operator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def _sanitize_exprs(cls, expressions, **kwargs):
194194
@classmethod
195195
def _build(cls, expressions, **kwargs):
196196
# Python- (i.e., compile-) and C-level (i.e., run-time) performance
197-
profiler = create_profile('timers')
197+
profiler = create_profile('timers', kwargs['language'])
198198

199199
# Lower the input expressions into an IET
200200
irs, byproduct = cls._lower(expressions, profiler=profiler, **kwargs)
@@ -1004,7 +1004,9 @@ def _emit_apply_profiling(self, args):
10041004
elapsed = fround(self._profiler.py_timers['apply'])
10051005
info(f"Operator `{self.name}` ran in {elapsed:.2f} s")
10061006

1007-
summary = self._profiler.summary(args, self._dtype, reduce_over=elapsed)
1007+
summary = self._profiler.summary(
1008+
args, self._dtype, self.parameters, reduce_over=elapsed
1009+
)
10081010

10091011
if not is_log_enabled_for('PERF'):
10101012
# Do not waste time

devito/operator/profiling.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from devito.parameters import configuration
1818
from devito.symbolics import subs_op_args
1919
from devito.tools import DefaultOrderedDict, flatten
20+
from devito.petsc.logging import PetscSummary
2021

2122
__all__ = ['create_profile']
2223

@@ -42,7 +43,7 @@ class Profiler:
4243

4344
_attempted_init = False
4445

45-
def __init__(self, name):
46+
def __init__(self, name, language):
4647
self.name = name
4748

4849
# Operation reductions observed in sections
@@ -55,6 +56,9 @@ def __init__(self, name):
5556
# Python-level timers
5657
self.py_timers = OrderedDict()
5758

59+
# For language specific summaries
60+
self.language = language
61+
5862
self._attempted_init = True
5963

6064
def analyze(self, iet):
@@ -179,7 +183,7 @@ def record_ops_variation(self, initial, final):
179183
def all_sections(self):
180184
return list(self._sections) + flatten(self._subsections.values())
181185

182-
def summary(self, args, dtype, reduce_over=None):
186+
def summary(self, args, dtype, params, reduce_over=None):
183187
"""
184188
Return a PerformanceSummary of the profiled sections.
185189
@@ -277,7 +281,7 @@ def _allgather_from_comm(self, comm, time, ops, points, traffic, sops, itershape
277281
return list(zip(times, opss, pointss, traffics, sops, itershapess))
278282

279283
# Override basic summary so that arguments other than runtime are computed.
280-
def summary(self, args, dtype, reduce_over=None):
284+
def summary(self, args, dtype, params, reduce_over=None):
281285
grid = args.grid
282286
comm = args.comm
283287

@@ -338,6 +342,11 @@ def summary(self, args, dtype, reduce_over=None):
338342
# data transfers)
339343
summary.add_glb_fdlike('fdlike-nosetup', points, reduce_over_nosetup)
340344

345+
# Add the language specific summary if necessary
346+
mapper_func = language_summary_mapper.get(self.language)
347+
if mapper_func:
348+
summary.add_language_summary(self.language, mapper_func(params))
349+
341350
return summary
342351

343352

@@ -366,11 +375,11 @@ class AdvisorProfiler(AdvancedProfiler):
366375
_default_libs = ['ittnotify']
367376
_ext_calls = [_api_resume, _api_pause]
368377

369-
def __init__(self, name):
378+
def __init__(self, name, language):
370379
if self._attempted_init:
371380
return
372381

373-
super().__init__(name)
382+
super().__init__(name, language)
374383

375384
path = get_advisor_path()
376385
if path:
@@ -478,6 +487,16 @@ def add_glb_fdlike(self, key, points, time):
478487

479488
self.globals[key] = PerfEntry(time, None, gpointss, None, None, None)
480489

490+
def add_language_summary(self, lang, summary):
491+
"""
492+
Register a language specific summary (e.g., PetscSummary)
493+
and dynamically add a property to access it via perf_summary.<language_name>.
494+
"""
495+
# TODO: Consider renaming `PerformanceSummary` to something more generic
496+
# (e.g., `Summary`), or separating `PetscSummary` entirely from
497+
# `PerformanceSummary`.
498+
setattr(self, lang, summary)
499+
481500
@property
482501
def globals_all(self):
483502
v0 = self.globals['vanilla']
@@ -503,21 +522,21 @@ def timings(self):
503522
return OrderedDict([(k, v.time) for k, v in self.items()])
504523

505524

506-
def create_profile(name):
525+
def create_profile(name, language):
507526
"""Create a new Profiler."""
508527
if configuration['log-level'] in ['DEBUG', 'PERF'] and \
509528
configuration['profiling'] == 'basic':
510529
# Enforce performance profiling in DEBUG mode
511530
level = 'advanced'
512531
else:
513532
level = configuration['profiling']
514-
profiler = profiler_registry[level](name)
533+
profiler = profiler_registry[level](name, language)
515534

516535
if profiler._attempted_init:
517536
return profiler
518537
else:
519538
warning(f"Couldn't set up `{level}` profiler; reverting to 'advanced'")
520-
profiler = profiler_registry['advanced'](name)
539+
profiler = profiler_registry['advanced'](name, language)
521540
# We expect the `advanced` profiler to always initialize successfully
522541
assert profiler._attempted_init
523542
return profiler
@@ -533,3 +552,8 @@ def create_profile(name):
533552
'advisor': AdvisorProfiler
534553
}
535554
"""Profiling levels."""
555+
556+
557+
language_summary_mapper = {
558+
'petsc': PetscSummary
559+
}

0 commit comments

Comments
 (0)