public BatchForWorker(int sidx, int eidx, int add, int bsize, Action <int, BatchLoopState> body, BatchLoopState state) { sidx_cur = sidx; sidx_add = add; batch_sz = bsize; this.eidx = eidx; this.body = body; this.state = state; }
public static void BatchFor( int from_inclusive, int to_exclusive, int batch_size, ParallelOptions options, Action <int, BatchLoopState> body) { int add_idx = batch_size * (options.MaxDegreeOfParallelism - 1); Action[] acts = new Action[options.MaxDegreeOfParallelism]; BatchLoopState state = new BatchLoopState(); for (int i = options.MaxDegreeOfParallelism; --i >= 0;) { acts[i] = new BatchForWorker(from_inclusive * batch_size, to_exclusive, add_idx, batch_size, body, state).Run; } Parallel.Invoke(options, acts); }
public void Run() { int sidx = sidx_cur; int add = sidx_add; Action <int, BatchLoopState> body = this.body; BatchLoopState state = this.state; int bsize = batch_sz; for (int i = eidx; sidx < i && state.NeedBreak(sidx); sidx += add) { for (int j = 0; j++ < bsize && state.NeedBreak(sidx); sidx++) { body.Invoke(sidx, state); if (state.m_state == BatchLoopState.STATE_BREAK) { state.m_lowestBreak.Min(sidx); } } } }