Re: [petsc-users] Checking if a vector is a localvector of a given DMDA

2018-09-25 Thread Dave May
On Tue, 25 Sep 2018 at 13:31, Phil Tooley 
wrote:

> 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)
>

Not necessarily. The Get/Restore strategy will re-use internally cached
vectors.


> 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  wrote:
>
>> On Tue, Sep 25, 2018 at 7:03 AM Dave May  wrote:
>>
>>> On Tue, 25 Sep 2018 at 11:49, Phil Tooley 
>>> 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/
>> 
>>
>
> --
> Phil Tooley
> Research Software Engineering
> University of Sheffield
>
>


Re: [petsc-users] Checking if a vector is a localvector of a given DMDA

2018-09-25 Thread Phil Tooley
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  > wrote:
>
> On Tue, Sep 25, 2018 at 7:03 AM Dave May  > wrote:
>
> On Tue, 25 Sep 2018 at 11:49, Phil Tooley
>  > 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/
> 
>

-- 
Phil Tooley
Research Software Engineering
University of Sheffield



Re: [petsc-users] Checking if a vector is a localvector of a given DMDA

2018-09-25 Thread Dave May
On Tue, 25 Sep 2018 at 13:20, Matthew Knepley  wrote:

> On Tue, Sep 25, 2018 at 7:03 AM Dave May  wrote:
>
>> On Tue, 25 Sep 2018 at 11:49, Phil Tooley 
>> 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/
> 
>


Re: [petsc-users] Checking if a vector is a localvector of a given DMDA

2018-09-25 Thread Matthew Knepley
On Tue, Sep 25, 2018 at 7:03 AM Dave May  wrote:

> On Tue, 25 Sep 2018 at 11:49, Phil Tooley 
> 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.

   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/ 


Re: [petsc-users] Checking if a vector is a localvector of a given DMDA

2018-09-25 Thread Phil Tooley
Hi Matt,

Thanks for the rapid response.  The reason I want to ensure I have a
DMDA is that this is a custom gradient function, the results of which
are meaningless for anything but a regular grid. I would rather raise an
exception upfront with the user than allow the program to continue with
garbage data.

Phil

On 25/09/18 11:55, Matthew Knepley wrote:
> On Tue, Sep 25, 2018 at 6:49 AM Phil Tooley
> 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
>
>
> Get a local vector from the DM and check the sizes.
>  
>
> b) the DM is a DMDA rather than some other subclass
>
>
> You can do this (PetscObjectTypeCompare), but it is not recommended.
> Why would
> you want to do that?
>
>   Thanks,
>
>      Matt
>  
>
> 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/
> 

-- 
Phil Tooley
Research Software Engineering
University of Sheffield



Re: [petsc-users] Checking if a vector is a localvector of a given DMDA

2018-09-25 Thread Dave May
On Tue, 25 Sep 2018 at 11:49, Phil Tooley 
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.

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
>
>


Re: [petsc-users] Checking if a vector is a localvector of a given DMDA

2018-09-25 Thread Matthew Knepley
On Tue, Sep 25, 2018 at 6:49 AM Phil Tooley 
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
>

Get a local vector from the DM and check the sizes.


> b) the DM is a DMDA rather than some other subclass
>

You can do this (PetscObjectTypeCompare), but it is not recommended. Why
would
you want to do that?

  Thanks,

 Matt


> 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/ 


[petsc-users] Checking if a vector is a localvector of a given DMDA

2018-09-25 Thread Phil Tooley
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

b) the DM is a DMDA rather than some other subclass

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