[petsc-users] problems with MatCreateSeqAIJWithArrays
Jed Brown
jedbrown at mcs.anl.gov
Mon Nov 28 19:34:29 CST 2011
On Mon, Nov 28, 2011 at 19:30, Nisoli Isaia <isaia.nisoli at gmail.com> wrote:
> I tried
> *rowindices=new PetscInt[sizerow_ptr+1];
> *allocating some more memory is not a problem...
> but I get the same error.
>
> How is sizerow_ptr related to size?
Are you also filling in those indices correctly?
>
>
> >>* 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.
>
> Well, the matrix has no way to know what should go in that last row. It's
likely reading off the end of the array because you didn't make the arrays
large enough. Run in Valgrind if you are having trouble.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111128/e83a6bf3/attachment.htm>
More information about the petsc-users
mailing list