forked from valentina-kustikova/parallel-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29123.88 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mp", "Mp\Mp.vcxproj", "{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}.Debug|x64.ActiveCfg = Debug|x64 | ||
{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}.Debug|x64.Build.0 = Debug|x64 | ||
{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}.Debug|x86.Build.0 = Debug|Win32 | ||
{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}.Release|x64.ActiveCfg = Release|x64 | ||
{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}.Release|x64.Build.0 = Release|x64 | ||
{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}.Release|x86.ActiveCfg = Release|Win32 | ||
{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B3510363-CB81-4C33-961E-3F4A9A963B2C} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>16.0</VCProjectVersion> | ||
<ProjectGuid>{4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}</ProjectGuid> | ||
<RootNamespace>Mp</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
<AdditionalIncludeDirectories>C:\Library\Microsoft SDKs\MPI\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<AdditionalLibraryDirectories>C:\Library\Microsoft SDKs\MPI\Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||
<AdditionalDependencies>msmpi.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Исходные файлы"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Файлы заголовков"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Файлы ресурсов"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp"> | ||
<Filter>Файлы ресурсов</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#include "mpi.h" | ||
#include <iostream> | ||
#include "stdlib.h" | ||
#include <random> | ||
|
||
using namespace::std; | ||
|
||
int procs; //÷èñëî ïðîöåññîâ | ||
int rankprocs; //íîìåð ðàíãà(ïðèíèìàåò ðàçíûå çíà÷åíèÿ â ðàçíûõ ïðîöåññàõ) | ||
|
||
//çàïîëíåíèå ñòðîêè | ||
char* FillStr(int n) | ||
{ | ||
char* str; | ||
str = new char[n]; | ||
char ar[33]; | ||
for (int i = 0, j = 97; i < 26; i++) | ||
{ | ||
ar[i] = (char)j; | ||
j++; | ||
} | ||
ar[26] = ' '; | ||
ar[27] = ' '; | ||
ar[28] = ' '; | ||
ar[29] = ' '; | ||
ar[30] = ' '; | ||
ar[31] = ' '; | ||
ar[32] = ' '; | ||
for (int i = 0; i < n; i++) | ||
str[i] = ar[(rand() % 33)]; | ||
str[n] = '\0'; | ||
return str; | ||
} | ||
|
||
char* FillStr1(int n) | ||
{ | ||
char* str; | ||
str = new char[n]; | ||
char stroka[1000] = ""; | ||
cin.getline(stroka, n + 1);//âûäåëÿåì äëÿ \0 | ||
for (int i = 0; i < n; i++) | ||
{ | ||
str[i] = stroka[i]; | ||
} | ||
str[n] = '\0'; | ||
|
||
//cin.getline(str, n); | ||
/*for (int i = 0; i < n; i++) | ||
cin >> str[i];*/ | ||
return str; | ||
} | ||
|
||
int main(int argc, char *argv[])//êîëè÷åñòâî ïðîöåññîâ è ññûëêà íà exe | ||
{ | ||
double t1 = 0.0, t2, dt; | ||
//double precision; | ||
//setlocale(LC_ALL, "ru"); | ||
//ïîäðàçóìåâàåòñÿ, ÷òî ñëîâà ðàçäåëÿþòñÿ ïðîáåëàìè | ||
char* str; | ||
str = new char[1000]; | ||
/*char str[128] = "";*/ | ||
int n = 1000; | ||
double N = 0; | ||
//MPI_Status stat; | ||
MPI_Init(&argc, &argv);//Èíèöèàëèçàöèÿ ñðåäû âûïîëíåíèÿ MPI ïðîãðàììû, ïàðàìåòðû - êîë-âî àðãóìåíòîâ êîìàíäíîé ñòðîêè è ñàìè àðãóìåíòû | ||
MPI_Comm_size(MPI_COMM_WORLD, &procs);//êîëè÷åñòâî ïðîöåññîâ | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rankprocs);//îïðåäåëÿåò ðàíã ïðîöåññà(êîòîðûé âûçâàë ýòó ôóíêöèþ) | ||
|
||
//MPI_Barrier(MPI_COMM_WORLD); | ||
|
||
/*precision = MPI_Wtick(); | ||
cout << precision << endl;*/ | ||
//procs = 4;/////////////// | ||
|
||
if (rankprocs == 0) | ||
{ | ||
bool flag = false; | ||
|
||
while (flag == false) | ||
{ | ||
cout << "size str " << endl; | ||
cin >> n; | ||
if (n > 0) | ||
flag = true; | ||
else { | ||
cout << "size str > 0" << endl; | ||
cin.clear(); | ||
} | ||
} | ||
cin.getline(str, n); | ||
str = FillStr(n);//// | ||
if (procs < 1) | ||
{ | ||
cout << "size str < 0" << endl; | ||
return 0; | ||
} | ||
else | ||
cout << "Number proc : " << procs << endl; | ||
} | ||
if (rankprocs == 0) | ||
t1 = MPI_Wtime(); | ||
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); //ðàññûëêà ÷èñëà | ||
|
||
MPI_Bcast(str, n, MPI_CHAR, 0, MPI_COMM_WORLD); //ðàññûëêà ñòðîêè | ||
|
||
int size = n / procs; | ||
if ((n % procs) != 0) | ||
size++; | ||
//size += procs - 1; | ||
int i1 = size * rankprocs; | ||
int i2 = size * (rankprocs + 1); | ||
|
||
double summ = 0; | ||
cout << rankprocs << " proc start work" << endl; | ||
for (int i = i1; i < i2; i++) | ||
{ | ||
if (str[i] == ' ') | ||
summ++; | ||
//if (str[i] == ' ' && (str[i + 1] == ' ' || str[i + 1] == 0)) // ïðîâåðêà íà ëèøíèå ïðîáåëû//äëÿ ñëó÷àåâ, êîãäà ïîñë ñèìâîë ïðîáåë | ||
//if ((str[i] == ' ' && str[i + 1] == ' ') || (str[i] == ' ' && str[i + 1] == 0)) | ||
if (str[i] == ' ' && str[i + 1] == ' ') | ||
summ--; | ||
} | ||
double sums = 0; | ||
MPI_Reduce(&summ, &sums, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); | ||
//N++; | ||
if (rankprocs == 0) | ||
{ | ||
N = sums; | ||
//for (int i = 1; i < procs; i++) | ||
//{ | ||
// MPI_Recv(&summ, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD, &stat);//Ïîëó÷èòü | ||
// N += summ; | ||
//} | ||
//MPI_Reduce(&summ, &N, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); | ||
N++;//???????????????????????????åñëè íåò ïðîáåëîâ | ||
if (str[0] == ' ')//ïðîâåðêà íà ïåðâûé íóëåâîé | ||
N--; | ||
if (str[n - 1] == ' ') | ||
N--; | ||
t2 = MPI_Wtime(); | ||
dt = t2 - t1; | ||
cout << "Procnum " << rankprocs<< " time= " << dt << endl; | ||
cout << "Words: " << N << endl; | ||
for (int i = 0; i < n; i++) | ||
cout << str[i]; | ||
cout << endl; | ||
} | ||
else { | ||
//MPI_Send(&summ, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD);//Îòïðàâèòü | ||
/* t2 = MPI_Wtime(); | ||
dt = t2 - t1; | ||
cout << "Procnum " << rankprocs << " time= " << dt << endl;*/ | ||
} | ||
//cout << t2 - t1; | ||
MPI_Finalize();//Ïîñëåäíÿÿ âûçûâàåìàÿ ô-ÿ MPI | ||
return 0; | ||
} | ||
|
||
|
||
|
||
|