Sorry, I mixed up things.<br>It is probably simply<br><br>rowindices[size]=rowindices[size-1];<br><div id=":y2"><br></div>Is it?<br>Isaia<br><br><br><br><div class="gmail_quote">On Tue, Nov 29, 2011 at 9:48 AM, Nisoli Isaia <span dir="ltr"><<a href="mailto:isaia.nisoli@gmail.com" target="_blank">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">So, if I want to add another row, what I should do is that:<br><br>rowindices[size]=rowindices[size-1];<br><br>rowindices[size-1]=size+1;<br>
is this last line right?<br>When a CSR matrix has a line 'i' which contains only 0s, how should I set rowindices[i]?<br>
<br>Is there any place where the number of columns is taken into account in <br><div><pre><i>PetscInt* rowindices;
</i><i>PetscInt* colindices;
</i><i>PetscScalar* values;</i></pre></div>reading the documentation about CSR, it does not look like that.<br><br>Thank you again<span><font color="#888888"><br>Isaia</font></span><div><div>
<br><br><br><div class="gmail_quote">On Mon, Nov 28, 2011 at 11:30 PM, Nisoli Isaia <span dir="ltr"><<a href="mailto:isaia.nisoli@gmail.com" target="_blank">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><div>>><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></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).
<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.<div><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>
>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>
</blockquote></div><br>
</div></div></blockquote></div><br>