<div dir="ltr">Yes, this is exactly what I need. And it works now. For the record to other potential users:<div>1) PetscInitialize and PCMPIServerBegin</div><div>looping start</div><div> 2) Sequential code part, and as Junchao said, MatSetValues on each row to create matrices.</div><div> 3) parallel KSPSolve</div><div>looping end</div><div>4) PCMPIServerEnd and PetscFinalize</div><div><br></div><div>Thank you all for these suggestions. Have a good weekend.</div><div><br></div><div>Qiyue Lu</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 26, 2023 at 9:30 AM Barry Smith <<a href="mailto:bsmith@petsc.dev">bsmith@petsc.dev</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><br></div> Is your code sequential (with possibly OpenMP) or MPI parallel? Do you plan to make your part of the code MPI parallel?<div><br></div><div> If it is sequential or OpenMP parallel you might consider using the new feature <a href="https://petsc.org/release/manualpages/PC/PCMPI/#pcmpi" target="_blank">https://petsc.org/release/manualpages/PC/PCMPI/#pcmpi</a> 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.<br id="m_8960810348438748408lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Oct 26, 2023, at 8:58 AM, Qiyue Lu <<a href="mailto:qiyuelu1@gmail.com" target="_blank">qiyuelu1@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Hello,<br><div>I am trying to incorporate PETSc as a linear solver to compute Ax=b in my code. Currently, the sequential version works. </div><div>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. </div><div>2) I am trying to use multicores, and when I use "srun -n 6", I got the error <b>Comm must be of size 1</b> from the MatCreateSeqAIJWithArrays. Saying I cannot use SEQ function in a parallel context. </div><div>3) I don't think MatCreateMPIAIJWithArrays and MatMPIAIJSetPreallocationCSR are good options for me, since I already have the global matrix as a whole. </div><div><br></div><div>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?</div><div><br></div><div>Thanks,</div><div>Qiyue Lu</div></div>
</div></blockquote></div><br></div></div></blockquote></div>