Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
169a8cf
compiler: Add petscsection header file
ZoeLeibowitz Jan 14, 2026
7b9d763
compiler: Started ghosted subdomain implementation
ZoeLeibowitz Jan 16, 2026
7b0d38e
compiler: Start SubDimMax
ZoeLeibowitz Jan 19, 2026
649aec2
progress with unsafe index global to local
ZoeLeibowitz Jan 19, 2026
0b6b282
mpi: Fix index_glb_to_loc_unsafe using base
ZoeLeibowitz Jan 19, 2026
9f68bb2
compiler: Progress with petscsection constrain bc callback
ZoeLeibowitz Jan 21, 2026
4bd4f8e
tests: Start tests for petscsection constraining bcs in 1d
ZoeLeibowitz Jan 22, 2026
f57ea60
tests: Add more 1d tests for constraining indices with petsc
ZoeLeibowitz Jan 23, 2026
abdcc91
compiler: Add new petsc types for utilising petscsections
ZoeLeibowitz Jan 23, 2026
154a4dc
compiler: Some development with the bc callback automation
ZoeLeibowitz Jan 26, 2026
10c590c
broken loops in 2d but working jitback for 2d ed bueler example
ZoeLeibowitz Jan 27, 2026
91564c0
compiler: Fix constrain_essential_bcs with implicit_dims
ZoeLeibowitz Jan 27, 2026
913b3b4
compiler: Support increment indexing
ZoeLeibowitz Jan 28, 2026
5cce561
compiler: Progress with the SetPointBCs0 callback petsc
ZoeLeibowitz Jan 28, 2026
3089dc5
compiler: Some progress with setpointbc petsc callback
ZoeLeibowitz Jan 28, 2026
81e4036
rffraq
ZoeLeibowitz Jan 29, 2026
07bbfc2
compiler: Working petscsection ed bueler example apart from the byref…
ZoeLeibowitz Jan 29, 2026
8a09272
compiler: Working ed bueler example with petscsection
ZoeLeibowitz Jan 29, 2026
5208924
need to fix with space dimensions
ZoeLeibowitz Jan 30, 2026
7ba6dfb
compiler: Switch to use CustomDimension
ZoeLeibowitz Feb 2, 2026
8bda24e
compiler: Fix essential bc handling in lower exprs
ZoeLeibowitz Feb 2, 2026
7e83811
misc: Bit of clean up
ZoeLeibowitz Feb 3, 2026
42535d0
bit of clean up
ZoeLeibowitz Feb 4, 2026
c0a62d2
misc: Clean up and flake8
ZoeLeibowitz Feb 5, 2026
198b040
misc: More clean up
ZoeLeibowitz Feb 5, 2026
27c3822
misc: More clean up
ZoeLeibowitz Feb 5, 2026
bd4e7bc
misc: Delete old files
ZoeLeibowitz Feb 5, 2026
4326bf9
misc: More cleanup
ZoeLeibowitz Feb 5, 2026
71b57a3
misc: Clean up
ZoeLeibowitz Feb 5, 2026
cdf9c43
misc: Comment
ZoeLeibowitz Feb 6, 2026
27e0d87
misc: Fix sregistry extraction constrain_essential_bcs
ZoeLeibowitz Feb 6, 2026
0b1f4eb
compiler: Fix petscsection constrain bcs in 1d
ZoeLeibowitz Feb 6, 2026
e3e4eb6
workflows: Support single docker image don't have two separate
ZoeLeibowitz Feb 6, 2026
b731340
compiler: Add destroy matop ctx for submats but need to fix when thin…
ZoeLeibowitz Feb 12, 2026
f592204
compiler: Suitably destroy the submats inside the jacobianstruct
ZoeLeibowitz Feb 12, 2026
a8b8b1f
tests: Fix tests due to new destroys and callback for coupled solves …
ZoeLeibowitz Feb 12, 2026
cef2e7f
test segfault is from kspgettype in logging - temp remove
ZoeLeibowitz Feb 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/docker-petsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ permissions:
on:
push:
branches:
- petsc # Push events on petsc branch
- petsc
# will be dropped after merge into petsc branch
- petscsection

jobs:
build-and-push:
Expand All @@ -16,6 +18,9 @@ jobs:
# Use buildkit
DOCKER_BUILDKIT: "1"

PETSC_REPO: https://gitlab.com/ZoeLeibowitz/petsc.git
PETSC_BRANCH: zoe/feature-da-section-sf

