Zoltan2
Zoltan2_IdentifierModel.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// Zoltan2: A package of combinatorial algorithms for scientific computing
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 Karen Devine (kddevin@sandia.gov)
39// Erik Boman (egboman@sandia.gov)
40// Siva Rajamanickam (srajama@sandia.gov)
41//
42// ***********************************************************************
43//
44// @HEADER
45
50#ifndef _ZOLTAN2_IDENTIFIERMODEL_HPP_
51#define _ZOLTAN2_IDENTIFIERMODEL_HPP_
52
53#include <Zoltan2_Adapter.hpp>
54#include <Zoltan2_Model.hpp>
56
57namespace Zoltan2 {
58
69template <typename Adapter>
70class IdentifierModel : public Model<Adapter>
71{
72public:
73
74#ifndef DOXYGEN_SHOULD_SKIP_THIS
75 typedef typename Adapter::scalar_t scalar_t;
76 typedef typename Adapter::gno_t gno_t;
77 typedef typename Adapter::lno_t lno_t;
78 typedef StridedData<lno_t, scalar_t> input_t;
79#endif
80
88 IdentifierModel(const RCP<const Adapter> &ia,
89 const RCP<const Environment> &env,
90 const RCP<const Comm<int> > &comm, modelFlag_t &modelFlags);
91
94 inline size_t getLocalNumIdentifiers() const { return gids_.size(); }
95
99 return numGlobalIdentifiers_;
100 }
101
110 inline size_t getIdentifierList(ArrayView<const gno_t> &Ids,
111 ArrayView<input_t> &wgts) const
112 {
113 Ids = ArrayView<const gno_t>();
114 wgts = weights_.view(0, nUserWeights_);
115 size_t n = getLocalNumIdentifiers();
116 if (n){
117 Ids = ArrayView<const gno_t>(
118 reinterpret_cast<const gno_t*>(gids_.getRawPtr()), n);
119 }
120 return n;
121 }
122
124 // The Model interface.
126
127 inline size_t getLocalNumObjects() const {return getLocalNumIdentifiers();}
128
129 inline size_t getGlobalNumObjects() const {return getGlobalNumIdentifiers();}
130
131private:
132 gno_t numGlobalIdentifiers_;
133 const RCP<const Environment> env_;
134 const RCP<const Comm<int> > comm_;
135 ArrayRCP<const gno_t> gids_;
136 int nUserWeights_;
137 ArrayRCP<input_t> weights_;
138};
139
141template <typename Adapter>
143 const RCP<const Adapter> &ia,
144 const RCP<const Environment> &env,
145 const RCP<const Comm<int> > &comm,
146 modelFlag_t &/* modelFlags */):
147 numGlobalIdentifiers_(), env_(env), comm_(comm),
148 gids_(), nUserWeights_(0), weights_()
149{
150 // Get the local and global problem size
151 size_t nLocalIds = ia->getLocalNumIDs();
152 gno_t lsum = nLocalIds;
153 reduceAll<int, gno_t>(*comm_, Teuchos::REDUCE_SUM, 1, &lsum,
154 &numGlobalIdentifiers_);
155
156 // Get the number of weights
157 int tmp = ia->getNumWeightsPerID();
158 // Use max number of weights over all processes as nUserWeights_
159 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 1,
160 &tmp, &nUserWeights_);
161
162 // Prepare to store views from input adapter
163 // TODO: Do we have to store these views, or can we get them on an
164 // TODO: as-needed basis?
165 Array<const scalar_t *> wgts(nUserWeights_, (const scalar_t *)NULL);
166 Array<int> wgtStrides(nUserWeights_, 0);
167
168 if (nUserWeights_ > 0){
169 input_t *w = new input_t [nUserWeights_];
170 weights_ = arcp<input_t>(w, 0, nUserWeights_);
171 }
172
173 const gno_t *gids=NULL;
174
175 // Get the input adapter's views
176 try{
177 ia->getIDsView(gids);
178 for (int idx=0; idx < nUserWeights_; idx++)
179 ia->getWeightsView(wgts[idx], wgtStrides[idx], idx);
180 }
182
183 if (nLocalIds){
184 gids_ = arcp(gids, 0, nLocalIds, false);
185
186 if (nUserWeights_ > 0){
187 for (int idx=0; idx < nUserWeights_; idx++){
188 ArrayRCP<const scalar_t> wgtArray(wgts[idx], 0,
189 nLocalIds*wgtStrides[idx], false);
190 weights_[idx] = input_t(wgtArray, wgtStrides[idx]);
191 }
192 }
193 }
194
195 env_->memory("After construction of identifier model");
196}
197
198} // namespace Zoltan2
199
200#endif
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Defines the Model interface.
This file defines the StridedData class.
IdentifierModel defines the interface for all identifier models.
size_t getLocalNumObjects() const
Return the local number of objects.
global_size_t getGlobalNumIdentifiers() const
IdentifierModel(const RCP< const Adapter > &ia, const RCP< const Environment > &env, const RCP< const Comm< int > > &comm, modelFlag_t &modelFlags)
Constructor.
size_t getGlobalNumObjects() const
Return the global number of objects.
size_t getIdentifierList(ArrayView< const gno_t > &Ids, ArrayView< input_t > &wgts) const
The base class for all model classes.
The StridedData class manages lists of weights or coordinates.
map_t::local_ordinal_type lno_t
Definition: mapRemotes.cpp:17
map_t::global_ordinal_type gno_t
Definition: mapRemotes.cpp:18
Created by mbenlioglu on Aug 31, 2020.
Tpetra::global_size_t global_size_t
std::bitset< NUM_MODEL_FLAGS > modelFlag_t