Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultSpmdVectorSpace_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_DEFAULT_SPMD_VECTOR_SPACE_DEF_HPP
11 #define THYRA_DEFAULT_SPMD_VECTOR_SPACE_DEF_HPP
12 
13 #include "Thyra_DefaultSpmdVectorSpace_decl.hpp"
14 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
15 #include "Thyra_VectorSpaceFactoryBase.hpp"
16 #include "Thyra_DefaultSpmdMultiVector.hpp"
17 #include "Thyra_DefaultSpmdVector.hpp"
18 #include "Teuchos_CommHelpers.hpp"
19 
20 
21 namespace Thyra {
22 
23 
24 template<class Scalar>
25 RCP<DefaultSpmdVectorSpace<Scalar> >
27 {
29  vs->weakSelfPtr_ = vs.create_weak();
30  return vs;
31 }
32 
33 
34 template<class Scalar>
36  const Ordinal dim_in
37  )
38 {
39  this->initialize(Teuchos::null, dim_in, dim_in);
40 }
41 
42 
43 template<class Scalar>
45  const RCP<const Teuchos::Comm<Ordinal> > &comm,
46  const Ordinal localSubDim_in, const Ordinal globalDim,
47  const bool isLocallyReplicated_in
48  )
49 {
50 #ifdef TEUCHOS_DEBUG
51  TEUCHOS_TEST_FOR_EXCEPT( !( localSubDim_in >= 0 ) );
52 #endif
53  comm_ = comm;
54  localSubDim_ = localSubDim_in;
55  if (! comm.is_null ()) {
56  numProc_ = comm->getSize ();
57  procRank_ = comm->getRank ();
58  }
59  else {
60  numProc_ = 1;
61  procRank_ = 0;
62  }
63  this->updateState(globalDim, isLocallyReplicated_in);
64 }
65 
66 
67 template<class Scalar>
69 {
70  comm_ = Teuchos::null;
71  localSubDim_ = 0;
72 }
73 
74 
75 // Overridden from VectorSpace
76 
77 
78 template<class Scalar>
81 {
82  ArrayRCP<Scalar> values;
83  if (localSubDim_)
84  values = Teuchos::arcp<Scalar>(localSubDim_);
85  return Teuchos::rcp(
87  weakSelfPtr_.create_strong(),
88  values,
89  1 // stride
90  )
91  );
92 }
93 
94 
95 template<class Scalar>
98 {
99  return Teuchos::rcp(
101  weakSelfPtr_.create_strong(),
102  Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
103  this->smallVecSpcFcty()->createVecSpc(numMembers),true
104  )
105  )
106  );
107 }
108 
109 
110 template<class Scalar>
114  ) const
115 {
116 #ifdef TEUCHOS_DEBUG
117  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
118 #endif
119  return Teuchos::rcp(
121  weakSelfPtr_.create_strong(),
122  Teuchos::arcp(raw_v.values().get(),0,raw_v.subDim(),false),
123  raw_v.stride()
124  )
125  );
126 }
127 
128 
129 template<class Scalar>
133  ) const
134 {
135 #ifdef TEUCHOS_DEBUG
136  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
137 #endif
138  return Teuchos::rcp(
140  weakSelfPtr_.create_strong(),
141  Teuchos::arcp(const_cast<Scalar*>(raw_v.values().get()),0,raw_v.subDim(),false),
142  raw_v.stride()
143  )
144  );
145 }
146 
147 
148 template<class Scalar>
152  ) const
153 {
154 #ifdef TEUCHOS_DEBUG
155  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
156 #endif
157  return Teuchos::rcp(
159  weakSelfPtr_.create_strong(),
160  Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
161  this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true),
162  Teuchos::arcp(raw_mv.values().get(),0,raw_mv.leadingDim()*raw_mv.numSubCols(),false),
163  raw_mv.leadingDim()
164  )
165  );
166 }
167 
168 
169 template<class Scalar>
173  ) const
174 {
175 #ifdef TEUCHOS_DEBUG
176  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
177 #endif
178  return Teuchos::rcp(
180  weakSelfPtr_.create_strong(),
181  Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
182  this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true),
183  Teuchos::arcp(
184  const_cast<Scalar*>(raw_mv.values().get()),
185  0,raw_mv.leadingDim()*raw_mv.numSubCols(),false),
186  raw_mv.leadingDim()
187  )
188  );
189 }
190 
191 
192 template<class Scalar>
194  const Range1D& rng_in, const EViewType /* viewType */, const EStrideType /* strideType */
195  ) const
196 {
197  const Range1D rng = full_range(rng_in,0,this->dim()-1);
198  const Ordinal l_localOffset = this->localOffset();
199  return ( l_localOffset<=rng.lbound() && rng.ubound()<l_localOffset+localSubDim_ );
200 }
201 
202 
203 template<class Scalar>
206 {
207  return defaultSpmdVectorSpace<Scalar>(comm_, localSubDim_, this->dim(),
208  this->isLocallyReplicated());
209 }
210 
211 
212 // Overridden from SpmdVectorSpaceDefaultBase
213 
214 
215 template<class Scalar>
218 {
219  return comm_;
220 }
221 
222 
223 template<class Scalar>
225 {
226  return localSubDim_;
227 }
228 
229 
230 // private
231 
232 
233 template<class Scalar>
235  :localSubDim_(-1), numProc_(-1), procRank_(-1)
236 {
237  // The base classes should automatically default initialize to a safe
238  // uninitialized state.
239 }
240 
241 
242 } // end namespace Thyra
243 
244 
245 #endif // THYRA_DEFAULT_SPMD_VECTOR_SPACE_DEF_HPP
void initialize(int *argc, char ***argv)
ptrdiff_t stride() const
bool hasInCoreView(const Range1D &rng, const EViewType viewType, const EStrideType strideType) const
Returns true if all the elements in rng are in this process.
RCP< T > create_weak() const
RCP< MultiVectorBase< Scalar > > createMembersView(const RTOpPack::SubMultiVectorView< Scalar > &raw_mv) const
const ArrayRCP< Scalar > values() const
RCP< const Teuchos::Comm< Ordinal > > getComm() const
EViewType
Determines if a view is a direct view of data or a detached copy of data.
RCP< const VectorSpaceBase< Scalar > > clone() const
Ordinal ubound() const
const ArrayRCP< Scalar > values() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
RCP< MultiVectorBase< Scalar > > createMembers(int numMembers) const
void uninitialize()
Set to an uninitialized state.
RCP< VectorBase< Scalar > > createMember() const
Concrete implementation of an SPMD vector space subclass which creates DefaultSpmdVector and DefaultS...
void initialize(const Ordinal dim)
Initialize a serial space.
Efficient concrete implementation subclass for SPMD vectors.
const ArrayRCP< const Scalar > values() const
Ordinal lbound() const
RCP< VectorBase< Scalar > > createMemberView(const RTOpPack::SubVectorView< Scalar > &raw_v) const
Efficient concrete implementation subclass for SPMD multi-vectors.
EStrideType
Determine if data is unit stride or non-unit stride.
static RCP< DefaultSpmdVectorSpace< Scalar > > create()
Create with weak ownership to self.
T * get() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
const ArrayRCP< const Scalar > values() const