diff --git a/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB.sln b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB.sln
new file mode 100644
index 0000000..0b44d5c
--- /dev/null
+++ b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB.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}") = "CCS_TBB", "CCS_TBB\CCS_TBB.vcxproj", "{C6B7ACB0-50CF-4411-8E20-5F3D34384254}"
+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
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}.Debug|x64.ActiveCfg = Debug|x64
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}.Debug|x64.Build.0 = Debug|x64
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}.Debug|x86.ActiveCfg = Debug|Win32
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}.Debug|x86.Build.0 = Debug|Win32
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}.Release|x64.ActiveCfg = Release|x64
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}.Release|x64.Build.0 = Release|x64
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}.Release|x86.ActiveCfg = Release|Win32
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {21163EBA-7533-4615-A22A-A547AEA86CA0}
+ EndGlobalSection
+EndGlobal
diff --git a/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/CCS_TBB.vcxproj b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/CCS_TBB.vcxproj
new file mode 100644
index 0000000..8965898
--- /dev/null
+++ b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/CCS_TBB.vcxproj
@@ -0,0 +1,135 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ {C6B7ACB0-50CF-4411-8E20-5F3D34384254}
+ CCSTBB
+ 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:\OpenMP\pp_2020_spring-master\tbb_downloaded\tbb-2020\tbb\include;%(AdditionalIncludeDirectories)
+
+
+ Console
+ C:\OpenMP\pp_2020_spring-master\tbb_downloaded\tbb-2020\tbb\lib\ia32\vc14;%(AdditionalLibraryDirectories)
+
+
+
+
+ Level3
+ Disabled
+ true
+ true
+ C:\OpenMP\pp_2020_spring-master\tbb_downloaded\tbb-2020\tbb\include;%(AdditionalIncludeDirectories)
+
+
+ Console
+ C:\OpenMP\pp_2020_spring-master\tbb_downloaded\tbb-2020\tbb\lib\ia32\vc14;%(AdditionalLibraryDirectories)
+
+
+
+
+ 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/CCS_TBB/CCS_TBB/CCS_TBB.vcxproj.filters b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/CCS_TBB.vcxproj.filters
new file mode 100644
index 0000000..bc6688b
--- /dev/null
+++ b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/CCS_TBB.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/CCS_TBB/CCS_TBB/CCS_TBB.vcxproj.user b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/CCS_TBB.vcxproj.user
new file mode 100644
index 0000000..88a5509
--- /dev/null
+++ b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/CCS_TBB.vcxproj.user
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/main.cpp b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/main.cpp
new file mode 100644
index 0000000..db9069b
--- /dev/null
+++ b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/main.cpp
@@ -0,0 +1,472 @@
+#pragma once
+#include
+#include
+#include
+#include
+#include
+#include
+#include "tbb\tbb.h"
+
+using namespace std;
+
+typedef double type;
+
+struct Task
+{
+ int pointerStart;
+ int pointerEnd;
+ int taskIndex;
+ Task() :pointerStart(0), pointerEnd(0), taskIndex(0) {}
+ Task(int a, int b, int c) :pointerStart(a), pointerEnd(b), taskIndex(c) {}
+};
+
+class Matrix
+{
+protected:
+ int row = 0;
+ int col = 0;
+public:
+ std::vector vv;
+ Matrix()
+ {
+ vv = vector();
+ }
+ Matrix(int col, int row)
+ {
+ this->row = row;
+ this->col = col;
+ vv = vector(row * col);//
+ }
+ Matrix(int col, int row, type val)
+ {
+ this->row = row;
+ this->col = col;
+ vv = vector(row * col, val);
+ }
+
+ int gRow() const
+ {
+ return row;
+ }
+ int gCol() const
+ {
+ return col;
+ }
+ type* operator [] (int j)
+ {
+ return &vv[j * col];
+ }
+ void transposition()
+ {
+ Matrix A(row, col);
+ for (int i = 0; i < col; i++)
+ for (int j = 0; j < row; j++)
+ {
+ A[i][j] = (*this)[j][i];
+ }
+ std::swap(row, col);
+ vv = A.vv;
+ }
+
+ bool operator == (const Matrix& m)
+ {
+ bool res = (row == m.row & col == m.col);
+ if (res == false)
+ return false;
+
+ for (int i = 0; i < vv.size(); i++)
+ if (vv[i] != m.vv[i]) return false;
+ return true;
+ }
+
+ static void readMatrix(Matrix& A, Matrix& B, int N, string name)// ( )
+ {
+ ifstream input(name);
+ input >> A.vv[0];// ,
+ for (int i = 0; i < A.vv.size() + B.vv.size(); i++)
+ {
+ if (i < A.vv.size())
+ input >> A.vv[i];
+ else
+ {
+ for (int j = 0; j < B.vv.size(); j++)
+ input >> B.vv[j];
+ }
+ }
+ input.close();
+ A.transposition();
+ B.transposition();
+ }
+
+ static void writeMatrix(Matrix& A, int N)//
+ {
+ A.transposition();
+ ofstream input("resMatrix.txt");
+ for (int i = 0; i < A.vv.size(); i++)
+ {
+ if (i < A.vv.size())
+ input << A.vv[i] << "\t ";
+ if ((i + 1) % N == 0)
+ input << endl;
+ }
+ input.close();
+ }
+
+ static void randMatrixdata(Matrix& A, Matrix& B, int N)//
+ {
+ for (int i = 0; i < N * N; i++)
+ {
+ int prob;//
+ prob = rand() % 100;
+ if (prob < 15)
+ A.vv[i] = (rand() % 10) + (double)(rand() % 10) / 10;//
+ else
+ A.vv[i] = 0;
+ }
+
+ for (int i = 0; i < N * N; i++)
+ {
+ int prob;//
+ prob = rand() % 100;
+ if (prob < 15)
+ B.vv[i] = (rand() % 10) + (double)(rand() % 10) / 10;
+ else
+ B.vv[i] = 0;
+ }
+ }
+};
+
+class MatrixCCS
+{
+protected:
+ vector values;
+ vector rows;
+ vector pointer;
+ int N;
+public:
+ friend class FunctorTBB;
+ MatrixCCS() {}
+ MatrixCCS(int n) :N(n)
+ {
+ pointer.push_back(0);
+ }
+ MatrixCCS(Matrix& M) :N(M.gRow())
+ {
+ pointer = vector(N + 1);
+ int lastCount = 0;
+ for (int j = 0; j < N; j++)
+ {
+ int curCount = 0;
+ for (int i = 0; i < N; i++)
+ {
+ type el = M[j][i];//
+ if (el != 0.0)
+ {
+ curCount++;
+ rows.push_back(i);//
+ values.push_back(el);
+ }
+ }
+ if (j != 0)
+ {
+ pointer[j] = pointer[j - 1] + lastCount;// values,
+ }
+ lastCount = curCount;
+ }
+ pointer[N] = (int)values.size();
+ }
+ void transposition()
+ {
+ vector>> tmp(N, vector>());
+ int pCount = 0;//
+ int numElementsInCol = 0;//
+ for (int i = 0; i < values.size(); i += numElementsInCol)
+ {
+ numElementsInCol = pointer[pCount + 1] - pointer[pCount];//
+ for (int z = i; z < i + numElementsInCol; z++)//
+ {
+ int row = rows[z];//
+ int col = pCount;
+ type el = values[z];
+ tmp[row].push_back(make_pair(el, col));
+ }
+ pCount++;
+ }
+ pCount = 0;// pointer
+ vector* cols = &rows;
+ int lastCount = 0;
+ int vCount = 0;
+ for (int i = 0; i < N; i++)
+ {
+ int numElementInCol = (int)tmp[i].size();//
+ if (numElementInCol > 0)//
+ {
+ for (int j = 0; j < numElementInCol; j++)// CCS
+ {
+ values[vCount] = tmp[i][j].first;//
+ (*cols)[vCount] = tmp[i][j].second;
+ vCount++;
+ }
+ }
+ if (pCount != 0)
+ {
+ pointer[pCount] = pointer[pCount - 1] + lastCount;
+ }
+ lastCount = numElementInCol;
+ pCount++;
+
+ }
+ }
+ void uniteMatrix(const MatrixCCS& m)//
+ {
+ for (int i = 0; i < m.values.size(); i++)// values rows
+ {
+ values.push_back(m.values[i]);
+ rows.push_back(m.rows[i]);
+ }
+ for (int i = 1; i < m.pointer.size(); i++)// pointer
+ {
+ int start = pointer[pointer.size() - 1];// pointer
+ pointer.push_back(m.pointer[i] - m.pointer[i - 1] + start);
+ }
+ }
+
+ MatrixCCS parallelMult(MatrixCCS& m, const int numThreads)
+ {
+ class FunctorTBB
+ {
+ private:
+ MatrixCCS* m1;
+ MatrixCCS* m2;
+ vector* tasks;
+ vector* tmp;
+ vector* elCountM;
+ public:
+ FunctorTBB()
+ {
+ m1 = nullptr;
+ m2 = nullptr;
+ tasks = nullptr;
+ tmp = nullptr;
+ elCountM = nullptr;
+ }
+ FunctorTBB(MatrixCCS* m1_, MatrixCCS* m2_, vector* tasks_, vector* tmp_, vector* elCountM_)
+ {//
+ m1 = m1_;
+ m2 = m2_;
+ tasks = tasks_;
+ tmp = tmp_;
+ elCountM = elCountM_;
+ }
+ FunctorTBB(const FunctorTBB& f)
+ {
+ m1 = f.m1;
+ m2 = f.m2;
+ tasks = f.tasks;
+ tmp = f.tmp;
+ elCountM = f.elCountM;
+ }
+ void operator()(const tbb::blocked_range& range) const
+ {
+ int N = m1->N;
+ vector* cols = &(m1->rows);
+ for (size_t itask = range.begin(); itask < range.end(); itask++)
+ for (int j = (*tasks)[itask].pointerStart; j < (*tasks)[itask].pointerEnd; j++)
+ {
+ int numElInResCol = 0;//
+ const int numElementInCol = m2->pointer[j + 1] - m2->pointer[j];//
+ if (numElementInCol == 0)//
+ {
+ int size = (*tmp)[itask].pointer.size();
+ (*tmp)[itask].pointer.push_back((*tmp)[itask].pointer[size - 1]);
+ continue;
+ }
+ int elCountThis = 0;
+ for (int i = 0; i < N; i++)
+ {
+ const int numElementInRow = m1->pointer[i + 1] - m1->pointer[i];
+ if (numElementInRow == 0)
+ {
+ continue;
+ }
+ int tmpNumElRow = numElementInRow;// A
+ int tmpNumElCol = numElementInCol;// B
+
+ type sum = 0;
+ int tmpElCountM = (*elCountM)[itask];
+ for (int z = 0; z < min(tmpNumElCol, tmpNumElRow);)//
+ {
+ int colThis = (*cols)[elCountThis];//cols==rows( A)
+ int rowM = m2->rows[tmpElCountM];// rows task( rows B)
+ if (colThis == rowM)
+ {
+ sum += m1->values[elCountThis] * m2->values[tmpElCountM];
+ tmpNumElCol--;
+ tmpNumElRow--;
+ tmpElCountM++;
+ elCountThis++;
+ }
+ else if (colThis < rowM)
+ {
+ tmpNumElRow--;//
+ elCountThis++;//
+ }
+ else
+ {
+ tmpNumElCol--;
+ tmpElCountM++;
+ }
+ }
+ for (int z = 0; z < tmpNumElRow; z++)// rows,
+ elCountThis++;
+
+ if (sum != 0)// ( )
+ {
+ (*tmp)[itask].values.push_back(sum);
+ (*tmp)[itask].rows.push_back(i);
+ numElInResCol++;
+ }
+ }
+ const int size = (*tmp)[itask].pointer.size();
+ (*tmp)[itask].pointer.push_back((*tmp)[itask].pointer[size - 1] + numElInResCol);// + ,
+ (*elCountM)[itask] += numElementInCol;
+ }
+ }
+ ~FunctorTBB()
+ {
+
+ }
+ };
+ int numTask = numThreads;
+ if (numTask > N)
+ numTask = N;
+ vector tmpMatrix(numTask, MatrixCCS(N));
+ vector elCountM(numTask);
+ vector* cols = &rows;
+ vector task(numTask);// , numTask
+ //
+ {
+ int sizeTask = m.N / numTask + (bool)(m.N % numTask);// , + 0, + 1 ( )
+ for (int i = 0; i < numTask; i++)
+ task[i] = Task(i * sizeTask, min((i + 1) * sizeTask, m.N), i % numTask);//(, , )
+ int lastPointerM = 0;
+ for (int i = 0; i < numTask; i++)
+ {
+ elCountM[i] = lastPointerM;
+ int jstart = task[i].pointerStart;
+ const int jend = task[i].pointerEnd;
+ for (jstart; jstart < jend; jstart++)
+ {
+ lastPointerM += m.pointer[jstart + 1] - m.pointer[jstart];//
+ }
+ }
+ }
+
+ FunctorTBB fctor(this, &m, &task, &tmpMatrix, &elCountM);
+ tbb::parallel_for(tbb::blocked_range((size_t)0, task.size(), (size_t)4), fctor);
+
+ for (int i = 1; i < tmpMatrix.size(); i++)
+ {
+ tmpMatrix[0].uniteMatrix(tmpMatrix[i]);// ,
+ }
+ if (tmpMatrix[0].pointer.size() < N + 1)
+ tmpMatrix[0].pointer.push_back(tmpMatrix[0].values.size());
+ return tmpMatrix[0];
+ }
+
+ Matrix CCStoMatrix()
+ {
+ Matrix res(N, N);
+
+ int Elem = 0;
+ int count = 0;
+ int resCount = 0;
+
+ for (int i = 0; i < N; i++)
+ {
+ int numOfElem = pointer[i + 1] - pointer[i];
+
+ if (numOfElem != 0)
+ for (int j = 0; j < N; j++)
+ {
+ if (numOfElem != 0 && rows[resCount] == j)
+ {
+ res.vv[count] = values[Elem];
+ Elem++;
+ resCount++;
+ numOfElem--;
+ }
+ else
+ res.vv[count] = 0;
+ count++;
+ }
+ else
+ for (int j = 0; j < N; j++)
+ {
+ res.vv[count] = 0;
+ count++;
+ }
+ }
+
+ return res;
+ }
+};
+
+
+int main()
+{
+ int numThreads;
+ int mSize;
+ cout << "NumThreads = ";
+ cin >> numThreads;
+
+ tbb::task_scheduler_init init(numThreads);
+
+ cout << "1.Rand" << endl;
+ cout << "2.From file" << endl;
+ int choice;
+ cin >> choice;
+
+ if (choice == 1)
+ {
+ cout << "Size of Matrix = ";
+ cin >> mSize;
+ Matrix a(mSize, mSize), b(mSize, mSize), c(mSize, mSize);//
+ Matrix::randMatrixdata(a, b, mSize);//
+ MatrixCCS a1(a), b1(b), c1(c);// CCS
+
+
+
+ double time = omp_get_wtime();//
+ c1 = a1.parallelMult(b1, numThreads);
+ time = omp_get_wtime() - time;
+ cout << "Time: " << time << endl;//
+ c = c1.CCStoMatrix();
+
+ Matrix::writeMatrix(c, mSize);//
+
+ }
+ else if (choice == 2)
+ {
+ ifstream input("matrix.txt");//
+ input >> mSize;
+ input.close();
+
+ Matrix a(mSize, mSize), b(mSize, mSize), c(mSize, mSize);//
+ Matrix::readMatrix(a, b, mSize, "matrix.txt");
+ MatrixCCS a1(a), b1(b), c1(c);
+ a1.transposition();
+
+ double time = omp_get_wtime();//
+ c1 = a1.parallelMult(b1, numThreads);
+ time = omp_get_wtime() - time;
+ cout << "Time: " << time << endl;//
+ c = c1.CCStoMatrix();
+
+ Matrix::writeMatrix(c, mSize);//
+ }
+ else
+ cout << "Error" << endl;
+
+ return 0;
+}
\ No newline at end of file
diff --git a/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/matrix.txt b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/matrix.txt
new file mode 100644
index 0000000..60a3e30
--- /dev/null
+++ b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/matrix.txt
@@ -0,0 +1,10 @@
+4
+1 0 0 5
+0 0 0 2
+0 4 0 1
+2.5 0 0 0
+
+0 0 0 0
+7 0 1 4.2
+0 2 0 8
+3 0 0 0
\ No newline at end of file
diff --git a/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/resMatrix.txt b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/resMatrix.txt
new file mode 100644
index 0000000..a374184
--- /dev/null
+++ b/1706-4/Pushkarev_DS/CCS_TBB/CCS_TBB/resMatrix.txt
@@ -0,0 +1,4 @@
+15 0 0 0
+6 0 0 0
+31 0 4 16.8
+0 0 0 0
diff --git a/1706-4/Pushkarev_DS/task1/Mp.sln b/1706-4/Pushkarev_DS/task1/Mp.sln
new file mode 100644
index 0000000..36b0ab6
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task1/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/task1/Mp/Mp.vcxproj b/1706-4/Pushkarev_DS/task1/Mp/Mp.vcxproj
new file mode 100644
index 0000000..4f3c27c
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task1/Mp/Mp.vcxproj
@@ -0,0 +1,143 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ {4FA340D8-A5B8-4CF5-9854-CD1DCC9D3630}
+ Mp
+ 10.0.18362.0
+
+
+
+ Application
+ true
+ v142
+ MultiByte
+
+
+ Application
+ false
+ v142
+ true
+ MultiByte
+
+
+ Application
+ true
+ v142
+ MultiByte
+
+
+ Application
+ false
+ v141
+ true
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Level3
+ Disabled
+ true
+ true
+ C:\Program Files (x86)\Microsoft SDKs\MPI\Include;%(AdditionalIncludeDirectories)
+
+
+ Console
+ C:\Program Files (x86)\Microsoft SDKs\MPI\Lib;%(AdditionalLibraryDirectories)
+ msmpi.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+ Disabled
+ true
+ true
+ C:\Library\Microsoft SDKs\MPI\Include;%(AdditionalIncludeDirectories)
+
+
+ Console
+ C:\Library\Microsoft SDKs\MPI\Lib\x64;%(AdditionalLibraryDirectories)
+ msmpi.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ true
+ true
+ C:\Program Files (x86)\Microsoft SDKs\MPI\Include;%(AdditionalIncludeDirectories)
+
+
+ Console
+ true
+ true
+ C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x86;%(AdditionalLibraryDirectories)
+ msmpi.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ true
+ true
+ C:\Program Files (x86)\Microsoft SDKs\MPI\Include;%(AdditionalIncludeDirectories)
+
+
+ Console
+ true
+ true
+ C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64;%(AdditionalLibraryDirectories)
+ msmpi.lib;%(AdditionalDependencies)
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/1706-4/Pushkarev_DS/task1/Mp/Mp.vcxproj.filters b/1706-4/Pushkarev_DS/task1/Mp/Mp.vcxproj.filters
new file mode 100644
index 0000000..bc6688b
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task1/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/task1/Mp/Mp.vcxproj.user b/1706-4/Pushkarev_DS/task1/Mp/Mp.vcxproj.user
new file mode 100644
index 0000000..88a5509
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task1/Mp/Mp.vcxproj.user
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/1706-4/Pushkarev_DS/task1/Mp/main.cpp b/1706-4/Pushkarev_DS/task1/Mp/main.cpp
new file mode 100644
index 0000000..436a52f
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task1/Mp/main.cpp
@@ -0,0 +1,303 @@
+#include "mpi.h"
+#include
+#include
+#include
+
+using namespace::std;
+
+int procs; //
+int rankprocs; // ( )
+int razmer = 0;
+int proverka = 0;
+//
+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* localArray;
+ //localArray = 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 = 2;///////////////
+
+ 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);
+ t1 = MPI_Wtime();
+ str = FillStr(n);////
+ if (procs < 1)
+ {
+ cout << "size str < 0" << endl;
+ return 0;
+ }
+ else
+ cout << "Number proc : " << procs << endl;
+
+ razmer = (n + 1) / procs;//5
+ proverka = razmer;
+ if (((n+1) % procs) != 0)
+ {
+ proverka += (n + 1) % procs;
+ //razmer++;
+ }
+ //razmer++;
+ razmer += 1;//
+ //cout << proverka << "PROVERKA" << endl;
+ }
+ //t1 = MPI_Wtime();
+ //MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); //
+
+
+ //MPI_Bcast(&razmer, 1, MPI_INT, 0, MPI_COMM_WORLD); //
+
+
+ if (rankprocs == 0)
+ for (int i = 1; i < procs; i++)
+ {
+ if (i != (procs - 1)) {
+ MPI_Send(&razmer, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
+ }
+ else {
+ MPI_Send(&proverka, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
+ }
+ }
+ else
+ {
+ if (rankprocs != (procs - 1))
+ {
+ MPI_Recv(&razmer, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat);
+ }
+ else
+ {
+ MPI_Recv(&razmer, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat);
+ }
+ }
+
+ /*if (rankprocs == 0)
+ {
+ MPI_Send(&proverka, 1, MPI_INT, procs, 0, MPI_COMM_WORLD);
+ }*/
+ /*else if (rankprocs == procs)
+ MPI_Recv(&razmer, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat);*/
+ //int razmer = 0;
+ // razmer = n / procs;//5
+ // if ((n % procs) != 0)
+ // razmer++;
+ // razmer += 2;//7
+ //int s = razmer + 2;// // \0
+// \0
+ localArray = new char[razmer+1];
+ localArray[razmer] = '\0';
+ /*for (int i = 0; i < razmer + 1; i++)
+ cout << localArray[i];
+ cout << endl;*/
+ //localArray[razmer] = 'A';
+ /*if (!rankprocs)
+ {
+ for (int i = 0; i <= razmer; i++)
+ cout << localArray[i];
+ cout << endl;
+ }*/
+ ///////
+
+ //for (int i = 1; i < procs; i++)
+ //MPI_Scatterv(str, razmer - 1, MPI_CHAR, localArray, razmer - 1, MPI_CHAR, 0, MPI_COMM_WORLD);
+ //MPI_Barrier(MPI_COMM_WORLD);
+ //int kolichestvo = razmer * (rankprocs + 1);//
+ if (rankprocs == 0)
+ {
+ for (int i = 1; i < procs; i++)
+ {
+ /*MPI_Recv(&razmer, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD, &stat);
+ MPI_Recv(&kolichestvo, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD, &stat);*/
+ //MPI_Send(&str[razmer * i], razmer + 1, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
+ //MPI_Send(&str[(razmer * i) - 2], razmer - 1, MPI_CHAR, i, 0, MPI_COMM_WORLD);
+ if (i == (procs - 1))
+ {
+ MPI_Send(&str[((razmer - 1) * i)], proverka, MPI_CHAR, i, 0, MPI_COMM_WORLD);
+ }
+ else
+ MPI_Send(&str[((razmer - 1) * i)], razmer, MPI_CHAR, i, 0, MPI_COMM_WORLD);
+ //MPI_Scatter(&str[((razmer -2) *i)], razmer - 1, MPI_CHAR, localArray, razmer - 1, MPI_CHAR, 0, MPI_COMM_WORLD);
+ }
+ for (int i = 0; i < razmer; i++)
+ localArray[i] = str[i];
+ /*for (int i = 0; i < razmer; i++)
+ cout << localArray[i];*/
+ //localArray[razmer - 1] = '\0';
+ }
+
+ else
+ {
+ if (rankprocs == (procs - 1))
+ MPI_Recv(localArray, razmer, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &stat);
+
+ else
+ MPI_Recv(localArray, razmer, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &stat);
+
+ /*cout << rankprocs << "MASSIV" << endl;
+ for (int i = 0; i <= razmer; i++)
+ cout << localArray[i];
+ cout << endl;*/
+
+
+
+ /*localArray[0] = ' ';
+ localArray[1] = 'q';
+ localArray[2] = ' ';
+ localArray[3] = 'v';
+ localArray[4] = '\0';*/
+ //localArray[razmer - 1] = '\0';
+ }
+ ///////////
+
+ //MPI_Bcast(str, n, MPI_CHAR, 0, MPI_COMM_WORLD); //
+
+ double summ = 0;
+ cout << rankprocs << " proc start work" << endl;
+ for (int i = 0; i < razmer-1; i++)
+ {
+ if (localArray[i] == ' ')
+ summ++;
+ if (localArray[i] == ' ' && localArray[i + 1] == ' ')
+ summ--;
+ }
+ /*for (int i = 0; i < razmer; i++)
+ cout << localArray[i];
+ cout << endl;*/
+ //cout << rankprocs << " PROCESS : " << summ << endl;
+
+ /*cout << rankprocs << " PROCESS : " << summ << endl;
+ for (int i = 0; i < razmer; i++)
+ {
+ cout << localArray[i];
+ }
+ cout << endl;*/
+
+ //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 = 0; i < razmer; 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;
+ //delete[] str;
+ //delete[] localArray;
+ MPI_Finalize();// - MPI
+ return 0;
+}
+
+
+
+
diff --git a/1706-4/Pushkarev_DS/task2/NewComm/NewComm.sln b/1706-4/Pushkarev_DS/task2/NewComm/NewComm.sln
new file mode 100644
index 0000000..5c971e2
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task2/NewComm/NewComm.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}") = "NewComm", "NewComm\NewComm.vcxproj", "{6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}"
+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
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}.Debug|x64.ActiveCfg = Debug|x64
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}.Debug|x64.Build.0 = Debug|x64
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}.Debug|x86.ActiveCfg = Debug|Win32
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}.Debug|x86.Build.0 = Debug|Win32
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}.Release|x64.ActiveCfg = Release|x64
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}.Release|x64.Build.0 = Release|x64
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}.Release|x86.ActiveCfg = Release|Win32
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {4131190D-493E-4109-B39B-B750C4325DAD}
+ EndGlobalSection
+EndGlobal
diff --git a/1706-4/Pushkarev_DS/task2/NewComm/NewComm/NewComm.vcxproj b/1706-4/Pushkarev_DS/task2/NewComm/NewComm/NewComm.vcxproj
new file mode 100644
index 0000000..e8b3dbc
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task2/NewComm/NewComm/NewComm.vcxproj
@@ -0,0 +1,134 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ {6A8B4C4C-01BB-4192-BFD0-6188DC68FC97}
+ NewComm
+ 10.0
+
+
+
+ Application
+ true
+ v142
+ MultiByte
+
+
+ Application
+ false
+ v142
+ true
+ MultiByte
+
+
+ Application
+ true
+ v142
+ MultiByte
+
+
+ Application
+ false
+ v142
+ true
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Level3
+ Disabled
+ true
+ true
+
+
+ Console
+
+
+
+
+ Level3
+ Disabled
+ true
+ true
+ C:\Library\Microsoft SDKs\MPI\Include
+
+
+ Console
+ C:\Library\Microsoft SDKs\MPI\Lib\x64
+ msmpi.lib;%(AdditionalDependencies)
+
+
+
+
+ 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/task2/NewComm/NewComm/NewComm.vcxproj.filters b/1706-4/Pushkarev_DS/task2/NewComm/NewComm/NewComm.vcxproj.filters
new file mode 100644
index 0000000..bc6688b
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task2/NewComm/NewComm/NewComm.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/task2/NewComm/NewComm/NewComm.vcxproj.user b/1706-4/Pushkarev_DS/task2/NewComm/NewComm/NewComm.vcxproj.user
new file mode 100644
index 0000000..88a5509
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task2/NewComm/NewComm/NewComm.vcxproj.user
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/1706-4/Pushkarev_DS/task2/NewComm/NewComm/main.cpp b/1706-4/Pushkarev_DS/task2/NewComm/NewComm/main.cpp
new file mode 100644
index 0000000..4f100dc
--- /dev/null
+++ b/1706-4/Pushkarev_DS/task2/NewComm/NewComm/main.cpp
@@ -0,0 +1,650 @@
+#include
+#include
+#include
+//#include
+#include
+//#include
+//#include
+//#include
+//#include
+//#include
+#include
+
+void test_add(void* a, void* b, int n);
+void test_add_double(void* a, void* b, int n);
+void PROD_int(void* a, void* b, int n);
+void PROD_double(void* a, void* b, int n);
+void MAX_int(void* a, void* b, int n);
+void MAX_double(void* a, void* b, int n);
+void MIN_int(void* a, void* b, int n);
+void MIN_double(void* a, void* b, int n);
+void LAND_int(void* a, void* b, int n);
+void LAND_double(void* a, void* b, int n);
+void LOR_int(void* a, void* b, int n);
+void LOR_double(void* a, void* b, int n);
+void LXOR_int(void* a, void* b, int n);
+void LXOR_double(void* a, void* b, int n);
+void BOR_int(void* a, void* b, int n);
+void BXOR_int(void* a, void* b, int n);
+void BAND_int(void* a, void* b, int n);
+void MAXLOC_double(void* a, void* b, int n, MPI_Comm comm);
+void MINLOC_double(void* a, void* b, int n, MPI_Comm fcomm);
+
+struct A {
+
+ double value; int proc;
+
+}local_max[3], global_max[3];
+
+
+
+void Reduce(void* where_to_send_from, void* where_to_send_to, int how_much, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
+{
+ MPI_Status status;
+
+ int rank_came, num_of_proc;
+
+ MPI_Comm_rank(comm, &rank_came);//
+
+ MPI_Comm_size(comm, &num_of_proc);
+
+
+
+ int rank = rank_came, num = num_of_proc;////////////////////////////////
+
+ int ost = 0, type_size, step = 1;//,
+
+
+
+ while (num > 1)//
+ {
+
+ if (rank < num)// , < ( )
+ {
+
+ ost = num % 2;
+
+ if (rank % 2 != 0)//
+ {
+
+ MPI_Send(where_to_send_from, how_much, datatype, (rank - 1) * step, 5, comm);
+
+ rank *= num;
+
+ break;
+
+ }
+ else
+ {
+
+ if (rank != (num - 1))//
+ {
+
+ MPI_Recv(where_to_send_to, how_much, datatype, (rank + 1) * step, 5, comm, &status);
+ //op(where_to_send_to, where_to_send_from, how_much);
+ if (datatype == MPI_INT)
+ {
+ if (op == MPI_SUM)
+ {
+ test_add(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_PROD)
+ {
+ PROD_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_MAX)
+ {
+ MAX_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_MIN)
+ {
+ MIN_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_LAND)
+ {
+ LAND_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_LOR)
+ {
+ LOR_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_LXOR)
+ {
+ LXOR_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_BOR)
+ {
+ BOR_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_BXOR)
+ {
+ BXOR_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_BAND)
+ {
+ BAND_int(where_to_send_to, where_to_send_from, how_much);
+ }
+ }
+ else if (datatype == MPI_DOUBLE)
+ {
+ if (op == MPI_SUM)
+ {
+ test_add_double(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_PROD)
+ {
+ PROD_double(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_MAX)
+ {
+ MAX_double(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_MIN)
+ {
+ MIN_double(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_LAND)
+ {
+ LAND_double(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_LOR)
+ {
+ LOR_double(where_to_send_to, where_to_send_from, how_much);
+ }
+ else if (op == MPI_LXOR)
+ {
+ LXOR_double(where_to_send_to, where_to_send_from, how_much);
+ }
+ }
+ else if (datatype == MPI_DOUBLE_INT)
+ {
+ if (op == MPI_MAXLOC)
+ {
+ MAXLOC_double(where_to_send_to, where_to_send_from, how_much,comm);
+ }
+ else if (op == MPI_MINLOC)
+ {
+ MINLOC_double(where_to_send_to, where_to_send_from, how_much, comm);
+ }
+ }
+
+ //op(where_to_send_to, where_to_send_from, how_much);
+
+ }
+
+ rank /= 2;///////////////// 2
+
+ }
+
+ step *= 2;
+
+ }
+
+ num = num / 2 + ost;
+
+ }
+
+ if (rank_came == 0)
+ {
+
+ MPI_Type_size(datatype, &type_size);
+
+ for (int i = 0; i < how_much; i++)
+ std::cout << "POSMOTRI " << ((A*)(double*)where_to_send_from)[i].value << std::endl;
+ if (datatype != MPI_DOUBLE_INT)
+ memcpy(where_to_send_to, where_to_send_from, how_much* type_size);
+ else
+ memcpy(where_to_send_to, where_to_send_from, how_much* sizeof(struct A));
+
+ }
+
+}
+
+
+int SumOfMatrixElementsPartly(std::vector matrix) {
+
+ int sum = 0;
+
+ int size = matrix.size();
+
+ for (int i = 0; i < size; i++)
+
+ sum += matrix[i];
+
+ return sum;
+
+}
+
+
+
+int MultiplicationOfMatrixElementsPartly(std::vector matrix) {
+
+ int sum = 0;
+
+ int size = matrix.size();
+
+ for (int i = 0; i < size; i++)
+
+ sum *= matrix[i];
+
+ return sum;
+
+}
+
+void test_add(void* a, void* b, int n)
+{
+
+ //*b += *a;
+
+
+ for (int i = 0; i < n; i++)
+ ((int*)b)[i] += ((int*)a)[i];
+
+}
+
+void test_add_double(void* a, void* b, int n)
+{
+
+ //*b += *a;
+
+
+ for (int i = 0; i < n; i++)
+ ((double*)b)[i] += ((double*)a)[i];
+
+}
+
+void PROD_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ ((int*)b)[i] *= ((int*)a)[i];
+
+}
+
+void PROD_double(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ ((double*)b)[i] *= ((double*)a)[i];
+
+}
+
+void MAX_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ if (((int*)b)[i] < ((int*)a)[i])
+ ((int*)b)[i] = ((int*)a)[i];
+ }
+
+}
+
+void MAX_double(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ if(((double*)b)[i] < ((double*)a)[i])
+ ((double*)b)[i] = ((double*)a)[i];
+ }
+
+}
+
+void MIN_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ if (((int*)b)[i] > ((int*)a)[i])
+ ((int*)b)[i] = ((int*)a)[i];
+ }
+
+}
+
+void MIN_double(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ if (((double*)b)[i] > ((double*)a)[i])
+ ((double*)b)[i] = ((double*)a)[i];
+ }
+
+}
+
+void LAND_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((int*)b)[i] = ((int*)b)[i] && ((int*)a)[i];
+ }
+
+}
+
+void LAND_double(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((double*)b)[i]= ((double*)b)[i] && ((double*)a)[i];
+ }
+
+}
+
+void LOR_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((int*)b)[i] = ((int*)b)[i] || ((int*)a)[i];
+ }
+
+}
+
+void LOR_double(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((double*)b)[i] = ((double*)b)[i] || ((double*)a)[i];
+ }
+
+}
+
+void LXOR_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((int*)b)[i] = ((int*)b)[i] != ((int*)a)[i];
+ }
+
+}
+
+void LXOR_double(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((double*)b)[i] = ((double*)b)[i] != ((double*)a)[i];
+ }
+
+}
+
+void BOR_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((int*)b)[i] = ((int*)b)[i] | ((int*)a)[i];
+ }
+
+}
+
+void BXOR_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((int*)b)[i] = ((int*)b)[i] ^ ((int*)a)[i];
+ }
+
+}
+
+void BAND_int(void* a, void* b, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ ((int*)b)[i] = ((int*)b)[i] & ((int*)a)[i];
+ }
+
+}
+
+void MAXLOC_double(void* a, void* b, int n, MPI_Comm fcomm)
+{
+ int rank;
+MPI_Comm_rank(fcomm, &rank);
+
+ for (int i = 0; i < n; i++)
+ {
+ std::cout< ((A*)(int*)a)[i].proc)
+ ((A*)(int*)b)[i].proc = ((A*)(int*)a)[i].proc;
+ std::cout << "AFTER" << ((A*)(double*)b)[i].value << std::endl;
+ }
+ std::cout << std::endl << std::endl;
+}
+
+void MINLOC_double(void* a, void* b, int n, MPI_Comm fcomm)
+{
+ int rank;
+ MPI_Comm_rank(fcomm, &rank);
+ for (int i = 0; i < n; i++)
+ {
+ std::cout << rank << "PROCESSSSSSSS " << ((A*)(double*)b)[i].proc << std::endl;
+ std::cout << rank << "VALUE_B " << ((A*)(double*)b)[i].value << std::endl;
+ std::cout << rank << "VALUE_A " << ((A*)(double*)a)[i].value << std::endl;
+ if (((A*)(double*)b)[i].value > ((A*)(double*)a)[i].value)
+ {
+ ((A*)(double*)b)[i].value = ((A*)(double*)a)[i].value;
+ ((A*)(int*)b)[i].proc = ((A*)(int*)a)[i].proc;
+ }
+ else if(((A*)(double*)b)[i].value == ((A*)(double*)a)[i].value)
+ if(((A*)(int*)b)[i].proc > ((A*)(int*)a)[i].proc)
+ ((A*)(int*)b)[i].proc = ((A*)(int*)a)[i].proc;
+ std::cout << rank << "VALUE_B_AFTER " << ((A*)(double*)b)[i].value << std::endl;
+ std::cout <