Compare commits
1 Commits
dunaev-oi-
...
dunaev-oi-
| Author | SHA1 | Date | |
|---|---|---|---|
| c117a58277 |
38
tasks/dunaev-oi/lab_5/README.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Отчет по лабораторной работе №5
|
||||
|
||||
Выполнил студент гр. ИСЭбд-41 Дунаев О.И.
|
||||
|
||||
## Создание приложения
|
||||
|
||||
Выбрал язык C#, Windows Forms.
|
||||
|
||||
Приложение имеет три текстовых поля, в которых можно через пробел вносить элементы матрицы. В матрицы-множители значения можно сгенерировать внутри программы. Размерность можно регулировать от 2 до 1000 в специальном поле. При необходимости можно очистить все матрицы. Также есть флажок выключения вывода значений матриц в текстовые поля, т.к. это занимает слишком много времени. Количество потоков в параллельном алгоритме регулируется в соответствующем поле.
|
||||
|
||||
Попробуем запустить обычный и паралелльный алгоритмы на матрицах 10х10 и зафиксировать результат выполнения по времени.
|
||||
|
||||

|
||||

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

|
||||

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

|
||||

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

|
||||

|
||||
|
||||
|
||||
Вывод: Параллельный алгоритм работает быстрее только при наличии большого количества операций и данных. Если элементов не так много, то обычный алгоритм справляется быстрее. Также была обнаружено оптимальное количество потоков для лучшей работы обработки матриц 500х500 - 4 потока.
|
||||
34
tasks/dunaev-oi/lab_5/RVIP_Lab5/Alg1.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace RVIP_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
tasks/dunaev-oi/lab_5/RVIP_Lab5/Alg2.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
namespace RVIP_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,27 +1,9 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace Lab6
|
||||
namespace RVIP_Lab5
|
||||
{
|
||||
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)
|
||||
{
|
||||
string resultString = "";
|
||||
@@ -85,7 +67,7 @@ namespace Lab6
|
||||
{
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
matrix[i, j] = random.Next(1, 5);
|
||||
matrix[i, j] = random.Next(1, 26);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Lab6
|
||||
namespace RVIP_Lab5
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
@@ -31,41 +31,44 @@
|
||||
textBoxMatrix1 = new TextBox();
|
||||
textBoxResult = new TextBox();
|
||||
buttonAlg1 = new Button();
|
||||
label1 = new Label();
|
||||
textBoxMatrix2 = new TextBox();
|
||||
label2 = new Label();
|
||||
buttonAlg2 = new Button();
|
||||
openFileDialog1 = new OpenFileDialog();
|
||||
label3 = new Label();
|
||||
labelResultTime = new Label();
|
||||
label4 = new Label();
|
||||
countStream = new NumericUpDown();
|
||||
buttonGenerateMatrix1 = new Button();
|
||||
label5 = new Label();
|
||||
genCountRowCol = new NumericUpDown();
|
||||
button1 = new Button();
|
||||
label1 = new Label();
|
||||
buttonGenerateMatrix2 = new Button();
|
||||
buttonGenerateMatrix1 = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)countStream).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)genCountRowCol).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBoxMatrix1
|
||||
//
|
||||
textBoxMatrix1.Location = new Point(58, 48);
|
||||
textBoxMatrix1.Location = new Point(12, 50);
|
||||
textBoxMatrix1.Multiline = true;
|
||||
textBoxMatrix1.Name = "textBoxMatrix1";
|
||||
textBoxMatrix1.Size = new Size(565, 274);
|
||||
textBoxMatrix1.Size = new Size(258, 258);
|
||||
textBoxMatrix1.TabIndex = 0;
|
||||
//
|
||||
// textBoxResult
|
||||
//
|
||||
textBoxResult.Location = new Point(833, 48);
|
||||
textBoxResult.Location = new Point(768, 50);
|
||||
textBoxResult.Multiline = true;
|
||||
textBoxResult.Name = "textBoxResult";
|
||||
textBoxResult.Size = new Size(258, 40);
|
||||
textBoxResult.Size = new Size(258, 258);
|
||||
textBoxResult.TabIndex = 1;
|
||||
//
|
||||
// buttonAlg1
|
||||
//
|
||||
buttonAlg1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonAlg1.Location = new Point(833, 186);
|
||||
buttonAlg1.Location = new Point(1080, 60);
|
||||
buttonAlg1.Name = "buttonAlg1";
|
||||
buttonAlg1.Size = new Size(258, 40);
|
||||
buttonAlg1.TabIndex = 2;
|
||||
@@ -73,10 +76,40 @@
|
||||
buttonAlg1.UseVisualStyleBackColor = true;
|
||||
buttonAlg1.Click += buttonAlg1_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.BackColor = Color.Transparent;
|
||||
label1.Font = new Font("Segoe UI", 72F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
label1.Location = new Point(276, 117);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(111, 128);
|
||||
label1.TabIndex = 3;
|
||||
label1.Text = "X";
|
||||
//
|
||||
// textBoxMatrix2
|
||||
//
|
||||
textBoxMatrix2.Location = new Point(378, 50);
|
||||
textBoxMatrix2.Multiline = true;
|
||||
textBoxMatrix2.Name = "textBoxMatrix2";
|
||||
textBoxMatrix2.Size = new Size(258, 258);
|
||||
textBoxMatrix2.TabIndex = 4;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.BackColor = Color.Transparent;
|
||||
label2.Font = new Font("Segoe UI", 72F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
label2.Location = new Point(642, 117);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(120, 128);
|
||||
label2.TabIndex = 5;
|
||||
label2.Text = "=";
|
||||
//
|
||||
// buttonAlg2
|
||||
//
|
||||
buttonAlg2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonAlg2.Location = new Point(833, 232);
|
||||
buttonAlg2.Location = new Point(1080, 117);
|
||||
buttonAlg2.Name = "buttonAlg2";
|
||||
buttonAlg2.Size = new Size(258, 39);
|
||||
buttonAlg2.TabIndex = 8;
|
||||
@@ -92,7 +125,7 @@
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
label3.Location = new Point(23, 370);
|
||||
label3.Location = new Point(574, 349);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(111, 30);
|
||||
label3.TabIndex = 9;
|
||||
@@ -102,7 +135,7 @@
|
||||
//
|
||||
labelResultTime.AutoSize = true;
|
||||
labelResultTime.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
labelResultTime.Location = new Point(165, 370);
|
||||
labelResultTime.Location = new Point(719, 349);
|
||||
labelResultTime.Name = "labelResultTime";
|
||||
labelResultTime.Size = new Size(0, 30);
|
||||
labelResultTime.TabIndex = 10;
|
||||
@@ -110,7 +143,7 @@
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(833, 129);
|
||||
label4.Location = new Point(15, 394);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(123, 15);
|
||||
label4.TabIndex = 12;
|
||||
@@ -118,7 +151,7 @@
|
||||
//
|
||||
// countStream
|
||||
//
|
||||
countStream.Location = new Point(1007, 127);
|
||||
countStream.Location = new Point(144, 392);
|
||||
countStream.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
|
||||
countStream.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
||||
countStream.Name = "countStream";
|
||||
@@ -126,20 +159,10 @@
|
||||
countStream.TabIndex = 13;
|
||||
countStream.Value = new decimal(new int[] { 4, 0, 0, 0 });
|
||||
//
|
||||
// buttonGenerateMatrix1
|
||||
//
|
||||
buttonGenerateMatrix1.Location = new Point(268, 10);
|
||||
buttonGenerateMatrix1.Name = "buttonGenerateMatrix1";
|
||||
buttonGenerateMatrix1.Size = new Size(122, 32);
|
||||
buttonGenerateMatrix1.TabIndex = 14;
|
||||
buttonGenerateMatrix1.Text = "Сгенерировать";
|
||||
buttonGenerateMatrix1.UseVisualStyleBackColor = true;
|
||||
buttonGenerateMatrix1.Click += buttonGenerateMatrix1_Click;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
label5.AutoSize = true;
|
||||
label5.Location = new Point(833, 100);
|
||||
label5.Location = new Point(15, 349);
|
||||
label5.Name = "label5";
|
||||
label5.Size = new Size(166, 15);
|
||||
label5.TabIndex = 16;
|
||||
@@ -147,18 +170,18 @@
|
||||
//
|
||||
// genCountRowCol
|
||||
//
|
||||
genCountRowCol.Location = new Point(1007, 98);
|
||||
genCountRowCol.Maximum = new decimal(new int[] { 500, 0, 0, 0 });
|
||||
genCountRowCol.Location = new Point(187, 347);
|
||||
genCountRowCol.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
genCountRowCol.Minimum = new decimal(new int[] { 2, 0, 0, 0 });
|
||||
genCountRowCol.Name = "genCountRowCol";
|
||||
genCountRowCol.Size = new Size(66, 23);
|
||||
genCountRowCol.TabIndex = 17;
|
||||
genCountRowCol.Value = new decimal(new int[] { 3, 0, 0, 0 });
|
||||
genCountRowCol.Value = new decimal(new int[] { 10, 0, 0, 0 });
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
button1.Location = new Point(833, 295);
|
||||
button1.Location = new Point(1080, 171);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(258, 46);
|
||||
button1.TabIndex = 22;
|
||||
@@ -166,36 +189,50 @@
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += button1_Click;
|
||||
//
|
||||
// label1
|
||||
// buttonGenerateMatrix2
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
label1.Location = new Point(833, 12);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(240, 30);
|
||||
label1.TabIndex = 23;
|
||||
label1.Text = "Детерминант матрицы:";
|
||||
buttonGenerateMatrix2.Location = new Point(447, 12);
|
||||
buttonGenerateMatrix2.Name = "buttonGenerateMatrix2";
|
||||
buttonGenerateMatrix2.Size = new Size(122, 32);
|
||||
buttonGenerateMatrix2.TabIndex = 15;
|
||||
buttonGenerateMatrix2.Text = "Сгенерировать";
|
||||
buttonGenerateMatrix2.UseVisualStyleBackColor = true;
|
||||
buttonGenerateMatrix2.Click += buttonGenerateMatrix2_Click;
|
||||
//
|
||||
// buttonGenerateMatrix1
|
||||
//
|
||||
buttonGenerateMatrix1.Location = new Point(75, 12);
|
||||
buttonGenerateMatrix1.Name = "buttonGenerateMatrix1";
|
||||
buttonGenerateMatrix1.Size = new Size(122, 32);
|
||||
buttonGenerateMatrix1.TabIndex = 14;
|
||||
buttonGenerateMatrix1.Text = "Сгенерировать";
|
||||
buttonGenerateMatrix1.UseVisualStyleBackColor = true;
|
||||
buttonGenerateMatrix1.Click += buttonGenerateMatrix1_Click;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1132, 534);
|
||||
Controls.Add(label1);
|
||||
ClientSize = new Size(1507, 446);
|
||||
Controls.Add(button1);
|
||||
Controls.Add(genCountRowCol);
|
||||
Controls.Add(label5);
|
||||
Controls.Add(buttonGenerateMatrix2);
|
||||
Controls.Add(buttonGenerateMatrix1);
|
||||
Controls.Add(countStream);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(labelResultTime);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(buttonAlg2);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(textBoxMatrix2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonAlg1);
|
||||
Controls.Add(textBoxResult);
|
||||
Controls.Add(textBoxMatrix1);
|
||||
Name = "Form1";
|
||||
Text = "Перемножение матриц: Дунаев О.И. ИСЭбд-41";
|
||||
|
||||
((System.ComponentModel.ISupportInitialize)countStream).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)genCountRowCol).EndInit();
|
||||
ResumeLayout(false);
|
||||
@@ -207,16 +244,19 @@
|
||||
private TextBox textBoxMatrix1;
|
||||
private TextBox textBoxResult;
|
||||
private Button buttonAlg1;
|
||||
private Label label1;
|
||||
private TextBox textBoxMatrix2;
|
||||
private Label label2;
|
||||
private Button buttonAlg2;
|
||||
private OpenFileDialog openFileDialog1;
|
||||
private Label label3;
|
||||
private Label labelResultTime;
|
||||
private Label label4;
|
||||
private NumericUpDown countStream;
|
||||
private Button buttonGenerateMatrix1;
|
||||
private Label label5;
|
||||
private NumericUpDown genCountRowCol;
|
||||
private Button button1;
|
||||
private Label label1;
|
||||
private Button buttonGenerateMatrix2;
|
||||
private Button buttonGenerateMatrix1;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Lab6
|
||||
namespace RVIP_Lab5
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
@@ -9,6 +9,7 @@ namespace Lab6
|
||||
public Alg2 Alg2;
|
||||
public Stopwatch stopwatch;
|
||||
public int[,] matrixA;
|
||||
public int[,] matrixB;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
@@ -24,11 +25,14 @@ namespace Lab6
|
||||
try
|
||||
{
|
||||
stopwatch.Start();
|
||||
int result = Alg1.Begin(matrixA);
|
||||
int[,] matrixResult = Alg1.Begin(matrixA, matrixB);
|
||||
stopwatch.Stop();
|
||||
|
||||
labelResultTime.Text = "" + stopwatch.Elapsed;
|
||||
textBoxResult.Text = Convert.ToString(result);
|
||||
|
||||
|
||||
textBoxResult.Text = service.PrintResultMatrix(matrixResult);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -41,13 +45,15 @@ namespace Lab6
|
||||
{
|
||||
try
|
||||
{
|
||||
double[,] doubleMatrix = service.ConvertArray(matrixA);
|
||||
|
||||
stopwatch.Start();
|
||||
textBoxResult.Text = Convert.ToString(Alg2.Begin(doubleMatrix, (int)countStream.Value));
|
||||
int[,] matrixResult = Alg2.Begin(matrixA, matrixB, (int)countStream.Value);
|
||||
stopwatch.Stop();
|
||||
|
||||
labelResultTime.Text = "" + stopwatch.Elapsed;
|
||||
|
||||
|
||||
textBoxResult.Text = service.PrintResultMatrix(matrixResult);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -61,30 +67,55 @@ namespace Lab6
|
||||
openFileDialog1.ShowDialog();
|
||||
string filePath = openFileDialog1.FileName;
|
||||
string result = service.GetTextFromFile(filePath);
|
||||
|
||||
textBoxMatrix1.Text = result;
|
||||
|
||||
|
||||
|
||||
textBoxMatrix1.Text = result;
|
||||
|
||||
matrixA = service.GetMatrixFromTextbox(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void buttonLoadMatrix2_Click(object sender, EventArgs e)
|
||||
{
|
||||
openFileDialog1.ShowDialog();
|
||||
string filePath = openFileDialog1.FileName;
|
||||
string result = service.GetTextFromFile(filePath);
|
||||
|
||||
textBoxMatrix2.Text = result;
|
||||
|
||||
matrixB = service.GetMatrixFromTextbox(result);
|
||||
|
||||
}
|
||||
|
||||
private void buttonGenerateMatrix1_Click(object sender, EventArgs e)
|
||||
{
|
||||
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)
|
||||
{
|
||||
textBoxMatrix1.Text = "";
|
||||
textBoxMatrix2.Text = "";
|
||||
textBoxResult.Text = "";
|
||||
matrixA = null;
|
||||
matrixB = null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Lab6
|
||||
namespace RVIP_Lab5
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32811.315
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab6", "Lab6.csproj", "{5E467820-7298-4466-AD82-CEDEB780CA68}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RVIP_Lab5", "RVIP_Lab5.csproj", "{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -11,15 +11,15 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5E467820-7298-4466-AD82-CEDEB780CA68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5E467820-7298-4466-AD82-CEDEB780CA68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5E467820-7298-4466-AD82-CEDEB780CA68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5E467820-7298-4466-AD82-CEDEB780CA68}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1DB0461C-8F6E-4BE5-B697-09C4F10570BF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7933D480-E7B1-4658-8726-83CCD3BED00D}
|
||||
SolutionGuid = {7B6008C5-2210-4BAA-B61A-F6C7D82930FA}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
BIN
tasks/dunaev-oi/lab_5/pic/1.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
tasks/dunaev-oi/lab_5/pic/2.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
tasks/dunaev-oi/lab_5/pic/3.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
tasks/dunaev-oi/lab_5/pic/4.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
tasks/dunaev-oi/lab_5/pic/5.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
tasks/dunaev-oi/lab_5/pic/6.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
tasks/dunaev-oi/lab_5/pic/7.png
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
tasks/dunaev-oi/lab_5/pic/8.png
Normal file
|
After Width: | Height: | Size: 58 KiB |
@@ -1,46 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
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,42 +0,0 @@
|
||||
# Отчет по лабораторной работе №6
|
||||
|
||||
Выполнил студент гр. ИСЭбд-41 Дунаев О.И.
|
||||
|
||||
## Создание приложения
|
||||
|
||||
Выбрал язык C#, Windows Forms.
|
||||
|
||||
Приложение имеет поле ввода матрицы, в которое можно через пробел вносить элементы матрицы. При необходимости можно сгенерировать матрицу указав её размерность . При необходимости можно очистить матрицу и определитель. Количество потоков в параллельном алгоритме регулируется в соответствующем поле.
|
||||
|
||||
Попробуем запустить обычный и паралелльный алгоритмы на матрицах 3х3 и зафиксировать результат выполнения по времени.
|
||||
|
||||

|
||||

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

|
||||

|
||||
|
||||
Матрицы 8x8
|
||||
|
||||

|
||||

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

|
||||

|
||||
|
||||
Вывод: Параллельный алгоритм работает быстрее только при наличии большого количества операций. Если операций не так много, то обычный алгоритм справляется быстрее.
|
||||
|
||||
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 19 KiB |