<div class="gmail_quote">On Mon, Nov 28, 2011 at 19:03, Nisoli Isaia <span dir="ltr"><<a href="mailto:isaia.nisoli@gmail.com">isaia.nisoli@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":9mb">int convertPETSc(srmatrix &sA, Mat * const Aaddr)<br>
{ <br> PetscErrorCode ierr;<br> PetscInt size=(sA.A).size1();<br> unsigned int totnnz=(sA.A).nnz();<br> <br> (sA.A).complete_index1_data();<br> long unsigned int *row_ptr =(sA.A).index1_data().begin();<br>
long unsigned int *col_ptr =(sA.A).index2_data().begin();<br> double * value_ptr = (sA.A).value_data().begin();<br> unsigned int sizerow_ptr=(sA.A).index1_data().size();<br> unsigned int sizecol_ptr=(sA.A).index2_data().size();<br>
PetscInt* rowindices;<br> PetscInt* colindices;<br> PetscScalar* values;<br> rowindices=new PetscInt[sizerow_ptr];<br></div></blockquote><div><br></div><div>This array is probably one too short. It needs to have length nrows+1 (so that the length of the last row is known).</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id=":9mb"> colindices=new PetscInt[sizecol_ptr];<br> values=new PetscScalar[totnnz];<br> for (unsigned int i=0;i<sizerow_ptr;i++) rowindices[i]=PetscInt(row_ptr[i]);<br>
for (unsigned int i=0;i<sizecol_ptr;i++) colindices[i]=PetscInt(col_ptr[i]);<br> for (unsigned int i=0;i<totnnz;i++) values[i]=PetscScalar(value_ptr[i]);<br> ierr=MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD,size+1,size+1,rowindices,colindices,values,Aaddr);CHKERRQ(ierr);<br>
</div></blockquote><div><br></div><div>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".</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id=":9mb">
ierr=MatAssemblyBegin(*Aaddr,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br> ierr=MatAssemblyEnd(*Aaddr,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br> return 0;<br>}</div></blockquote></div><br>