[petsc-users] Use MatConvert
Chung-Kan Huang
ckhuangf at gmail.com
Tue Mar 17 11:40:01 CDT 2015
Hi,
I wonder what I did wrong when using MATConvert...
MatCreate(* comm_, &J_);
PetscInt * d_nnz = NULL;
PetscInt * o_nnz = NULL;
PetscMalloc(local_size * sizeof(PetscInt), & d_nnz);
PetscMalloc(local_size * sizeof(PetscInt), & o_nnz);
for (int i = 0; i < local_size; i++) {
d_nnz[i] = d_nnz_v[i];
o_nnz[i] = o_nnz_v[i];
}
MatSetSizes(J_,
local_size,
local_size,
PETSC_DECIDE,
PETSC_DECIDE);
MatSetBlockSize(J_, M_SIZE); // So MatSetValuesBlocked can be used
MatSetType(J_, MATAIJ);
if (comm_->Get_size() > 1) {
// MPI
MatMPIAIJSetPreallocation(J_,
max_d_nz,
d_nnz,
max_o_nz,
o_nnz);
} else {
// Seq
MatSeqAIJSetPreallocation(J_,
PETSC_DEFAULT,
d_nnz);
}
PetscFree(d_nnz);
PetscFree(o_nnz);
// Column oriented
MatSetOption(J_, MAT_ROW_ORIENTED, PETSC_FALSE);
// Test code to check if J_ has right structure
preAssembeJ();
[image: Inline image 1]
MatAssemblyBegin(J_, MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(J_, MAT_FINAL_ASSEMBLY);
MatConvert(J_, MATBAIJ, MAT_REUSE_MATRIX, & J_);
MatZeroEntries(J_);
// Test code to check if J_ has right structure
preAssembeJ();
[image: Inline image 2]
Thanks,
Kan
*Cheers*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150317/445bb81d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 1041 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150317/445bb81d/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 1027 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150317/445bb81d/attachment-0001.png>
More information about the petsc-users
mailing list