mat creation

Barry Smith bsmith at
Mon Feb 6 09:15:15 CST 2006

On Mon, 6 Feb 2006, Roberto Gori wrote:

> Hi, guys,
> I'm trying to solve a linear system with M equations and N unknowns (M >> N) using the LSQR method.
> I have a C parallel sparse matrix MxN with NZ nonzero elements stored in this way:
> double values[NZ]; // the nonzero values
> int idxn[NZ]; // the column indices
> int nz[M]; // the number of nonzero values for each row

This needs to be instead indices to start of each row in idxn and values
instead of the length of each row.
> what is the best way to create a PETSc matrix?

> Do exists a statement like VecCreateMPIWithArray for already distributed vectors that could do all the work in one shot without copy?


>  Just another detail. Initially M is unknown.  All my structures are
> allocated dynamically because the number of rows M (and the number
> of nonzero NZ also) is determined just before to solve the system,
> so I think it's no feasible for me to call MatCreateMPIAIJ at the
> begin of my code and to perform the MatSetValues loop.

  There is nothing saying that you must "call MatCreateMPIAIJ at the
beginning of your code", you can call it anytime that you have the
needed information.


>     Roberto
> ================================================================
> | Roberto Gori                                            CINECA
> | High Performance System Group         Via Magnanelli 6/3 40033
> | e-mail: r.gori at                          Casalecchio di Reno
> | Tel: 051/6171522                                    Bologna - ITALY
> | Fax: 051/6132198                         
> ================================================================

More information about the petsc-users mailing list