[petsc-users] problems with MatCreateSeqAIJWithArrays
Jed Brown
jedbrown at mcs.anl.gov
Mon Nov 28 19:08:17 CST 2011
On Mon, Nov 28, 2011 at 19:03, 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).
> 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".
> 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/20111128/dfd53531/attachment.htm>
More information about the petsc-users
mailing list