[petsc-users] Shell matrix and MatMultAdd.

Barry Smith bsmith at mcs.anl.gov
Thu Dec 2 14:51:39 CST 2010


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