All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Xpetra_StridedMapFactory.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 
47 // WARNING: This code is experimental. Backwards compatibility should not be expected.
48 
49 #ifndef XPETRA_STRIDEDMAPFACTORY_HPP
50 #define XPETRA_STRIDEDMAPFACTORY_HPP
51 
52 #include <Kokkos_DefaultNode.hpp>
53 
54 #include "Xpetra_ConfigDefs.hpp"
55 #include "Xpetra_Exceptions.hpp"
56 
57 #include "Xpetra_StridedMap.hpp"
58 
59 // This factory creates Xpetra::Map. User have to specify the exact class of object that he want to create (ie: a Xpetra::TpetraMap or a Xpetra::EpetraMap).
60 
61 namespace Xpetra {
62 
63  template <class LocalOrdinal = StridedMap<>::local_ordinal_type,
64  class GlobalOrdinal =
65  typename StridedMap<LocalOrdinal>::global_ordinal_type,
66  class Node =
67  typename StridedMap<LocalOrdinal, GlobalOrdinal>::node_type>
68  class StridedMapFactory {
69 #undef XPETRA_STRIDEDMAPFACTORY_SHORT
71 
72  private:
75 
76  public:
77 
79 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
80  TPETRA_DEPRECATED
81  static RCP<StridedMap> Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase,
82  std::vector<size_t>& stridingInfo, const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
83  LocalOrdinal stridedBlockId, GlobalOrdinal offset, LocalGlobal lg,
84  const Teuchos::RCP<Node> & /* node */)
85  {
86  return Build(lib, numGlobalElements, indexBase, stridingInfo, comm,
87  stridedBlockId, offset, lg);
88  }
89 #endif // TPETRA_ENABLE_DEPRECATED_CODE
90  static RCP<StridedMap> Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase,
91  std::vector<size_t>& stridingInfo, const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
92  LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0, LocalGlobal lg = Xpetra::GloballyDistributed)
93  {
94  return rcp(new StridedMap(lib, numGlobalElements, indexBase, stridingInfo, comm, stridedBlockId, offset, lg));
95  }
96 
98 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
99  TPETRA_DEPRECATED
100  static RCP<StridedMap> Build(UnderlyingLib lib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase,
101  std::vector<size_t>& stridingInfo, const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
102  LocalOrdinal stridedBlockId, GlobalOrdinal offset,
103  const Teuchos::RCP<Node> & /* node */)
104  {
105  return Build(lib, numGlobalElements, numLocalElements, indexBase,
106  stridingInfo, comm, stridedBlockId, offset);
107  }
108 #endif // TPETRA_ENABLE_DEPRECATED_CODE
109  static RCP<StridedMap> Build(UnderlyingLib lib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase,
110  std::vector<size_t>& stridingInfo, const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
111  LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0)
112  {
113  return rcp(new StridedMap(lib, numGlobalElements, numLocalElements, indexBase, stridingInfo, comm, stridedBlockId, offset));
114  }
115 
116  static RCP<StridedMap> Build(const RCP<const Map>& map, std::vector<size_t>& stridingInfo, LocalOrdinal stridedBlockId = -1, GlobalOrdinal offset = 0) {
117  return rcp(new StridedMap(map, stridingInfo, map->getIndexBase(), stridedBlockId, offset));
118  }
119 
120  // special constructor for generating a given subblock of a strided map
121  static RCP<StridedMap> Build(const RCP<const StridedMap>& map, LocalOrdinal stridedBlockId) {
123  "Xpetra::StridedMapFactory::Build: constructor expects stridedBlockId > -1.");
124  TEUCHOS_TEST_FOR_EXCEPTION(map->getStridedBlockId() != -1, Exceptions::RuntimeError,
125  "Xpetra::StridedMapFactory::Build: constructor expects a full map (stridedBlockId == -1).");
126 
127  std::vector<size_t> stridingInfo = map->getStridingData();
128 
129  Teuchos::ArrayView<const GlobalOrdinal> dofGids = map->getNodeElementList();
130  // std::sort(dofGids.begin(),dofGids.end()); // TODO: do we need this?
131 
132  // determine nStridedOffset
133  size_t nStridedOffset = 0;
134  for (int j = 0; j < map->getStridedBlockId(); j++)
135  nStridedOffset += stridingInfo[j];
136 
137  size_t numMyBlockDofs = (stridingInfo[stridedBlockId] * map->getNodeNumElements()) / map->getFixedBlockSize();
138  std::vector<GlobalOrdinal> subBlockDofGids(numMyBlockDofs);
139 
140  // TODO fill vector with dofs
141  LocalOrdinal ind = 0;
142  for (typename Teuchos::ArrayView< const GlobalOrdinal >::iterator it = dofGids.begin(); it!=dofGids.end(); ++it)
143  if (map->GID2StridingBlockId(*it) == Teuchos::as<size_t>(stridedBlockId))
144  subBlockDofGids[ind++] = *it;
145 
146  const Teuchos::ArrayView<const GlobalOrdinal> subBlockDofGids_view(&subBlockDofGids[0],subBlockDofGids.size());
147 
148  return rcp(new StridedMap(map->lib(), Teuchos::OrdinalTraits<global_size_t>::invalid(), subBlockDofGids_view, map->getIndexBase(), stridingInfo, map->getComm(), stridedBlockId));
149  }
150 
152  static RCP<StridedMap> Build(const StridedMap& map) {
153  XPETRA_MONITOR("MapFactory::Build");
154 
155  LocalOrdinal N = map.getNodeNumElements();
158  for (LocalOrdinal i = 0; i < N; i++)
159  newElements[i] = oldElements[i];
160 
161  std::vector<size_t> strData = map.getStridingData();
162  return rcp(new StridedMap(map.lib(), map.getGlobalNumElements(), newElements, map.getIndexBase(), strData, map.getComm(), map.getStridedBlockId()));
163 
164  //XPETRA_FACTORY_END;
165  }
166 
168 #ifdef TPETRA_ENABLE_DEPRECATED_CODE
169  TPETRA_DEPRECATED
170  static RCP<StridedMap>
171  Build (UnderlyingLib lib,
172  global_size_t numGlobalElements,
173  const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
174  GlobalOrdinal indexBase,
175  std::vector<size_t>& stridingInfo,
176  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
177  LocalOrdinal stridedBlockId, // FIXME (mfh 03 Sep 2014) This breaks if LocalOrdinal is unsigned
178  GlobalOrdinal offset,
179  const Teuchos::RCP<Node> & /* node */)
180  {
181  return Build(lib, numGlobalElements, elementList, indexBase, stridingInfo,
182  comm, stridedBlockId, offset);
183  }
184 #endif // TPETRA_ENABLE_DEPRECATED_CODE
185  static RCP<StridedMap>
187  global_size_t numGlobalElements,
188  const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
189  GlobalOrdinal indexBase,
190  std::vector<size_t>& stridingInfo,
191  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
192  LocalOrdinal stridedBlockId = -1, // FIXME (mfh 03 Sep 2014) This breaks if LocalOrdinal is unsigned
193  GlobalOrdinal /* offset */ = 0)
194  {
195  return rcp (new StridedMap (lib, numGlobalElements, elementList,
196  indexBase, stridingInfo, comm,
197  stridedBlockId));
198  }
199  };
200 }
201 
202 #define XPETRA_STRIDEDMAPFACTORY_SHORT
203 #endif
204 //TODO: removed unused methods
LocalOrdinal getStridedBlockId() const
static RCP< StridedMap > Build(UnderlyingLib lib, global_size_t numGlobalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0, LocalGlobal lg=Xpetra::GloballyDistributed)
Map constructor with Xpetra-defined contiguous uniform distribution.
iterator begin() const
static RCP< StridedMap > Build(const RCP< const Map > &map, std::vector< size_t > &stridingInfo, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a list of the global indices owned by this node.
Exception throws to report errors in the internal logical of the program.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Get the Comm object for this Map.
static RCP< StridedMap > Build(UnderlyingLib lib, global_size_t numGlobalElements, size_t numLocalElements, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal offset=0)
Map constructor with a user-defined contiguous distribution.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static RCP< StridedMap > Build(const StridedMap &map)
Create copy of existing map (this just creates a copy of your map, it&#39;s not a clone in the sense of T...
std::vector< size_t > getStridingData() const
size_t getNodeNumElements() const
Returns the number of elements belonging to the calling node.
size_t global_size_t
Global size_t object.
GlobalOrdinal getIndexBase() const
Returns the index base for this Map.
global_size_t getGlobalNumElements() const
Returns the number of elements in this Map.
static RCP< StridedMap > Build(UnderlyingLib lib, global_size_t numGlobalElements, const Teuchos::ArrayView< const GlobalOrdinal > &elementList, GlobalOrdinal indexBase, std::vector< size_t > &stridingInfo, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, LocalOrdinal stridedBlockId=-1, GlobalOrdinal=0)
Map constructor with a user-defined contiguous distribution. (for experts only. There is no special c...
UnderlyingLib lib() const
Get the library used by this object (Tpetra or Epetra?)
iterator end() const
StridedMapFactory()
Private constructor. This is a static class.
#define XPETRA_MONITOR(funcName)
static RCP< StridedMap > Build(const RCP< const StridedMap > &map, LocalOrdinal stridedBlockId)
Class that stores a strided map.