Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialise PETSc, drop LinSolveExprs in lower_petsc, add PETScStruct, create matvec callback and move files into PETSc folder #14

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ZoeLeibowitz
Copy link
Owner

No description provided.

@ZoeLeibowitz ZoeLeibowitz changed the title Remove LinSolveExprs Initialise PETSc, drop LinSolveExprs in lower_petsc and add PETScStruct May 10, 2024
@ZoeLeibowitz ZoeLeibowitz marked this pull request as ready for review May 10, 2024 15:40
Copy link
Collaborator

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, but it's mostly minor stuff, looking good!

devito/ir/iet/nodes.py Outdated Show resolved Hide resolved
devito/passes/iet/petsc.py Outdated Show resolved Hide resolved
devito/passes/iet/petsc.py Outdated Show resolved Hide resolved
devito/passes/iet/petsc.py Outdated Show resolved Hide resolved
devito/passes/iet/petsc.py Outdated Show resolved Hide resolved
devito/passes/iet/petsc.py Outdated Show resolved Hide resolved
@@ -247,3 +247,24 @@ def solver_parameters(self):
return self._solver_parameters

func = Reconstructable._rebuild


class PETScStruct(CompositeObject):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placing this question here, but I should have asked time ago. Do we actually need types/petsc?

I'm now thinking PETSc support might deserve its own folder in the root directory, alongside ir, types, passes, mpi, etc

I'd prefer it centralised rather than distributed, but perhaps it's just me, thoughts @ZoeLeibowitz @mloubout @EdCaunt

@ZoeLeibowitz ZoeLeibowitz changed the title Initialise PETSc, drop LinSolveExprs in lower_petsc and add PETScStruct Initialise PETSc, drop LinSolveExprs in lower_petsc, add PETScStruct, create matvec callback and move files into PETSc folder May 30, 2024
Copy link
Collaborator

@EdCaunt EdCaunt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, mainly code style comments

devito/petsc/iet/passes.py Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/types.py Outdated Show resolved Hide resolved
devito/petsc/types.py Outdated Show resolved Hide resolved
devito/petsc/types.py Outdated Show resolved Hide resolved
devito/petsc/types.py Outdated Show resolved Hide resolved
devito/petsc/types.py Outdated Show resolved Hide resolved
devito/ir/iet/algorithms.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
dm_get_app_context = Call(petsc_call, [Call('DMGetApplicationContext', arguments=[
objs['da'], Byref(struct._C_symbol)])])

dm_get_local_xvec = Call(petsc_call, [Call('DMGetLocalVector', arguments=[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to improve readability you may add simple utility functions creating Call(... [Call(....)])


func_return = Call('PetscFunctionReturn', arguments=[0])

matvec_body = List(body=[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that or one word per line, it doesn't matter if it gets long

devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
unique_targets = list(set([i.expr.rhs.target for i in petsc_nodes]))
init = init_petsc(**kwargs)
struct = build_petsc_struct(iet)
objs = build_core_objects(unique_targets[-1], **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unsafe? list(set()) returns an iterable with non-deterministic order, so taking the last item doesn't guarantee getting the same thing every time

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to sort here for determinism.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok, at least for now, because I assume that all targets have the same Grid and so it does not matter which one I use

devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just left a bunch of minuscule comments, this is imho already looking good enough for merge

conftest.py Outdated Show resolved Hide resolved
devito/ir/equations/equation.py Outdated Show resolved Hide resolved
@@ -1169,8 +1140,9 @@ class Callback(Call):
engine fails to bind the callback to a specific Call. Consequently,
errors occur during the creation of the call graph.
"""

def __init__(self, name, retval, param_types):
# TODO: Create a common base class for Call and Callback to avoid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like an easy one

devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/iet/passes.py Show resolved Hide resolved
devito/petsc/iet/passes.py Outdated Show resolved Hide resolved
devito/petsc/types.py Outdated Show resolved Hide resolved
devito/petsc/utils.py Show resolved Hide resolved
Comment on lines 146 to 169
@cached_property
def _shape_with_inhalo(self):
"""
Shape of the domain+inhalo region. The inhalo region comprises the
outhalo as well as any additional "ghost" layers for MPI halo
exchanges. Data in the inhalo region are exchanged when running
Operators to maintain consistent values as in sequential runs.

Notes
-----
Typically, this property won't be used in user code, but it may come
in handy for testing or debugging
"""
return tuple(j + i + k for i, (j, k) in zip(self.shape, self._halo))

@cached_property
def shape_allocated(self):
"""
Shape of the allocated data of the Function type object from which
this PETScArray was derived. It includes the domain and inhalo regions,
as well as any additional padding surrounding the halo.

Notes
-----
In an MPI context, this is the *local* with_halo region shape.
"""
return DimensionTuple(*[j + i + k for i, (j, k) in zip(self._shape_with_inhalo,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a duplication to what devito has already?

Copy link
Collaborator

@mloubout mloubout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some docker comments will go through whole PR Later

docker/Dockerfile.devito Outdated Show resolved Hide resolved
apt-get update && apt-get install -y libopenblas-serial-dev git pkgconf mpich && \
python3 -m venv /venv && \
/venv/bin/pip install --no-cache-dir --upgrade pip && \
/venv/bin/pip install --no-cache-dir --no-binary numpy numpy && \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to avoid using pre-built binary wheels for numpy. This is important to ensure that PETSc and numpy are built against the same BLAS/LAPACK library. This is why the PETSc install stage is before Devito.

docker/Dockerfile.devito Outdated Show resolved Hide resolved
docker/Dockerfile.devito Outdated Show resolved Hide resolved
docker/Dockerfile.devito Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants