[petsc-users] alternative for MatCreateSeqAIJWithArrays

Qiyue Lu qiyuelu1 at gmail.com
Sat Oct 28 09:20:16 CDT 2023


Yes, this is exactly what I need. And it works now. For the record to other
potential users:
1) PetscInitialize and PCMPIServerBegin
looping start
         2) Sequential code part, and as Junchao said, MatSetValues on each
row to create matrices.
         3) parallel KSPSolve
looping end
4) PCMPIServerEnd and PetscFinalize

Thank you all for these suggestions. Have a good weekend.

Qiyue Lu

On Thu, Oct 26, 2023 at 9:30 AM Barry Smith <bsmith at petsc.dev> wrote:

>
>    Is your code sequential (with possibly OpenMP) or MPI parallel? Do you
> plan to make your part of the code MPI parallel?
>
>     If it is sequential or OpenMP parallel you might consider using the
> new feature https://petsc.org/release/manualpages/PC/PCMPI/#pcmpi Depending
> on your system it is an easy way to run linear solver in parallel while the
> code is sequential and can give some reasonable speedup.
>
> On Oct 26, 2023, at 8:58 AM, Qiyue Lu <qiyuelu1 at gmail.com> wrote:
>
> Hello,
> I am trying to incorporate PETSc as a linear solver to compute Ax=b in my
> code. Currently, the sequential version works.
> 1) I have the global matrix A in CSR format and they are stored in three
> 1-dimensional arrays: row_ptr[ ], col_idx[ ], values[ ], and I am using
> MatCreateSeqAIJWithArrays to get the PETSc format matrix. This works.
> 2) I am trying to use multicores, and when I use "srun -n 6", I got the
> error *Comm must be of size 1* from the MatCreateSeqAIJWithArrays. Saying
> I cannot use SEQ function in a parallel context.
> 3) I don't think MatCreateMPIAIJWithArrays and
> MatMPIAIJSetPreallocationCSR are good options for me, since I already have
> the global matrix as a whole.
>
> I wonder, from the global CSR format data, how can I reach the PETSc
> format matrix for parallel KSP computation. Are the MatSetValue,
> MatSetValues what I need?
>
> Thanks,
> Qiyue Lu
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20231028/4f8c33ad/attachment-0001.html>


More information about the petsc-users mailing list