<div dir="ltr"><div>Hi,<br><br></div>I wonder what I did wrong when using MATConvert...<br clear="all"><div><div><div><br> MatCreate(* comm_, &J_);<br><br> PetscInt * d_nnz = NULL;<br> PetscInt * o_nnz = NULL;<br> PetscMalloc(local_size * sizeof(PetscInt), & d_nnz);<br> PetscMalloc(local_size * sizeof(PetscInt), & o_nnz);<br> for (int i = 0; i < local_size; i++) {<br> d_nnz[i] = d_nnz_v[i];<br> o_nnz[i] = o_nnz_v[i];<br> }<br> MatSetSizes(J_,<br> local_size,<br> local_size,<br> PETSC_DECIDE,<br> PETSC_DECIDE);<br> <br> MatSetBlockSize(J_, M_SIZE); // So MatSetValuesBlocked can be used<br> MatSetType(J_, MATAIJ);<br> <br> if (comm_->Get_size() > 1) {<br> // MPI<br> MatMPIAIJSetPreallocation(J_,<br> max_d_nz,<br> d_nnz,<br> max_o_nz,<br> o_nnz);<br> <br> } else {<br> // Seq<br> MatSeqAIJSetPreallocation(J_,<br> PETSC_DEFAULT, <br> d_nnz);<br> }<br> <br> PetscFree(d_nnz);<br> PetscFree(o_nnz);<br><br> <br> // Column oriented<br> MatSetOption(J_, MAT_ROW_ORIENTED, PETSC_FALSE);<br></div><div> // Test code to check if J_ has right structure<br></div><div> preAssembeJ(); <br><br><img alt="Inline image 1" src="cid:ii_14c289a05b6ccd4b" height="291" width="291"><br></div><div> MatAssemblyBegin(J_, MAT_FINAL_ASSEMBLY);<br> MatAssemblyEnd(J_, MAT_FINAL_ASSEMBLY);<br><br><br> MatConvert(J_, MATBAIJ, MAT_REUSE_MATRIX, & J_);<br><br><div> <br> MatZeroEntries(J_); <br>// Test code to check if J_ has right structure <br></div> preAssembeJ();<br><img alt="Inline image 2" src="cid:ii_14c289a87062eb3b" height="265" width="284"><br></div><div>Thanks,<br></div><div>Kan<br></div><div><div class="gmail_signature"><p><b>Cheers</b></p></div>
</div></div></div></div>