[petsc-users] Copy dense matrix into half part of another dense matrix

Matthew Knepley knepley at gmail.com
Mon Jan 27 07:52:36 CST 2025


On Mon, Jan 27, 2025 at 8:42 AM Pierre Jolivet <pierre at joliv.et> wrote:

> > On 27 Jan 2025, at 2:23 PM, medane.tchakorom at univ-fcomte.fr wrote:
> >
> > Dear PETSc users,
> >
> > I hope this message finds you well. I don’t know If my question is
> relevant, but I’am currently working with DENSE type matrix, and would like
> to copy one matrix R_part [ n/2 x m] (resulted from a MatMatMult operation)
> into another dense matrix R_full [n x m].
> > Both matrices being on the same communicator, I would like to
> efficiently copy R_part in the first half of R_full.
> > I have being using MatSetValues, but for large matrices, the subsequent
> assembling operation is costly.
>
> Could you please share the output of -log_view as well as a single file
> that will be generated with -info dump (e.g., dump.0, the file associated
> to process #0)?
> This shouldn’t be that costly, so there may be an option missing, like
> MAT_NO_OFF_PROC_ENTRIES.
> Anyway, if you want to optimize this, the fastest way would be to call
> MatDenseGetArray[Read,Write]() and then do the necessary PetscArraycpy().
>

The other alternative (which I think makes cleaner code) is to use

  https://urldefense.us/v3/__https://petsc.org/main/manualpages/Mat/MatDenseGetSubMatrix/__;!!G_uCfscf7eWS!ZOoOupB2xSO9fOY1fdeyPQU6bNVEuctFDItgqZzhKerRBnX3177w7U4_2rlep0tcSVOrNgKt75z9xd8BvjI9$ 

to create your R_part matrix. Then you are directly acting on the memory
you want when assemble the smaller matrix.

  THanks,

     Matt


> Thanks,
> Pierre
>
> > Please could you suggest me some strategies or functions to do this
> efficiently.
> >
> > Thank you for your time and assistance.
> >
> > Best regards,
> > Tchakorom Medane
> >
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZOoOupB2xSO9fOY1fdeyPQU6bNVEuctFDItgqZzhKerRBnX3177w7U4_2rlep0tcSVOrNgKt75z9xRlvvjmx$  <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZOoOupB2xSO9fOY1fdeyPQU6bNVEuctFDItgqZzhKerRBnX3177w7U4_2rlep0tcSVOrNgKt75z9xasPQhF0$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250127/c52e7eb2/attachment.html>


More information about the petsc-users mailing list