Tpetra parallel linear algebra  Version of the Day
Tpetra_Experimental_BlockMultiVector_decl.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
43 #define TPETRA_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
44 
45 #include <Tpetra_MultiVector.hpp>
47 
48 namespace Tpetra {
49 namespace Experimental {
50 
51 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 // Forward declaration of BlockCrsMatrix, needed for debugging.
53 template<class S, class LO, class GO, class N> class BlockCrsMatrix;
54 #endif // DOXYGEN_SHOULD_SKIP_THIS
55 
144 template<class Scalar = Details::DefaultTypes::scalar_type,
146  class GO = Details::DefaultTypes::global_ordinal_type,
149  public Tpetra::DistObject<Scalar, LO, GO, Node>
150 {
151 private:
153  typedef Teuchos::ScalarTraits<Scalar> STS;
154 
155 protected:
156  typedef Scalar packet_type;
157 
158 public:
160 
161 
166 
168  typedef Scalar scalar_type;
177  typedef LO local_ordinal_type;
181  typedef Node node_type;
182 
199 
206 
208 
210 
241  BlockMultiVector (const map_type& meshMap,
242  const LO blockSize,
243  const LO numVecs);
244 
249  BlockMultiVector (const map_type& meshMap,
250  const map_type& pointMap,
251  const LO blockSize,
252  const LO numVecs);
253 
266  BlockMultiVector (const mv_type& X_mv,
267  const map_type& meshMap,
268  const LO blockSize);
269 
274  BlockMultiVector ();
275 
277 
279 
286  static map_type
287  makePointMap (const map_type& meshMap, const LO blockSize);
288 
293  map_type getPointMap () const {
294  return pointMap_;
295  }
296 
298  LO getBlockSize () const {
299  return blockSize_;
300  }
301 
303  LO getNumVectors () const {
304  return static_cast<LO> (mv_.getNumVectors ());
305  }
306 
312  mv_type getMultiVectorView ();
313 
315 
317 
319  void putScalar (const Scalar& val);
320 
322  void scale (const Scalar& val);
323 
325 
327 
345  bool replaceLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]) const;
346 
357  bool replaceGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const;
358 
369  bool sumIntoLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]) const;
370 
381  bool sumIntoGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const;
382 
393  bool getLocalRowView (const LO localRowIndex, const LO colIndex, Scalar*& vals) const;
394 
405  bool getGlobalRowView (const GO globalRowIndex, const LO colIndex, Scalar*& vals) const;
406 
418  little_vec_type
419  getLocalBlock (const LO localRowIndex, const LO colIndex) const;
421 
422 protected:
429 
430 
431  virtual bool checkSizes (const Tpetra::SrcDistObject& source);
432 
433  virtual void
434  copyAndPermute (const Tpetra::SrcDistObject& source,
435  size_t numSameIDs,
436  const Teuchos::ArrayView<const LO>& permuteToLIDs,
437  const Teuchos::ArrayView<const LO>& permuteFromLIDs);
438 
439  virtual void
440  packAndPrepare (const Tpetra::SrcDistObject& source,
441  const Teuchos::ArrayView<const LO>& exportLIDs,
442  Teuchos::Array<impl_scalar_type>& exports,
443  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
444  size_t& constantNumPackets,
445  Tpetra::Distributor& distor);
446 
447  virtual void
448  unpackAndCombine (const Teuchos::ArrayView<const LO> &importLIDs,
449  const Teuchos::ArrayView<const impl_scalar_type> &imports,
450  const Teuchos::ArrayView<size_t> &numPacketsPerLID,
451  size_t constantNumPackets,
452  Tpetra::Distributor& distor,
455 
456 protected:
458  impl_scalar_type* getRawPtr () const {
459  return mvData_;
460  }
461 
463  size_t getStrideX () const {
464  return static_cast<size_t> (1);
465  }
466 
468  size_t getStrideY () const {
469  return mv_.getStride ();
470  }
471 
474  bool isValidLocalMeshIndex (const LO meshLocalIndex) const {
475  return meshLocalIndex != Teuchos::OrdinalTraits<LO>::invalid () &&
476  meshMap_.isNodeLocalElement (meshLocalIndex);
477  }
478 
479 private:
480  // mfh 20 May 2014: I'm only using this for debugging.
481  template<class Scalar2, class LO2, class GO2, class Node2>
482  friend class BlockCrsMatrix;
483 
489  map_type meshMap_;
490 
492  map_type pointMap_;
493 
494 protected:
496  mv_type mv_;
497 
498 private:
507  impl_scalar_type* mvData_;
508 
510  LO blockSize_;
511 
513  void
514  replaceLocalValuesImpl (const LO localRowIndex,
515  const LO colIndex,
516  const Scalar vals[]) const;
518  void
519  sumIntoLocalValuesImpl (const LO localRowIndex,
520  const LO colIndex,
521  const Scalar vals[]) const;
522 
523  static Teuchos::RCP<const mv_type>
524  getMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject&);
525 
526  static Teuchos::RCP<const BlockMultiVector<Scalar, LO, GO, Node> >
527  getBlockMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject& src);
528 };
529 
530 } // namespace Experimental
531 } // namespace Tpetra
532 
533 #endif // TPETRA_EXPERIMENTAL_BLOCKMULTIVECTOR_DECL_HPP
Namespace Tpetra contains the class and methods constituting the Tpetra library.
mv_type mv_
The Tpetra::MultiVector used to represent the data.
KokkosClassic::DefaultNode::DefaultNodeType node_type
Default value of Node template parameter.
void putScalar(const Scalar &val)
Fill all entries with the given value val.
mv_type getMultiVectorView()
Get a Tpetra::MultiVector that views this BlockMultiVector&#39;s data.
Tpetra::Map< LO, GO, Node > map_type
The specialization of Tpetra::Map that this class uses.
bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const
Replace all values at the given mesh point, using a global index.
bool sumIntoGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[]) const
Sum into all values at the given mesh point, using a global index.
MultiVector for multiple degrees of freedom per mesh point.
static map_type makePointMap(const map_type &meshMap, const LO blockSize)
Create and return the point Map corresponding to the given mesh Map and block size.
virtual void unpackAndCombine(const Teuchos::ArrayView< const LO > &importLIDs, const Teuchos::ArrayView< const impl_scalar_type > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Tpetra::Distributor &distor, Tpetra::CombineMode CM)
Perform any unpacking and combining after communication.
int local_ordinal_type
Default value of LocalOrdinal template parameter.
void scale(const Scalar &val)
Multiply all entries in place by the given value val.
mv_type::impl_scalar_type impl_scalar_type
The implementation type of entries in the matrix.
little_vec_type getLocalBlock(const LO localRowIndex, const LO colIndex) const
Get a view of the degrees of freedom at the given mesh point.
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on the calling process.
LO getBlockSize() const
Get the number of degrees of freedom per mesh point.
impl_scalar_type * getRawPtr() const
Raw pointer to the MultiVector&#39;s data.
Declaration and definition of LittleBlock and LittleVector.
Nonowning view of a set of degrees of freedom corresponding to a mesh point in a block vector or mult...
LO getNumVectors() const
Get the number of columns (vectors) in the BlockMultiVector.
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Rule for combining data in an Import or Export.
bool getLocalRowView(const LO localRowIndex, const LO colIndex, Scalar *&vals) const
Get a writeable view of the entries at the given mesh point, using a local index. ...
Abstract base class for objects that can be the source of an Import or Export operation.
double scalar_type
Default value of Scalar template parameter.
bool isValidLocalMeshIndex(const LO meshLocalIndex) const
True if and only if meshLocalIndex is a valid local index in the mesh Map.
size_t getStride() const
Stride between columns in the multivector.
Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
map_type getPointMap() const
Get this BlockMultiVector&#39;s (previously computed) point Map.
virtual bool checkSizes(const Tpetra::SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
LittleVector< impl_scalar_type, LO > little_vec_type
"Block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector...
size_t getStrideY() const
Stride between consecutive local entries in the same row.
LittleVector< const impl_scalar_type, LO > const_little_vec_type
"Const block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector...
virtual void copyAndPermute(const Tpetra::SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LO > &permuteToLIDs, const Teuchos::ArrayView< const LO > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
size_t getNumVectors() const
Number of columns in the multivector.
bool replaceLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[]) const
Replace all values at the given mesh point, using local row and column indices.
size_t getStrideX() const
Stride between consecutive local entries in the same column.
virtual void packAndPrepare(const Tpetra::SrcDistObject &source, const Teuchos::ArrayView< const LO > &exportLIDs, Teuchos::Array< impl_scalar_type > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Tpetra::Distributor &distor)
Perform any packing or preparation required for communication.
Base class for distributed Tpetra objects that support data redistribution.
bool sumIntoLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[]) const
Sum into all values at the given mesh point, using a local index.
Tpetra::MultiVector< Scalar, LO, GO, Node > mv_type
The specialization of Tpetra::MultiVector that this class uses.
bool getGlobalRowView(const GO globalRowIndex, const LO colIndex, Scalar *&vals) const
Get a writeable view of the entries at the given mesh point, using a global index.