[petsc-users] problems with MatCreateSeqAIJWithArrays

Nisoli Isaia isaia.nisoli at gmail.com
Tue Nov 29 05:48:02 CST 2011


So, if I want to add another row, what I should do is that:

rowindices[size]=rowindices[size-1];

rowindices[size-1]=size+1;
is this last line right?
When a CSR matrix has a line 'i' which contains only 0s, how should I set
rowindices[i]?

Is there any place where the number of columns is taken into account in

*PetscInt* rowindices;**PetscInt* colindices;**PetscScalar* values;*

reading the documentation about CSR, it does not look like that.

Thank you again
Isaia


On Mon, Nov 28, 2011 at 11:30 PM, Nisoli Isaia <isaia.nisoli at gmail.com>wrote:

> >>* int convertPETSc(srmatrix &sA, Mat * const Aaddr)*>>* {*>>*     PetscErrorCode ierr;*>>*     PetscInt size=(sA.A).size1();*>>*     unsigned int totnnz=(sA.A).nnz();*>>**>>*     (sA.A).complete_index1_data();*>>*     long unsigned int *row_ptr =(sA.A).index1_data().begin();*>>*     long unsigned int *col_ptr =(sA.A).index2_data().begin();*>>*     double * value_ptr = (sA.A).value_data().begin();*>>*     unsigned int sizerow_ptr=(sA.A).index1_data().size();*>>*     unsigned int sizecol_ptr=(sA.A).index2_data().size();*>>*     PetscInt* rowindices;*>>*     PetscInt* colindices;*>>*     PetscScalar* values;*>>*     rowindices=new PetscInt[sizerow_ptr];*>>**
>
> >This array is probably one too short. It needs to have length nrows+1 (so
> >that the length of the last row is known).
> I tried
> *rowindices=new PetscInt[sizerow_ptr+1];
> *allocating some more memory is not a problem...
> but I get the same error.
>
>
> >>*     colindices=new PetscInt[sizecol_ptr];*>>*     values=new PetscScalar[totnnz];*>>*     for (unsigned int i=0;i<sizerow_ptr;i++)*>>* rowindices[i]=PetscInt(row_ptr[i]);*>>*     for (unsigned int i=0;i<sizecol_ptr;i++)*>>* colindices[i]=PetscInt(col_ptr[i]);*>>*     for (unsigned int i=0;i<totnnz;i++)*>>* values[i]=PetscScalar(value_ptr[i]);*>>**>>* ierr=MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD,size+1,size+1,rowindices,colindices,values,Aaddr);CHKERRQ(ierr);*>>**
>
> >You haven't explained your API, but you have a lot of "size" things running
> >around. You should probably pass in "size" here instead of "size+1".
> I'm sorry, I didn't say that in the first mail, but I want the function to add one last row and one last column of zeros to the matrix.
> So that the output matrix is (size+1)*(size+1) if the input matrix is size*size.
>
> >*     ierr=MatAssemblyBegin(*Aaddr,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);*>*     ierr=MatAssemblyEnd(*Aaddr,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);*>*     return 0;*>* }*>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111129/1dd1c88b/attachment.htm>


More information about the petsc-users mailing list