<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:12pt"><div><span class="Apple-style-span" style="font-size: 13px; ">&gt;&gt;How much of a difference?</span></div><div style="font-family:arial, helvetica, sans-serif;font-size:12pt"><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">With the applied XYZPeriodic, if I keep the follwoing lines&nbsp;</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;if (i==0 || j==0 || k==0 || i==mx-1 || j==my-1 || k==mz-1){</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v[0] = 2.0*(HxHydHz + HxHzdHy + HyHzdHx);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ierr =
 MatSetValuesStencil(B,1,&amp;row,1,&amp;row,v,INSERT_VALUES);CHKERRQ(ierr);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;} else&nbsp;</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;Then the error between 1proc and 4 procs is only after 5th decimal point. However, if I comment out the&nbsp;</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">above lines then the results are completely different for 1 and 4 procs.</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">I am attaching the output of some last data points of a 10X10X8 grid.</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">1 proc output:</div><div style="font-family:arial,
 helvetica, sans-serif;font-size:10pt"><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">-4.40214</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">-4.39202</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">-4.38693</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">-4.38547</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">-4.38687</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">-4.39047</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div>4 proc output:</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000188031</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000169784</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000157229</div><div style="font-family:arial, helvetica,
 sans-serif;font-size:10pt">0.000178713</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000179637</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000188031</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000169784</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000157229</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000178713</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">0.000179637</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">I am attaching the faulty code here for your review.</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">Thanks.</div><div style="font-family:arial,
 helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">Khalid</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">static char help[] = "Solves 3D Laplacian using multigrid.\n\n";</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">#include "petscda.h"</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">#include "petscksp.h"</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">#include "petscdmmg.h"</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">#include "myHeaderfile.h"</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div
 style="font-family:arial, helvetica, sans-serif;font-size:10pt">extern PetscErrorCode ComputeMatrix(DMMG,Mat,Mat);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">extern PetscErrorCode ComputeRHS(DMMG,Vec);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">#undef __FUNCT__</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">#define __FUNCT__ "main"</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">int main(int argc,char **argv)</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">{</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;PetscErrorCode ierr;</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;DMMG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *dmmg;</div><div style="font-family:arial,
 helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;PetscReal &nbsp; &nbsp; &nbsp;norm;</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;DA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; da;</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;PetscInitialize(&amp;argc,&amp;argv,(char *)0,help);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;ierr = DMMGCreate(PETSC_COMM_WORLD,1,PETSC_NULL,&amp;dmmg);CHKERRQ(ierr);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;ierr = DACreate3d(PETSC_COMM_WORLD,DA_XYZPERIODIC,DA_STENCIL_STAR,10,10,8,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,0,0,0,&amp;da);CHKERRQ(ierr);</div><div style="font-family:arial, helvetica,
 sans-serif;font-size:10pt">&nbsp;&nbsp;ierr = DMMGSetDM(dmmg,(DM)da);CHKERRQ(ierr);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;// ierr = DADestroy(da);CHKERRQ(ierr);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><br></div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;ierr = DMMGSetKSP(dmmg,ComputeRHS,ComputeMatrix);CHKERRQ(ierr);</div><div style="font-family:arial, helvetica, sans-serif;font-size:10pt">&nbsp;&nbsp;ierr =DMMGSetNullSpace(dmmg,PETSC_TRUE,0,PETSC_NULL);</div><div><br></div><div><div>&nbsp;ierr = DMMGSetUp(dmmg);CHKERRQ(ierr);</div><div>&nbsp;&nbsp;ierr = DMMGSolve(dmmg);CHKERRQ(ierr);</div><div><br></div><div>&nbsp;&nbsp;ierr = MatMult(DMMGGetJ(dmmg),DMMGGetx(dmmg),DMMGGetr(dmmg));CHKERRQ(ierr);</div><div>&nbsp;&nbsp;ierr = VecAXPY(DMMGGetr(dmmg),-1.0,DMMGGetRHS(dmmg));CHKERRQ(ierr);</div><div>&nbsp;&nbsp;ierr =
 VecNorm(DMMGGetr(dmmg),NORM_2,&amp;norm);CHKERRQ(ierr);</div><div>&nbsp;&nbsp;/* ierr = PetscPrintf(PETSC_COMM_WORLD,"Residual norm %G\n",norm);CHKERRQ(ierr); */</div><div>&nbsp;&nbsp;ierr=VecView_VTK(DMMGGetx(dmmg),"X",&amp;appctx);</div><div><br></div><div>&nbsp;&nbsp;ierr = DMMGDestroy(dmmg);CHKERRQ(ierr);</div><div>&nbsp;&nbsp;ierr = PetscFinalize();CHKERRQ(ierr);</div><div><br></div><div>&nbsp;&nbsp;return 0;</div><div>}</div><div><br></div><div>#undef __FUNCT__</div><div>#define __FUNCT__ "ComputeRHS"</div><div>PetscErrorCode ComputeRHS(DMMG dmmg,Vec b)</div><div>{</div><div>&nbsp;&nbsp;PetscErrorCode ierr;</div><div>&nbsp;&nbsp;PetscInt &nbsp; &nbsp; &nbsp; mx,my,mz;</div><div>&nbsp;&nbsp;PetscScalar &nbsp; &nbsp;h;</div><div><br></div><div>&nbsp;&nbsp;PetscFunctionBegin;</div><div>&nbsp;&nbsp;ierr = DAGetInfo((DA)dmmg-&gt;dm,0,&amp;mx,&amp;my,&amp;mz,0,0,0,0,0,0,0);CHKERRQ(ierr);</div><div>&nbsp;&nbsp;h &nbsp; &nbsp;=
 10.0/((mx-1)*(my-1)*(mz-1));</div><div>&nbsp;&nbsp;ierr = VecSet(b,h);CHKERRQ(ierr);</div><div>&nbsp;&nbsp;PetscFunctionReturn(0);</div><div>}</div><div><br></div><div><div>#undef __FUNCT__</div><div>#define __FUNCT__ "ComputeMatrix"</div><div>PetscErrorCode ComputeMatrix(DMMG dmmg,Mat jac,Mat B)</div><div>{</div><div>&nbsp;&nbsp;DA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; da = (DA)dmmg-&gt;dm;</div><div>&nbsp;&nbsp;PetscErrorCode ierr;</div><div>&nbsp;&nbsp;PetscInt &nbsp; &nbsp; &nbsp; i,j,k,mx,my,mz,xm,ym,zm,xs,ys,zs;</div><div>&nbsp;&nbsp;PetscScalar &nbsp; &nbsp;v[7],Hx,Hy,Hz,HxHydHz,HyHzdHx,HxHzdHy;</div><div>&nbsp;&nbsp;MatStencil &nbsp; &nbsp; row,col[7];</div><div><br></div><div>&nbsp;&nbsp;ierr = DAGetInfo(da,0,&amp;mx,&amp;my,&amp;mz,0,0,0,0,0,0,0);CHKERRQ(ierr);</div><div>&nbsp;&nbsp;Hx = 1.0 / (PetscReal)(mx-1); Hy = 1.0 / (PetscReal)(my-1); Hz = 1.0 / (PetscReal)(mz-1);</div><div>&nbsp;&nbsp;HxHydHz = Hx*Hy/Hz; HxHzdHy = Hx*Hz/Hy; HyHzdHx
 = Hy*Hz/Hx;</div><div>&nbsp;&nbsp;ierr = DAGetCorners(da,&amp;xs,&amp;ys,&amp;zs,&amp;xm,&amp;ym,&amp;zm);CHKERRQ(ierr);</div><div><br></div><div>&nbsp;&nbsp;for (k=zs; k&lt;zs+zm; k++){</div><div>&nbsp;&nbsp; &nbsp;for (j=ys; j&lt;ys+ym; j++){</div><div>&nbsp;&nbsp; &nbsp; &nbsp;for(i=xs; i&lt;xs+xm; i++){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;row.i = i; row.j = j; row.k = k;</div><div>&nbsp;&nbsp; /* &nbsp; &nbsp; if (i==0 || j==0 || k==0 || i==mx-1 || j==my-1 || k==mz-1){</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v[0] = 2.0*(HxHydHz + HxHzdHy + HyHzdHx);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ierr = MatSetValuesStencil(B,1,&amp;row,1,&amp;row,v,INSERT_VALUES);CHKERRQ(ierr);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;} else */</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v[0] = -HxHydHz;col[0].i = i; col[0].j = j; col[0].k = k-1;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;
 &nbsp; &nbsp;v[1] = -HxHzdHy;col[1].i = i; col[1].j = j-1; col[1].k = k;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v[2] = -HyHzdHx;col[2].i = i-1; col[2].j = j; col[2].k = k;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v[3] = 2.0*(HxHydHz + HxHzdHy + HyHzdHx);col[3].i = row.i; col[3].j = row.j; col[3].k = row.k;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v[4] = -HyHzdHx;col[4].i = i+1; col[4].j = j; col[4].k = k;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v[5] = -HxHzdHy;col[5].i = i; col[5].j = j+1; col[5].k = k;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v[6] = -HxHydHz;col[6].i = i; col[6].j = j; col[6].k = k+1;</div><div><div>&nbsp;&nbsp; &nbsp;ierr = MatSetValuesStencil(B,1,&amp;row,7,col,v,INSERT_VALUES);CHKERRQ(ierr);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp; &nbsp;}</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp;}</div><div>&nbsp;&nbsp;ierr =
 MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);</div><div>&nbsp;&nbsp;ierr = MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);</div><div>&nbsp;&nbsp;return 0;</div><div>}</div><div><br></div></div></div></div></div></div></div><div style="position:fixed"></div>


</div></body></html>