[Trilinos-Users] insertion/deletion in Tpetra vector/multivector

Hoemmen, Mark mhoemme at sandia.gov
Sun Jun 15 22:24:44 MDT 2014



On 6/14/14, 12:00 PM, "trilinos-users-request at software.sandia.gov"
<trilinos-users-request at software.sandia.gov> wrote:
>Message: 1
>Date: Fri, 13 Jun 2014 15:16:51 +0000
>From: "Templeton, Jeremy Alan" <jatempl at sandia.gov>
>To: "trilinos-users at software.sandia.gov"
>	<trilinos-users at software.sandia.gov>
>Subject: [Trilinos-Users] insertion/deletion in Tpetra
>	vector/multivector
>Message-ID: <6D01B8B4-FEB6-4D1A-A59A-9E2FC7D661BD at sandia.gov>
>Content-Type: text/plain; charset="us-ascii"
>
>Hi there.  I'm using Tpetra multi vectors to represent data that can be
>adaptively updated, i.e., there is the need to efficiently remove and
>insert elements.  What I've done in other codes is maintain a double *
>allocated beyond the length needed which can then be wrapped by a vector
>class by telling it the fill length and letting the vector do efficient
>math.  Insertion and deletion are then either constant or log N time
>depending on whether the array is unsorted or sorted.  Is there a way to
>get this same functionality directly with multi vector, or failing that,
>is there an easy way to manage a C++ array and have the multi vector wrap
>that?

Hi Jeremy!

Thanks for the helpful explanation!  MultiVector wasn't designed for
dynamic resizing.  You may _view_ a subset of the MultiVector using a
different Map, possibly with an offset.  You may even change the Map in
place (replaceMap).  However, MultiVector doesn't give you a way to
increase its local dimensions after its creation.  (That would change the
MultiVector's Map on one process, without telling the other processes
about the change.)

You may certainly use a MultiVector to view any column-major array of type
Scalar.  The constructor that takes four arguments (Teuchos::RCP<const
Map<...> >, Teuchos::ArrayRCP<Scalar>, size_t LDA, size_t numVectors)
supports this use case.  However, MultiVector does not give you a way to
change what data a MultiVector views (that is, change its local data
pointer), after the MultiVector has been constructed.  Thus, if you need
to increase the number of rows on a process, you will have to create a new
MultiVector with a new Map that has the appropriate number of local
entries on that process.

If you have an upper bound on the local dimensions on each process, you
could create a MultiVector of maximum size, and then get views of
(contiguous) subsets of rows and/or (possibly noncontiguous) subsets of
columns.  See the "Data copy and view methods" section of MultiVector's
documentation:

http://trilinos.sandia.gov/packages/docs/dev/packages/tpetra/doc/html/class
Tpetra_1_1MultiVector.html

The above only applies to Tpetra (and Epetra, which has the same
restrictions).  If you want dynamically resizable data structures on a
single process, the Kokkos package might have what you want.  Note that
dynamic resizing makes thread parallelism hard and should be treated like
a barrier or collective.  "Count, Allocate, Fill, Compute"! :-)

Please feel free to contact us directly, in case you have more questions!
mfh 



More information about the Trilinos-Users mailing list