[petsc-users] creating csr matrix from 3 arrays

Jed Brown jed at 59A2.org
Fri May 20 06:33:00 CDT 2011


2011/5/20 Dürrwang, Jürgen <Juergen.Duerrwang at iosb.fraunhofer.de>

> MatSetValues(A,n,prow,nz,pcol,pval,INSERT_VALUES);


This function inserts logically dense blocks. You would loop over rows:

for (row=0; row<n; row++) {
  PetscInt ncol = prow[row+1] - prow[row];
  PetscInt offset = prow[row];
  MatSetValues(A,1,&row,ncol,&pcol[offset],&pval[offset],INSERT_VALUES);
}

You should preallocate if at all possible. If your format is exactly as
described here and you want the matrix to use your memory, look at:

http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Mat/MatCreateSeqAIJWithArrays.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110520/b1c0cd29/attachment.htm>


More information about the petsc-users mailing list