[petsc-users] a question about MatSetValue

Dave May dave.mayhem23 at gmail.com
Thu May 21 04:42:29 CDT 2020


On Thu 21. May 2020 at 10:49, Yang Bo (Asst Prof) <yang.bo at ntu.edu.sg>
wrote:

> 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.
>

Meaning the number of reported mallocs is still non-zero?
Is the number reported with you preallocation calls lower than what you
originally saw?

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…
>

This looks fine. However MatSeqAIJSetPreallocation() has no effect if the
Mat type is not SEQAIJ.

Are you running in parallel? If yes then the Mat type will be MATMPIAIJ and
you either have to call the MPI specific preallocator or use the generic
one I pointed you too.

Thanks
Dave



> Cheers,
>
> Yang Bo
>
>
>
> On 21 May 2020, at 4:08 PM, Dave May <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/37d0f7ce/attachment.html>


More information about the petsc-users mailing list