steps:
- name: Checkout devito
uses: actions/checkout@v5
Expand All @@ -38,10 +43,13 @@ jobs:
context: .
file: docker/Dockerfile.petsc
push: true
platforms: linux/amd64
tags: |
devitocodes/devito-petsc:latest
build-args: base=devitocodes/devito:gcc-dev-amd64
platforms: linux/amd64
build-args: |
base=devitocodes/devito:gcc-dev-amd64
PETSC_REPO=${{ env.PETSC_REPO }}
PETSC_BRANCH=${{ env.PETSC_BRANCH }}

- name: Remove dangling layers
run: docker system prune -f
8 changes: 5 additions & 3 deletions .github/workflows/pytest-petsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ concurrency:
cancel-in-progress: true

on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- main
Expand Down Expand Up @@ -50,7 +48,11 @@ jobs:

- name: Build docker image
run: |
docker build -f docker/Dockerfile.petsc --tag devito_petsc_image:test .
docker build \
-f docker/Dockerfile.petsc \
--build-arg PETSC_REPO=https://gitlab.com/ZoeLeibowitz/petsc.git \
--build-arg PETSC_BRANCH=zoe/feature-da-section-sf \
--tag devito_petsc_image:test .

- name: Set run prefix
run: |
Expand Down
33 changes: 33 additions & 0 deletions devito/data/decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,39 @@ def index_loc_to_glb(self, *args):
else:
raise TypeError("Expected 1 arguments, found %d" % len(args))

def index_glb_to_loc_unsafe(self, glb_idx, rel=True):
"""
Convert a global index to a local index even if not owned.
WARNING: Must not be used to index data as there are no guard
rails against returning out of bound indices.
"""
if not self.loc_empty:
loc_abs_min = self.loc_abs_min - self.glb_min
loc_abs_max = self.loc_abs_max - self.glb_min
glb_max = self.glb_max - self.glb_min
else:
loc_abs_min = self.loc_abs_min
loc_abs_max = self.loc_abs_max
glb_max = self.glb_max

glb_min = 0

base = loc_abs_min if rel else 0

# index_glb_to_loc(index)
# -> Base case, empty local subdomain
if self.loc_empty:
return None
# -> Handle negative index
if glb_idx < 0:
glb_idx = glb_max + glb_idx + 1
# -> Do the actual conversion
if loc_abs_min <= glb_idx <= loc_abs_max or glb_min <= glb_idx <= glb_max:
return glb_idx - base
else:
# This should raise an exception when used to access a numpy.array
return glb_idx

def reshape(self, *args):
"""
Create a new Decomposition with extended or reduced boundary subdomains.
Expand Down
10 changes: 8 additions & 2 deletions devito/ir/cgen/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from devito.symbolics.inspection import has_integer_args, sympy_dtype
from devito.symbolics.queries import q_leaf
from devito.types.basic import AbstractFunction
from devito.types.misc import PostIncrementIndex
from devito.tools import ctypes_to_cstr, dtype_to_ctype, ctypes_vector_mapper

__all__ = ['BasePrinter', 'ccode']
Expand Down Expand Up @@ -148,8 +149,13 @@ def _print_Indexed(self, expr):
--------
U[t,x,y,z] -> U[t][x][y][z]
"""
inds = ''.join(['[' + self._print(x) + ']' for x in expr.indices])
return f'{self._print(expr.base.label)}{inds}'
inds = []
for i in expr.indices:
if isinstance(i, PostIncrementIndex):
inds.append(f"[{self._print(i)}++]")
else:
inds.append(f"[{self._print(i)}]")
return f"{self._print(expr.base.label)}{''.join(inds)}"

