Thyra Version of the Day
Loading...
Searching...
No Matches
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
21namespace Thyra {
22
23
24template<class Scalar>
27{
28 const RCP<DefaultSpmdVectorSpace<Scalar> > vs(new DefaultSpmdVectorSpace<Scalar>);
29 vs->weakSelfPtr_ = vs.create_weak();
30 return vs;
31}
32
33
34template<class Scalar>
36 const Ordinal dim_in
37 )
38{
39 this->initialize(Teuchos::null, dim_in, dim_in);
40}
41
42
43template<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
67template<class Scalar>
69{
70 comm_ = Teuchos::null;
71 localSubDim_ = 0;
72}
73
74
75// Overridden from VectorSpace
76
77
78template<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
95template<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
110template<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
129template<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
148template<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
169template<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
192template<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
203template<class Scalar>
206{
207 return defaultSpmdVectorSpace<Scalar>(comm_, localSubDim_, this->dim(),
208 this->isLocallyReplicated());
209}
210
211
212// Overridden from SpmdVectorSpaceDefaultBase
213
214
215template<class Scalar>
218{
219 return comm_;
220}
221
222
223template<class Scalar>
225{
226 return localSubDim_;
227}
228
229
230// private
231
232
233template<class Scalar>
234DefaultSpmdVectorSpace<Scalar>::DefaultSpmdVectorSpace()
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
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
RCP< T > create_weak() const
Ordinal lbound() const
Ordinal ubound() const
Efficient concrete implementation subclass for SPMD multi-vectors.
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< DefaultSpmdVectorSpace< Scalar > > defaultSpmdVectorSpace()
Nonmember consturctor that creats an uninitialized vector space.
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.
virtual void updateState(const Ordinal globalDim, const bool isLocallyReplicated=false)
This function must be called whenever the state of this changes and some internal state must be updat...
bool isLocallyReplicated() const
Returns true if vector space is locally replicated space.
Ordinal dim() const
Returns the sum of the local number of elements on every process.
#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::Range1D Range1D
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)