<div dir="ltr"><div dir="ltr">On Wed, May 17, 2023 at 6:58 PM neil liu <<a href="mailto:liufield@gmail.com">liufield@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Dear Petsc developers, <div><br></div><div>I am writing my own code to calculate the FEM matrix. The following is my general framework,</div><div><br></div><div>DMPlexCreateGmsh();</div><div>MPI_Comm_rank (Petsc_comm_world, &rank);</div><div>DMPlexDistribute (.., .., &dmDist);</div><div><br></div><div>dm = dmDist;</div><div>//This can create separate dm s for different processors. (reordering.)</div><div><br></div><div>MatCreate (Petsc_comm_world, &A)</div><div>// Loop over every tetrahedral element to calculate the local matrix for each processor. Then we can get a local matrix A for each processor.</div><div><br></div><div><i>My question is : it seems we should build a global matrix B (assemble all the As for each partition) and then transfer B to KSP. KSP will do the parallelization correctly, right? </i></div></div></blockquote><div><br></div><div>I would not suggest this. The more common strategy is to assemble each element matrix directly into the</div><div>global matrix B, by mapping the cell indices directly to global indices (rather than to local indices in the matrix A). You can do this in two stages. You can create a LocalToGlobalMapping in PETSc that maps</div><div>every local index to a global index. Then you can assemble into B exactly as you would assemble into A by calling MatSetValuesLocal().</div><div><br></div><div>DMPlex handles these mappings for you automatically, but I realize that it is a large number of things to buy into.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>If that is right, I should define a whole domain matrix B before the partitioning (MatCreate (Petsc_comm_world, &B); ), and then use localtoglobal (which petsc function should I use? Do you have any examples.) map to add A to B at the right positions (MatSetValues) ? </div><div><br></div><div>Does that make sense? </div><div><br></div><div>Thanks, </div><div><br></div><div>Xiaodong</div><div> </div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>