Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_PartitioningHelpers.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Zoltan2: A package of combinatorial algorithms for scientific computing
4
//
5
// Copyright 2012 NTESS and the Zoltan2 contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
13
14
#ifndef _ZOLTAN2_PARTITIONINGHELPERS_HPP_
15
#define _ZOLTAN2_PARTITIONINGHELPERS_HPP_
16
17
#ifdef _MSC_VER
18
#define NOMINMAX
19
#include <windows.h>
20
#endif
21
22
23
#include <
Zoltan2_PartitioningSolution.hpp
>
24
#include <
Zoltan2_AlltoAll.hpp
>
25
26
namespace
Zoltan2
{
27
42
43
template
<
typename
SolutionAdapter,
typename
DataAdapter>
44
size_t
getImportList
(
45
const
PartitioningSolution<SolutionAdapter>
&solution,
46
const
DataAdapter *
const
data,
47
ArrayRCP<typename DataAdapter::gno_t> &imports
// output
48
)
49
{
50
typedef
typename
PartitioningSolution<SolutionAdapter>::part_t
part_t
;
51
typedef
typename
PartitioningSolution<SolutionAdapter>::gno_t
gno_t
;
52
53
size_t
numParts = solution.
getActualGlobalNumberOfParts
();
54
int
numProcs = solution.
getCommunicator
()->getSize();
55
56
if
(numParts >
size_t
(numProcs)) {
57
char
msg[256];
58
sprintf(msg,
"Number of parts %lu exceeds number of ranks %d; "
59
"%s requires a MappingSolution for this case\n"
,
60
numParts, numProcs, __func__);
61
throw
std::logic_error(msg);
62
}
63
64
size_t
localNumIds = data->getLocalNumIDs();
65
const
typename
DataAdapter::gno_t *gids = NULL;
66
data->getIDsView(gids);
67
68
const
part_t
*parts = solution.
getPartListView
();
69
70
// How many ids to each process?
71
Array<int> counts(numProcs, 0);
72
for
(
size_t
i=0; i < localNumIds; i++)
73
counts[parts[i]]++;
74
75
Array<gno_t> offsets(numProcs+1, 0);
76
for
(
int
i=1; i <= numProcs; i++){
77
offsets[i] = offsets[i-1] + counts[i-1];
78
}
79
80
Array<typename DataAdapter::gno_t> gidList(localNumIds);
81
for
(
size_t
i=0; i < localNumIds; i++) {
82
gno_t
idx = offsets[parts[i]];
83
gidList[idx] = gids[i];
84
offsets[parts[i]] = idx + 1;
85
}
86
87
Array<int> recvCounts(numProcs, 0);
88
try
{
89
AlltoAllv<typename DataAdapter::gno_t>
(*(solution.
getCommunicator
()),
90
*(solution.
getEnvironment
()),
91
gidList(), counts(), imports, recvCounts());
92
}
93
Z2_FORWARD_EXCEPTIONS
;
94
95
return
imports.size();
96
}
97
98
}
// namespace Zoltan2
99
100
#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:70
Zoltan2_PartitioningSolution.hpp
Defines the PartitioningSolution class.
Zoltan2::PartitioningSolution
A PartitioningSolution is a solution to a partitioning problem.
Definition
Zoltan2_PartitioningSolution.hpp:57
Zoltan2::PartitioningSolution::getActualGlobalNumberOfParts
size_t getActualGlobalNumberOfParts() const
Returns the actual global number of parts provided in setParts().
Definition
Zoltan2_PartitioningSolution.hpp:134
Zoltan2::PartitioningSolution::getEnvironment
const RCP< const Environment > & getEnvironment() const
Return the environment associated with the solution.
Definition
Zoltan2_PartitioningSolution.hpp:333
Zoltan2::PartitioningSolution::getPartListView
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
Definition
Zoltan2_PartitioningSolution.hpp:337
Zoltan2::PartitioningSolution::getCommunicator
const RCP< const Comm< int > > & getCommunicator() const
Return the communicator associated with the solution.
Definition
Zoltan2_PartitioningSolution.hpp:329
Zoltan2
Created by mbenlioglu on Aug 31, 2020.
Definition
Zoltan2_AlgHybrid2GL.hpp:47
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:44
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:95
Zoltan2::part_t
core
src
problems
Zoltan2_PartitioningHelpers.hpp
Generated by
1.17.0