<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<span style="font-family:Menlo;font-size:12px;background-color:rgb(255, 255, 255);display:inline !important" class="ContentPasted0">Karhik,</span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<span style="font-family:Menlo;font-size:12px;background-color:rgb(255, 255, 255);display:inline !important" class="ContentPasted0">Can you find out the condition number of your matrix?</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<span style="font-family:Menlo;font-size:12px;background-color:rgb(255, 255, 255);display:inline !important" class="ContentPasted0">Hong</span></div>
<div id="signature_bookmark"></div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> petsc-users <petsc-users-bounces@mcs.anl.gov> on behalf of Karthikeyan Chockalingam - STFC UKRI via petsc-users <petsc-users@mcs.anl.gov><br>
<b>Sent:</b> Wednesday, November 16, 2022 6:04 PM<br>
<b>To:</b> petsc-users@mcs.anl.gov <petsc-users@mcs.anl.gov><br>
<b>Subject:</b> [petsc-users] Different solution while running in parallel</font>
<div> </div>
</div>
<div lang="EN-GB" style="word-wrap:break-word">
<div class="x_WordSection1">
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">  Hello,</span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space"> </span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">   I tried to solve a (FE discretized) Poisson equation using PCLU. For some reason I am getting different solutions while running the problem on one and two cores. I have attached the output file (out.txt) from both the
 runs. I am printing A, b and x from both the runs – while A and b are the same but the solution seems is different.</span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space"> </span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">I am not sure what I doing wrong.</span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space"> </span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">Below is my matrix, vector, and solve setup.
</span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space"> </span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space"> </span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">   </span> <span style="color:#3900A0">Mat</span> A;<span style="color:#3900A0"></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">    </span><span style="font-size:9.0pt; font-family:Menlo; color:#3900A0">Vec</span><span style="font-size:9.0pt; font-family:Menlo; color:black"> b, x;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">    </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">    ierr = </span><span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">MatCreate</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(</span><span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">PETSC_COMM_WORLD</span><span style="font-size:9.0pt; font-family:Menlo; color:black">,
 &A); </span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">CHKERRQ</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(ierr);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">    ierr = </span><span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">MatSetType</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(A,
</span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">MATMPIAIJ</span><span style="font-size:9.0pt; font-family:Menlo; color:black">);
</span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">CHKERRQ</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(ierr);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">    ierr = </span><span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">MatSetSizes</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(A,
</span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">PETSC_DECIDE</span><span style="font-size:9.0pt; font-family:Menlo; color:black">,
</span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">PETSC_DECIDE</span><span style="font-size:9.0pt; font-family:Menlo; color:black">, N, N);
</span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">CHKERRQ</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(ierr);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">    ierr = </span><span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">MatMPIAIJSetPreallocation</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(A,d_nz,
</span><b><span style="font-size:9.0pt; font-family:Menlo; color:#9B2393">NULL</span></b><span style="font-size:9.0pt; font-family:Menlo; color:black">, o_nz,
</span><b><span style="font-size:9.0pt; font-family:Menlo; color:#9B2393">NULL</span></b><span style="font-size:9.0pt; font-family:Menlo; color:black">);
</span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">CHKERRQ</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(ierr);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">    ierr = MatSetOption(A,MAT_SYMMETRIC,PETSC_TRUE);
</span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">CHKERRQ</span><span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">(ierr);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">    ierr = </span><span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">MatCreateVecs</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(A, &b, &x);
</span><span style="font-size:9.0pt; font-family:Menlo; color:#643820">CHKERRQ</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(ierr);</span></p>
<p class="x_p1" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
 </p>
<p class="x_p2" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">    </span><span class="x_s1" style="color: rgb(57, 0, 160);">KSP</span>
<span class="x_apple-converted-space">          </span>ksp;</p>
<p class="x_p2" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">    </span><span class="x_s1" style="color: rgb(57, 0, 160);">PC</span><span class="x_apple-converted-space">           
</span>pc;</p>
<p class="x_p3" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: rgb(108, 54, 169);">
<span class="x_apple-converted-space">    </span>KSPCreate<span class="x_s2">(</span>PETSC_COMM_WORLD<span class="x_s2">, &ksp);</span></p>
<p class="x_p2" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">    </span><span class="x_s3" style="color: rgb(108, 54, 169);">KSPSetOperators</span>(ksp, A, A);</p>
<p class="x_p2" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">    </span>ierr = <span class="x_s3" style="color: rgb(108, 54, 169);">
KSPSetType</span>(ksp,<span class="x_s5" style="color: rgb(100, 56, 32);">KSPPREONLY</span>);<span class="x_s5" style="color: rgb(100, 56, 32);">CHKERRQ</span>(ierr);</p>
<p class="x_p2" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">    </span>ierr = <span class="x_s3" style="color: rgb(108, 54, 169);">
KSPGetPC</span>(ksp,&pc);<span class="x_s5" style="color: rgb(100, 56, 32);">CHKERRQ</span>(ierr);</p>
<p class="x_p2" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: black;">
<span class="x_apple-converted-space">    </span>ierr = <span class="x_s3" style="color: rgb(108, 54, 169);">
PCSetType</span>(pc,<span class="x_s5" style="color: rgb(100, 56, 32);">PCLU</span>);<span class="x_s5" style="color: rgb(100, 56, 32);">CHKERRQ</span>(ierr);</p>
<p class="x_p3" style="margin: 0cm; background: white; font-size: 9pt; font-family: Menlo; color: rgb(108, 54, 169);">
<span class="x_apple-converted-space">    </span><span class="x_s2">ierr = </span>
PCFactorSetMatSolverType<span class="x_s2">(pc,</span><span class="x_s5" style="color: rgb(100, 56, 32);">MATSOLVERMUMPS</span><span class="x_s2">);</span><span class="x_s5" style="color: rgb(100, 56, 32);">CHKERRQ</span><span class="x_s2">(ierr);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">    </span><span style="font-size:9.0pt; font-family:Menlo; color:#6C36A9">KSPSolve</span><span style="font-size:9.0pt; font-family:Menlo; color:black">(ksp, b, x);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">Thank you for your help.</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;background:white">
<span style="font-size:9.0pt; font-family:Menlo; color:black">Karhik.</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;">
 </p>
</div>
<p><span style="font-size:6pt">This email and any attachments are intended solely for the use of the named recipients. If you are not the intended recipient you must not use, disclose, copy or distribute this email or any of its attachments and should notify
 the sender immediately and delete this email from your system. UK Research and Innovation (UKRI) has taken every reasonable precaution to minimise risk of this email or any attachments containing viruses or malware but the recipient should carry out its own
 virus and malware checks before opening the attachments. UKRI does not accept any liability for any losses or damages which the recipient may sustain due to presence of any viruses. </span></p>
</div>
</body>
</html>