private void ChangeMax(Element element, float value, int row, int column) { lock (locker) { element.Row = row; element.Value = value; element.Column = column; } }
private void ChangeMax(Element el1, Element el2) { el1.Value = el2.Value; el1.Column = el2.Column; el1.Row = el2.Row; }
private void GetMaxValue(Element element, int start, int end, int it) { var el = new Element() {Value = 0}; for (var i = start; i < end; i++) { for (var j = 0; j < size / 4; j++) { if (matrix[i, j].X > el.Value) { ChangeMax(el, matrix[i, j].X, i, j * 4); } if (matrix[i, j].Y > el.Value) { ChangeMax(el, matrix[i, j].Y, i, j * 4 + 1); } if (matrix[i, j].Z > el.Value) { ChangeMax(el, matrix[i, j].Z, i, j * 4 + 2); } if (matrix[i, j].W > el.Value) { ChangeMax(el, matrix[i, j].W, i, j * 4 + 3); } } } if (el == null) Console.WriteLine("NUUUUUUUUUUUUUUUUUUUUUUUUL"); elements[it] = el; }
public Element GetMaxValuePar(Element element) { elements = new Element[procCount]; for (var i = 0; i < procCount; i++) { var it = i; tasks.Add(Task.Factory.StartNew(() => GetMaxValue(element, size * it / procCount, ((it + 1) * size) / procCount, it))); } foreach (var task in tasks) { task.Wait(); } tasks.Clear(); foreach (var el in elements) { if (el == null) { Console.WriteLine("nulll"); } if (el.Value > element.Value) { ChangeMax(element, el); } } return element; }
//поиск максимального элемента public void GetMaxParWrapper(Element element) { _element = element; var с = Parallel.For(0, size, GetMaxParHelper); }