-
Notifications
You must be signed in to change notification settings - Fork 1
/
WorkDistribution.h
44 lines (34 loc) · 1.36 KB
/
WorkDistribution.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef WORK_DISTRIBUTION_H
#define WORK_DISTRIBUTION_H
#include <memory>
// Forward declaration to not include Matrix.h
struct MatrixCOO;
/// Chunks for distributing the work.
struct WorkDistribution {
/// Number of chunks represented by this structure.
int numberOfChunks;
/// Offsets of chunks.
std::unique_ptr<int[]> offsets;
/// Lengths of chunks.
std::unique_ptr<int[]> lengths;
/// Fill structure with given data.
WorkDistribution(int numberOfChunks, std::unique_ptr<int[]> &&offsets,
std::unique_ptr<int[]> &&lengths)
: numberOfChunks(numberOfChunks), offsets(std::move(offsets)),
lengths(std::move(lengths)) {}
/// @return chunk that contains \a row.
int findChunk(int row) const;
/// @return true if \a column is on the diagonal of \a chunk.
bool isOnDiagonal(int chunk, int column) const {
return offsets[chunk] <= column && column < offsets[chunk] + lengths[chunk];
}
/// @return a distribution where each chunk received roughly the same number
/// of rows.
static WorkDistribution *calculateByRow(int N, int numberOfChunks);
/// @return a distribution where each chunk received roughly the same amount
/// of nonzeros.
static WorkDistribution *calculateByNz(const MatrixCOO &coo,
int numberOfChunks);
};
#endif