Zoltan2
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
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
24#include <Zoltan2_AlltoAll.hpp>
25
26namespace Zoltan2 {
27
43template <typename SolutionAdapter, typename DataAdapter>
46 const DataAdapter * const data,
47 ArrayRCP<typename DataAdapter::gno_t> &imports // output
48)
49{
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 }
94
95 return imports.size();
96}
97
98} // namespace Zoltan2
99
100#endif // _ZOLTAN2_PARTITIONINGHELPERS_HPP_
AlltoAll communication methods.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Defines the PartitioningSolution class.
A PartitioningSolution is a solution to a partitioning problem.
size_t getActualGlobalNumberOfParts() const
Returns the actual global number of parts provided in setParts().
const RCP< const Environment > & getEnvironment() const
Return the environment associated with the solution.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
const RCP< const Comm< int > > & getCommunicator() const
Return the communicator associated with the solution.
map_t::global_ordinal_type gno_t
Created by mbenlioglu on Aug 31, 2020.
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...
SparseMatrixAdapter_t::part_t part_t