Thyra Version of the Day
Loading...
Searching...
No Matches
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
53namespace Thyra {
54
55
56template<class Scalar>
57RCP<DefaultSpmdVectorSpace<Scalar> >
64
65
66template<class Scalar>
68 const Ordinal dim_in
69 )
70{
71 this->initialize(Teuchos::null, dim_in, dim_in);
72}
73
74
75template<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
99template<class Scalar>
101{
102 comm_ = Teuchos::null;
103 localSubDim_ = 0;
104}
105
106
107// Overridden from VectorSpace
108
109
110template<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
127template<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
142template<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
161template<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
180template<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
201template<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
224template<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
235template<class Scalar>
238{
239 return defaultSpmdVectorSpace<Scalar>(comm_, localSubDim_, this->dim(),
240 this->isLocallyReplicated());
241}
242
243
244// Overridden from SpmdVectorSpaceDefaultBase
245
246
247template<class Scalar>
250{
251 return comm_;
252}
253
254
255template<class Scalar>
257{
258 return localSubDim_;
259}
260
261
262// private
263
264
265template<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
const ArrayRCP< const Scalar > values() const
const ArrayRCP< const Scalar > values() const
ptrdiff_t stride() const
const ArrayRCP< Scalar > values() const
const ArrayRCP< Scalar > values() const
T * get() const
RCP< T > create_weak() const
Ordinal lbound() const
Ordinal ubound() const
Efficient concrete implementation subclass for SPMD multi-vectors.
Concrete implementation of an SPMD vector space subclass which creates DefaultSpmdVector and DefaultS...
RCP< const Teuchos::Comm< Ordinal > > getComm() 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< MultiVectorBase< Scalar > > createMembers(int numMembers) const
static RCP< DefaultSpmdVectorSpace< Scalar > > create()
Create with weak ownership to self.
RCP< const VectorSpaceBase< Scalar > > clone() const
RCP< MultiVectorBase< Scalar > > createMembersView(const RTOpPack::SubMultiVectorView< Scalar > &raw_mv) const
void initialize(const Ordinal dim)
Initialize a serial space.
RCP< VectorBase< Scalar > > createMemberView(const RTOpPack::SubVectorView< Scalar > &raw_v) const
RCP< VectorBase< Scalar > > createMember() const
void uninitialize()
Set to an uninitialized state.
Efficient concrete implementation subclass for SPMD vectors.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
EStrideType
Determine if data is unit stride or non-unit stride.
EViewType
Determines if a view is a direct view of data or a detached copy of data.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
T_To & dyn_cast(T_From &from)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)