Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_SpmdVectorSpaceUtilities.cpp
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 #include "Thyra_SpmdVectorSpaceUtilities.hpp"
11 #include "Teuchos_CommHelpers.hpp"
12 
13 
14 namespace Thyra {
15 
16 
17 Ordinal SpmdVectorSpaceUtilities::computeMapCode(
18  const Teuchos::Comm<Ordinal> &comm, const Ordinal localSubDim
19  )
20 {
21  using Teuchos::outArg;
22  using Teuchos::REDUCE_SUM;
23  using Teuchos::reduceAll;
24  //
25  // Here we will make a map code out of just the local sub-dimension on each
26  // processor. If each processor has the same number of local elements, then
27  // the map codes will be the same and this is all you need for RTOp
28  // compatibility.
29  //
30  const int procRank = comm.getSize ();
31  Ordinal mapCode = -1;
32  Ordinal localCode = localSubDim % (procRank+1) + localSubDim;
33  reduceAll<Ordinal, Ordinal> (comm, REDUCE_SUM, localCode, outArg (mapCode));
34  return mapCode;
35 }
36 
37 
38 Ordinal SpmdVectorSpaceUtilities::computeLocalOffset(
39  const Teuchos::Comm<Ordinal> &comm, const Ordinal localSubDim
40  )
41 {
42  using Teuchos::outArg;
43  using Teuchos::REDUCE_SUM;
44  using Teuchos::scan;
45 
46  Ordinal localOffset;
47  const Ordinal _localOffset = localSubDim;
48  scan<Ordinal, Ordinal> (comm, REDUCE_SUM, _localOffset, outArg (localOffset));
49  localOffset -= localSubDim;
50  return localOffset;
51 }
52 
53 
54 Ordinal SpmdVectorSpaceUtilities::computeGlobalDim(
55  const Teuchos::Comm<Ordinal> &comm, const Ordinal localSubDim
56  )
57 {
58  using Teuchos::outArg;
59  using Teuchos::REDUCE_SUM;
60  using Teuchos::reduceAll;
61 
62  Ordinal globalDim = -1;
63  reduceAll<Ordinal, Ordinal> (comm, REDUCE_SUM, localSubDim, outArg (globalDim));
64  return globalDim;
65 }
66 
67 
68 } // namespace Thyra
virtual int getSize() const =0
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.