Zoltan2
Loading...
Searching...
No Matches
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 typename Adapter::node_t node_t;
79 typedef StridedData<lno_t, scalar_t> input_t;
80#endif
81
89 IdentifierModel(const RCP<const Adapter> &ia,
90 const RCP<const Environment> &env,
91 const RCP<const Comm<int> > &comm, modelFlag_t &modelFlags);
92
95 inline size_t getLocalNumIdentifiers() const { return gids_.size(); }
96
100 return numGlobalIdentifiers_;
101 }
102
111 inline size_t getIdentifierList(ArrayView<const gno_t> &Ids,
112 ArrayView<input_t> &wgts) const
113 {
114 Ids = ArrayView<const gno_t>();
115 wgts = weights_.view(0, nUserWeights_);
116 size_t n = getLocalNumIdentifiers();
117 if (n){
118 Ids = ArrayView<const gno_t>(
119 reinterpret_cast<const gno_t*>(gids_.getRawPtr()), n);
120 }
121 return n;
122 }
123
125 Kokkos::View<const gno_t *, typename node_t::device_type> &Ids,
126 Kokkos::View<scalar_t **, typename node_t::device_type> &wgts) const {
127 try {
128 adapter_->getIDsKokkosView(Ids);
129 adapter_->getWeightsKokkosView(wgts);
130 }
132
133 return getLocalNumIdentifiers();
134 }
135
137 // The Model interface.
139
140 inline size_t getLocalNumObjects() const {return getLocalNumIdentifiers();}
141
142 inline size_t getGlobalNumObjects() const {return getGlobalNumIdentifiers();}
143
144private:
145 gno_t numGlobalIdentifiers_;
146 const RCP<const Environment> env_;
147 const RCP<const Comm<int> > comm_;
148 ArrayRCP<const gno_t> gids_;
149 const RCP<const Adapter> adapter_;
150 int nUserWeights_;
151 ArrayRCP<input_t> weights_;
152};
153
155template <typename Adapter>
157 const RCP<const Adapter> &ia,
158 const RCP<const Environment> &env,
159 const RCP<const Comm<int> > &comm,
160 modelFlag_t &/* modelFlags */):
161 numGlobalIdentifiers_(), env_(env), comm_(comm),
162 gids_(), adapter_(ia), nUserWeights_(0), weights_()
163{
164 // Get the local and global problem size
165 size_t nLocalIds = ia->getLocalNumIDs();
166 gno_t lsum = nLocalIds;
167 reduceAll<int, gno_t>(*comm_, Teuchos::REDUCE_SUM, 1, &lsum,
168 &numGlobalIdentifiers_);
169
170 // Get the number of weights
171 int tmp = ia->getNumWeightsPerID();
172 // Use max number of weights over all processes as nUserWeights_
173 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_MAX, 1,
174 &tmp, &nUserWeights_);
175
176 // Prepare to store views from input adapter
177 // TODO: Do we have to store these views, or can we get them on an
178 // TODO: as-needed basis?
179 Array<const scalar_t *> wgts(nUserWeights_, (const scalar_t *)NULL);
180 Array<int> wgtStrides(nUserWeights_, 0);
181
182 if (nUserWeights_ > 0){
183 input_t *w = new input_t [nUserWeights_];
184 weights_ = arcp<input_t>(w, 0, nUserWeights_);
185 }
186
187 const gno_t *gids=NULL;
188
189 // Get the input adapter's views
190 try{
191 ia->getIDsView(gids);
192 for (int idx=0; idx < nUserWeights_; idx++)
193 ia->getWeightsView(wgts[idx], wgtStrides[idx], idx);
194 }
196
197 if (nLocalIds){
198 gids_ = arcp(gids, 0, nLocalIds, false);
199
200 if (nUserWeights_ > 0){
201 for (int idx=0; idx < nUserWeights_; idx++){
202 ArrayRCP<const scalar_t> wgtArray(wgts[idx], 0,
203 nLocalIds*wgtStrides[idx], false);
204 weights_[idx] = input_t(wgtArray, wgtStrides[idx]);
205 }
206 }
207 }
208
209 env_->memory("After construction of identifier model");
210}
211
212} // namespace Zoltan2
213
214#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 getIdentifierListKokkos(Kokkos::View< const gno_t *, typename node_t::device_type > &Ids, Kokkos::View< scalar_t **, typename node_t::device_type > &wgts) const
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