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

more types? #145

Closed
jkozdon opened this issue Jul 14, 2021 · 5 comments
Closed

more types? #145

jkozdon opened this issue Jul 14, 2021 · 5 comments

Comments

@jkozdon
Copy link
Member

jkozdon commented Jul 14, 2021

Should we have more types, for example:

  • LocalVec and GlobalVec?
  • DMDA and DMStag and DMXXX?

PETSc doesn't really distinguish between these, but we could leverage the Julia type system to make sure that the right functions are called always. (Not sure how to handle cases when we do not necessarily know the type, such as what's returned from DMGetCoordinateDM.)

@simonbyrne
Copy link
Member

It does have different Vec types (see https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Vec/VecType.html#VecType), but it's a bit more dynamic than Julia (e.g. you can modify the type of an existing Vec)

I think the main question is whether the distinction is useful from a dispatch perspective. In particular, I had originally planned that VecSeq objects would have finalizers, but not the MPI ones (though that could be handled differently).

@jkozdon
Copy link
Member Author

jkozdon commented Jul 14, 2021

Right. I meant mainly from the dispatch perspective.

For instance, the function DMGlobalToLocal takes two Vecs, but really one should be a "local" vector and one a "global" vector. This could be tracked with the type system in Julia.

What I meant by "PETSc doesn't really distinguish between these " I meat at the C-types level. For instance everything is really just a Vec, though the types can be queried at runtime through the VecGetType.

I'm also not sure that you can really change a vector in PETSc once it's been setup, this is mainly for initialization. My read o the code is that if you call VecSetType on an existing vector, you first destroy the data then create a new one (data is not preserved through VecSetType)

@psanan
Copy link
Contributor

psanan commented Jul 14, 2021

The way it enforces that things are the correct size wrt being local or global is that it the DM contains a VecScatter object which defines the local-global mapping, and (in debug mode only!) it'll check that the Vecs passed as arguments to DMGlobalToLocal() are the expected local and global sizes, which are calculated during DMSetup() when the VecScatter is also created. Here's the actual check in the source for VecScatterBegin().

@jkozdon
Copy link
Member Author

jkozdon commented Jul 14, 2021

Right. I was wondering if there would be any benefit to having any checks at compile time (obviously some stuff can only be checked at run time such as whether you can actually scatter between two vectors). But some sanity checks might be possible at run time, but maybe it's not worth it for now.

For example, I was thinking that DMCreateGlobalVector and DMCreateLocalVector could return different types, they would still be AbstractVec subtypes and usable anywhere a Vec could be used, but also would allow for making sure that the right vecs get passed into DMGlobalToLocal

@jkozdon
Copy link
Member Author

jkozdon commented Jul 14, 2021

Probably worth waiting until we have more concrete use cases.

@jkozdon jkozdon closed this as completed Jul 14, 2021
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

No branches or pull requests

3 participants