Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_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 // ************************************************************************
38 // @HEADER
39 
40 // clang-format off
41 #ifndef TPETRA_BLOCKMULTIVECTOR_DECL_HPP
42 #define TPETRA_BLOCKMULTIVECTOR_DECL_HPP
43 
46 #include "Tpetra_MultiVector.hpp"
47 #include <memory>
48 #include <utility>
49 
50 namespace Tpetra {
51 
136 template<class Scalar,
137  class LO,
138  class GO,
139  class Node>
141  public Tpetra::DistObject<Scalar, LO, GO, Node>
142 {
143 private:
145  using STS = Teuchos::ScalarTraits<Scalar>;
146  using packet_type = typename dist_object_type::packet_type;
147 
148 public:
150 
151 
156 
158  using scalar_type = Scalar;
166  using local_ordinal_type = LO;
171 
173  using node_type = Node;
174 
177 
193  typedef Kokkos::View<impl_scalar_type *, device_type> little_vec_type;
194  typedef typename little_vec_type::HostMirror little_host_vec_type;
195 
201  typedef Kokkos::View<const impl_scalar_type *, device_type>
203 
205  host_device_type;
206  typedef Kokkos::View<const impl_scalar_type*, host_device_type>
207  const_little_host_vec_type;
208 
210 
212 
217  BlockMultiVector ();
218 
221 
224 
228 
232 
235  const Teuchos::DataAccess copyOrView);
236 
267  BlockMultiVector (const map_type& meshMap,
268  const LO blockSize,
269  const LO numVecs);
270 
275  BlockMultiVector (const map_type& meshMap,
276  const map_type& pointMap,
277  const LO blockSize,
278  const LO numVecs);
279 
292  BlockMultiVector (const mv_type& X_mv,
293  const map_type& meshMap,
294  const LO blockSize);
295 
301  const map_type& newMeshMap,
302  const map_type& newPointMap,
303  const size_t offset = 0);
304 
310  const map_type& newMeshMap,
311  const size_t offset = 0);
312 
314 
316 
324  static map_type
325  makePointMap (const map_type& meshMap, const LO blockSize);
326 
333  static Teuchos::RCP<const map_type>
334  makePointMapRCP (const map_type& meshMap, const LO blockSize);
335 
340  const map_type getPointMap () const {
341  return *pointMap_;
342  }
343 
345  LO getBlockSize () const {
346  return blockSize_;
347  }
348 
350  LO getNumVectors () const {
351  return static_cast<LO> (mv_.getNumVectors ());
352  }
353 
359  mv_type getMultiVectorView () const;
360 
362 
364 
366  void putScalar (const Scalar& val);
367 
369  void scale (const Scalar& val);
370 
377  void
378  update (const Scalar& alpha,
380  const Scalar& beta);
381 
403  void
404  blockWiseMultiply (const Scalar& alpha,
405  const Kokkos::View<const impl_scalar_type***,
406  device_type, Kokkos::MemoryUnmanaged>& D,
408 
439  void
440  blockJacobiUpdate (const Scalar& alpha,
441  const Kokkos::View<const impl_scalar_type***,
442  device_type, Kokkos::MemoryUnmanaged>& D,
445  const Scalar& beta);
446 
447 
449  template<class TargetMemorySpace>
450  bool need_sync () const {
451  return mv_.template need_sync<typename TargetMemorySpace::memory_space> ();
452  }
453 
455  bool need_sync_host() const {
456  return mv_.need_sync_host();
457  }
458 
460  bool need_sync_device() const {
461  return mv_.need_sync_device();
462  }
463 
465 
467 
485  bool replaceLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]);
486 
497  bool replaceGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]);
498 
509  bool sumIntoLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]);
510 
521  bool sumIntoGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]);
522 
523 
524  const_little_host_vec_type getLocalBlockHost(
525  const LO localRowIndex,
526  const LO colIndex,
527  const Access::ReadOnlyStruct) const;
528 
529  little_host_vec_type getLocalBlockHost(
530  const LO localRowIndex,
531  const LO colIndex,
532  const Access::ReadWriteStruct);
533 
537  little_host_vec_type getLocalBlockHost(
538  const LO localRowIndex,
539  const LO colIndex,
540  const Access::OverwriteAllStruct);
542 
543 protected:
549 
550 
551  // clang-format on
552  virtual bool checkSizes(const Tpetra::SrcDistObject &source) override;
553 
554  using dist_object_type::
556  // clang-format off
558 
559  virtual void
561  (const SrcDistObject& source,
562  const size_t numSameIDs,
563  const Kokkos::DualView<const local_ordinal_type*,
564  buffer_device_type>& permuteToLIDs,
565  const Kokkos::DualView<const local_ordinal_type*,
566  buffer_device_type>& permuteFromLIDs,
567  const CombineMode CM) override;
568 
570  // clang-format off
574 
575  virtual void
577  (const SrcDistObject& source,
578  const Kokkos::DualView<const local_ordinal_type*,
579  buffer_device_type>& exportLIDs,
580  Kokkos::DualView<packet_type*,
581  buffer_device_type>& exports,
582  Kokkos::DualView<size_t*,
583  buffer_device_type> numPacketsPerLID,
584  size_t& constantNumPackets) override;
585 
587  // clang-format off
591 
592  virtual void
594  (const Kokkos::DualView<const local_ordinal_type*,
595  buffer_device_type>& importLIDs,
596  Kokkos::DualView<packet_type*,
597  buffer_device_type> imports,
598  Kokkos::DualView<size_t*,
599  buffer_device_type> numPacketsPerLID,
600  const size_t constantNumPackets,
601  const CombineMode combineMode) override;
602  // clang-format off
603 
605 
606 protected:
607 
609  size_t getStrideX () const {
610  return static_cast<size_t> (1);
611  }
612 
614  size_t getStrideY () const {
615  return mv_.getStride ();
616  }
617 
620  bool isValidLocalMeshIndex (const LO meshLocalIndex) const;
621 
628 
629 private:
631  Teuchos::RCP<const map_type> pointMap_;
632 
633 protected:
636 
637 private:
638 
640  LO blockSize_;
641 
643  void
644  replaceLocalValuesImpl (const LO localRowIndex,
645  const LO colIndex,
646  const Scalar vals[]);
648  void
649  sumIntoLocalValuesImpl (const LO localRowIndex,
650  const LO colIndex,
651  const Scalar vals[]);
652 
653  static Teuchos::RCP<const mv_type>
654  getMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject&);
655 
656  static Teuchos::RCP<const BlockMultiVector<Scalar, LO, GO, Node> >
657  getBlockMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject& src);
658 };
659 
660 } // namespace Tpetra
661 
662 #endif // TPETRA_BLOCKMULTIVECTOR_DECL_HPP
Node node_type
The Kokkos Node type; a legacy thing that will go away at some point.
BlockMultiVector< Scalar, LO, GO, Node > & operator=(const BlockMultiVector< Scalar, LO, GO, Node > &)=default
Copy assigment (shallow copy).
void update(const Scalar &alpha, const BlockMultiVector< Scalar, LO, GO, Node > &X, const Scalar &beta)
Update: this = beta*this + alpha*X.
Kokkos::View< const impl_scalar_type *, device_type > const_little_vec_type
&quot;Const block view&quot; of all degrees of freedom at a mesh point, for a single column of the MultiVector...
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM)
Perform copies and permutations that are local to the calling (MPI) process.
void putScalar(const Scalar &val)
Fill all entries with the given value val.
bool need_sync_device() const
Whether this object needs synchronization to the device.
LO local_ordinal_type
The type of local indices.
size_t getNumVectors() const
Number of columns in the multivector.
typename::Kokkos::ArithTraits< Scalar >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
typename map_type::device_type device_type
This class&#39; preferred Kokkos device type.
Kokkos::View< impl_scalar_type *, device_type > little_vec_type
&quot;Block view&quot; of all degrees of freedom at a mesh point, for a single column of the MultiVector...
void blockJacobiUpdate(const Scalar &alpha, const Kokkos::View< const impl_scalar_type ***, device_type, Kokkos::MemoryUnmanaged > &D, const BlockMultiVector< Scalar, LO, GO, Node > &X, BlockMultiVector< Scalar, LO, GO, Node > &Z, const Scalar &beta)
Block Jacobi update .
void blockWiseMultiply(const Scalar &alpha, const Kokkos::View< const impl_scalar_type ***, device_type, Kokkos::MemoryUnmanaged > &D, const BlockMultiVector< Scalar, LO, GO, Node > &X)
*this := alpha * D * X, where D is a block diagonal matrix.
size_t getStrideX() const
Stride between consecutive local entries in the same column.
const map_type getPointMap() const
Get this BlockMultiVector&#39;s (previously computed) point Map.
Forward declaration of Tpetra::BlockCrsMatrix.
GO global_ordinal_type
The type of global indices.
bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[])
Replace all values at the given mesh point, using a global index.
static Teuchos::RCP< const map_type > makePointMapRCP(const map_type &meshMap, const LO blockSize)
Create and return an owning RCP to the point Map corresponding to the given mesh Map and block size...
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode)
Perform any unpacking and combining after communication.
size_t getStrideY() const
Stride between consecutive local entries in the same row.
bool replaceLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[])
Replace all values at the given mesh point, using local row and column indices.
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.
bool sumIntoLocalValues(const LO localRowIndex, const LO colIndex, const Scalar vals[])
Sum into all values at the given mesh point, using a local index.
bool need_sync_device() const
Whether this MultiVector needs synchronization to the device.
MultiVector for multiple degrees of freedom per mesh point.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
virtual bool checkSizes(const Tpetra::SrcDistObject &source) override
Compare the source and target (this) objects for compatibility.
bool need_sync_host() const
Whether this object needs synchronization to the host.
LO getBlockSize() const
Get the number of degrees of freedom per mesh point.
bool isValidLocalMeshIndex(const LO meshLocalIndex) const
True if and only if meshLocalIndex is a valid local index in the mesh Map.
virtual void unpackAndCombine(const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &importLIDs, Kokkos::DualView< packet_type *, buffer_device_type > imports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, const size_t constantNumPackets, const CombineMode combineMode) override
virtual void packAndPrepare(const SrcDistObject &source, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< packet_type *, buffer_device_type > &exports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, size_t &constantNumPackets)
Pack data and metadata for communication (sends).
typename mv_type::device_type device_type
The Kokkos Device type.
CombineMode
Rule for combining data in an Import or Export.
Tpetra::MultiVector< Scalar, LO, GO, Node > mv_type
The specialization of Tpetra::MultiVector that this class uses.
bool sumIntoGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[])
Sum into all values at the given mesh point, using a global index.
bool need_sync_host() const
Whether this MultiVector needs synchronization to the host.
mv_type mv_
The Tpetra::MultiVector used to represent the data.
Abstract base class for objects that can be the source of an Import or Export operation.
Forward declaration of Tpetra::BlockMultiVector.
virtual void copyAndPermute(const SrcDistObject &source, const size_t numSameIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteToLIDs, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &permuteFromLIDs, const CombineMode CM) override
Scalar scalar_type
The type of entries in the object.
bool need_sync() const
Whether this object needs synchronization to the given memory space.
LO getNumVectors() const
Get the number of columns (vectors) in the BlockMultiVector.
mv_type getMultiVectorView() const
Get a Tpetra::MultiVector that views this BlockMultiVector&#39;s data.
typename dist_object_type::buffer_device_type buffer_device_type
Kokkos::Device specialization used for communication buffers.
size_t getStride() const
Stride between columns in the multivector.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
void scale(const Scalar &val)
Multiply all entries in place by the given value val.
Base class for distributed Tpetra objects that support data redistribution.
typename mv_type::impl_scalar_type impl_scalar_type
The implementation type of entries in the object.
map_type meshMap_
Mesh Map given to constructor.
virtual void packAndPrepare(const SrcDistObject &source, const Kokkos::DualView< const local_ordinal_type *, buffer_device_type > &exportLIDs, Kokkos::DualView< packet_type *, buffer_device_type > &exports, Kokkos::DualView< size_t *, buffer_device_type > numPacketsPerLID, size_t &constantNumPackets) override