Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-21 Thread Matthew Knepley
On Wed, Jun 21, 2023 at 9:22 AM Diego Magela Lemos wrote: > Please, could you provide a minimal working example (or link) of how to do > this? > You can see here https://petsc.org/main/src/ksp/ksp/tutorials/ex2.c.html that each process only sets values for the rows it owns. Thanks,

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-21 Thread Diego Magela Lemos via petsc-users
Please, could you provide a minimal working example (or link) of how to do this? Thank you. Em ter., 20 de jun. de 2023 às 15:08, Matthew Knepley escreveu: > On Tue, Jun 20, 2023 at 2:02 PM Diego Magela Lemos > wrote: > >> So... what do I need to do, please? >> Why am I getting wrong results

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Matthew Knepley
On Tue, Jun 20, 2023 at 2:02 PM Diego Magela Lemos wrote: > So... what do I need to do, please? > Why am I getting wrong results when solving the linear system if the > matrix is filled in with MatSetPreallocationCOO and MatSetValuesCOO? > It appears that you have _all_ processes submit _all_

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Diego Magela Lemos via petsc-users
So... what do I need to do, please? Why am I getting wrong results when solving the linear system if the matrix is filled in with MatSetPreallocationCOO and MatSetValuesCOO? Em ter., 20 de jun. de 2023 às 14:56, Jed Brown escreveu: > Matthew Knepley writes: > > >> The matrix entries are

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Jed Brown
Matthew Knepley writes: >> The matrix entries are multiplied by 2, that is, the number of processes >> used to execute the code. >> > > No. This was mostly intended for GPUs, where there is 1 process. If you > want to use multiple MPI processes, then each process can only introduce > some

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Jed Brown
You should partition the entries so each entry is submitted by only one process. Note that duplicate entries (on the same or different proceses) are summed as you've seen. For example, in finite elements, it's typical to partition the elements and each process submits entries from its elements.

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Matthew Knepley
On Tue, Jun 20, 2023 at 1:43 PM Diego Magela Lemos wrote: > Using all recommended approaches it worked! > Thank you all in advance. > > Now, I'm facing problems when solving a linear system using each approach. > > *COO approach* > I can answer this one. > Using MatSetPreallocationCOO and

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Diego Magela Lemos via petsc-users
Using all recommended approaches it worked! Thank you all in advance. Now, I'm facing problems when solving a linear system using each approach. *COO approach* Using MatSetPreallocationCOO and then MatSetValuesCOO, I'm able to fill in the matrix when running with 1 MPI process. But, if I run

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Barry Smith
Since you have 6 entries that needed to be added to the matrix you will need to call MatSetValues() six time for the six entries. > On Jun 20, 2023, at 11:06 AM, Matthew Knepley wrote: > > On Tue, Jun 20, 2023 at 10:55 AM Diego Magela Lemos via petsc-users >

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Stefano Zampini
The loop should iterate on the number of entries of the array, not the number of local rows On Tue, Jun 20, 2023, 17:07 Matthew Knepley wrote: > On Tue, Jun 20, 2023 at 10:55 AM Diego Magela Lemos via petsc-users < > petsc-users@mcs.anl.gov> wrote: > >> Considering, for instance, the following

Re: [petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Matthew Knepley
On Tue, Jun 20, 2023 at 10:55 AM Diego Magela Lemos via petsc-users < petsc-users@mcs.anl.gov> wrote: > Considering, for instance, the following COO sparse matrix format, with > repeated indices: > > std::vector rows{0, 0, 1, 2, 3, 4}; > std::vector cols{0, 0, 1, 2, 3, 4}; > std::vector values{2,

[petsc-users] How to efficiently fill in, in parallel, a PETSc matrix from a COO sparse matrix?

2023-06-20 Thread Diego Magela Lemos via petsc-users
Considering, for instance, the following COO sparse matrix format, with repeated indices: std::vector rows{0, 0, 1, 2, 3, 4}; std::vector cols{0, 0, 1, 2, 3, 4}; std::vector values{2, -1, 2, 3, 4, 5}; that represents a 5x5 diagonal matrix A. So far, the code that I have is: //