<div class="gmail_quote">On Mon, Nov 28, 2011 at 19:30, 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;">
<pre>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.</pre></blockquote><div>How is sizerow_ptr related to size? </div><div><br></div>
<div>Are you also filling in those indices correctly?</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><pre><div class="im"><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></div><div class="im">
>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></div>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.</pre>
</blockquote><div>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.</div>
</div>