Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <sharder.h>
Classes | |
class | Shard |
Public Types | |
using | ConstSparseColumnBlock |
using | SparseColumnBlock |
Public Member Functions | |
Sharder (int64_t num_elements, int num_shards, ThreadPool *thread_pool, const std::function< int64_t(int64_t)> &element_mass) | |
Sharder (int64_t num_elements, int num_shards, ThreadPool *thread_pool) | |
Sharder (const Eigen::SparseMatrix< double, Eigen::ColMajor, int64_t > &matrix, int num_shards, ThreadPool *thread_pool) | |
Sharder (const Sharder &other_sharder, int64_t num_elements) | |
Sharder (const Sharder &other)=delete | |
Sharder & | operator= (const Sharder &other)=delete |
Sharder (Sharder &&other)=default | |
Sharder & | operator= (Sharder &&other)=default |
int | NumShards () const |
int64_t | NumElements () const |
The number of elements that are split into shards. | |
int64_t | ShardSize (int shard) const |
int64_t | ShardStart (int shard) const |
int64_t | ShardMass (int shard) const |
void | ParallelForEachShard (const std::function< void(const Shard &)> &func) const |
Runs func on each of the shards. | |
double | ParallelSumOverShards (const std::function< double(const Shard &)> &func) const |
Runs func on each of the shards and sums the results. | |
bool | ParallelTrueForAllShards (const std::function< bool(const Shard &)> &func) const |
const std::vector< int64_t > & | ShardStartsForTesting () const |
Public for testing only. | |
This class represents a way to shard elements for multi-threading. The elements may be entries of a vector or the columns of a (column-major) matrix. The shards are selected to have roughly the same mass, where the mass of an entry depends on the constructor used. See the free functions below and in the .cc file for example usage.
operations_research::pdlp::Sharder::Sharder | ( | int64_t | num_elements, |
int | num_shards, | ||
ThreadPool * | thread_pool, | ||
const std::function< int64_t(int64_t)> & | element_mass ) |
Creates a Sharder
for problems with num_elements
elements and mass of each element given by element_mass
. Each shard will have roughly the same mass. The number of shards in the resulting Sharder
will be approximately num_shards
but may differ. The thread_pool
will be used for parallel operations executed by e.g. ParallelForEachShard()
. The thread_pool
may be nullptr, which means work will be executed in the same thread. If thread_pool
is not nullptr, the underlying object is not owned and must outlive the Sharder
.
elem
starts a new shard.
Definition at line 36 of file sharder.cc.
operations_research::pdlp::Sharder::Sharder | ( | int64_t | num_elements, |
int | num_shards, | ||
ThreadPool * | thread_pool ) |
Creates a Sharder
for problems with num_elements
elements and unit mass. This constructor exploits having all element mass equal to 1 to take time proportional to num_shards
instead of num_elements
. Also see the comments above the first constructor.
Definition at line 72 of file sharder.cc.
|
inline |
operations_research::pdlp::Sharder::Sharder | ( | const Sharder & | other_sharder, |
int64_t | num_elements ) |
Constructs a Sharder
with the same thread pool as other_sharder
, for problems with num_elements
elements and unit mass. The number of shards will be approximately the same as that of other_sharder
. Also see the comments on the first constructor.
The std::max()
protects against other_sharder.NumShards() == 0
, which will happen if other_sharder
had num_elements == 0
.
Definition at line 103 of file sharder.cc.
|
delete |
Sharder
may be moved, but not copied. Moved-from objects may be in an invalid state. The only methods that may be called on a moved-from object are the destructor or operator=
.
|
default |
|
inline |
|
inline |
void operations_research::pdlp::Sharder::ParallelForEachShard | ( | const std::function< void(const Shard &)> & | func | ) | const |
Runs func
on each of the shards.
Definition at line 109 of file sharder.cc.
double operations_research::pdlp::Sharder::ParallelSumOverShards | ( | const std::function< double(const Shard &)> & | func | ) | const |
Runs func
on each of the shards and sums the results.
Definition at line 143 of file sharder.cc.
bool operations_research::pdlp::Sharder::ParallelTrueForAllShards | ( | const std::function< bool(const Shard &)> & | func | ) | const |
Runs func
on each of the shards. Returns true iff all shards returned true.
Recall std::vector<bool>
is not thread-safe.
Definition at line 152 of file sharder.cc.
|
inline |
|
inline |
|
inline |
|
inline |