Compare commits
1 Commits
melnikov-k
...
melnikov-k
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b86c45ff1 |
@@ -1,34 +0,0 @@
|
|||||||
namespace Lab5
|
|
||||||
{
|
|
||||||
public class Alg1
|
|
||||||
{
|
|
||||||
static int[,] MultiplyMatrices(int[,] matrix1, int[,] matrix2)
|
|
||||||
{
|
|
||||||
int rows1 = matrix1.GetLength(0);
|
|
||||||
int cols1 = matrix1.GetLength(1);
|
|
||||||
int cols2 = matrix2.GetLength(1);
|
|
||||||
|
|
||||||
int[,] result = new int[rows1, cols2];
|
|
||||||
|
|
||||||
for (int i = 0; i < rows1; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < cols2; j++)
|
|
||||||
{
|
|
||||||
for (int k = 0; k < cols1; k++)
|
|
||||||
{
|
|
||||||
result[i, j] += matrix1[i, k] * matrix2[k, j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[,] Begin(int[,] matrix1, int[,] matrix2)
|
|
||||||
{
|
|
||||||
int[,] result = MultiplyMatrices(matrix1, matrix2);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
namespace Lab5
|
|
||||||
{
|
|
||||||
public class Alg2
|
|
||||||
{
|
|
||||||
public int[,] Begin(int[,] matrix1, int[,] matrix2, int numThreads)
|
|
||||||
{
|
|
||||||
int rowsA = matrix1.GetLength(0);
|
|
||||||
int columnsA = matrix1.GetLength(1);
|
|
||||||
int rowsB = matrix2.GetLength(0);
|
|
||||||
int columnsB = matrix2.GetLength(1);
|
|
||||||
|
|
||||||
int[,] resultMatrix = new int[rowsA, columnsB];
|
|
||||||
|
|
||||||
int rowsPerThread = rowsA / numThreads;
|
|
||||||
|
|
||||||
Thread[] threads = new Thread[numThreads];
|
|
||||||
|
|
||||||
for (int i = 0; i < numThreads; i++)
|
|
||||||
{
|
|
||||||
int startRow = i * rowsPerThread;
|
|
||||||
int endRow = (i == numThreads - 1) ? rowsA : startRow + rowsPerThread;
|
|
||||||
threads[i] = new Thread(() => MultiplyRows(startRow, endRow, matrix1, matrix2, resultMatrix));
|
|
||||||
threads[i].Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Thread thread in threads)
|
|
||||||
{
|
|
||||||
thread.Join();
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void MultiplyRows(int startRow, int endRow, int[,] matrixA, int[,] matrixB, int[,] resultMatrix)
|
|
||||||
{
|
|
||||||
for (int i = startRow; i < endRow; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < matrixB.GetLength(1); j++)
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (int k = 0; k < matrixA.GetLength(1); k++)
|
|
||||||
{
|
|
||||||
sum += matrixA[i, k] * matrixB[k, j];
|
|
||||||
}
|
|
||||||
resultMatrix[i, j] = sum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
# Отчет по лабораторной работе №5
|
|
||||||
|
|
||||||
Выполнил студент гр. ИСЭбд-41 Мельников К.Ю.
|
|
||||||
|
|
||||||
## Создание приложения
|
|
||||||
|
|
||||||
Выбрал язык C#, Windows Forms.
|
|
||||||
|
|
||||||
Приложение имеет три текстовых поля, в которых можно через пробел вносить элементы матрицы. В матрицы-множители значения можно сгенерировать внутри программы. Размерность можно регулировать от 2 до 1000 в специальном поле. При необходимости можно очистить все матрицы. Количество потоков в параллельном алгоритме регулируется в соответствующем поле.
|
|
||||||
|
|
||||||
Попробуем запустить обычный и паралелльный алгоритмы на матрицах 10х10 и зафиксировать результат выполнения по времени.
|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
В результате обычный алгоритм выполнился за 0.0004351 секунды, в то время как паралелльный выполнился за 0.0132985 секунды.
|
|
||||||
|
|
||||||
## Бенчмарки
|
|
||||||
|
|
||||||
Протестируем обычный и параллельный алгоритм матрицах 100х100, 300х300 и 500х500.
|
|
||||||
Сверху отображен результат обычного алгоритма, снизу паралелльного.
|
|
||||||
|
|
||||||
Матрицы 100х100
|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
Матрицы 300х300
|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
Матрицы 500х500
|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 101 KiB |
46
tasks/melnikov-ky/lab_6/Lab6/Algorithm1.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
namespace Lab6
|
||||||
|
{
|
||||||
|
public class Alg1
|
||||||
|
{
|
||||||
|
public int Begin(int[,] matrix)
|
||||||
|
{
|
||||||
|
return CalculateDeterminant(matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int CalculateDeterminant(int[,] matrix)
|
||||||
|
{
|
||||||
|
int n = matrix.GetLength(0);
|
||||||
|
|
||||||
|
if (n == 1)
|
||||||
|
{
|
||||||
|
return matrix[0, 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int determinant = 0;
|
||||||
|
|
||||||
|
for (int j = 0; j < n; j++)
|
||||||
|
{
|
||||||
|
int[,] submatrix = new int[n - 1, n - 1];
|
||||||
|
|
||||||
|
for (int i = 1; i < n; i++)
|
||||||
|
{
|
||||||
|
for (int k = 0; k < n; k++)
|
||||||
|
{
|
||||||
|
if (k < j)
|
||||||
|
{
|
||||||
|
submatrix[i - 1, k] = matrix[i, k];
|
||||||
|
}
|
||||||
|
else if (k > j)
|
||||||
|
{
|
||||||
|
submatrix[i - 1, k - 1] = matrix[i, k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
determinant += (int)Math.Pow(-1, j) * matrix[0, j] * CalculateDeterminant(submatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
return determinant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
90
tasks/melnikov-ky/lab_6/Lab6/Algorithm2.cs
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
|
namespace Lab6
|
||||||
|
{
|
||||||
|
public class Alg2
|
||||||
|
{
|
||||||
|
public double Begin(double[,] matrixA, int threadCount)
|
||||||
|
{
|
||||||
|
int size = matrixA.GetLength(0);
|
||||||
|
|
||||||
|
if (size == 1)
|
||||||
|
{
|
||||||
|
return matrixA[0, 0];
|
||||||
|
}
|
||||||
|
else if (size == 2)
|
||||||
|
{
|
||||||
|
return matrixA[0, 0] * matrixA[1, 1] - matrixA[0, 1] * matrixA[1, 0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double determinant = 0;
|
||||||
|
object lockObject = new object();
|
||||||
|
|
||||||
|
Parallel.For(0, size, new ParallelOptions { MaxDegreeOfParallelism = threadCount }, i =>
|
||||||
|
{
|
||||||
|
double[,] subMatrix = GetSubMatrix(matrixA, i);
|
||||||
|
double subDeterminant = matrixA[0, i] * Determinant(subMatrix);
|
||||||
|
|
||||||
|
lock (lockObject)
|
||||||
|
{
|
||||||
|
determinant += Math.Pow(-1, i) * subDeterminant;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return determinant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static double[,] GetSubMatrix(double[,] matrix, int columnIndex)
|
||||||
|
{
|
||||||
|
int size = matrix.GetLength(0);
|
||||||
|
double[,] subMatrix = new double[size - 1, size - 1];
|
||||||
|
|
||||||
|
for (int i = 1; i < size; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < size; j++)
|
||||||
|
{
|
||||||
|
if (j < columnIndex)
|
||||||
|
{
|
||||||
|
subMatrix[i - 1, j] = matrix[i, j];
|
||||||
|
}
|
||||||
|
else if (j > columnIndex)
|
||||||
|
{
|
||||||
|
subMatrix[i - 1, j - 1] = matrix[i, j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return subMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double Determinant(double[,] matrix)
|
||||||
|
{
|
||||||
|
int size = matrix.GetLength(0);
|
||||||
|
|
||||||
|
if (size == 1)
|
||||||
|
{
|
||||||
|
return matrix[0, 0];
|
||||||
|
}
|
||||||
|
else if (size == 2)
|
||||||
|
{
|
||||||
|
return matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double determinant = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
double[,] subMatrix = GetSubMatrix(matrix, i);
|
||||||
|
|
||||||
|
determinant += Math.Pow(-1, i) * matrix[0, i] * Determinant(subMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
return determinant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,27 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace Lab5
|
namespace Lab6
|
||||||
{
|
{
|
||||||
public class Controller
|
public class Controller
|
||||||
{
|
{
|
||||||
|
public double[,] ConvertArray(int[,] intArray)
|
||||||
|
{
|
||||||
|
int rows = intArray.GetLength(0);
|
||||||
|
int cols = intArray.GetLength(1);
|
||||||
|
|
||||||
|
double[,] doubleArray = new double[rows, cols];
|
||||||
|
|
||||||
|
for (int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < cols; j++)
|
||||||
|
{
|
||||||
|
doubleArray[i, j] = (double)intArray[i, j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return doubleArray;
|
||||||
|
}
|
||||||
|
|
||||||
public string PrintResultMatrix(int[,] result)
|
public string PrintResultMatrix(int[,] result)
|
||||||
{
|
{
|
||||||
string resultString = "";
|
string resultString = "";
|
||||||
@@ -67,7 +85,7 @@ namespace Lab5
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < count; j++)
|
for (int j = 0; j < count; j++)
|
||||||
{
|
{
|
||||||
matrix[i, j] = random.Next(1, 26);
|
matrix[i, j] = random.Next(1, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Lab5
|
namespace Lab6
|
||||||
{
|
{
|
||||||
partial class Form1
|
partial class Form1
|
||||||
{
|
{
|
||||||
@@ -31,7 +31,6 @@
|
|||||||
textBoxMatrix1 = new TextBox();
|
textBoxMatrix1 = new TextBox();
|
||||||
textBoxResult = new TextBox();
|
textBoxResult = new TextBox();
|
||||||
buttonAlg1 = new Button();
|
buttonAlg1 = new Button();
|
||||||
textBoxMatrix2 = new TextBox();
|
|
||||||
buttonAlg2 = new Button();
|
buttonAlg2 = new Button();
|
||||||
openFileDialog1 = new OpenFileDialog();
|
openFileDialog1 = new OpenFileDialog();
|
||||||
label3 = new Label();
|
label3 = new Label();
|
||||||
@@ -39,63 +38,49 @@
|
|||||||
label4 = new Label();
|
label4 = new Label();
|
||||||
countStream = new NumericUpDown();
|
countStream = new NumericUpDown();
|
||||||
buttonGenerateMatrix1 = new Button();
|
buttonGenerateMatrix1 = new Button();
|
||||||
buttonGenerateMatrix2 = new Button();
|
|
||||||
label5 = new Label();
|
label5 = new Label();
|
||||||
genCountRowCol = new NumericUpDown();
|
genCountRowCol = new NumericUpDown();
|
||||||
button1 = new Button();
|
button1 = new Button();
|
||||||
|
label1 = new Label();
|
||||||
((System.ComponentModel.ISupportInitialize)countStream).BeginInit();
|
((System.ComponentModel.ISupportInitialize)countStream).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)genCountRowCol).BeginInit();
|
((System.ComponentModel.ISupportInitialize)genCountRowCol).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// textBoxMatrix1
|
// textBoxMatrix1
|
||||||
//
|
//
|
||||||
textBoxMatrix1.BackColor = SystemColors.ButtonFace;
|
textBoxMatrix1.Location = new Point(12, 50);
|
||||||
textBoxMatrix1.Location = new Point(12, 1);
|
|
||||||
textBoxMatrix1.Multiline = true;
|
textBoxMatrix1.Multiline = true;
|
||||||
textBoxMatrix1.Name = "textBoxMatrix1";
|
textBoxMatrix1.Name = "textBoxMatrix1";
|
||||||
textBoxMatrix1.ScrollBars = ScrollBars.Vertical;
|
textBoxMatrix1.Size = new Size(258, 258);
|
||||||
textBoxMatrix1.Size = new Size(273, 252);
|
|
||||||
textBoxMatrix1.TabIndex = 0;
|
textBoxMatrix1.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// textBoxResult
|
// textBoxResult
|
||||||
//
|
//
|
||||||
textBoxResult.BackColor = SystemColors.ButtonFace;
|
textBoxResult.Location = new Point(446, 211);
|
||||||
textBoxResult.Location = new Point(389, 260);
|
|
||||||
textBoxResult.Multiline = true;
|
textBoxResult.Multiline = true;
|
||||||
textBoxResult.Name = "textBoxResult";
|
textBoxResult.Name = "textBoxResult";
|
||||||
textBoxResult.ScrollBars = ScrollBars.Vertical;
|
textBoxResult.Size = new Size(258, 40);
|
||||||
textBoxResult.Size = new Size(609, 341);
|
|
||||||
textBoxResult.TabIndex = 1;
|
textBoxResult.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// buttonAlg1
|
// buttonAlg1
|
||||||
//
|
//
|
||||||
buttonAlg1.BackColor = Color.SpringGreen;
|
buttonAlg1.BackColor = Color.PaleGreen;
|
||||||
buttonAlg1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonAlg1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
buttonAlg1.Location = new Point(389, 103);
|
buttonAlg1.Location = new Point(12, 314);
|
||||||
buttonAlg1.Name = "buttonAlg1";
|
buttonAlg1.Name = "buttonAlg1";
|
||||||
buttonAlg1.Size = new Size(609, 34);
|
buttonAlg1.Size = new Size(258, 40);
|
||||||
buttonAlg1.TabIndex = 2;
|
buttonAlg1.TabIndex = 2;
|
||||||
buttonAlg1.Text = "Обычный алгоритм";
|
buttonAlg1.Text = "Обычный алгоритм";
|
||||||
buttonAlg1.UseVisualStyleBackColor = false;
|
buttonAlg1.UseVisualStyleBackColor = false;
|
||||||
buttonAlg1.Click += buttonAlg1_Click;
|
buttonAlg1.Click += buttonAlg1_Click;
|
||||||
//
|
//
|
||||||
// textBoxMatrix2
|
|
||||||
//
|
|
||||||
textBoxMatrix2.BackColor = SystemColors.ButtonFace;
|
|
||||||
textBoxMatrix2.Location = new Point(1102, 1);
|
|
||||||
textBoxMatrix2.Multiline = true;
|
|
||||||
textBoxMatrix2.Name = "textBoxMatrix2";
|
|
||||||
textBoxMatrix2.ScrollBars = ScrollBars.Vertical;
|
|
||||||
textBoxMatrix2.Size = new Size(273, 253);
|
|
||||||
textBoxMatrix2.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// buttonAlg2
|
// buttonAlg2
|
||||||
//
|
//
|
||||||
buttonAlg2.BackColor = Color.SpringGreen;
|
buttonAlg2.BackColor = Color.PaleGreen;
|
||||||
buttonAlg2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonAlg2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
buttonAlg2.Location = new Point(389, 166);
|
buttonAlg2.Location = new Point(12, 360);
|
||||||
buttonAlg2.Name = "buttonAlg2";
|
buttonAlg2.Name = "buttonAlg2";
|
||||||
buttonAlg2.Size = new Size(609, 34);
|
buttonAlg2.Size = new Size(258, 39);
|
||||||
buttonAlg2.TabIndex = 8;
|
buttonAlg2.TabIndex = 8;
|
||||||
buttonAlg2.Text = "Паралелльный алгоритм";
|
buttonAlg2.Text = "Паралелльный алгоритм";
|
||||||
buttonAlg2.UseVisualStyleBackColor = false;
|
buttonAlg2.UseVisualStyleBackColor = false;
|
||||||
@@ -108,10 +93,10 @@
|
|||||||
// label3
|
// label3
|
||||||
//
|
//
|
||||||
label3.AutoSize = true;
|
label3.AutoSize = true;
|
||||||
label3.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
label3.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
label3.Location = new Point(409, 645);
|
label3.Location = new Point(293, 277);
|
||||||
label3.Name = "label3";
|
label3.Name = "label3";
|
||||||
label3.Size = new Size(83, 21);
|
label3.Size = new Size(111, 30);
|
||||||
label3.TabIndex = 9;
|
label3.TabIndex = 9;
|
||||||
label3.Text = "Результат:";
|
label3.Text = "Результат:";
|
||||||
//
|
//
|
||||||
@@ -119,7 +104,7 @@
|
|||||||
//
|
//
|
||||||
labelResultTime.AutoSize = true;
|
labelResultTime.AutoSize = true;
|
||||||
labelResultTime.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
labelResultTime.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
labelResultTime.Location = new Point(526, 642);
|
labelResultTime.Location = new Point(395, 277);
|
||||||
labelResultTime.Name = "labelResultTime";
|
labelResultTime.Name = "labelResultTime";
|
||||||
labelResultTime.Size = new Size(0, 30);
|
labelResultTime.Size = new Size(0, 30);
|
||||||
labelResultTime.TabIndex = 10;
|
labelResultTime.TabIndex = 10;
|
||||||
@@ -127,103 +112,97 @@
|
|||||||
// label4
|
// label4
|
||||||
//
|
//
|
||||||
label4.AutoSize = true;
|
label4.AutoSize = true;
|
||||||
label4.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
label4.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
label4.Location = new Point(1102, 398);
|
label4.Location = new Point(293, 62);
|
||||||
label4.Name = "label4";
|
label4.Name = "label4";
|
||||||
label4.Size = new Size(159, 21);
|
label4.Size = new Size(214, 30);
|
||||||
label4.TabIndex = 12;
|
label4.TabIndex = 12;
|
||||||
label4.Text = "Количество потоков:";
|
label4.Text = "Количество потоков:";
|
||||||
//
|
//
|
||||||
// countStream
|
// countStream
|
||||||
//
|
//
|
||||||
countStream.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
countStream.Location = new Point(610, 69);
|
||||||
countStream.Location = new Point(1309, 396);
|
|
||||||
countStream.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
|
countStream.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
|
||||||
countStream.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
countStream.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
||||||
countStream.Name = "countStream";
|
countStream.Name = "countStream";
|
||||||
countStream.Size = new Size(66, 29);
|
countStream.Size = new Size(66, 23);
|
||||||
countStream.TabIndex = 13;
|
countStream.TabIndex = 13;
|
||||||
countStream.Value = new decimal(new int[] { 4, 0, 0, 0 });
|
countStream.Value = new decimal(new int[] { 4, 0, 0, 0 });
|
||||||
//
|
//
|
||||||
// buttonGenerateMatrix1
|
// buttonGenerateMatrix1
|
||||||
//
|
//
|
||||||
buttonGenerateMatrix1.BackColor = Color.SpringGreen;
|
buttonGenerateMatrix1.BackColor = Color.PaleGreen;
|
||||||
buttonGenerateMatrix1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonGenerateMatrix1.Location = new Point(12, 12);
|
||||||
buttonGenerateMatrix1.Location = new Point(12, 279);
|
|
||||||
buttonGenerateMatrix1.Name = "buttonGenerateMatrix1";
|
buttonGenerateMatrix1.Name = "buttonGenerateMatrix1";
|
||||||
buttonGenerateMatrix1.Size = new Size(273, 32);
|
buttonGenerateMatrix1.Size = new Size(258, 32);
|
||||||
buttonGenerateMatrix1.TabIndex = 14;
|
buttonGenerateMatrix1.TabIndex = 14;
|
||||||
buttonGenerateMatrix1.Text = "Сгенерировать";
|
buttonGenerateMatrix1.Text = "Сгенерировать";
|
||||||
buttonGenerateMatrix1.UseVisualStyleBackColor = false;
|
buttonGenerateMatrix1.UseVisualStyleBackColor = false;
|
||||||
buttonGenerateMatrix1.Click += buttonGenerateMatrix1_Click;
|
buttonGenerateMatrix1.Click += buttonGenerateMatrix1_Click;
|
||||||
//
|
//
|
||||||
// buttonGenerateMatrix2
|
|
||||||
//
|
|
||||||
buttonGenerateMatrix2.BackColor = Color.SpringGreen;
|
|
||||||
buttonGenerateMatrix2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
|
||||||
buttonGenerateMatrix2.Location = new Point(1102, 279);
|
|
||||||
buttonGenerateMatrix2.Name = "buttonGenerateMatrix2";
|
|
||||||
buttonGenerateMatrix2.Size = new Size(273, 32);
|
|
||||||
buttonGenerateMatrix2.TabIndex = 15;
|
|
||||||
buttonGenerateMatrix2.Text = "Сгенерировать";
|
|
||||||
buttonGenerateMatrix2.UseVisualStyleBackColor = false;
|
|
||||||
buttonGenerateMatrix2.Click += buttonGenerateMatrix2_Click;
|
|
||||||
//
|
|
||||||
// label5
|
// label5
|
||||||
//
|
//
|
||||||
label5.AutoSize = true;
|
label5.AutoSize = true;
|
||||||
label5.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
label5.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
label5.Location = new Point(1102, 346);
|
label5.Location = new Point(293, 14);
|
||||||
label5.Name = "label5";
|
label5.Name = "label5";
|
||||||
label5.Size = new Size(136, 21);
|
label5.Size = new Size(292, 30);
|
||||||
label5.TabIndex = 16;
|
label5.TabIndex = 16;
|
||||||
label5.Text = "Размер массивов:";
|
label5.Text = "Размерность при генерации:";
|
||||||
//
|
//
|
||||||
// genCountRowCol
|
// genCountRowCol
|
||||||
//
|
//
|
||||||
genCountRowCol.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
genCountRowCol.Location = new Point(610, 21);
|
||||||
genCountRowCol.Location = new Point(1309, 344);
|
genCountRowCol.Maximum = new decimal(new int[] { 500, 0, 0, 0 });
|
||||||
genCountRowCol.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
|
||||||
genCountRowCol.Minimum = new decimal(new int[] { 2, 0, 0, 0 });
|
genCountRowCol.Minimum = new decimal(new int[] { 2, 0, 0, 0 });
|
||||||
genCountRowCol.Name = "genCountRowCol";
|
genCountRowCol.Name = "genCountRowCol";
|
||||||
genCountRowCol.Size = new Size(66, 29);
|
genCountRowCol.Size = new Size(66, 23);
|
||||||
genCountRowCol.TabIndex = 17;
|
genCountRowCol.TabIndex = 17;
|
||||||
genCountRowCol.Value = new decimal(new int[] { 10, 0, 0, 0 });
|
genCountRowCol.Value = new decimal(new int[] { 3, 0, 0, 0 });
|
||||||
//
|
//
|
||||||
// button1
|
// button1
|
||||||
//
|
//
|
||||||
button1.BackColor = Color.Orange;
|
button1.BackColor = Color.RosyBrown;
|
||||||
button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
button1.Location = new Point(389, 41);
|
button1.Location = new Point(12, 423);
|
||||||
button1.Name = "button1";
|
button1.Name = "button1";
|
||||||
button1.Size = new Size(609, 32);
|
button1.Size = new Size(258, 46);
|
||||||
button1.TabIndex = 22;
|
button1.TabIndex = 22;
|
||||||
button1.Text = "Очистить матрицы";
|
button1.Text = "Очистить матрицы";
|
||||||
button1.UseVisualStyleBackColor = false;
|
button1.UseVisualStyleBackColor = false;
|
||||||
button1.Click += button1_Click;
|
button1.Click += button1_Click;
|
||||||
//
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
label1.Location = new Point(293, 211);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(147, 30);
|
||||||
|
label1.TabIndex = 23;
|
||||||
|
label1.Text = "Детерминант:";
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
BackColor = SystemColors.GradientInactiveCaption;
|
BackColor = Color.PapayaWhip;
|
||||||
ClientSize = new Size(1523, 681);
|
ClientSize = new Size(729, 491);
|
||||||
|
Controls.Add(label1);
|
||||||
Controls.Add(button1);
|
Controls.Add(button1);
|
||||||
Controls.Add(genCountRowCol);
|
Controls.Add(genCountRowCol);
|
||||||
Controls.Add(label5);
|
Controls.Add(label5);
|
||||||
Controls.Add(buttonGenerateMatrix2);
|
|
||||||
Controls.Add(buttonGenerateMatrix1);
|
Controls.Add(buttonGenerateMatrix1);
|
||||||
Controls.Add(countStream);
|
Controls.Add(countStream);
|
||||||
Controls.Add(label4);
|
Controls.Add(label4);
|
||||||
Controls.Add(labelResultTime);
|
Controls.Add(labelResultTime);
|
||||||
Controls.Add(label3);
|
Controls.Add(label3);
|
||||||
Controls.Add(buttonAlg2);
|
Controls.Add(buttonAlg2);
|
||||||
Controls.Add(textBoxMatrix2);
|
|
||||||
Controls.Add(buttonAlg1);
|
Controls.Add(buttonAlg1);
|
||||||
Controls.Add(textBoxResult);
|
Controls.Add(textBoxResult);
|
||||||
Controls.Add(textBoxMatrix1);
|
Controls.Add(textBoxMatrix1);
|
||||||
Name = "Form1";
|
Name = "Form1";
|
||||||
Text = "Умножение матриц: Мельников К.Ю. ИСЭбд-41";
|
Text = "Умножение матриц: Мельников К.Ю. ИСЭбд-41";
|
||||||
((System.ComponentModel.ISupportInitialize)countStream).EndInit();
|
((System.ComponentModel.ISupportInitialize)countStream).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)genCountRowCol).EndInit();
|
((System.ComponentModel.ISupportInitialize)genCountRowCol).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
@@ -235,7 +214,6 @@
|
|||||||
private TextBox textBoxMatrix1;
|
private TextBox textBoxMatrix1;
|
||||||
private TextBox textBoxResult;
|
private TextBox textBoxResult;
|
||||||
private Button buttonAlg1;
|
private Button buttonAlg1;
|
||||||
private TextBox textBoxMatrix2;
|
|
||||||
private Button buttonAlg2;
|
private Button buttonAlg2;
|
||||||
private OpenFileDialog openFileDialog1;
|
private OpenFileDialog openFileDialog1;
|
||||||
private Label label3;
|
private Label label3;
|
||||||
@@ -243,9 +221,9 @@
|
|||||||
private Label label4;
|
private Label label4;
|
||||||
private NumericUpDown countStream;
|
private NumericUpDown countStream;
|
||||||
private Button buttonGenerateMatrix1;
|
private Button buttonGenerateMatrix1;
|
||||||
private Button buttonGenerateMatrix2;
|
|
||||||
private Label label5;
|
private Label label5;
|
||||||
private NumericUpDown genCountRowCol;
|
private NumericUpDown genCountRowCol;
|
||||||
private Button button1;
|
private Button button1;
|
||||||
|
private Label label1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Lab5
|
namespace Lab6
|
||||||
{
|
{
|
||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
{
|
{
|
||||||
@@ -9,7 +9,6 @@ namespace Lab5
|
|||||||
public Alg2 Alg2;
|
public Alg2 Alg2;
|
||||||
public Stopwatch stopwatch;
|
public Stopwatch stopwatch;
|
||||||
public int[,] matrixA;
|
public int[,] matrixA;
|
||||||
public int[,] matrixB;
|
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
@@ -25,19 +24,15 @@ namespace Lab5
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
int[,] matrixResult = Alg1.Begin(matrixA, matrixB);
|
int result = Alg1.Begin(matrixA);
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|
||||||
labelResultTime.Text = "" + stopwatch.Elapsed;
|
labelResultTime.Text = "" + stopwatch.Elapsed;
|
||||||
|
textBoxResult.Text = Convert.ToString(result);
|
||||||
|
|
||||||
|
|
||||||
textBoxResult.Text = service.PrintResultMatrix(matrixResult);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
stopwatch.Reset();
|
stopwatch.Reset();
|
||||||
}
|
}
|
||||||
@@ -46,50 +41,43 @@ namespace Lab5
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
double[,] doubleMatrix = service.ConvertArray(matrixA);
|
||||||
|
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
int[,] matrixResult = Alg2.Begin(matrixA, matrixB, (int)countStream.Value);
|
textBoxResult.Text = Convert.ToString(Alg2.Begin(doubleMatrix, (int)countStream.Value));
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|
||||||
labelResultTime.Text = "" + stopwatch.Elapsed;
|
labelResultTime.Text = "" + stopwatch.Elapsed;
|
||||||
|
|
||||||
|
|
||||||
textBoxResult.Text = service.PrintResultMatrix(matrixResult);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
stopwatch.Reset();
|
stopwatch.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonLoadMatrix1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
openFileDialog1.ShowDialog();
|
||||||
|
string filePath = openFileDialog1.FileName;
|
||||||
|
string result = service.GetTextFromFile(filePath);
|
||||||
|
|
||||||
|
textBoxMatrix1.Text = result;
|
||||||
|
|
||||||
|
matrixA = service.GetMatrixFromTextbox(result);
|
||||||
|
}
|
||||||
|
|
||||||
private void buttonGenerateMatrix1_Click(object sender, EventArgs e)
|
private void buttonGenerateMatrix1_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
matrixA = service.GenerateNewMatrix((int)genCountRowCol.Value);
|
matrixA = service.GenerateNewMatrix((int)genCountRowCol.Value);
|
||||||
|
|
||||||
|
|
||||||
textBoxMatrix1.Text = service.PrintResultMatrix(matrixA);
|
textBoxMatrix1.Text = service.PrintResultMatrix(matrixA);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonGenerateMatrix2_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
matrixB = service.GenerateNewMatrix((int)genCountRowCol.Value);
|
|
||||||
|
|
||||||
|
|
||||||
textBoxMatrix2.Text = service.PrintResultMatrix(matrixB);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button1_Click(object sender, EventArgs e)
|
private void button1_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
textBoxMatrix1.Text = "";
|
textBoxMatrix1.Text = "";
|
||||||
textBoxMatrix2.Text = "";
|
|
||||||
textBoxResult.Text = "";
|
textBoxResult.Text = "";
|
||||||
matrixA = null;
|
matrixA = null;
|
||||||
matrixB = null;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,4 @@
|
|||||||
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>7, 19</value>
|
<value>7, 19</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>25</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
</root>
|
||||||
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.3.32811.315
|
VisualStudioVersion = 17.3.32811.315
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab5", "Lab5.csproj", "{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab6", "Lab6.csproj", "{5E467820-7298-4466-AD82-CEDEB780CA68}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -11,15 +11,15 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{5E467820-7298-4466-AD82-CEDEB780CA68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{5E467820-7298-4466-AD82-CEDEB780CA68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{5E467820-7298-4466-AD82-CEDEB780CA68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}.Release|Any CPU.Build.0 = Release|Any CPU
|
{5E467820-7298-4466-AD82-CEDEB780CA68}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {7B6008C5-2210-4BAA-B61A-F6C7D82930FA}
|
SolutionGuid = {7933D480-E7B1-4658-8726-83CCD3BED00D}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Lab5
|
namespace Lab6
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
39
tasks/melnikov-ky/lab_6/README.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Отчет по лабораторной работе №6
|
||||||
|
|
||||||
|
Выполнил студент гр. ИСЭбд-41 Мельников К.Ю.
|
||||||
|
|
||||||
|
## Создание приложения
|
||||||
|
|
||||||
|
Выбрал язык C#, Windows Forms.
|
||||||
|
|
||||||
|
Приложение имеет поле ввода матрицы, в которое можно через пробел вносить элементы матрицы. Можно сгенерировать матрицу указав её размерность. При необходимости можно очистить матрицу и определитель. Количество потоков в параллельном алгоритме регулируется в соответствующем поле.
|
||||||
|
|
||||||
|
Попробуем запустить обычный и паралелльный алгоритмы на матрицах 2х2 и зафиксировать результат выполнения по времени.
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
## Бенчмарки
|
||||||
|
|
||||||
|
Протестируем обычный и параллельный алгоритм определение детерминанта на различной размерности матрицы.
|
||||||
|
|
||||||
|
В ходе экспериментов было установлено, что обработка матрицы размеров больше 11х11 занимает слишком много времени в обычном и параллельном алгоритмах, поэтому для тестирования возьмем матрицы 7х7, 9х9 и 11х11.
|
||||||
|
|
||||||
|
Сверху отображен результат обычного алгоритма, снизу паралелльного.
|
||||||
|
|
||||||
|
Матрица 7х7
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
Матрицы 9x9
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
Матрицы 11х11
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
Вывод: Параллельный алгоритм работает быстрее только при наличии большого количества операций. Если операций не так много, то обычный алгоритм справляется быстрее.
|
||||||
BIN
tasks/melnikov-ky/lab_6/scrins/1.1.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
tasks/melnikov-ky/lab_6/scrins/1.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
tasks/melnikov-ky/lab_6/scrins/2.2png.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
tasks/melnikov-ky/lab_6/scrins/2.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
tasks/melnikov-ky/lab_6/scrins/3.3.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
tasks/melnikov-ky/lab_6/scrins/3.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
tasks/melnikov-ky/lab_6/scrins/4.4.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
tasks/melnikov-ky/lab_6/scrins/4.png
Normal file
|
After Width: | Height: | Size: 27 KiB |