<div dir="ltr">On Tue, Sep 10, 2013 at 8:36 PM, Shri <span dir="ltr"><<a href="mailto:abhyshr@mcs.anl.gov" target="_blank">abhyshr@mcs.anl.gov</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br><div><div class="im"><div>On Sep 10, 2013, at 6:57 PM, Matthew Knepley wrote:</div><br><blockquote type="cite"><div dir="ltr">On Tue, Sep 10, 2013 at 6:53 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br>
On Sep 10, 2013, at 6:11 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br>
<br>
> On Tue, Sep 10, 2013 at 5:14 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> We had this discussion last November. Now that DMPlex has further matured and is likely to play a big role in some major applications I'd like to revisit the issue and see if PetscSection can be refactored to be easier to understand and more useful and more "compatible" with how DMPlex is developing.<br>
><br>
> PetscSection seems to have two distinct roles:<br>
><br>
> Role 1 (I'll call this object XX) Provides a way of indexing into an array of "items" where different items can be of different sizes and there can be spaces in the memory between items.<br>
><br>
> ---------<br>
> struct _n_PetscUniformSection atlasLayout; /* Layout for the atlas */<br>
> PetscInt *atlasDof; /* Describes layout of storage, point --> # of values */<br>
> PetscInt *atlasOff; /* Describes layout of storage, point --> offset into storage */<br>
> PetscInt maxDof; /* Maximum dof on any point */<br>
> PetscBool setup;<br>
><br>
> So if we have a regular C array pointer to type int, double etc we do addr = array + p == &array[p] to get the address of the pth item (where p may only be valid between pstart and pend.) With PetscSection instead one would do XXGetOffset(xx,p,&offset); addr = (type*) (array + offset); while XXGetDOF(xx,p,dof); gives you the "size" of the memory at location addr.<br>
><br>
> For historical reasons the offsets are in terms of int* instead of char*; (this should be fixed)<br>
><br>
> I do not understand this. The offsets are integers, and I think they should be.<br>
<br>
</div> I was unclear. The offset value should be in bytes from the beginning of the array, currently it is in ints from the beginning of the array. Ints is just plan confusing, Shri has to have this strange size sizeof(his struct)/sizeof(PetscInt) to indicate how big his chunk is.</blockquote>
<div><br></div><div>No, its has nothing to do with Int. Where did this come from? In fact, I use it all the time to mean Scalar offsets. It is</div><div>interpreter by the creator of the Section. I told him to put in bytes for the sizes. Then you do not need any of that crap.</div>
</div></div></div></blockquote><div><br></div></div><div>After speaking with Barry today, I realized that I was abusing PetscSection and doing a roundabout indexing to access the desired data. I was using four sections to distribute data for four different structures. I understand now that I need to </div>
<div>i) Create only one section to manage the parameters and use PetscSectionAddDof() to add the dofs (sizes of structs) for the different structs required for residual evaluation.</div><div>ii) Allocate a chunk of memory equal to the size returned from PetscSectionGetStorageSize(). Note that the user can do (i) and (ii) directly while reading the circuit parameters file. I am doing this after the file has been read and the different structs have been created, hence the need for allocating the chunk of memory.</div>
<div>iii) Loop over the edges, vertices and copy over the parameters using PetscSectionGetOffset().</div><div>iv) Use DMPlexDistributeData() with this section and the chunk of memory.</div><div><br></div><div>I tried to use MPI_BYTE as the MPI_DataType in DMPlexDistributeData() but got the following error. Jed explained that it had something to do with how the data is packed and suggested to divide the sizes of the structs in (ii) by PetscInt and use MPI_INT for DMPlexDistributeData() as a workaround.</div>
</div></div></div></blockquote><div><br></div><div>I wish the guy who write PetscSF believed in types smaller than int. Just because they are small, does not mean they</div><div>cannot achieve great things. MPI_BYTE is the Little Type That Could.</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 style="word-wrap:break-word"><div><div><div><div>[0]PETSC ERROR: --------------------- Error Message ------------------------------------</div>
<div>[0]PETSC ERROR: No support for this operation for this object type!</div><div>[0]PETSC ERROR: No support for type size not divisible by 4!</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div>
<div>[0]PETSC ERROR: Petsc Development GIT revision: d45619dec29bfb59cf96225a84e0a74106da50ca GIT Date: 2013-08-17 23:45:05 -0500</div><div>[1]PETSC ERROR: --------------------- Error Message ------------------------------------</div>
<div>[1]PETSC ERROR: No support for this operation for this object type!</div><div>[1]PETSC ERROR: No support for type size not divisible by 4!</div><div>[1]PETSC ERROR: ------------------------------------------------------------------------</div>
<div>[1]PETSC ERROR: Petsc Development GIT revision: d45619dec29bfb59cf96225a84e0a74106da50ca GIT Date: 2013-08-17 23:45:05 -0500</div><div>[0]PETSC ERROR: See docs/changes/index.html for recent updates.</div><div>[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.</div>
<div>[0]PETSC ERROR: See docs/index.html for manual pages.</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: ./PF2 on a debug-mode named Shrirangs-MacBook-Pro.local by Shri Tue Sep 10 20:22:44 2013</div>
<div>[0]PETSC ERROR: Libraries linked from /Users/Shri/Documents/petsc/debug-mode/lib</div><div>[0]PETSC ERROR: Configure run at Sat Aug 31 09:27:36 2013</div><div>[0]PETSC ERROR: Configure options --download-chaco --download-metis --download-mpich --download-mumps --download-parmetis --download-scalapack --download-superlu_dist COPTFLAGS=-g CLFAGS=-g FLAGS=-g FOPTFLAGS=-g PETSC_ARCH=debug-mode</div>
<div>[1]PETSC ERROR: See docs/changes/index.html for recent updates.</div><div>[1]PETSC ERROR: See docs/faq.html for hints about trouble shooting.</div><div>[1]PETSC ERROR: See docs/index.html for manual pages.</div><div>
[1]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: PetscSFBasicPackTypeSetup() line 386 in /Users/Shri/Documents/petsc/src/vec/is/sf/impls/basic/sfbasic.c</div>
<div>[0]PETSC ERROR: PetscSFBasicGetPack() line 509 in /Users/Shri/Documents/petsc/src/vec/is/sf/impls/basic/sfbasic.c</div><div>[0]PETSC ERROR: [1]PETSC ERROR: ./PF2 on a debug-mode named Shrirangs-MacBook-Pro.local by Shri Tue Sep 10 20:22:44 2013</div>
<div>[1]PETSC ERROR: Libraries linked from /Users/Shri/Documents/petsc/debug-mode/lib</div><div>[1]PETSC ERROR: Configure run at Sat Aug 31 09:27:36 2013</div><div>[1]PETSC ERROR: Configure options --download-chaco --download-metis --download-mpich --download-mumps --download-parmetis --download-scalapack --download-superlu_dist COPTFLAGS=-g CLFAGS=-g FLAGS=-g FOPTFLAGS=-g PETSC_ARCH=debug-mode</div>
<div>[1]PETSC ERROR: ------------------------------------------------------------------------</div><div>[1]PETSC ERROR: PetscSFBcastBegin_Basic() line 645 in /Users/Shri/Documents/petsc/src/vec/is/sf/impls/basic/sfbasic.c</div>
<div>[0]PETSC ERROR: PetscSFBcastBegin() line 918 in /Users/Shri/Documents/petsc/src/vec/is/sf/interface/sf.c</div><div>[0]PETSC ERROR: DMPlexDistributeData() line 2796 in /Users/Shri/Documents/petsc/src/dm/impls/plex/plex.c</div>
<div>[0]PETSC ERROR: PetscSFBasicPackTypeSetup() line 386 in /Users/Shri/Documents/petsc/src/vec/is/sf/impls/basic/sfbasic.c</div><div>[1]PETSC ERROR: PetscSFBasicGetPack() line 509 in /Users/Shri/Documents/petsc/src/vec/is/sf/impls/basic/sfbasic.c</div>
<div>[1]PETSC ERROR: PetscSFBcastBegin_Basic() line 645 in /Users/Shri/Documents/petsc/src/vec/is/sf/impls/basic/sfbasic.c</div><div>main() line 582 in pf2.c</div><div>[1]PETSC ERROR: PetscSFBcastBegin() line 918 in /Users/Shri/Documents/petsc/src/vec/is/sf/interface/sf.c</div>
<div>[1]PETSC ERROR: DMPlexDistributeData() line 2796 in /Users/Shri/Documents/petsc/src/dm/impls/plex/plex.c</div><div>[1]PETSC ERROR: main() line 582 in pf2.c</div><div>application called MPI_Abort(MPI_COMM_WORLD, 56) - process 0</div>
<div>[cli_0]: aborting job:</div><div>application called MPI_Abort(MPI_COMM_WORLD, 56) - process 0</div><div>application called MPI_Abort(MPI_COMM_WORLD, 56) - process 1</div><div>[cli_1]: aborting job:</div><div>application called MPI_Abort(MPI_COMM_WORLD, 56) - process 1</div>
<div><br></div><div>===================================================================================</div><div>= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES</div><div>= EXIT CODE: 56</div><div>= CLEANING UP REMAINING PROCESSES</div>
<div>= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES</div><div>===================================================================================</div><div><br></div><div>Btw, DMPlexDistributeData() is missing an extern declaration in petscdmplex.h.</div>
</div><div><div class="h5"><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div>
><br>
><br>
> This is a useful thing but in itself not a killer app. What makes it a killer app are<br>
><br>
> DMPlexDistributeField(DM dm, PetscSF pointSF, XX originalSection, Vec originalVec, XX newSection, Vec newVec)<br>
> DMPlexDistributeData(DM dm, PetscSF pointSF, XX originalSection, MPI_Datatype datatype, void *originalData, XX newSection, void **newData)<br>
><br>
> Note that these do not actually even use the DM (the code should be fixed by moving it out of DMPlex into the "lower level" code.) Note also these really create newSection internally (the code should be fixed by making these take PetscSection *newSection).<br>
><br>
> I can move them over to vsectionis.c. I do not agree that the signature should change. I thought we were going to<br>
> the VecLoad() paradigm where an empty object comes in.<br>
><br>
> What this means is that if I have a set of "points" distributed across MPI processes and for each point a "bunch of data" (in an "array" offsetted by a XX) and I redistribute the points across MPI processes including adding ghost points then I can redistribute all the "bunch of data" (including that needed for ghost points) trivially and conveniently access it using the newSection.<br>
><br>
> Yep, this should be very useful, an extension of the very useful VecScatter.<br>
><br>
><br>
> Role 2 (I'll call this object CC) Provides a container that tells you which parts of "bunches of data" in an array or Vec are associated with different "physical simulation fields" and are possibly constrained (for example by boundary conditions). Uses XX to indicate each field etc.<br>
><br>
> --------<br>
> PetscSection bc; /* Describes constraints, point --> # local dofs which are constrained */<br>
> PetscInt *bcIndices; /* Local indices for constrained dofs */<br>
><br>
><br>
> PetscInt numFields; /* The number of fields making up the degrees of freedom */<br>
> const char **fieldNames; /* The field names */<br>
> PetscInt *numFieldComponents; /* The number of components in each field */<br>
> PetscSection *field; /* A section describing the layout and constraints for each field */<br>
><br>
><br>
> Suggestion:<br>
><br>
> We split PetscSection into XX and CC reorganize and clean them up.<br>
><br>
> Okay. The reason I did it this way was that any FEM code is going to need CC, and it needs to contain XX, so<br>
> I just made XX the container. We can make CC the container and have the split that you want. It makes sense.<br>
><br>
> Relationship of XX to IS.<br>
><br>
> An IS defines a subset of entries in a Vec or possibly in an array of type int. Generally individual entries in an IS do not have particular meaning relative to other entries. That is one does not iterate over entries in an IS, one just uses the IS to get a new Vec and then does whatever on that Vec.<br>
><br>
> An XX is something you often iterate over, for example<br>
><br>
> for (p = pStart; p < pEnd; ++p) {<br>
> PetscInt dof, off, s;<br>
> ierr = PetscSectionGetDof(mesh->supportSection, p, &dof);CHKERRQ(ierr);<br>
> ierr = PetscSectionGetOffset(mesh->supportSection, p, &off);CHKERRQ(ierr);<br>
> do something<br>
><br>
> that is you get a single entry of XX and do something with it (though you can also get a bunch of entries and do something on the whole bunch).<br>
><br>
> We do have these kind of offset structures in PETSc (MatAIJ), but they are hardcoded in.<br>
><br>
> Question:<br>
><br>
> Is XX a powerful and useful thing? Do we have the correct API for it? Can it be used for other purposes?<br>
><br>
> I think its all yes.<br>
><br>
> Can it be made more powerful: for example the "chunk" that it gives you is always a contiqous set of bytes in the "array". Would be be better off with a YY object that allowed them to be non-contiquous? Or should YY be a higher level object implemented with XX?<br>
><br>
> Let me take this statement apart. So for any point p, the Section gives you back (offset, dof), so that you can use it to refer to<br>
><br>
> array[offset]...array[offset+dof]<br>
><br>
> which is the "chunk" that Barry is talking about. It is contiguous by design. That is how we achieve compression in the representation. I claim you<br>
> can get the YY object with two XX objects. The first XX object says how many "points" in the second XX correspond to each chunk. Each one of<br>
> the subchunks in the second XX is contiguous but they create a non-contiguous chunk for the first XX. In general, any non-contiguous thing is<br>
> represented by a set of contiguous things. This is not a good representation is you mostly have scatter, scalar data. However, I think we mostly have<br>
> scattered blocks of data.<br>
<br>
</div></div> Is this second thing, built on two XX worthing of its own abstraction? For example when I way give me the coordinates of the nodes of a triangular in a mesh?</blockquote><div><br></div><div>I am not sure I understand what you want here. I don't think this YY thing is all that useful since I can't see the generality.</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><div>
><br>
> Looking for a vigorous discussion and then code that I can better understand.<br>
><br>
> Me too, so "Jed is probably all wrong about this" :)<br>
><br>
> Matt<br>
><br>
><br>
> Barry<br>
><br>
><br>
><br>
> On Nov 8, 2012, at 10:18 PM, Jed Brown <<a href="mailto:jedbrown@mcs.anl.gov" target="_blank">jedbrown@mcs.anl.gov</a>> wrote:<br>
><br>
> > This is inevitable, but may still not resolve anything. I'm sure Matt will correct whatever below is incorrect. The main question is whether to promote PetscSection to a PetscObject or to hide/replace it with something else.<br>
> ><br>
> > So PetscSection is an unloved (by most) beastie that is sort of intermediate between an IS and a DM. Its core functionality is to provide indirect indexing with variable block sizes. It consists of two parts, the first of which is less than a PetscLayout.<br>
> ><br>
> > struct _n_PetscUniformSection {<br>
> > MPI_Comm comm;<br>
> > PetscInt pStart, pEnd; /* The chart: all points are contained in [pStart, pEnd) */<br>
> > PetscInt numDof; /* Describes layout of storage, point --> (constant # of values, (p - pStart)*constant # of values) */<br>
> > };<br>
> ><br>
> > numDof is always 1 and PetscUniformSection is never referenced from a *.c file so this is really just a range of valid "point" values [pStart...pEnd).<br>
> ><br>
> > struct _n_PetscSection {<br>
> > struct _n_PetscUniformSection atlasLayout; /* Layout for the atlas */<br>
> > PetscInt *atlasDof; /* Describes layout of storage, point --> # of values */<br>
> > PetscInt *atlasOff; /* Describes layout of storage, point --> offset into storage */<br>
> ><br>
> > ^^ These two fields are the essential part. Each index in [pStart,pEnd) is mapped to a block of size atlasDof[p-pStart] located at atlasOff[p-pStart]. Matt composes these indirect maps for storing meshes and other indexing tasks. This "unsorted offset mapping" is indeed used frequently in PETSc, though outside of Matt's code, it's just raw arrays.<br>
> ><br>
> > User's primarily encounter PetscSection when accessing unstructured meshes or any time the number of degrees of freedom or locations of each "point" (topological entity in the mesh) is not uniform. DMs do a similar thing (provide more logical access to a Vec), but DMDAVecGetArray() is of course only natural for a structured grid.<br>
> ><br>
> > At the user interface level, provided the user doesn't need low-level access to topology, I think there are three possibilities.<br>
> ><br>
> > 1. To compute a residual at a cell, user does<br>
> ><br>
> > VecGetArray(F,&f); // normal access to the Vec<br>
> > DMComplexGetHeightStratum(dm,0,&cstart,&cend); // "height 0" is like codimension 0 with respect to the maximum topological dimension. Matt and I have have a philosophical debate over whether users prefer to think in "strata" (that can skip dimensions, so "height 1" could be a face, an edge, or a vertex depending on what is stored in the mesh) or in "topological dimensions" (where codim=1 is a "face" for a 3D mesh and an edge for a 2D mesh).<br>
> ><br>
> > DMGetDefaultSection(dm,§ion);<br>
> > for (c=cstart; c<cend; c++) {<br>
> > PetscInt off;<br>
> > PetscSectionGetOffset(section,c,&off);<br>
> > f[off+0] = residual of first equation at this cell;<br>
> > f[off+1] = residual of second equation;<br>
> > // brushing under the rug how we access neighbor values<br>
> > }<br>
> ><br>
> > The above is basically the current model. Matt has DMComplexGet/SetClosure(), but that interface carries a sleeper reference to the Vec's array and he says he plans to remove it.<br>
> ><br>
> > 2. Add DMComplex-specific access routines so the user does not need to see the PetscSection. Presumably this would be something like<br>
> > DMComplexGetPointOffset(dm,c,&offset); // offset into owned part of global vector?<br>
> > DMComplexGetPointOffsetLocal(dm,c,&loffset); // offset into local vector<br>
> ><br>
> > 3. Access cursors (another object).<br>
> > DMComplexGetCursors(dm,Vec U,3,&uface,&ucellL,&ucellR);<br>
> > // similar for F<br>
> > DMComplexGetHeightStratum(dm,1,&fstart,&fend);<br>
> > for (f=fstart; f<fend; f++) {<br>
> > const PetscInt *c;<br>
> > const PetscScalar *uL,*uR,*uF;<br>
> > DMComplexGetSupport(dm,f,&c); // left and right cells<br>
> > DMCursorGetValues(uface,f,&uF); // only used for staggered/mixed discretization<br>
> > DMCursorGetValues(ucellL,c[0],&uL);<br>
> > DMCursorGetValues(ucellR,c[1],&uR);<br>
> > // Solve Riemann problem with "face" values uF[] (if using a staggered discretization), uL[], and uR[].<br>
> > DMCursorRestoreValues(uface,f,&uF); // ...<br>
> ><br>
> > The "advantage" of the cursors here is that DMComplex doesn't need to hold the context manager itself (perhaps for multiple threads), the code dealing with the number of concurrent accesses is outside the inner loop, and the implementations of these accessors are trivial (offset). I think it's still not compelling for the sketched discretization above, but consider also FEM methods where we need to access all degrees of freedom on the closure of an element. The following packs a buffer with the closure (because it's not contiguous in memory).<br>
> ><br>
> > DMCursorGetClosure(cell,c[0],&uc);<br>
> ><br>
> ><br>
> > 4. Alternative suggestions?<br>
> ><br>
> ><br>
> > I'm so sick of the name DMComplex. Let's just rename to DMPlex. It's shorter and doesn't have a double-meaning. Or pretty much any other name but "Complex".<br>
> ><br>
> > For completeness, the last bit of _n_PetscSection:<br>
> ><br>
> > PetscInt maxDof; /* Maximum dof on any point */<br>
> > PetscSection bc; /* Describes constraints, point --> # local dofs which are constrained */<br>
> > PetscInt *bcIndices; /* Local indices for constrained dofs */<br>
> ><br>
> > These BC fields are for doing masked updates, such as VecSetValuesSection() which ignores constrained dofs.<br>
> ><br>
> > PetscInt refcnt; /* Vecs obtained with VecDuplicate() and from MatGetVecs() reuse map of input object */<br>
> > PetscBool setup;<br>
> ><br>
> > PetscInt numFields; /* The number of fields making up the degrees of freedom */<br>
> > const char **fieldNames; /* The field names */<br>
> > PetscInt *numFieldComponents; /* The number of components in each field */<br>
> > PetscSection *field; /* A section describing the layout and constraints for each field */<br>
> > };<br>
> ><br>
><br>
><br>
><br>
><br>
> --<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>
<br>
</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
</div></div>
</blockquote></div></div></div><br></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
</div></div>