[petsc-users] a question about MatSetValue

Yang Bo (Asst Prof) yang.bo at ntu.edu.sg
Thu May 21 03:49:38 CDT 2020


Hi Dave,

Thank you very much for your reply. That is indeed the problem. I have been working with matrices in Slepc but I don’t really understand it. I tried to preallocate but it still does not work. If you look at my code below:

ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,h_dim,h_dim);                      // h_dim is the dimension of the square matrix A
ierr = MatSetFromOptions(A);CHKERRQ(ierr);
ierr = MatSetUp(A);CHKERRQ(ierr);
ierr = MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr);

MatSeqAIJSetPreallocation(A,0,nnz);                                       // I try to preallocate here, where nnz is the array containing the number of non-zero entries each row

for (int i=0;i<row.size();i++) {
MatSetValue(A,row[i],column[i],h[i],INSERT_VALUES);
}

I am not sure what other information I need to give for the pre-allocation…

Cheers,

Yang Bo



On 21 May 2020, at 4:08 PM, Dave May <dave.mayhem23 at gmail.com<mailto:dave.mayhem23 at gmail.com>> wrote:

-info | grep malloc

________________________________

CONFIDENTIALITY: This email is intended solely for the person(s) named and may be confidential and/or privileged. If you are not the intended recipient, please delete it, notify us and do not copy, use, or disclose its contents.
Towards a sustainable earth: Print only when necessary. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200521/9d13c7b5/attachment.html>


More information about the petsc-users mailing list