#include <ChunkMaker.hpp>
Public Member Functions | |
ChunkMaker () | |
bool | callForNext (const std::function< void(size_t firstIndex, size_t numIndices)> &target) |
void | initialize (size_t maxIndex, int numThreads, int numProcs=1) |
bool | next (size_t &firstIndex, size_t &numIndices) |
Private Attributes | |
size_t | _chunkSize |
size_t | _maxIndex |
std::atomic< size_t > | _nextIndex |
The ChunkMaker class implements a heuristic for chopping a range of indices from zero to
ChunkMaker::ChunkMaker | ( | ) |
The default (and only) constructor initializes the ChunkMaker object to an empty range.
bool ChunkMaker::callForNext | ( | const std::function< void(size_t firstIndex, size_t numIndices)> & | target | ) |
This function gets the next chunk, and if one is still available, it calls the specified target with the corresponding first index and number of indices, and returns true. If no more chunks are available, the target is not invoked and this function returns false. This function uses an atomic operation to obtain the next chunk so it can safely be called from multiple concurrent execution threads, as long as the target function is thread-safe as well.
void ChunkMaker::initialize | ( | size_t | maxIndex, |
int | numThreads, | ||
int | numProcs = 1 |
||
) |
This function initializes the ChunkMaker object to the specified range (from zero to
bool ChunkMaker::next | ( | size_t & | firstIndex, |
size_t & | numIndices | ||
) |
This function gets the next chunk, in the form of the first index and the number of indices in the chunk. If a chunk is still available, the function places a chunk index range in its arguments and returns true. If no more chunks are available, the output arguments remain unchanged and the function returns false. This function uses an atomic operation to obtain the next chunk so it can safely be called from multiple concurrent execution threads.