Thanks both, I now have what I need. For now I am checking that the vector I am passed has the same local size, global size, and Comm as the vector provided by DMGetLocalVector, mostly because I already have a compatibility check function written. (I assume this requires a malloc and free behind the scenes)
At some point I will likely change to explicitly checking for comm size of one and appropriate global and local sizes based on the DMDA properties instead, for now I want to get to an alpha version I can let people play with. Phil On 25/09/18 13:07, Dave May wrote: > > > On Tue, 25 Sep 2018 at 13:20, Matthew Knepley <knep...@gmail.com > <mailto:knep...@gmail.com>> wrote: > > On Tue, Sep 25, 2018 at 7:03 AM Dave May <dave.mayhe...@gmail.com > <mailto:dave.mayhe...@gmail.com>> wrote: > > On Tue, 25 Sep 2018 at 11:49, Phil Tooley > <phil.too...@sheffield.ac.uk > <mailto:phil.too...@sheffield.ac.uk>> wrote: > > Hi all, > > Given a vector I know I can get an associated DM (if there > is one) by > calling VecGetDM, but I need to also be able to check that > > a) the vector is the localvector of that DM rather than > the global > > > Given the vector, you can check the communicator size via > PetscObjectGetComm() > > > > https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscObjectGetComm.html > and then MPI_Comm_size() > If the comm size 1, it is local vector. > > > In serial, both vectors have comm size 1. > > > Right - and the local and global sizes are the same. > > My point was to check the comm size first. If it's 1 then you have a > candidate for a local vector. Then you'd check the vec global size > matches the dmda local size. If the commsize is anything other than 1 > then it cannot be a local vector > > > Matt > > > You can check the size matches your local DMDA space by using > DMDAGetGhostCorners() > > > https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMDA/DMDAGetGhostCorners.html > > and return the quantities m, n, and p. > > You also need to use DMDAGetInfo() > > > https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMDA/DMDAGetInfo.html > > The important quantity you want returned is "dof" > > If m x n x p x dof matches the number returned by VecGetSize() > (assuming you know the vector is sequential) then you know the > local space will fit within your vector. > > > > > b) the DM is a DMDA rather than some other subclass > > > See Matt's answer > > > > I can't immediately see routines that do what I need, but > I am likely > missing something obvious. Is there a way to achieve the > above? > > Thanks > > Phil > > -- > Phil Tooley > Research Software Engineering > University of Sheffield > > > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to > which their experiments lead. > -- Norbert Wiener > > https://www.cse.buffalo.edu/~knepley/ > <http://www.cse.buffalo.edu/%7Eknepley/> > -- Phil Tooley Research Software Engineering University of Sheffield