-
Notifications
You must be signed in to change notification settings - Fork 0
Parallel matrix multiplication #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| { | ||
| /// <summary> | ||
| /// then file is empty | ||
| /// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что-то с отступами злое
| namespace ParallelMatrixMultiplication | ||
| { | ||
| /// <summary> | ||
| /// then we couldn't multiplication matrices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как-то не по-английски
| static void Main(string[] args) | ||
| { | ||
| var matrixTest = new int[1000, 1000]; | ||
| Stopwatch stopWatch = new Stopwatch(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var?
| stopWatch.Start(); | ||
| for (int i = 0; i < 10; i++) | ||
| { | ||
| var testTime =MatrixFunctions.MatrixMultiplicationParallel(matrixTest, matrixTest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| var testTime =MatrixFunctions.MatrixMultiplicationParallel(matrixTest, matrixTest); | |
| var testTime = MatrixFunctions.MatrixMultiplicationParallel(matrixTest, matrixTest); |
| stopWatch.Stop(); | ||
| var time = stopWatch.ElapsedMilliseconds; | ||
| Console.WriteLine($"Среднее время обычного умножения матриц 1000*1000: {time / 10} ms"); | ||
| Console.WriteLine($"Среднее время параллельного умножения матриц 1000*1000: {timeParallel / 10} ms"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это лучше, чем ничего, но надо было на разных размерностях попробовать, чтобы понять, всегда ли многопоточный алгоритм быстрее. И записать сюда в комментарии результаты, которые конкретно у Вас получились
| { | ||
| if (filePath == "") | ||
| { | ||
| throw new Exception(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArgumentException лучше. Просто Exception вообще никогда не надо кидать, его не отфильтровать потом в catch-е
| fileOut.Delete(); | ||
| } | ||
| using var newFile = new FileStream(filePath, FileMode.Create); | ||
| var file = new StreamWriter(newFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Он вроде тоже IDisposable, так что using
| [Test] | ||
| public void TestNormalDataParallel() | ||
| { | ||
| var matrix1 = new int[1000,1000]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пробелов после "," не хватает
| var matrix1 = new int[1000,1000]; | ||
| var matrix2 = new int[1000,1000]; | ||
| var result = new int[1000,1000]; | ||
| var matrix = MatrixFunctions.MatrixMultiplicationParallel(matrix1, matrix2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мм, нулевые матрицы перемножаются?
| { | ||
| static void Main(string[] args) | ||
| { | ||
| var matrixTest = new int[1000, 1000]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Непоказательно. Надо именно сгенерировать какие-нибудь матрицы с какими-нибудь адекватными числами
yurii-litvinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Надо немного код в порядок привести
| [Test] | ||
| public void TestNormalFilePath() | ||
| { | ||
| int[,] result = {{ 2, 1, 2}, {4, 1, 5}, {1, 5, 3}} ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что-то как-то пробелы то ли один лишний, то ли много не хватает. И двумерные массивы лучше на нескольких строчках писать, чтобы было в виде матрицы.
| namespace ParallelMatrixMultiplication | ||
| { | ||
| /// <summary> | ||
| /// File's function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Функция Файла? :) Какая функция и какого файла? Надо по-английски тренироваться писать (можно сначала с Google Translate или аналогичным сервисом от Яндекса, потом привыкнете и можно будет без них)
| } | ||
| } | ||
|
|
||
| private static (int, int) CountSizeMatrix(string filePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CountMatrixSize
| /// </summary> | ||
| public static class MatrixFunctions | ||
| { | ||
| public static int[,] MatrixMultiplicationParallel(int[,] matrix1, int[,] matrix2) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| Результаты на матрицах размеров 128*128. | ||
| Количество повторов: 100. | ||
| Паралельное умножение: | ||
| Матожидание = 13,75 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Обязательно приводите размерность величин
| Количество повторов: 100. | ||
| Паралельное умножение: | ||
| Матожидание = 13,75 | ||
| Среднеквадратичное отклонение = 3,897114317029974 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не надо столько знаков после запятой. Матожидание имеет два знака, так и тут можно.
|
|
||
| namespace ParallelMatrixMultiplication | ||
| { | ||
| public class Statistics |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
yurii-litvinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут уже число попыток близко к исчерпанию, поэтому надо, чтобы в следующий раз всё было идеально, или всё-таки минус полбалла :)
| var matrix1 = new int[3,4]; | ||
| var matrix2 = new int[3,3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
С пробелами беда. Научитесь пользоваться https://github.com/DotNetAnalyzers/StyleCopAnalyzers, поможет :)
| { | ||
| if (string.IsNullOrEmpty(filePath)) | ||
| { | ||
| throw new FilePathException("Error file path!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
С английским беда. "Ошибка файл путь!"
|
|
||
| private static (int, int) CountMatrixSize(string filePath) | ||
| { | ||
| CheckFilePath((filePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CheckFilePath((filePath)); | |
| CheckFilePath(filePath); |
| CheckFilePath((filePath)); | ||
| (int length, int width) size = CountMatrixSize((filePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Скобочки богу скобочек! https://lurkmore.to/LISP
| throw new MultiplicationException("Number of columns in the first matrix are not equal to the rows in the second matrix!"); | ||
| } | ||
| var matrix = new int[matrix1.GetLength(0), matrix2.GetLength(1)]; | ||
| var threads = new Thread[Environment.ProcessorCount]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если в матрице меньше строк, чем Environment.ProcessorCount, просто зря потоки создаёте
| */ | ||
|
|
||
| var matrixFirst = FileFunctions.CreateMatrix((args[0])); | ||
| var matrixSecond = FileFunctions.CreateMatrix(((args[1]))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
О, ещё больше скобок
| results[0] = (averageParallel, standardDeviationParallel); | ||
| results[1] = (averageNotParallel, standardDeviationNotParallel); | ||
| return results; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут вот с отступом не повезло, а я уж было хотел зачесть задачу полностью :) Рекомендую при коммите или хотя бы когда делаете пуллреквест просматривать диффы на предмет таких косяков, они сразу в глаза бросаются
yurii-litvinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, всё хорошо, зачтена
No description provided.