[petsc-users] Shell matrix and MatMultAdd.

Vijay S. Mahadevan vijay.m at gmail.com
Thu Dec 2 22:46:09 CST 2010


>   Well one could argue that MatMult() is a special case of MatMultAdd() with a zero vector input.

This is true and can be done but just that I truly believe in the
philosophy of building higher functions based on atomistic actions.
Here, MatMultAdd is just a composite of MatMult and a VecAXPY, two
basic operations. From a design stand-point, it is just confusing for
me to look at it as a top-down scenario. Just my 2 cents.

Again, from my implementation stand-point, I am going to proceed as
you suggested because I just want to get my code working for now...

Vijay

On Thu, Dec 2, 2010 at 6:37 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
> On Dec 2, 2010, at 3:02 PM, Vijay S. Mahadevan wrote:
>
>>>   I suggest making a shell MatMultAdd_Mine() that does everything then
>>> also code a MatMult_Mine() that zeros the output vector and then calls directly MatMultAdd_Mine(). This way you'll
>>> have one code to routine but can handle both operations.
>>
>> Barry, thanks for the suggestion. I will implement the MatMultAdd in
>> this way. Puristically speaking though, this does reverse the
>> dependency between the two routines !
>
>   Well one could argue that MatMult() is a special case of MatMultAdd() with a zero vector input.
>
>  Barry
>
>>
>> Vijay
>>
>> On Thu, Dec 2, 2010 at 2:51 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>>
>>> On Dec 2, 2010, at 2:45 PM, Vijay S. Mahadevan wrote:
>>>
>>>> Hi all,
>>>>
>>>> There is probably some minor inconsistency in my understanding but is
>>>> there a fundamental difference between the following two options ?
>>>>
>>>> // Option 1
>>>> ierr = MatMult(A, solution, temporaryvec) ;CHKERRQ(ierr);
>>>> ierr = VecAXPY(rhs, 1.0, temporaryvec) ;CHKERRQ(ierr);
>>>> // Option 2
>>>> ierr = MatMultAdd(A, solution, rhs, rhs) ;CHKERRQ(ierr);
>>>>
>>>> Here A is a shell matrix (serial) that has a routine defined to
>>>> perform MATOP_MULT only.
>>>>
>>>> I ask because Option 1 gives me the right result while Option 2
>>>> segfaults at the MatMultAdd line. My only logical conclusion is that I
>>>> need to define a MATOP_MULT_ADD or something similar for the shell for
>>>> this to work. Is this understanding correct ?
>>>
>>>   Yes, if your code will use a MatMultAdd() then you need to provide that to the shell matrix.
>>>
>>>> I implicitly assumed
>>>> that petsc recognizes that MATOP_MULT has been defined already and
>>>> since MatMultAdd only requires the action of a matrix on a vector to
>>>> perform its operation, should this not be computed by petsc
>>>> automatically ?
>>>
>>>   Sorry it doesn't though of course it could.
>>>
>>>> I really do not want to creat an extra vector here
>>>> with Option 1 since this occurs at a finer level in my calculation.
>>>> But is there any way that you would suggest I do this without extra
>>>> allocations ? Any comments or pointers will be much appreciated.
>>>
>>>   I suggest making a shell MatMultAdd_Mine() that does everything then
>>> also code a MatMult_Mine() that zeros the output vector and then calls directly MatMultAdd_Mine(). This way you'll
>>> have one code to routine but can handle both operations.
>>>
>>>   Barry
>>>
>>>
>>>
>>>>
>>>> Vijay
>>>
>>>
>
>


More information about the petsc-users mailing list