<pre>>><i> int convertPETSc(srmatrix &sA, Mat * const Aaddr)
</i>>><i> {
</i>>><i> PetscErrorCode ierr;
</i>>><i> PetscInt size=(sA.A).size1();
</i>>><i> unsigned int totnnz=(sA.A).nnz();
</i>>><i>
</i>>><i> (sA.A).complete_index1_data();
</i>>><i> long unsigned int *row_ptr =(sA.A).index1_data().begin();
</i>>><i> long unsigned int *col_ptr =(sA.A).index2_data().begin();
</i>>><i> double * value_ptr = (sA.A).value_data().begin();
</i>>><i> unsigned int sizerow_ptr=(sA.A).index1_data().size();
</i>>><i> unsigned int sizecol_ptr=(sA.A).index2_data().size();
</i>>><i> PetscInt* rowindices;
</i>>><i> PetscInt* colindices;
</i>>><i> PetscScalar* values;
</i>>><i> rowindices=new PetscInt[sizerow_ptr];
</i>>><i>
</i>
>This array is probably one too short. It needs to have length nrows+1 (so
>that the length of the last row is known).
<br>I tried <br><i>rowindices=new PetscInt[sizerow_ptr+1];<br></i>allocating some more memory is not a problem...<br>but I get the same error.<br><br>>><i> colindices=new PetscInt[sizecol_ptr];
</i>>><i> values=new PetscScalar[totnnz];
</i>>><i> for (unsigned int i=0;i<sizerow_ptr;i++)
</i>>><i> rowindices[i]=PetscInt(row_ptr[i]);
</i>>><i> for (unsigned int i=0;i<sizecol_ptr;i++)
</i>>><i> colindices[i]=PetscInt(col_ptr[i]);
</i>>><i> for (unsigned int i=0;i<totnnz;i++)
</i>>><i> values[i]=PetscScalar(value_ptr[i]);
</i>>><i>
</i>>><i> ierr=MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD,size+1,size+1,rowindices,colindices,values,Aaddr);CHKERRQ(ierr);
</i>>><i>
</i>
>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".
<br>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. <br>So that the output matrix is (size+1)*(size+1) if the input matrix is size*size.
><i> ierr=MatAssemblyBegin(*Aaddr,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
</i>><i> ierr=MatAssemblyEnd(*Aaddr,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
</i>><i> return 0;
</i>><i> }
</i>></pre>