[petsc-users] problems with MatCreateSeqAIJWithArrays

Nisoli Isaia isaia.nisoli at gmail.com
Mon Nov 28 19:30:08 CST 2011


>>* 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/f648473e/attachment.htm>


More information about the petsc-users mailing list