namespace Robust.Shared.Threading;
///
/// Represents a generic parallel job that processes a range of indices.
///
public interface IParallelRangeRobustJob
{
///
/// Minimum amount of batches required to engage in parallelism.
/// If the total number of batches is less than this, the job will run serially.
///
int MinimumBatchParallel => 2;
///
/// The amount of elements to process in each batch.
///
int BatchSize => 1;
///
/// Processes a range of indices from startIndex to endIndex.
///
/// The starting index of the range.
/// The ending index of the range.
void ExecuteRange(int startIndex, int endIndex);
}
///
/// Represents a parallel job that processes individual indices.
///
public interface IParallelRobustJob : IParallelRangeRobustJob
{
///
/// Default implementation that executes the job for each index in the specified range.
///
void IParallelRangeRobustJob.ExecuteRange(int startIndex, int endIndex)
{
for (var i = startIndex; i < endIndex; i++)
{
Execute(i);
}
}
///
/// Executes the job for the specified index.
///
/// The index to process.
void Execute(int index);
}
///
/// Represents a parallel job that processes a bulk range of indices.
/// Good for jobs that can operate on ranges more efficiently (SIMD) than individual indices.
///
public interface IParallelBulkRobustJob : IParallelRangeRobustJob;