<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;"><div><div><div><br></div></div></div><div><br></div><span id="OLK_SRC_BODY_SECTION"><div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt"><span style="font-weight:bold">From: </span> <<a href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a>> on behalf of Dave May <<a href="mailto:dave.mayhem23@gmail.com">dave.mayhem23@gmail.com</a>><br><span style="font-weight:bold">Date: </span> Thursday, May 12, 2016 at 2:48 AM<br><span style="font-weight:bold">To: </span> Sean Dettrick <<a href="mailto:sdettrick@trialphaenergy.com">sdettrick@trialphaenergy.com</a>><br><span style="font-weight:bold">Cc: </span> "<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>" <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>><br><span style="font-weight:bold">Subject: </span> Re: [petsc-users] accessing DMDA Vec ghost values<br></div><div><br></div><blockquote id="MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style="BORDER-LEFT: #b5c4df 5 solid; PADDING:0 0 0 5; MARGIN:0 0 0 5;"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 12 May 2016 at 10:42, Sean Dettrick <span dir="ltr"><<a href="mailto:sdettrick@trialphaenergy.com" target="_blank">sdettrick@trialphaenergy.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

                
        <div style="word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Calibri,sans-serif;font-size:14px">Hi,</div><div style="color:rgb(0,0,0);font-family:Calibri,sans-serif;font-size:14px"><br></div><div><font face="Calibri,sans-serif">When discussing DMDAVecGetArrayDOF etc in section 2.4.4,  the PETSc 3.7 manual says "</font><span style="color:rgb(0,0,0);font-family:NimbusRomNo9L;font-size:11pt">The </span><span style="color:rgb(0,0,0);font-family:NimbusMonL;font-size:11pt">array </span><span style="color:rgb(0,0,0);font-family:NimbusRomNo9L;font-size:11pt">is accessed using the usual </span><span style="color:rgb(0,0,0);font-family:NimbusRomNo9L;font-size:11pt">global </span><span style="color:rgb(0,0,0);font-family:NimbusRomNo9L;font-size:11pt">indexing on the entire grid,
but the user may </span><span style="color:rgb(0,0,0);font-family:NimbusRomNo9L;font-size:11pt">only </span><font face="NimbusRomNo9L" size="3">refer to the local and ghost entries of this array as all other entries are undefined</font><font face="NimbusRomNo9L"><span style="font-size:15px">”</span></font><font face="NimbusRomNo9L" size="3">.</font></div><div><font face="NimbusRomNo9L" size="3"><br></font></div><div><font face="NimbusRomNo9L" size="3">OK so far.  But how to access the ghost entries?</font></div><div><font face="NimbusRomNo9L" size="3"><br></font></div><div>With a 2D DMDA, I can do this OK:</div><div><p style="margin:0px;font-size:11px;font-family:Menlo"><br></p><p style="margin:0px;font-size:11px;font-family:Menlo">        <span style="color:rgb(53,163,39)">PetscInt</span>    <span style="color:rgb(199,156,36)">xs</span>,<span style="color:rgb(199,156,36)">xm</span>,<span style="color:rgb(199,156,36)">ys</span>,<span style="color:rgb(199,156,36)">ym</span>;</p><p style="margin:0px;font-size:11px;font-family:Menlo">        ierr=DMDAGetCorners(da,&xs,&ys,0,&xm,&ym,0);CHKERRQ(ierr);</p><p style="margin:0px;font-size:11px;font-family:Menlo">        <span style="color:rgb(53,163,39)">PetscScalar</span> ***<span style="color:rgb(199,156,36)">es</span>;</p><p style="margin:0px;font-size:11px;font-family:Menlo">        ierr=DMDAVecGetArrayDOF(da,Es,&es);CHKERRQ(ierr);</p><p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;font-family:Menlo">        <span style="color:rgb(208,60,255)">for</span> (<span style="color:rgb(53,163,39)">int</span> <span style="color:rgb(199,156,36)">j</span>=ys; j < ys+ym; j++) {</p><p style="margin:0px;font-size:11px;font-family:Menlo">            <span style="color:rgb(208,60,255)">for</span> (<span style="color:rgb(53,163,39)">int</span> <span style="color:rgb(199,156,36)">i</span>=xs; i < xs+xm;i++) {</p><p style="margin:0px;font-size:11px;font-family:Menlo"><span style="white-space:pre-wrap">            </span>es[j][i][0]=1.;</p><p style="margin:0px;font-size:11px;font-family:Menlo">                es[j][i][1]=1.;</p><p style="margin:0px;font-size:11px;font-family:Menlo">            }</p><p style="margin:0px;font-size:11px;font-family:Menlo">        }</p><p style="margin:0px;font-size:11px;font-family:Menlo">        ierr=DMDAVecRestoreArrayDOF(da,Es,&es);CHKERRQ(ierr);</p></div><div><br></div><div>But if I replace DMDAGetCorners with DMDAGetGhostCorners, then the code crashes with a seg fault, presumably due to out of bounds memory access.</div><div><br></div><div>Is that supposed to happen?  </div></div></blockquote><div><br></div><div><font face="arial,helvetica,sans-serif">If you created the vector Es using the function DM{Get,Create}GlobalVector(), then the answer is yes.</font></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div>What’s the remedy?</div></div></blockquote><div><br></div><div>If you want to access the ghost entries, you need to create the vector using the function DM{Get,Create}LocalVector().</div></div></div></div></blockquote></span><div><br></div><div><br></div><div><br></div><div><div>Thanks!  Somehow I missed DM{Get,Create}LocalVector().  BTW what is the difference between the Get and Create versions?  It is not obvious from the documentation.</div><div><br></div><div>Also, can you explain the difference between DMDAVecGetArrayDOF and DMDAVecGetArrayDOFRead?</div><div><br></div><div>Thanks again,</div><div>Sean</div></div><div><br></div><div><br></div><span id="OLK_SRC_BODY_SECTION"><blockquote id="MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style="BORDER-LEFT: #b5c4df 5 solid; PADDING:0 0 0 5; MARGIN:0 0 0 5;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Thanks,</div><div>  Dave</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Thanks very much!</div><span class=""><font color="#888888"><div><br></div><div>Sean Dettrick</div>
                
        
        
                <div title="Page 52" style="color:rgb(0,0,0);font-family:Calibri,sans-serif;font-size:14px">
                        <div>
                                <div>
                                        <div><div><div><br></div></div></div></div></div></div></font></span></div></blockquote></div><br></div></div></blockquote></span></body></html>