def _print_FIndexed(self, expr):
"""
Expand Down
8 changes: 4 additions & 4 deletions devito/ir/equations/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def detect(cls, expr):
ReduceMin: OpMin,
PetscEq: OpPetsc
}
try:
return reduction_mapper[type(expr)]
except KeyError:
pass

for expr_type, op in reduction_mapper.items():
if isinstance(expr, expr_type):
return op

# NOTE: in the future we might want to track down other kinds
# of operations here (e.g., memcpy). However, we don't care for
Expand Down
4 changes: 2 additions & 2 deletions devito/ir/iet/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,8 @@ def expr_symbols(self):
ret.extend([self.pointer._C_symbol, self.pointee._C_symbol])
else:
ret.extend([self.pointer, self.pointee.indexed])
ret.extend(flatten(i.free_symbols
for i in self.pointee.symbolic_shape[1:]))
ret.extend(flatten(i.free_symbols
for i in self.pointee.symbolic_shape[1:]))
else:
assert False, f"Unexpected pointer type {type(self.pointer)}"

Expand Down
3 changes: 3 additions & 0 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from devito.types.dimension import Thickness
from devito.petsc.iet.passes import lower_petsc
from devito.petsc.clusters import petsc_preprocess
from devito.petsc.equations import lower_exprs_petsc

__all__ = ['Operator']

Expand Down Expand Up @@ -368,6 +369,8 @@ def _lower_exprs(cls, expressions, **kwargs):
# in particular uniqueness across expressions is ensured
expressions = concretize_subdims(expressions, **kwargs)

expressions = lower_exprs_petsc(expressions, **kwargs)

processed = [LoweredEq(i) for i in expressions]

return processed
Expand Down
3 changes: 2 additions & 1 deletion devito/petsc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def core_metadata():
petsc_lib = tuple([arch / 'lib' for arch in petsc_dir])

return {
'includes': ('petscsnes.h', 'petscdmda.h'),
# TODO: Only add petscsection header when needed
'includes': ('petscsnes.h', 'petscdmda.h', 'petscsection.h'),
'include_dirs': petsc_include,
'libs': ('petsc'),
'lib_dirs': petsc_lib,
Expand Down
100 changes: 100 additions & 0 deletions devito/petsc/equations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from devito.symbolics import retrieve_indexed, retrieve_dimensions, uxreplace
from devito.types.dimension import SpaceDimension, CustomDimension
from devito import Min, Max

from devito.petsc.types.equation import ConstrainBC
from devito.petsc.types.dimension import (
SubDimMax, SubDimMin,
SpaceDimMax, SpaceDimMin,
)


def lower_exprs_petsc(expressions, **kwargs):

# Process `ConstrainBC` equations
expressions = constrain_essential_bcs(expressions, **kwargs)

return expressions


def constrain_essential_bcs(expressions, **kwargs):
"""
"""
constrain_expressions = [e for e in expressions if isinstance(e, ConstrainBC)]
if not constrain_expressions:
return expressions

sregistry = kwargs.get('sregistry')
new_exprs = []

# TODO: rethink
halo_size = {e.target.function._size_halo for e in constrain_expressions}
assert len(halo_size) == 1
halo_size = halo_size.pop()

all_dims = {d for e in constrain_expressions for d in extract_dims(e)}
subdims = [d for d in all_dims if d.is_Sub and not d.local]
space_dims = [d for d in all_dims if isinstance(d, SpaceDimension)]

mapper = {}

for d in subdims:
halo = halo_size[d]

subdim_max = SubDimMax(
sregistry.make_name(prefix=f"{d.name}_max"), subdim=d
)
subdim_min = SubDimMin(
sregistry.make_name(prefix=f"{d.name}_min"), subdim=d
)

mapper[d] = CustomDimension(
name=d.name,
symbolic_min=Max(subdim_min, d.parent.symbolic_min - halo.left),
symbolic_max=Min(subdim_max, d.parent.symbolic_max + halo.right),
)

for d in space_dims:
halo = halo_size[d]
space_dim_max = SpaceDimMax(
sregistry.make_name(prefix=f"{d.name}_max"), space_dim=d
)
space_dim_min = SpaceDimMin(
sregistry.make_name(prefix=f"{d.name}_min"), space_dim=d
)

mapper[d] = CustomDimension(
name=sregistry.make_name(prefix=f"{d.name}_expanded"),
symbolic_min=Max(space_dim_min, d.symbolic_min - halo.left),
symbolic_max=Min(space_dim_max, d.symbolic_max + halo.right),
)

# Apply mapper to expressions
for e in expressions:
if not isinstance(e, ConstrainBC):
new_exprs.append(e)
continue

dims = extract_dims(e)
if not dims:
new_exprs.append(e)
continue

new_e = uxreplace(e, mapper)

if e.implicit_dims:
new_e = new_e._rebuild(
implicit_dims=tuple(mapper.get(d, d) for d in e.implicit_dims)
)
new_exprs.append(new_e)
return new_exprs


def extract_dims(expr):
indexeds = retrieve_indexed(expr)
dims = retrieve_dimensions(
[i for j in indexeds for i in j.indices],
mode="unique",
)
dims.update(expr.implicit_dims)
return dims
Loading
Loading