Conversation
|
|
||
| public static class ComparisonMatrixCountingSpeeds | ||
| { | ||
| public static (double, double)[] Experiments(int sizeOfData, int amountOfTestsInSample) //size of data, mat ozgidanie, dispersiia |
There was a problem hiding this comment.
комментарии транслитом? Ты серьёзно?))
| for (int i = 0; i < time.Count; i++) | ||
| { | ||
| double difference = time[i] - mathematicalExpectation; | ||
| sumOfSquareDifference += difference * difference; |
There was a problem hiding this comment.
можно написать короче:
var sumOfSquareDifference = Enumerable.Range(0, time.Count).Sum(i => (time[i] - mathematicalExpectation) * (time[i] - mathematicalExpectation));
| public int[,] matrixOfNumbers { get; private set; } | ||
| public int Height { get; private set; } = 0; | ||
| public int Width { get; private set; } = 0; | ||
| public Matrix(string filePath) |
There was a problem hiding this comment.
лучше передавать в конструктор сразу ширину, высоту и данные. Так положено по правилам инкапсуляции. Вдруг пользователь захочет вводить из консоли?
Homework1/Matrix.cs
Outdated
| var matrix3Numbers = new int[matrix1.Height, matrix2.Width]; | ||
|
|
||
| var matrixMyltiplyingThreads = new Thread[4]; | ||
| for (byte i = 0; i < matrixMyltiplyingThreads.Length; i++) |
There was a problem hiding this comment.
а зачем тут byte? Мы же не на Си пишем :)
Homework1/Matrix.cs
Outdated
| } | ||
| var matrix3Numbers = new int[matrix1.Height, matrix2.Width]; | ||
|
|
||
| var matrixMyltiplyingThreads = new Thread[4]; |
There was a problem hiding this comment.
а что, если программа будет запускаться на сервере со 128 процессорами? 4 потока -- это как-то маловато. Лучше написать var matrixMyltiplyingThreads = new Thread[Environment.ProcessorCount];
Homework1/Matrix.cs
Outdated
| matrix3Numbers[currentLine, currentColumn] = 0; | ||
| for (int k = 0; k < matrix1.Width; k++) | ||
| { | ||
| matrix3Numbers[currentLine, currentColumn] += matrix1.matrixOfNumbers[currentLine, k] * matrix2.matrixOfNumbers[k, currentColumn]; |
There was a problem hiding this comment.
можно короче написать:
matrix3Numbers[currentLine, currentColumn] = Enumerable.Range(0, matrix1.Width).Sum(k => matrix1.matrixOfNumbers[currentLine, k] * matrix2.matrixOfNumbers[k, currentColumn]);
Homework1/Matrix.cs
Outdated
| uint amountOfElementsInMatrix = (uint)matrix1.Height * (uint)matrix2.Width; | ||
| matrixMyltiplyingThreads[i] = new Thread(() => | ||
| { | ||
| uint currentElement = (uint)numberOfStartElement; |
There was a problem hiding this comment.
можно сделать проще:
var rowsPerThread = Math.Ceiling(matrix2.Height / Environment.ProcessorCount); и умножать по стольку строк в каждом потоке
Homework1/Matrix.cs
Outdated
| }); | ||
| } | ||
|
|
||
| foreach (var tread in matrixMyltiplyingThreads) |
There was a problem hiding this comment.
по-английски пишется thread.
tread -- это "шагать"
There was a problem hiding this comment.
было бы неплохо добавить возможность вводить матрицы из консоли
There was a problem hiding this comment.
кажется, у тебя что-то не то с результатами. Как при большой матрице параллельное умножение может работать медленнее последовательного?
…по количеству ядер
…ogram 2. Изменила способ счета потоками 3. Обновила результаты экспериментов в табличке results
| Matrix matrix1; | ||
| Matrix matrix2; |
There was a problem hiding this comment.
| Matrix matrix1; | |
| Matrix matrix2; | |
| private Matrix matrix1; | |
| private Matrix matrix2; |
В .NET по традиции всегда явно пишут модификаторы видимости, даже если умолчания устраивают
| [Test] | ||
| public void ExceptionsTest() | ||
| { | ||
| Assert.Throws<ArgumentNullException>(() => new Matrix(null)); |
There was a problem hiding this comment.
Тут nullability-анализ ругается, если хотите null, напишите null!. Надо, чтобы компилировалось без предупреждений.
|
|
||
| using System.Diagnostics; | ||
|
|
||
| public static class ComparisonMatrixCountingSpeeds |
There was a problem hiding this comment.
Надо комментарии ко всем типам и всем public-членам
| return new (double, double)[] { (mathematicalExpectationByThreads.Value, dispersionByThreads), (mathematicalExpectationSequential.Value, dispersionSequential) }; | ||
| } | ||
|
|
||
| private static double DispersionCalculator(List<long> time, double mathematicalExpectation) |
There was a problem hiding this comment.
Методы должны называться глаголами в повелительной форме
| double? mathematicalExpectationSequential = timeSequential.Average(); | ||
| double dispersionByThreads = DispersionCalculator(timeByThreads, mathematicalExpectationByThreads.Value); | ||
| double dispersionSequential = DispersionCalculator(timeSequential, mathematicalExpectationSequential.Value); | ||
| return new (double, double)[] { (mathematicalExpectationByThreads.Value, dispersionByThreads), (mathematicalExpectationSequential.Value, dispersionSequential) }; |
There was a problem hiding this comment.
Вместо массива кортежей, где всегда должно быть два элемента, сделали бы специальный struct. Явные именованные поля лучше соглашений
| if (matrix1 == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(matrix1)); | ||
| } |
There was a problem hiding this comment.
| if (matrix1 == null) | |
| { | |
| throw new ArgumentNullException(nameof(matrix1)); | |
| } | |
| ArgumentNullException.ThrowIfNull(matrix1); |
| for (byte i = 0; i < matrixMyltiplyingThreads.Length; i++) | ||
| { | ||
| int numberOfStartElement = i; | ||
| uint amountOfElementsInMatrix = (uint)matrix1.Height * (uint)matrix2.Width; |
There was a problem hiding this comment.
Всё так, хотя и некритично. Лишние аннотации типов в целом не мешают
| int amountOfThreads = Environment.ProcessorCount; | ||
| var matrixMyltiplyingThreads = new Thread[amountOfThreads]; |
There was a problem hiding this comment.
Так может получиться больше потоков, чем нужно. В матрице может быть меньше Environment.ProcessorCount строк
| FileStream fs = File.Create(matrix3FilePath); | ||
| if (!File.Exists(matrix3FilePath)) | ||
| { | ||
| throw new ArgumentException("Файл не был создан"); |
There was a problem hiding this comment.
В main нет смысла кидать исключения. потому что их даже в теории некому ловить. Выводите ошибку на консоль и всё.
| Потоки: Последовательно: | ||
| Размер матрицы: 200*200 | ||
| Мат ожидание: 231 150 | ||
| Дисперсия: 1026 135 |
There was a problem hiding this comment.
Дисперсия не нужна, нужно среднеквадратичное отклонение
No description provided.