<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:12pt"><div><span>Hi Matt, I ran the program on two processors. I am trying to enter value into a </span></div><div><span>vector associated with DA. I am using VecSetValues since I may need to assign nonlocal </span></div><div><span>values to the vector. However, I find that on 2 procs, a general parallel vector works but</span></div><div><span>the DAVector indexing is not working. Do you see any problem with the DA code ?</span></div><div><span><br></span></div><div><span>Thanks.</span></div><div><span><br></span></div><div><span>Khalid </span></div><div><span><br></span></div><div><span>THIS WORKS: 30 is written at index 5</span></div><div><span><div>-------------------------------</div><div>ppy=5;
ppx=30;</div><div>VecCreate(PETSC_COMM_WORLD,&testVec);</div><div>VecSetFromOptions(testVec);</div><div>VecSetSizes(testVec,PETSC_DECIDE,384);</div><div><br></div></span></div><div><div>VecSetValues(testVec,1,&ppy,&ppx,INSERT_VALUES);</div><div><div>VecAssemblyBegin(testVec);</div><div>VecAssemblyEnd(testVec);</div></div><div>=====================================</div><div><br></div><div>THIS DOES NOT WORK: puts 30 at index 9 instead of 5 when run on two procs.</div><div>---------------------------------</div><div>ppy=5; ppx=30;<br></div><div><div>ierr = DACreate3d(PETSC_COMM_WORLD,DA_YPERIODIC,DA_STENCIL_BOX,8,8,6,</div><div> PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,PETSC_NULL,PETSC_NULL,PETSC_NULL,</div><div> &appctx.da);CHKERRQ(ierr);</div></div><div> ierr =
DACreateGlobalVector(da,&testVec);CHKERRQ(ierr)<br></div><div>VecSetValues(testVec,1,&ppy,&ppx,INSERT_VALUES);</div><div>VecAssemblyBegin(testVec);<br></div><div>VecAssemblyEnd(testVec);</div></div> <div style="font-size: 12pt; font-family: arial, helvetica, sans-serif; "> <div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "> <div dir="ltr"> <font size="2" face="Arial"> <br><hr size="1"> <b><span style="font-weight:bold;">From:</span></b> Matthew Knepley <knepley@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> khalid ashraf <khalid_eee@yahoo.com> <br><b><span style="font-weight: bold;">Cc:</span></b> PETSc users list <petsc-users@mcs.anl.gov> <br> <b><span style="font-weight: bold;">Sent:</span></b> Monday, April 2, 2012 3:08 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [petsc-users] transfer vector data diagonally on DA<br> </font> </div> <br>
<div id="yiv1071495804"><div class="yiv1071495804gmail_quote">On Mon, Apr 2, 2012 at 4:53 PM, khalid ashraf <span dir="ltr"><<a rel="nofollow" ymailto="mailto:khalid_eee@yahoo.com" target="_blank" href="mailto:khalid_eee@yahoo.com">khalid_eee@yahoo.com</a>></span> wrote:<br><blockquote class="yiv1071495804gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="font-size: 12pt; font-family: arial, helvetica, sans-serif; "><div><span><div>Thanks Matt. It works now. </div><div><br></div><div>I have another problem. I am writing this program. </div></span></div></div></blockquote>
<div><br></div><div>1) Always test on 2 procs once</div><div><br></div><div>2) I have no idea what you actually want to do. However, it really simple to just print out</div><div> the indices you are using in row[] and the values in bodyFx[] and check that VecSetValues()</div>
<div> is working as you expect.</div><div><br></div><div> Matt</div><div> </div><blockquote class="yiv1071495804gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="font-size: 12pt; font-family: arial, helvetica, sans-serif; ">
<div><span><div><span style="font-size:12pt;"> </span></div><div><div> for (k=zs; k<zs+zm; k++) {</div><div> for (j=ys; j<ys+ym; j++) {</div><div> for (i=xs; i<xs+xm; i++) {</div><div><div> if ( i!=(mx-1) || j!=my-1 || k!=mz-1)</div>
<div>{</div></div></div><div>bodyFx[0]=1;</div><div>bodyFx[1]=-0.3;</div><div>bodyFx[2]=-0.3;</div><div>bodyFx[3]=-0.3;</div><div>row[0]=k*mx*my+j*mx+i;</div><div>row[1]=k*mx*my+j*mx+i+1;</div><div>row[2]=k*mx*my+(j+1)*mx+i;</div>
<div>row[3]=(k+1)*mx*my+j*mx+i;</div><div>VecSetValues(fx_test,4,row,bodyFx,ADD_VALUES);</div></span></div><div>}</div><div><div>VecAssemblyBegin(fx_test);</div><div>VecAssemblyEnd(fx_test);</div><div><br></div><div>Output: Print
fx_test</div><div><br></div></div><div> Here fx_test is a global vector. This program gives correct output on 1 proc. but on 4 processors,</div><div>the program runs but the outputs are wrong.</div><div><br></div><div>I also tried</div>
<div><div><div> for (k=zs; k<zs+zm; k++) {</div><div> for (j=ys; j<ys+ym; j++) {</div><div> for (i=xs; i<xs+xm; i++) {</div><div><div> if ( i!=(mx-1) || j!=my-1 || k!=mz-1)</div><div>{</div></div></div><div>bodyFx[0]=1;</div>
<div>bodyFx[1]=-0.3;</div><div>bodyFx[2]=-0.3;</div><div>bodyFx[3]=-0.3;</div><div><div> fx1_localptr[k][j][i+1]+=bodyFx[4];</div><div> fx1_localptr[k][j+1][i]+=bodyFx[3];</div><div> fx1_localptr[k+1][j][i]+=bodyFx[1];</div>
<div> fx1_localptr[k][j][i]+=bodyFx[0];</div><div>}</div><div>Here, fx1_localptr is an array from a local vector that is communicated from the global vector fx_test.</div><div>In this case as well, I get similar
errors. <br></div><div><div><br></div><div>Thanks.</div><div>Khalid</div><div><br></div><div>Some final numbers of the vector with 8*8*6 grid, 4 proc,
</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>1.0000000000000009e-01</div><div>1.0000000000000009e-01</div><div>1.0000000000000009e-01</div>
<div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>0.0000000000000000e+00</div><div>4.0000000000000002e-01</div><div>1.0000000000000009e-01</div>
<div>1.0000000000000009e-01</div><div>1.0000000000000009e-01</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div>1.0000000000000009e-01</div>
<div>1.0000000000000009e-01</div><div>1.0000000000000009e-01</div><div>-2.9999999999999999e-01</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div><br></div><div><br>
</div><div>Some final numbers
of the vector with 8*8*6 grid, 1 proc,
<br></div><div><div>0.0000000000000000e+00</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div>
<div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>0.0000000000000000e+00</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div>
<div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>0.0000000000000000e+00</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div>
<div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>-2.9999999999999999e-01</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div>
<div>0.0000000000000000e+00</div>
<div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div>0.0000000000000000e+00</div><div><br></div><div> </div>
</div><div><br></div></div></div></div> <div style="font-size: 12pt; font-family: arial, helvetica, sans-serif; "> <div style="font-size:12pt;"> <div dir="ltr">
<font face="Arial"> <hr size="1"> <b><span style="font-weight:bold;">From:</span></b> Matthew Knepley <<a rel="nofollow" ymailto="mailto:knepley@gmail.com" target="_blank" href="mailto:knepley@gmail.com">knepley@gmail.com</a>><br> <b><span style="font-weight:bold;">To:</span></b> khalid ashraf <<a rel="nofollow" ymailto="mailto:khalid_eee@yahoo.com" target="_blank" href="mailto:khalid_eee@yahoo.com">khalid_eee@yahoo.com</a>>; PETSc users list <<a rel="nofollow" ymailto="mailto:petsc-users@mcs.anl.gov" target="_blank" href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> <br>
<b><span style="font-weight:bold;">Sent:</span></b> Monday, April 2, 2012 5:41 AM<br> <b><span style="font-weight:bold;">Subject:</span></b> Re:
[petsc-users] transfer vector data diagonally on DA<br> </font> </div> <br>
<div>On Mon, Apr 2, 2012 at 3:36 AM, khalid ashraf <span dir="ltr"><<a rel="nofollow" ymailto="mailto:khalid_eee@yahoo.com" target="_blank" href="mailto:khalid_eee@yahoo.com">khalid_eee@yahoo.com</a>></span> wrote:<br><div><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div style="font-size: 12pt; font-family: arial, helvetica, sans-serif; "><div><span>Hi Jed,</span></div><div><span><br></span></div><div><span>I am using petsc/3.1 and the include file "petscdmda.h" is not working. I am using the "petscda.h"</span></div>
<div><span>and DACreate3D. </span></div><div><span><div>unew_localptr[][][] is from a global vector using VecGetArray</div><div>u_localptr[][][] is from a local vector communicated from a global vector.</div><div>I tried </div>
<div>unew_localptr[k][j][i]=u_localptr[k-1][j-1][i-1]<br></div><div>but it gives Segmentation Violation error. </div></span></div></div></div></blockquote><div><br></div><div>I would guess (because you provide almost no information about what you are doing), that</div>
<div>this is a domain on the edge. If you truly mean to have a periodic domain, you must set that in the</div><div>creation call. Then the local vector will also ghost regions outside the domain boundary.</div><div><br></div>
<div> Matt</div><div> </div><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div style="font-size: 12pt; font-family: arial, helvetica, sans-serif; "><div><span><div>I also tried unew_localptr[k][j][i]=u_localptr[k][j+1][i+1] which works but </div>
<div>unew_localptr[k][j][i]=u_localptr[k+1][j+1][i+1] or unew_localptr[k][j][i]=u_localptr[k][j-1][i-1]</div><div>does not work. I am running the program on4
processors.<br></div><div><br></div><div>Thanks.</div><div><br></div><div><br></div><div> ierr = DACreate3d(PETSC_COMM_WORLD,DA_YPERIODIC,DA_STENCIL_BOX,appctx.l,appctx.m,appctx.n,</div><div> PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,PETSC_NULL,PETSC_NULL,PETSC_NULL,</div>
<div> &appctx.da);CHKERRQ(ierr);</div><div><div><div> for (k=zs; k<zs+zm; k++) {</div><div> for (j=ys; j<ys+ym; j++) {</div><div> for (i=xs; i<xs+xm; i++) {</div><div><br></div>
</div><div> if(i!=0 || j!=0 || k!=0|| i!=mx-1 || j!=my-1 || k!=mz-1)</div><div><br></div></div></span></div><div> unew_localptr[k][j][i]=u_localptr[k+1][j+1][i+1];<br></div><div>}}}</div> <div style="font-size: 12pt; font-family: arial, helvetica, sans-serif; ">
<div style="font-size:12pt;"> <div dir="ltr"> <font face="Arial"> <hr size="1"><div> <b><span style="font-weight:bold;">From:</span></b> Jed Brown <<a rel="nofollow" ymailto="mailto:jedbrown@mcs.anl.gov" target="_blank" href="mailto:jedbrown@mcs.anl.gov">jedbrown@mcs.anl.gov</a>><br>
<b><span style="font-weight:bold;">To:</span></b> khalid ashraf <<a rel="nofollow" ymailto="mailto:khalid_eee@yahoo.com" target="_blank" href="mailto:khalid_eee@yahoo.com">khalid_eee@yahoo.com</a>>; PETSc users list <<a rel="nofollow" ymailto="mailto:petsc-users@mcs.anl.gov" target="_blank" href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> <br>
<b><span style="font-weight:bold;">Sent:</span></b> Sunday, April 1, 2012 10:07 PM<br> <b><span style="font-weight:bold;">Subject:</span></b> Re: [petsc-users] transfer vector data diagonally on DA<br> </div></font><div>
</div></div><div><div> <br>
<div><div>On Sun, Apr 1, 2012 at 22:01, khalid ashraf <span dir="ltr"><<a rel="nofollow" ymailto="mailto:khalid_eee@yahoo.com" target="_blank" href="mailto:khalid_eee@yahoo.com">khalid_eee@yahoo.com</a>></span> wrote:<br><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>I want to transfer vector data diagonally in the DA grid like </div><div><div> for (k=zs; k<zs+zm; k++) {</div><div> for (j=ys; j<ys+ym; j++) {</div><div> for (i=xs; i<xs+xm; i++) {</div><div>if(i!=mx-1 || j!=my-1 || k!=mz-1){</div>
</div><div>u_new[k+1][j+1][i+1]=u[k][j][i];}</div><div>}}}</div><div><br></div><div>Could you please suggest the best way to do it minimizing interprocessor assignments.</div></blockquote></div><br><div>Both are on the same DMDA?</div>
<div><br></div><div>Communicate U to Ulocal (DMGlobalToLocalBegin/End) using a BOX stencil with width at least 1, get the global array u_new[][][] from UGlobalNew and the local arrays u[][][] from Ulocal, then assign u_new[k][j][i] = u[k-1][j-1][i-1].</div>
</div><br><br><span class="yiv1071495804HOEnZb"><font color="#888888"> </font></span></div></div></div><span class="yiv1071495804HOEnZb"><font color="#888888"> </font></span></div><span class="yiv1071495804HOEnZb"><font color="#888888"> </font></span></div></div>
</blockquote></div><span class="yiv1071495804HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br>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<br>
</font></span></div><br><br> </div> </div> </div></blockquote></div><br><br clear="all"><div><br></div>-- <br>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<br>
</div><br><br> </div> </div> </div></body></html>