diff --git a/1706-4/Pushkarev_DS/Mp.sln b/1706-4/Pushkarev_DS/Mp.sln new file mode 100644 index 0000000..36b0ab6 --- /dev/null +++ b/1706-4/Pushkarev_DS/Mp.sln @@ -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 diff --git a/1706-4/Pushkarev_DS/Mp/Mp.vcxproj b/1706-4/Pushkarev_DS/Mp/Mp.vcxproj new file mode 100644 index 0000000..ecfb8be --- /dev/null +++ b/1706-4/Pushkarev_DS/Mp/Mp.vcxproj @@ -0,0 +1,134 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630} + Mp + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + C:\Library\Microsoft SDKs\MPI\Include;%(AdditionalIncludeDirectories) + + + Console + C:\Library\Microsoft SDKs\MPI\Lib\x86;%(AdditionalLibraryDirectories) + msmpi.lib;%(AdditionalDependencies) + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + + + + + \ No newline at end of file diff --git a/1706-4/Pushkarev_DS/Mp/Mp.vcxproj.filters b/1706-4/Pushkarev_DS/Mp/Mp.vcxproj.filters new file mode 100644 index 0000000..bc6688b --- /dev/null +++ b/1706-4/Pushkarev_DS/Mp/Mp.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Файлы ресурсов + + + \ No newline at end of file diff --git a/1706-4/Pushkarev_DS/Mp/Mp.vcxproj.user b/1706-4/Pushkarev_DS/Mp/Mp.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/1706-4/Pushkarev_DS/Mp/Mp.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/1706-4/Pushkarev_DS/Mp/main.cpp b/1706-4/Pushkarev_DS/Mp/main.cpp new file mode 100644 index 0000000..1bb9ea8 --- /dev/null +++ b/1706-4/Pushkarev_DS/Mp/main.cpp @@ -0,0 +1,162 @@ +#include "mpi.h" +#include +#include "stdlib.h" +#include + +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; +} + + + +