Tpetra parallel linear algebra  Version of the Day
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 #ifndef TPETRA_BLOCKMULTIVECTOR_DECL_HPP
41 #define TPETRA_BLOCKMULTIVECTOR_DECL_HPP
42 
45 #include "Tpetra_MultiVector.hpp"
46 #include <memory>
47 #include <utility>
48 
49 namespace Tpetra {
50 
135 template<class Scalar,
136  class LO,
137  class GO,
138  class Node>
140  public Tpetra::DistObject<Scalar, LO, GO, Node>
141 {
142 private:
144  using STS = Teuchos::ScalarTraits<Scalar>;
145  using packet_type = typename dist_object_type::packet_type;
146 
147 public:
149 
150 
155 
157  using scalar_type = Scalar;
165  using local_ordinal_type = LO;
170 
172  using node_type = Node;
173 
176 
192  typedef Kokkos::View<impl_scalar_type *, device_type> little_vec_type;
193  typedef typename little_vec_type::HostMirror little_host_vec_type;
194 
200  typedef Kokkos::View<const impl_scalar_type *, device_type>
202 
204  host_device_type;
205  typedef Kokkos::View<const impl_scalar_type*, host_device_type>
206  const_little_host_vec_type;
207 
209 
211 
216  BlockMultiVector ();
217 
220 
223 
227 
231 
234  const Teuchos::DataAccess copyOrView);
235 
266  BlockMultiVector (const map_type& meshMap,
267  const LO blockSize,
268  const LO numVecs);
269 
274  BlockMultiVector (const map_type& meshMap,
275  const map_type& pointMap,
276  const LO blockSize,
277  const LO numVecs);
278 
291  BlockMultiVector (const mv_type& X_mv,
292  const map_type& meshMap,
293  const LO blockSize);
294 
300  const map_type& newMeshMap,
301  const map_type& newPointMap,
302  const size_t offset = 0);
303 
309  const map_type& newMeshMap,
310  const size_t offset = 0);
311 
313 
315 
322  static map_type
323  makePointMap (const map_type& meshMap, const LO blockSize);
324 
330  return pointMap_;
331  }
332 
334  LO getBlockSize () const {
335  return blockSize_;
336  }
337 
339  LO getNumVectors () const {
340  return static_cast<LO> (mv_.getNumVectors ());
341  }
342 
348  mv_type getMultiVectorView () const;
349 
351 
353 
355  void putScalar (const Scalar& val);
356 
358  void scale (const Scalar& val);
359 
366  void
367  update (const Scalar& alpha,
369  const Scalar& beta);
370 
392  void
393  blockWiseMultiply (const Scalar& alpha,
394  const Kokkos::View<const impl_scalar_type***,
395  device_type, Kokkos::MemoryUnmanaged>& D,
397 
428  void
429  blockJacobiUpdate (const Scalar& alpha,
430  const Kokkos::View<const impl_scalar_type***,
431  device_type, Kokkos::MemoryUnmanaged>& D,
434  const Scalar& beta);
435 
436 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
438 
440 
459  template<class TargetMemorySpace>
460  //TPETRA_DEPRECATED
461  void sync () {
462  mv_.template sync<typename TargetMemorySpace::memory_space> ();
463  }
464 
466  //TPETRA_DEPRECATED
467  void sync_host() {
468  mv_.sync_host();
469  }
470 
472  //TPETRA_DEPRECATED
473  void sync_device() {
474  mv_.sync_device();
475  }
476 
477 #endif // TPETRA_ENABLE_DEPRECATED_CODE
478 
480  template<class TargetMemorySpace>
481  bool need_sync () const {
482  return mv_.template need_sync<typename TargetMemorySpace::memory_space> ();
483  }
484 
486  bool need_sync_host() const {
487  return mv_.need_sync_host();
488  }
489 
491  bool need_sync_device() const {
492  return mv_.need_sync_device();
493  }
494 
495 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
496 
502  template<class TargetMemorySpace>
503  //TPETRA_DEPRECATED
504  void modify () {
505  mv_.template modify<typename TargetMemorySpace::memory_space> ();
506  }
507 
509  //TPETRA_DEPRECATED
510  void modify_host() {
511  mv_.modify_host();
512  }
513 
515  //TPETRA_DEPRECATED
516  void modify_device() {
517  mv_.modify_device();
518  }
519 
520 #endif // TPETRA_ENABLE_DEPRECATED_CODE
522 
524 
542  bool replaceLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]);
543 
554  bool replaceGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]);
555 
566  bool sumIntoLocalValues (const LO localRowIndex, const LO colIndex, const Scalar vals[]);
567 
578  bool sumIntoGlobalValues (const GO globalRowIndex, const LO colIndex, const Scalar vals[]);
579 
580 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
591  // TPETRA_DEPRECATED
592  bool getLocalRowView (const LO localRowIndex, const LO colIndex, Scalar*& vals);
593 
604  // TPETRA_DEPRECATED
605  bool getGlobalRowView (const GO globalRowIndex, const LO colIndex, Scalar*& vals);
606 
615  //TPETRA_DEPRECATED
616  little_host_vec_type getLocalBlock (const LO localRowIndex, const LO colIndex);
617 
618 #endif // TPETRA_ENABLE_DEPRECATED_CODE
619 
620  const_little_host_vec_type getLocalBlockHost(
621  const LO localRowIndex,
622  const LO colIndex,
623  const Access::ReadOnlyStruct) const;
624 
625  little_host_vec_type getLocalBlockHost(
626  const LO localRowIndex,
627  const LO colIndex,
628  const Access::ReadWriteStruct);
629 
633  little_host_vec_type getLocalBlockHost(
634  const LO localRowIndex,
635  const LO colIndex,
636  const Access::OverwriteAllStruct);
638 
639 protected:
645 
646 
647  virtual bool checkSizes (const Tpetra::SrcDistObject& source);
648 
649  virtual void
650  copyAndPermute
651  (const SrcDistObject& source,
652  const size_t numSameIDs,
653  const Kokkos::DualView<const local_ordinal_type*,
654  buffer_device_type>& permuteToLIDs,
655  const Kokkos::DualView<const local_ordinal_type*,
656  buffer_device_type>& permuteFromLIDs,
657  const CombineMode CM);
658 
659  virtual void
660  packAndPrepare
661  (const SrcDistObject& source,
662  const Kokkos::DualView<const local_ordinal_type*,
663  buffer_device_type>& exportLIDs,
664  Kokkos::DualView<packet_type*,
665  buffer_device_type>& exports,
666  Kokkos::DualView<size_t*,
667  buffer_device_type> numPacketsPerLID,
668  size_t& constantNumPackets);
669 
670  virtual void
671  unpackAndCombine
672  (const Kokkos::DualView<const local_ordinal_type*,
673  buffer_device_type>& importLIDs,
674  Kokkos::DualView<packet_type*,
675  buffer_device_type> imports,
676  Kokkos::DualView<size_t*,
677  buffer_device_type> numPacketsPerLID,
678  const size_t constantNumPackets,
679  const CombineMode combineMode);
680 
682 
683 protected:
684 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
686  impl_scalar_type* getRawPtr () const {
687  return mvData_;
688  }
689 #endif // TPETRA_ENABLE_DEPRECATED_CODE
690 
692  size_t getStrideX () const {
693  return static_cast<size_t> (1);
694  }
695 
697  size_t getStrideY () const {
698  return mv_.getStride ();
699  }
700 
703  bool isValidLocalMeshIndex (const LO meshLocalIndex) const;
704 
705 private:
711  map_type meshMap_;
712 
714  map_type pointMap_;
715 
716 protected:
719 
720 private:
721 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
730  impl_scalar_type* mvData_;
731 #endif // TPETRA_ENABLE_DEPRECATED_CODE
732 
734  LO blockSize_;
735 
737  void
738  replaceLocalValuesImpl (const LO localRowIndex,
739  const LO colIndex,
740  const Scalar vals[]);
742  void
743  sumIntoLocalValuesImpl (const LO localRowIndex,
744  const LO colIndex,
745  const Scalar vals[]);
746 
747  static Teuchos::RCP<const mv_type>
748  getMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject&);
749 
750  static Teuchos::RCP<const BlockMultiVector<Scalar, LO, GO, Node> >
751  getBlockMultiVectorFromSrcDistObject (const Tpetra::SrcDistObject& src);
752 };
753 
754 } // namespace Tpetra
755 
756 #endif // TPETRA_BLOCKMULTIVECTOR_DECL_HPP
Forward declaration of Tpetra::BlockCrsMatrix.
Forward declaration of Tpetra::BlockMultiVector.
MultiVector for multiple degrees of freedom per mesh point.
BlockMultiVector< Scalar, LO, GO, Node > & operator=(const BlockMultiVector< Scalar, LO, GO, Node > &)=default
Copy assigment (shallow copy).
virtual bool checkSizes(const Tpetra::SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
void putScalar(const Scalar &val)
Fill all entries with the given value val.
BlockMultiVector(BlockMultiVector< Scalar, LO, GO, Node > &&)=default
Move constructor (shallow move).
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.
bool need_sync_host() const
Whether this object needs synchronization to the host.
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() const
Whether this object needs synchronization to the given memory space.
GO global_ordinal_type
The type of global indices.
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 .
BlockMultiVector(const BlockMultiVector< Scalar, LO, GO, Node > &)=default
Copy constructor (shallow copy).
void update(const Scalar &alpha, const BlockMultiVector< Scalar, LO, GO, Node > &X, const Scalar &beta)
Update: this = beta*this + alpha*X.
typename mv_type::impl_scalar_type impl_scalar_type
The implementation type of entries in the object.
bool sumIntoGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[])
Sum into all values at the given mesh point, using a global index.
mv_type getMultiVectorView() const
Get a Tpetra::MultiVector that views this BlockMultiVector's data.
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.
typename dist_object_type::buffer_device_type buffer_device_type
Kokkos::Device specialization used for communication buffers.
LO getNumVectors() const
Get the number of columns (vectors) in the BlockMultiVector.
Node node_type
The Kokkos Node type; a legacy thing that will go away at some point.
Tpetra::MultiVector< Scalar, LO, GO, Node > mv_type
The specialization of Tpetra::MultiVector that this class uses.
Kokkos::View< impl_scalar_type *, device_type > little_vec_type
"Block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector.
Tpetra::Map< LO, GO, Node > map_type
The specialization of Tpetra::Map that this class uses.
typename mv_type::device_type device_type
The Kokkos Device type.
size_t getStrideX() const
Stride between consecutive local entries in the same column.
void scale(const Scalar &val)
Multiply all entries in place by the given value val.
Kokkos::View< const impl_scalar_type *, device_type > const_little_vec_type
"Const block view" of all degrees of freedom at a mesh point, for a single column of the MultiVector.
LO local_ordinal_type
The type of local indices.
LO getBlockSize() const
Get the number of degrees of freedom per mesh point.
bool need_sync_device() const
Whether this object needs synchronization to the device.
map_type getPointMap() const
Get this BlockMultiVector's (previously computed) point Map.
bool replaceGlobalValues(const GO globalRowIndex, const LO colIndex, const Scalar vals[])
Replace all values at the given mesh point, using a global index.
size_t getStrideY() const
Stride between consecutive local entries in the same row.
bool isValidLocalMeshIndex(const LO meshLocalIndex) const
True if and only if meshLocalIndex is a valid local index in the mesh Map.
Scalar scalar_type
The type of entries in the object.
mv_type mv_
The Tpetra::MultiVector used to represent the data.
Base class for distributed Tpetra objects that support data redistribution.
Kokkos::Device< typename device_type::execution_space, buffer_memory_space > buffer_device_type
Kokkos::Device specialization for communication buffers.
typename ::Kokkos::Details::ArithTraits< Scalar >::val_type packet_type
The type of each datum being sent or received in an Import or Export.
size_t getStride() const
Stride between columns in the multivector.
bool need_sync_device() const
Whether this MultiVector needs synchronization to the device.
bool need_sync_host() const
Whether this MultiVector needs synchronization to the host.
typename Kokkos::Details::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
typename map_type::device_type device_type
This class' preferred Kokkos device type.
size_t getNumVectors() const
Number of columns in the multivector.
Abstract base class for objects that can be the source of an Import or Export operation.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
CombineMode
Rule for combining data in an Import or Export.