<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 9, 2018 at 1:15 PM, Songtao Chu <span dir="ltr"><<a href="mailto:st.chu@outlook.com" target="_blank">st.chu@outlook.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thank you for your correction.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I rebuilt the code under Linux, the bug disappeared. It seems this is a bug of WSL.</div></div></blockquote><div><br></div><div>Thanks,</div><div><br></div><div>    Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">
<hr style="display:inline-block;width:98%">
<div id="m_1785365727471285895divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Satish Balay <<a href="mailto:balay@mcs.anl.gov" target="_blank">balay@mcs.anl.gov</a>><br>
<b>Sent:</b> Tuesday, April 10, 2018 0:20<br>
<b>To:</b> Songtao Chu<br>
<b>Cc:</b> Matthew Knepley; <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><span class=""><br>
<b>Subject:</b> Re: [petsc-users] How to access Vector data properly</span></font>
<div> </div>
</div>
<div class="m_1785365727471285895BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="m_1785365727471285895PlainText"><span class="">On Mon, 9 Apr 2018, Songtao Chu wrote:<br>
<br>
> static char help[] = "\n\n";<br>
> #include <petscdm.h><br>
> #include <petscdmda.h><br>
> <br>
> <br>
> int main(int argc,char **argv)<br>
> {<br>
>     PetscMPIInt     rank;<br>
>     PetscErrorCode  ierr;<br>
>     Vec             global,local,natural;<br>
>     DM              da;<br>
>     PetscReal       *val;<br>
>     PetscInt        i,x,xm;<br>
> <br>
> <br>
>     ierr = PetscInitialize(&argc,&argv,(<wbr>char*)0,help);if (ierr) return ierr;<br>
>     ierr = MPI_Comm_rank(PETSC_COMM_<wbr>WORLD,&rank);CHKERRQ(ierr);<br>
> <br>
>     ierr = DMDACreate1d(PETSC_COMM_WORLD,<wbr>DM_BOUNDARY_NONE,5,1,1,NULL,&<wbr>da);CHKERRQ(ierr);<br>
>     ierr = DMSetUp(da);CHKERRQ(ierr);<br>
>     ierr = DMCreateGlobalVector(da,&<wbr>global);CHKERRQ(ierr);<br>
> <br>
>     ierr = DMDAGetCorners(da,&x,NULL,<wbr>NULL,&xm,NULL,NULL);CHKERRQ(<wbr>ierr);<br>
>     ierr = DMDAVecGetArray(da, global, &val);CHKERRQ(ierr);<br>
>     ierr = PetscSynchronizedPrintf(PETSC_<wbr>COMM_SELF, "Rank=%d\n", rank);CHKERRQ(ierr);<br>
<br></span>
Shouldn't this call be removed? Nothing of substance is printed here.<span class=""><br>
<br>
>     for (i = x; i < x + xm; ++i) {<br>
>         val[i] = i;<br>
>     }<br>
>     ierr = DMDAVecRestoreArray(da, global, &val);CHKERRQ(ierr);<br>
> <br>
>     VecView(global,PETSC_VIEWER_<wbr>STDOUT_WORLD);<br>
> <br>
>     ierr = DMDAGetCorners(da,&x,NULL,<wbr>NULL,&xm,NULL,NULL);CHKERRQ(<wbr>ierr);<br>
>     ierr = DMDAVecGetArray(da, global, &val);CHKERRQ(ierr);<br>
>     ierr = PetscSynchronizedPrintf(PETSC_<wbr>COMM_SELF, "Rank=%d\n", rank);CHKERRQ(ierr);<br>
<br></span>
Shouldn't this be on PETSC_COMM_WORLD?<span class=""><br>
<br>
>     for (i = x; i < x + xm; ++i) {<br>
>         ierr = PetscSynchronizedPrintf(PETSC_<wbr>COMM_SELF, "%4.f ", val[i]);CHKERRQ(ierr);<br>
<br></span>
Again PETSC_COMM_WORLD?<span class=""><br>
<br>
<br>
>     }<br>
>     ierr = DMDAVecRestoreArray(da, global, &val);CHKERRQ(ierr);<br>
>     PetscSynchronizedFlush(PETSC_<wbr>COMM_SELF, PETSC_STDOUT);<br>
> <br>
>     ierr = PetscFinalize();<br>
>     return ierr;<br>
> }<br>
<br></span>
Attaching the fixed code.<br>
<br>
Satish<br>
-------<br>
balay@asterix /home/balay/download-pine<br>
$ ./ex1<span class=""><br>
Vec Object: 1 MPI processes<br>
  type: seq<br></span><span class="">
0.<br>
1.<br>
2.<br>
3.<br>
4.<br>
Rank=0<br>
   0    1    2    3    4 <br></span>
balay@asterix /home/balay/download-pine<br>
$ mpiexec -n 2 ./ex1<span class=""><br>
Vec Object: 2 MPI processes<br>
  type: mpi<br>
Process [0]<br>
0.<br>
1.<br>
2.<br>
Process [1]<br>
3.<br>
4.<br>
Rank=0<br>
   0    1    2 <br>
Rank=1<br>
   3    4 <br></span>
balay@asterix /home/balay/download-pine<br>
$ mpiexec -n 3 ./ex1<br>
Vec Object: 3 MPI processes<span class=""><br>
  type: mpi<br>
Process [0]<br>
0.<br>
1.<br></span>
Process [1]<br>
2.<br>
3.<br>
Process [2]<br>
4.<br>
Rank=0<br>
   0    1 <br>
Rank=1<br>
   2    3 <br>
Rank=2<br>
   4 <br>
balay@asterix /home/balay/download-pine<br>
$</div>
</span></font></div>
</div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><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.caam.rice.edu/~mk51/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div>
</div></div>