<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks, as always. <div class=""><br class=""></div><div class="">Interesting that -Wall (with clang) didn’t catch that.  </div><div class=""><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;  ">-gideon</span>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Feb 27, 2017, at 10:28 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" class="">bsmith@mcs.anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">  You are using the info struct without ever having set values into it  You are, at a minimum, missing a call to DMDAGetLocalInfo(). Valgrind would immediately have found the use of uninitialized values. <br class=""><br class="">   Note that DMDAGetCorners() provides some of the information that DMDAGetLocalInfo() provides but in a slightly different format.<br class=""><br class=""><br class="">  Barry<br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class="">On Feb 27, 2017, at 9:18 PM, Gideon Simpson <<a href="mailto:gideon.simpson@gmail.com" class="">gideon.simpson@gmail.com</a>> wrote:<br class=""><br class="">Not sure if this is a bug or not, but, for the following code:<br class=""><br class="">#include <petscvec.h><br class="">#include <petscdm.h><br class="">#include <petscdmda.h><br class=""><br class="">typedef struct{<br class="">  PetscScalar u;<br class="">  PetscScalar v;<br class="">}b_node;<br class=""><br class=""><br class="">int main(int argc, char **args)<br class="">{<br class="">  char dataname[PETSC_MAX_PATH_LEN] = "testvec.bin";<br class="">  PetscInt N = 8;<br class="">  DM dm;<br class="">  Vec b;<br class="">  PetscScalar mass, eng;<br class="">  PetscViewer viewer;<br class="">  DMDALocalInfo info;<br class="">  b_node * b_array;<br class="">  Vec b_local;<br class="">  PetscInt local_index, local_width, i;<br class="">  PetscScalar u, v;<br class=""><br class=""><br class="">  PetscInitialize(&argc,&args,NULL,NULL);<br class=""><br class="">  PetscOptionsGetInt(NULL,NULL,"-N",&N,NULL);<br class=""><br class="">  DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED, N, 2 , 1 , NULL, &dm);<br class="">  DMCreateGlobalVector(dm ,&b);<br class=""><br class="">  /* Load vector from disk */<br class="">  PetscViewerBinaryOpen(PETSC_COMM_WORLD,dataname, FILE_MODE_READ, &viewer);<br class="">  VecLoad(b, viewer);<br class="">  PetscViewerDestroy(&viewer);<br class=""><br class="">  /* Inspect with viewer */<br class="">  VecView(b, PETSC_VIEWER_STDOUT_WORLD);<br class=""><br class="">  DMGetLocalVector(dm,&b_local);<br class="">  DMGlobalToLocalBegin(dm,b,INSERT_VALUES,b_local);<br class="">  DMGlobalToLocalEnd(dm,b,INSERT_VALUES,b_local);<br class=""><br class="">  DMDAVecGetArray(dm, b_local, &b_array);<br class="">  DMDAGetCorners (dm, &local_index, NULL, NULL,&local_width, NULL, NULL);<br class=""><br class="">  /* Zero out the ghost points */<br class="">  if(info.xs == 0){<br class="">    b_array[-1].u =0.0;<br class="">    b_array[-1].v =0.0;    <br class="">  }<br class="">  if(info.xs + info.xm == <a href="http://info.mx" class="">info.mx</a>){<br class="">    b_array[<a href="http://info.mx" class="">info.mx</a>].u =0.0;<br class="">    b_array[<a href="http://info.mx" class="">info.mx</a>].v =0.0;    <br class="">  }<br class=""><br class="">  /* Manually inspect */<br class="">  for(i=local_index;i<local_index+local_width;i++){<br class="">    u = b_array[i].u;<br class="">    v = b_array[i].v;<br class="">    PetscPrintf(PETSC_COMM_WORLD," %i: u = %g, v = %g\n", i, u, v);<br class="">  }<br class=""><br class="">  DMDAVecRestoreArray (dm,b_local,&b_array);<br class="">  DMRestoreLocalVector(dm,&b_local);<br class=""><br class="">  VecDestroy(&b);<br class="">  DMDestroy(&dm) ;<br class=""><br class="">  PetscFinalize();<br class="">  return 0;<br class=""><br class="">}<br class=""><br class="">I am getting the output <br class=""><br class="">Vec Object: 1 MPI processes<br class="">  type: seq<br class="">Vec Object:Vec_0x84000000_0 1 MPI processes<br class="">  type: mpi<br class="">Process [0]<br class="">1.<br class="">0.<br class="">0.707107<br class="">0.707107<br class="">6.12323e-17<br class="">1.<br class="">-0.707107<br class="">0.707107<br class="">-1.<br class="">1.22465e-16<br class="">-0.707107<br class="">-0.707107<br class="">-1.83697e-16<br class="">-1.<br class="">0.707107<br class="">-0.707107<br class=""> 0: u = 0., v = 0.<br class=""> 1: u = 0.707107, v = 0.707107<br class=""> 2: u = 6.12323e-17, v = 1.<br class=""> 3: u = -0.707107, v = 0.707107<br class=""> 4: u = -1., v = 1.22465e-16<br class=""> 5: u = -0.707107, v = -0.707107<br class=""> 6: u = -1.83697e-16, v = -1.<br class=""> 7: u = 0.707107, v = -0.707107<br class=""><br class="">The input vector is an alternating sequence of cos( pi / 4 * j), sin(pi/4 * j), for j = 0,1,2…7.  What I want to point out is that the first element of this vector, as it is read in,  is 1.  But when we do the manually looping, it spits out u = 0 at index i = 0.  If i turn off the piece of code that zeros out the ghost points, the problem disappears.  The reason I am concerned is that this kind of looping through the local vector with ghost points shows up in a piece of my code, and I am now concerned about the output.  Do I have a bug here?  <br class=""><br class=""><br class=""><br class="">-gideon<br class=""><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></body></html>