private void ZeroColumn(IBitMatrix matrix, int rows, int j, int k) { if (threads == 1 || rows < multiThreadedCutoff) { for (int i = 0; i < rows; i++) { if (i != j && matrix[i, k]) { matrix.XorRows(i, j, k); } } return; } signal.Reset(); int counter = threads; for (int thread = 0; thread < threads; thread++) { ThreadPool.QueueUserWorkItem(delegate(Object o) { for (int i = (int)o; i < rows; i += threads) { if (i != j && matrix[i, k]) { matrix.XorRows(i, j, k); } } if (Interlocked.Decrement(ref counter) == 0) { signal.Set(); } }, thread); } signal.WaitOne(); }
private void ZeroColumn(IBitMatrix matrix, int rows, int j, int k) { if (threads == 1 || rows < multiThreadedCutoff) { for (int i = 0; i < rows; i++) { if (i != j && matrix[i, k]) { matrix.XorRows(i, j, k); } } return; } Parallel.For(0, threads, thread => { for (int i = thread; i < rows; i += threads) { if (i != j && matrix[i, k]) { matrix.XorRows(i, j, k); } } }); }