public void Multiply(List <Block> treadList, Matrix mas, int a) { int N = 200; // event chto-to tam takoe int treadBlocksCount = treadList.Count / N; List <AutoResetEvent> masEv = new List <AutoResetEvent>(); if (treadBlocksCount == 0) { int count = treadList.Count; for (int i = 0; i < count; i++) { List <Block> t = new List <Block>(); t.Add(treadList[0]); treadList.RemoveAt(0); AutoResetEvent e = new AutoResetEvent(false); masEv.Add(e); MultThreadData d = new MultThreadData(e, t, mas, a); ThreadPool.QueueUserWorkItem(this.UThreadMult, d); } } else { for (int i = 0; i < N - 1; i++) { List <Block> t = new List <Block>(); for (int j = 0; j < treadBlocksCount; j++) { t.Add(treadList[0]); treadList.RemoveAt(0); } AutoResetEvent e = new AutoResetEvent(false); masEv.Add(e); MultThreadData d = new MultThreadData(e, t, mas, a); ThreadPool.QueueUserWorkItem(this.UThreadMult, d); } AutoResetEvent e2 = new AutoResetEvent(false); masEv.Add(e2); MultThreadData d2 = new MultThreadData(e2, treadList, mas, a); ThreadPool.QueueUserWorkItem(this.UThreadMult, d2); } bool index = WaitHandle.WaitAll(masEv.ToArray()); }
public void UThreadMult(object o) { MultThreadData td = (MultThreadData)o; for (int i = 0; i < td.blocks.Count; i++) { Block block = td.blocks[i]; for (int k = 0; k < block.Indexes.Count; k++) { Index ind = block.Indexes[k]; double h = td.matr.GetElement(ind) * td.a; td.matr.SetElement(h, ind); } } td.autoEv.Set(); }