[petsc-users] inserting into sparse matricies

John-Michael Fischer fischej at umich.edu
Fri Mar 26 11:09:41 CDT 2010


Yeah, I inherited an old code written by a very well intentioned physicist - hehe, and I think you know what kind of code that can produce.
He rolled his own Parallel  Vector and Matrix classes, yet used PETSC for the core matrix solver -- so theres all this horrible business at each step going from his ParallelSparse class to a PETSC one, running the solver, then moving all the data back.... ahhhhhhh.
Anyway, I'm replacing his custom classes with proper PETSC objects so we can move this code out of the 20th century and run it on some bigger machines.

I'm trying to go in chunks and not optimize everything at once, so I thought it would be nice if I could just insert this vector which one of his functions produces.

(sorry for the long answer to the short question).

Barring a magic-wand petsc_function I think I'll just find the indecies of the non-zero elements and matsetvalues those even if its inefficient -- i'll come back later and deconstruct his 'row-building' function into something more sane.

Thanks!
John-Michael

On Mar 26, 2010, at 11:28 AM, Jed Brown wrote:

> On Fri, 26 Mar 2010 11:18:08 -0400, John-Michael Fischer <fischej at umich.edu> wrote:
>> I have a vector of values I want to insert into a sparse matrix as a
>> row.  My vector contains non-zero values at their proper positions in
>> the row and zero's elsewhere.
> 
> How did you get this vector with all the explicit zeros?
> 
> There is an option MAT_IGNORE_ZERO_ENTRIES, but I don't think you want
> to use it here.
> 
>> Alternatively, I was thinking I could assemble a vector with the
>> indecies of the non-zero elements, then use that in the call to
>> MatSetValues with a row vector of non-zero values only - but I wanted
>> to ask first since this seems like a common usage pattern for PETSC
>> sparse mat's.
> 
> Usually you only compute the nonzero entries.
> 
> Jed
> 
> 



More information about the petsc-users mailing list