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 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
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 Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_DEFAULT_SPMD_VECTOR_SPACE_DEF_HPP
43 #define THYRA_DEFAULT_SPMD_VECTOR_SPACE_DEF_HPP
44 
45 #include "Thyra_DefaultSpmdVectorSpace_decl.hpp"
46 #include "Thyra_SpmdVectorSpaceDefaultBase.hpp"
47 #include "Thyra_VectorSpaceFactoryBase.hpp"
48 #include "Thyra_DefaultSpmdMultiVector.hpp"
49 #include "Thyra_DefaultSpmdVector.hpp"
50 #include "Teuchos_CommHelpers.hpp"
51 
52 
53 namespace Thyra {
54 
55 
56 template<class Scalar>
57 RCP<DefaultSpmdVectorSpace<Scalar> >
59 {
61  vs->weakSelfPtr_ = vs.create_weak();
62  return vs;
63 }
64 
65 
66 template<class Scalar>
68  const Ordinal dim_in
69  )
70 {
71  this->initialize(Teuchos::null, dim_in, dim_in);
72 }
73 
74 
75 template<class Scalar>
77  const RCP<const Teuchos::Comm<Ordinal> > &comm,
78  const Ordinal localSubDim_in, const Ordinal globalDim,
79  const bool isLocallyReplicated_in
80  )
81 {
82 #ifdef TEUCHOS_DEBUG
83  TEUCHOS_TEST_FOR_EXCEPT( !( localSubDim_in >= 0 ) );
84 #endif
85  comm_ = comm;
86  localSubDim_ = localSubDim_in;
87  if (! comm.is_null ()) {
88  numProc_ = comm->getSize ();
89  procRank_ = comm->getRank ();
90  }
91  else {
92  numProc_ = 1;
93  procRank_ = 0;
94  }
95  this->updateState(globalDim, isLocallyReplicated_in);
96 }
97 
98 
99 template<class Scalar>
101 {
102  comm_ = Teuchos::null;
103  localSubDim_ = 0;
104 }
105 
106 
107 // Overridden from VectorSpace
108 
109 
110 template<class Scalar>
113 {
114  ArrayRCP<Scalar> values;
115  if (localSubDim_)
116  values = Teuchos::arcp<Scalar>(localSubDim_);
117  return Teuchos::rcp(
119  weakSelfPtr_.create_strong(),
120  values,
121  1 // stride
122  )
123  );
124 }
125 
126 
127 template<class Scalar>
130 {
131  return Teuchos::rcp(
133  weakSelfPtr_.create_strong(),
134  Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
135  this->smallVecSpcFcty()->createVecSpc(numMembers),true
136  )
137  )
138  );
139 }
140 
141 
142 template<class Scalar>
146  ) const
147 {
148 #ifdef TEUCHOS_DEBUG
149  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
150 #endif
151  return Teuchos::rcp(
153  weakSelfPtr_.create_strong(),
154  Teuchos::arcp(raw_v.values().get(),0,raw_v.subDim(),false),
155  raw_v.stride()
156  )
157  );
158 }
159 
160 
161 template<class Scalar>
165  ) const
166 {
167 #ifdef TEUCHOS_DEBUG
168  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_v.subDim() );
169 #endif
170  return Teuchos::rcp(
172  weakSelfPtr_.create_strong(),
173  Teuchos::arcp(const_cast<Scalar*>(raw_v.values().get()),0,raw_v.subDim(),false),
174  raw_v.stride()
175  )
176  );
177 }
178 
179 
180 template<class Scalar>
184  ) const
185 {
186 #ifdef TEUCHOS_DEBUG
187  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
188 #endif
189  return Teuchos::rcp(
191  weakSelfPtr_.create_strong(),
192  Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
193  this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true),
194  Teuchos::arcp(raw_mv.values().get(),0,raw_mv.leadingDim()*raw_mv.numSubCols(),false),
195  raw_mv.leadingDim()
196  )
197  );
198 }
199 
200 
201 template<class Scalar>
205  ) const
206 {
207 #ifdef TEUCHOS_DEBUG
208  TEUCHOS_TEST_FOR_EXCEPT( localSubDim_ != raw_mv.subDim() );
209 #endif
210  return Teuchos::rcp(
212  weakSelfPtr_.create_strong(),
213  Teuchos::rcp_dynamic_cast<const ScalarProdVectorSpaceBase<Scalar> >(
214  this->smallVecSpcFcty()->createVecSpc(raw_mv.numSubCols()),true),
215  Teuchos::arcp(
216  const_cast<Scalar*>(raw_mv.values().get()),
217  0,raw_mv.leadingDim()*raw_mv.numSubCols(),false),
218  raw_mv.leadingDim()
219  )
220  );
221 }
222 
223 
224 template<class Scalar>
226  const Range1D& rng_in, const EViewType /* viewType */, const EStrideType /* strideType */
227  ) const
228 {
229  const Range1D rng = full_range(rng_in,0,this->dim()-1);
230  const Ordinal l_localOffset = this->localOffset();
231  return ( l_localOffset<=rng.lbound() && rng.ubound()<l_localOffset+localSubDim_ );
232 }
233 
234 
235 template<class Scalar>
238 {
239  return defaultSpmdVectorSpace<Scalar>(comm_, localSubDim_, this->dim(),
240  this->isLocallyReplicated());
241 }
242 
243 
244 // Overridden from SpmdVectorSpaceDefaultBase
245 
246 
247 template<class Scalar>
250 {
251  return comm_;
252 }
253 
254 
255 template<class Scalar>
257 {
258  return localSubDim_;
259 }
260 
261 
262 // private
263 
264 
265 template<class Scalar>
267  :localSubDim_(-1), numProc_(-1), procRank_(-1)
268 {
269  // The base classes should automatically default initialize to a safe
270  // uninitialized state.
271 }
272 
273 
274 } // end namespace Thyra
275 
276 
277 #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