Compare commits

...

3 Commits

12 changed files with 842 additions and 0 deletions

481
tasks/voronkova-es/lab_6/.gitignore vendored Normal file
View File

@ -0,0 +1,481 @@
## Наши данные для работы программы
result-1/
result/
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET
project.lock.json
project.fragment.lock.json
artifacts/
# Tye
.tye/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
##
## Visual studio for Mac
##
# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/
# Mac bundle stuff
*.dmg
*.app
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk

View File

@ -0,0 +1,6 @@
74 3 128 68 146 70
81 139 14 12 51 58
90 114 126 123 122 69
20 35 115 133 46 138
141 39 143 67 15 103
86 38 55 138 92 104

View File

@ -0,0 +1,12 @@
101 88 62 120 114 13 11 83 102 6 73 31
83 17 75 111 110 132 141 93 19 4 11 6
24 62 28 39 17 104 106 30 120 12 148 98
90 54 38 8 61 67 67 120 135 117 54 117
117 95 138 125 147 97 62 81 103 123 6 23
112 109 41 43 110 114 87 105 7 119 118 126
16 55 36 124 141 1 82 66 23 142 98 90
76 126 19 100 46 93 76 99 45 29 31 63
138 64 10 11 144 71 115 122 93 91 134 86
84 83 102 120 16 12 90 58 5 121 76 34
13 118 144 58 11 55 147 8 96 104 79 4
138 52 110 25 103 118 101 25 144 137 73 106

View File

@ -0,0 +1,16 @@
84 95 64 62 135 99 100 109 36 89 22 67 130 45 43 112
33 20 120 17 34 142 86 24 92 82 36 111 29 97 30 116
112 79 48 35 91 125 108 106 141 88 2 34 74 136 42 117
33 59 149 28 33 98 40 134 88 95 100 143 13 77 29 17
102 26 102 72 16 17 17 83 19 71 24 147 19 146 130 140
102 119 5 54 33 54 2 96 59 69 68 43 90 3 32 123
132 124 148 98 34 45 5 6 39 145 128 111 62 97 27 96
45 148 109 73 29 127 35 55 40 85 123 19 101 9 30 68
109 4 116 104 109 112 63 76 104 60 70 16 8 100 40 121
97 61 17 77 76 10 93 39 78 51 61 126 11 28 122 21
149 65 27 127 92 125 45 124 8 88 101 101 8 24 71 38
142 149 106 108 42 32 148 35 106 147 75 127 57 98 114 49
114 15 3 72 63 136 87 113 46 141 109 137 135 134 96 45
53 130 113 127 145 40 113 139 131 148 5 28 59 84 92 8
40 144 88 140 124 42 100 83 33 41 140 17 8 40 72 70
124 39 96 129 16 111 98 28 101 54 92 30 90 42 136 45

