Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_PartitioningHelpers.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
49
50
#ifndef _ZOLTAN2_PARTITIONINGHELPERS_HPP_
51
#define _ZOLTAN2_PARTITIONINGHELPERS_HPP_
52
53
#ifdef _MSC_VER
54
#define NOMINMAX
55
#include <windows.h>
56
#endif
57
58
59
#include <
Zoltan2_PartitioningSolution.hpp
>
60
#include <
Zoltan2_AlltoAll.hpp
>
61
62
namespace
Zoltan2
{
63
78
79
template
<
typename
SolutionAdapter,
typename
DataAdapter>
80
size_t
getImportList
(
81
const
PartitioningSolution<SolutionAdapter>
&solution,
82
const
DataAdapter *
const
data,
83
ArrayRCP<typename DataAdapter::gno_t> &imports
// output
84
)
85
{
86
typedef
typename
PartitioningSolution<SolutionAdapter>::part_t
part_t
;
87
typedef
typename
PartitioningSolution<SolutionAdapter>::gno_t
gno_t
;
88
89
size_t
numParts = solution.
getActualGlobalNumberOfParts
();
90
int
numProcs = solution.
getCommunicator
()->getSize();
91
92
if
(numParts >
size_t
(numProcs)) {
93
char
msg[256];
94
sprintf(msg,
"Number of parts %lu exceeds number of ranks %d; "
95
"%s requires a MappingSolution for this case\n"
,
96
numParts, numProcs, __func__);
97
throw
std::logic_error(msg);
98
}
99
100
size_t
localNumIds = data->getLocalNumIDs();
101
const
typename
DataAdapter::gno_t *gids = NULL;
102
data->getIDsView(gids);
103
104
const
part_t
*parts = solution.
getPartListView
();
105
106
// How many ids to each process?
107
Array<int> counts(numProcs, 0);
108
for
(
size_t
i=0; i < localNumIds; i++)
109
counts[parts[i]]++;
110
111
Array<gno_t> offsets(numProcs+1, 0);
112
for
(
int
i=1; i <= numProcs; i++){
113
offsets[i] = offsets[i-1] + counts[i-1];
114
}
115
116
Array<typename DataAdapter::gno_t> gidList(localNumIds);
117
for
(
size_t
i=0; i < localNumIds; i++) {
118
gno_t
idx = offsets[parts[i]];
119
gidList[idx] = gids[i];
120
offsets[parts[i]] = idx + 1;
121
}
122
123
Array<int> recvCounts(numProcs, 0);
124
try
{
125
AlltoAllv<typename DataAdapter::gno_t>
(*(solution.
getCommunicator
()),
126
*(solution.
getEnvironment
()),
127
gidList(), counts(), imports, recvCounts());
128
}
129
Z2_FORWARD_EXCEPTIONS
;
130
131
return
imports.size();
132
}
133
134
}
// namespace Zoltan2
135
136
#endif
// _ZOLTAN2_PARTITIONINGHELPERS_HPP_
Zoltan2_AlltoAll.hpp
AlltoAll communication methods.
Z2_FORWARD_EXCEPTIONS
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Definition
Zoltan2_Exceptions.hpp:106
Zoltan2_PartitioningSolution.hpp
Defines the PartitioningSolution class.
Zoltan2::PartitioningSolution
A PartitioningSolution is a solution to a partitioning problem.
Definition
Zoltan2_PartitioningSolution.hpp:92
Zoltan2::PartitioningSolution::getActualGlobalNumberOfParts
size_t getActualGlobalNumberOfParts() const
Returns the actual global number of parts provided in setParts().
Definition
Zoltan2_PartitioningSolution.hpp:169
Zoltan2::PartitioningSolution::getEnvironment
const RCP< const Environment > & getEnvironment() const
Return the environment associated with the solution.
Definition
Zoltan2_PartitioningSolution.hpp:368
Zoltan2::PartitioningSolution::getPartListView
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
Definition
Zoltan2_PartitioningSolution.hpp:372
Zoltan2::PartitioningSolution::getCommunicator
const RCP< const Comm< int > > & getCommunicator() const
Return the communicator associated with the solution.
Definition
Zoltan2_PartitioningSolution.hpp:364
Zoltan2
Created by mbenlioglu on Aug 31, 2020.
Definition
Zoltan2_AlgHybrid2GL.hpp:38
Zoltan2::getImportList
size_t getImportList(const PartitioningSolution< SolutionAdapter > &solution, const DataAdapter *const data, ArrayRCP< typename DataAdapter::gno_t > &imports)
From a PartitioningSolution, get a list of IDs to be imported. Assumes part numbers in PartitioningSo...
Definition
Zoltan2_PartitioningHelpers.hpp:80
Zoltan2::AlltoAllv
void AlltoAllv(const Comm< int > &comm, const Environment &env, const ArrayView< const std::string > &sendBuf, const ArrayView< const int > &sendCount, ArrayRCP< std::string > &recvBuf, const ArrayView< int > &recvCount)
Definition
Zoltan2_AlltoAll.cpp:131
Zoltan2::part_t
core
src
problems
Zoltan2_PartitioningHelpers.hpp
Generated by
1.17.0