View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33723.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixCalculator", "MatrixCalculator\MatrixCalculator.csproj", "{12D70107-84A8-4118-82E5-53535F1B2A4A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{12D70107-84A8-4118-82E5-53535F1B2A4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{12D70107-84A8-4118-82E5-53535F1B2A4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12D70107-84A8-4118-82E5-53535F1B2A4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12D70107-84A8-4118-82E5-53535F1B2A4A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {608D6B6A-88D3-43D4-A361-B488FB03C4AC}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,97 @@
using BenchmarkDotNet.Attributes;
namespace MatrixCalculator;
public class BenchmarkClass
{
private readonly int[,] matrix_100_100_1;
private readonly int[,] matrix_300_300_1;
private readonly int[,] matrix_500_500_1;
public BenchmarkClass()
{
static int[,] ReadMatrixFromFile(string filePath)
{
string[] lines = File.ReadAllLines(filePath);
int rows = lines.Length;
int cols = lines[0].Split(' ').Length;
int[,] matrix = new int[rows, cols];
for (int i = 0; i < rows; i++)
{
string[] values = lines[i].Split(' ');
for (int j = 0; j < cols; j++)
{
matrix[i, j] = int.Parse(values[j]);
}
}
return matrix;
}
string folder = "D:\\4 КУРС\\РВИП\\distributed-computing_liza_fork\\tasks\\voronkova-es\\lab_6\\MatrixCalculator\\Matrix";
//6 6
matrix_100_100_1 = ReadMatrixFromFile(Path.Combine(folder, "100_100_1.txt"));
//12 12
matrix_300_300_1 = ReadMatrixFromFile(Path.Combine(folder, "300_300_1.txt"));
//16 16
matrix_500_500_1 = ReadMatrixFromFile(Path.Combine(folder, "500_500_1.txt"));
}
[Benchmark]
public int Def_100_100_Matrix() => DefAlg.CalcDet(matrix_100_100_1);
[Benchmark]
public int Def_300_300_Matrix() => DefAlg.CalcDet(matrix_300_300_1);
[Benchmark]
public int Def_500_500_Matrix() => DefAlg.CalcDet(matrix_500_500_1);
[Benchmark]
public int Parallel_100_100_Matrix_MAX() => ParallelAlg.CalcDet(matrix_100_100_1, -1);
[Benchmark]
public int Parallel_300_300_Matrix_MAX() => ParallelAlg.CalcDet(matrix_300_300_1, -1);
[Benchmark]
public int Parallel_500_500_Matrix_MAX() => ParallelAlg.CalcDet(matrix_500_500_1, -1);
[Benchmark]
public int Parallel_100_100_Matrix_2() => ParallelAlg.CalcDet(matrix_100_100_1, 2);
[Benchmark]
public int Parallel_300_300_Matrix_2() => ParallelAlg.CalcDet(matrix_300_300_1, 2);
[Benchmark]
public int Parallel_500_500_Matrix_2() => ParallelAlg.CalcDet(matrix_500_500_1, 2);
[Benchmark]
public int Parallel_100_100_Matrix_4() => ParallelAlg.CalcDet(matrix_100_100_1, 4);
[Benchmark]
public int Parallel_300_300_Matrix_4() => ParallelAlg.CalcDet(matrix_300_300_1, 4);
[Benchmark]
public int Parallel_500_500_Matrix_4() => ParallelAlg.CalcDet(matrix_500_500_1, 4);
[Benchmark]
public int Parallel_100_100_Matrix_8() => ParallelAlg.CalcDet(matrix_100_100_1, 8);
[Benchmark]
public int Parallel_300_300_Matrix_8() => ParallelAlg.CalcDet(matrix_300_300_1, 8);
[Benchmark]
public int Parallel_500_500_Matrix_8() => ParallelAlg.CalcDet(matrix_500_500_1, 8);
[Benchmark]
public int Parallel_100_100_Matrix_16() => ParallelAlg.CalcDet(matrix_100_100_1, 16);
[Benchmark]
public int Parallel_300_300_Matrix_16() => ParallelAlg.CalcDet(matrix_300_300_1, 16);
[Benchmark]
public int Parallel_500_500_Matrix_16() => ParallelAlg.CalcDet(matrix_500_500_1, 16);
}

View File

@ -0,0 +1,84 @@
using BenchmarkDotNet.Reports;
using MathNet.Numerics.LinearAlgebra;
namespace MatrixCalculator;
internal class DefAlg
{
internal static int CalcDet(int[,] matrix)
{
int size = matrix.GetLength(0);
if (size == 1)
{
return matrix[0, 0];
}
int det = 0;
for (int i = 0; i < size; i++)
{
int[,] subMatrix = new int[size - 1, size - 1];
for (int j = 1; j < size; j++)
{
for (int k = 0; k < size; k++)
{
if (k < i)
{
subMatrix[j - 1, k] = matrix[j, k];
}
else if (k > i)
{
subMatrix[j - 1, k - 1] = matrix[j, k];
}
}
}
det += (i % 2 == 0 ? 1 : -1) * matrix[0, i] * CalcDet(subMatrix);
}
return det;
}
internal static int[,] MultiplyMatrices(int[,] matrix1, int[,] matrix2)
{
int rows1 = matrix1.GetLength(0);
int cols1 = matrix1.GetLength(1);
int rows2 = matrix2.GetLength(0);
int cols2 = matrix2.GetLength(1);
if (cols1 != rows2)
{
throw new Exception("Матрицы не могут быть перемножены: количество столбцов первой матрицы не равно количеству строк второй матрицы.");
}
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;
}
internal static void PrintMatrix(int[,] matrix)
{
int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
Console.Write(matrix[i, j] + " ");
}
Console.WriteLine();
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,86 @@
namespace MatrixCalculator;
internal class ParallelAlg
{
private static readonly object _locker = new();
internal static int CalcDet(int[,] matrix, int parallelismDegree = -1)
{
int size = matrix.GetLength(0);
if (size == 1)
{
return matrix[0, 0];
}
int det = 0;
Parallel.For(0, size, new ParallelOptions { MaxDegreeOfParallelism = parallelismDegree }, i =>
{
int[,] subMatrix = new int[size - 1, size - 1];
for (int j = 1; j < size; j++)
{
for (int k = 0; k < size; k++)
{
if (k < i)
{
subMatrix[j - 1, k] = matrix[j, k];
}
else if (k > i)
{
subMatrix[j - 1, k - 1] = matrix[j, k];
}
}
}
lock (_locker)
{
det += (i % 2 == 0 ? 1 : -1) * matrix[0, i] * CalcDet(subMatrix, parallelismDegree);
}
});
return det;
}
internal static int[,] MultiplyMatrices(int[,] matrix1, int[,] matrix2, int parallelismDegree)
{
int rows1 = matrix1.GetLength(0);
int cols1 = matrix1.GetLength(1);
int rows2 = matrix2.GetLength(0);
int cols2 = matrix2.GetLength(1);
if (cols1 != rows2)
{
throw new Exception("Матрицы не могут быть перемножены: количество столбцов первой матрицы не равно количеству строк второй матрицы.");
}
int[,] result = new int[rows1, cols2];
Parallel.For(0, rows1, new ParallelOptions { MaxDegreeOfParallelism = parallelismDegree }, 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;
}
internal static void PrintMatrix(int[,] matrix)
{
int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
Console.Write(matrix[i, j] + " ");
}
Console.WriteLine();
}
}
}

View File

@ -0,0 +1,4 @@
using BenchmarkDotNet.Running;
using MatrixCalculator;
BenchmarkRunner.Run<BenchmarkClass>();

View File

@ -0,0 +1,16 @@
# Отчет по лабораторной работе №6
Выполнила студентка гр. ИСЭбд-41 Воронкова Е.С.
# Описание работы приложения
Приложение реализовано в виде консольного приложения C# с использованием библиотеки BenchmarkDotNet
Был создан специальный класс в котором прописаны все методы которые мы хотим замерить
ТК по многу раз считать матрицы больших размеров слишком долго взяла для примера матрицы 6 на 6, 12 на 12 и 16 на 16
# Вывод
С использованием параллельного алгоритма скорость обработки может увеличиться, особенно при большой размерности матрицы, но нужно быть аккуратными с разделямыми ресурсами
В данном примере оптимальная скорость достигается при количестве потоков равном 16.
![](images/screen_1.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB