1   2   3   4   5   6   7   8   9
Ім'я файлу: Розраха.docx
Розширення: docx
Розмір: 845кб.
Дата: 12.08.2021
скачати
Пов'язані файли:
5.docx
Лаба 4_РТП_СЗІ_Кліщ Богдан.docx
Лаба 5_РТП_СЗІ_Кліщ.docx
Тести, статистика праці.docx
Реферат Лесько П.В. Авторське право ЕЛЕП-11.docx.doc
Індивідуальна нормативне.docx
lab2.docx
ЦЕРКВА РІЗДВА ПРЕСВЯТОЇ БОГОРОДИЦІ У САМБОРІ.docx
ШАБЕЛЬКО КУРСОВА.docx
Сучасні методики здорового харчування.docx
Звіт до БД 2.docx
звіт_від_ред.docx
lab_8_Kravets.docx
Сєрий.docx
Сенсорне виховання.doc
СПЗ_ЛАБ_1.docx
lab5_бд.docx
Фізика5 Моя лаба.doc
Вебинар англ.docx
5.docx
ЛР 3 ФДП.docx
Методичка до ПЗ №5-6.doc
зразок РГР 2021 (1).docx
курсова 1.docx
Міністерство_освіти_та_науки_України_PI.docx
Контрольна робота Павло Коцаба.docx
Метод Баркера.docx
Grej_R._S.docx
знайомий реферат.docx
ОКРО.docx
Zvit№1ПСМ.doc

P6.cpp:


#include "Header.h"

#include
using namespace std;
ofstream f6;

ifstream f66;

void CPU_6()

{

MPI_Status stat1;

//zminni

int flag = 1;

int N1 = 290;

int N2 = 168;

int N3 = 349;
int** A6;

int** Bi;

int** B7;

int** A6B0;

int** A6B1;

int** A6B2;

int** A6B3;

int** A6B4;

int** A6B5;

int** A6B6;

int** A6B7;

matrix(A6B0, 36, 43);

matrix(A6B1, 36, 43);

matrix(A6B2, 36, 43);

matrix(A6B3, 36, 43);

matrix(A6B4, 36, 43);

matrix(A6B5, 36, 43);

matrix(A6B6, 36, 43);

matrix(A6B7, 36, 48);

matrix(A6, 36, N2);

matrix(Bi, N2, 43);

matrix(B7, N2, 48);

auto start_MPI = chrono::steady_clock::now();
MPI_Recv(&flag, 1, MPI_INT, 4, 0, MPI_COMM_WORLD, &stat1);

cout << "Z(A6,B6)" << endl;

read_matrix_from_file(A6, "A6", 36, N2);

read_matrix_from_file(Bi, "B6", N2, 43);

MPI_Send(&flag, 1, MPI_FLOAT, 1, 0, MPI_COMM_WORLD);

MPI_Recv(&flag, 1, MPI_INT, 3, 0, MPI_COMM_WORLD, &stat1);
A6B6 = dobytok_2_matruc(36, 43, N2, A6, Bi);//M(A6;B6)
cout << "P6: Sending B6 to P1" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 1, 0, MPI_COMM_WORLD);//P(B6)->1

cout << "P6: Receiving B4 from P4" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 4, 0, MPI_COMM_WORLD, &stat1);//O(B4)<-4
A6B4 = dobytok_2_matruc(36, 43, N2, A6, Bi);//M(A6;B4)
cout << "P6: Sending B4 to P1" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 1, 0, MPI_COMM_WORLD);//P(B4)->1

cout << "P6: Receiving B2 from P4" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 4, 0, MPI_COMM_WORLD, &stat1);//O(B2)<-4
A6B2 = dobytok_2_matruc(36, 43, N2, A6, Bi);//M(A6;B2)
cout << "P6: Sending B2 to P1" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 1, 0, MPI_COMM_WORLD);//P(B2)->1

cout << "P6: Receiving B7 from P4" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(B7[i][0]), 48, MPI_INT, 4, 0, MPI_COMM_WORLD, &stat1);//O(B7)<-4
A6B7 = dobytok_2_matruc(36, 48, N2, A6, B7);//M(A6;B7)
cout << "P6: Sending B7 to P1" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(B7[i][0]), 48, MPI_INT, 1, 0, MPI_COMM_WORLD);//P(B7)->1

cout << "P6: Receiving B0 from P4" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 4, 0, MPI_COMM_WORLD, &stat1);//O(B0)<-4
A6B0 = dobytok_2_matruc(36, 43, N2, A6, Bi);//M(A6;B0)
cout << "P6: Sending B0 to P1" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 1, 0, MPI_COMM_WORLD);//P(B0)->1

cout << "P6: Receiving B3 from P4" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 4, 0, MPI_COMM_WORLD, &stat1);//O(B3)<-4
A6B3 = dobytok_2_matruc(36, 43, N2, A6, Bi);//M(A6;B3)
cout << "P6: Sending B3 to P1" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 1, 0, MPI_COMM_WORLD);//P(B3)->1

cout << "P6: Receiving B5 from P4" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 4, 0, MPI_COMM_WORLD, &stat1);//O(B5)<-4
A6B5 = dobytok_2_matruc(36, 43, N2, A6, Bi);//M(A6;B5)
cout << "P6: Sending B5 to P1" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 1, 0, MPI_COMM_WORLD);//P(B5)->1

cout << "P6: Receiving B1 from P4" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 4, 0, MPI_COMM_WORLD, &stat1);//O(B1)<-4
A6B1 = dobytok_2_matruc(36, 43, N2, A6, Bi);//M(A6;B1)
MPI_Recv(&flag, 1, MPI_INT, 5, 0, MPI_COMM_WORLD, &stat1);

write_matrix_to_fileC(f6, "C6", A6B0, A6B1, A6B2, A6B3, A6B4, A6B5, A6B6, A6B7, 36, 43, 48);

cout << "W(C6)" << endl;

MPI_Send(&flag, 1, MPI_FLOAT, 7, 0, MPI_COMM_WORLD);
auto end_MPI = chrono::steady_clock::now();
float elapsed_time_MPI = float(chrono::duration_cast (end_MPI - start_MPI).count());

cout << "Elapsed time for P6 (milliseconds): " << elapsed_time_MPI << endl;
MPI_Send(&elapsed_time_MPI, 1, MPI_FLOAT, 0, 0, MPI_COMM_WORLD);

}

P7.cpp:


#include "Header.h"

#include
using namespace std;
ofstream f7;

ifstream f77;

void CPU_7()

{

MPI_Status stat1;

//zminni

int flag = 1;

int N1 = 290;

int N2 = 168;

int N3 = 349;
int** A7;

int** Bi;

int** B7;

int** A7B0;

int** A7B1;

int** A7B2;

int** A7B3;

int** A7B4;

int** A7B5;

int** A7B6;

int** A7B7;

matrix(A7B0, 38, 43);

matrix(A7B1, 38, 43);

matrix(A7B2, 38, 43);

matrix(A7B3, 38, 43);

matrix(A7B4, 38, 43);

matrix(A7B5, 38, 43);

matrix(A7B6, 38, 43);

matrix(A7B7, 38, 48);
matrix(A7, 38, N2);

matrix(Bi, N2, 43);

matrix(B7, N2, 48);

auto start_MPI = chrono::steady_clock::now();
MPI_Recv(&flag, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat1);

cout << "Z(A7,B7)" << endl;

read_matrix_from_file(A7, "A7", 38, N2);

read_matrix_from_file(B7, "B7", N2, 48);

MPI_Send(&flag, 1, MPI_FLOAT, 2, 0, MPI_COMM_WORLD);

MPI_Recv(&flag, 1, MPI_INT, 3, 0, MPI_COMM_WORLD, &stat1);
A7B7 = dobytok_2_matruc(38, 48, N2, A7, B7);//M(A7;B7)
cout << "P7: Sending B7 to P2" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(B7[i][0]), 48, MPI_INT, 2, 0, MPI_COMM_WORLD);//P(B7)->2

cout << "P7: Receiving B0 from P0" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat1);//O(B0)<-0
A7B0 = dobytok_2_matruc(38, 43, N2, A7, Bi);//M(A7;B0)
cout << "P7: Sending B7 to P2" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 2, 0, MPI_COMM_WORLD);//P(B0)->2

cout << "P7: Receiving B3 from P0" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat1);//O(B3)<-0
A7B3 = dobytok_2_matruc(38, 43, N2, A7, Bi);//M(A7;B3)
cout << "P7: Sending B3 to P2" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 2, 0, MPI_COMM_WORLD);//P(B3)->2

cout << "P7: Receiving B5 from P0" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat1);//O(B5)<-0
A7B5 = dobytok_2_matruc(38, 43, N2, A7, Bi);//M(A7;B5)
cout << "P7: Sending B5 to P2" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 2, 0, MPI_COMM_WORLD);//P(B5)->2

cout << "P7: Receiving B1 from P0" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat1);//O(B1)<-0
A7B1 = dobytok_2_matruc(38, 43, N2, A7, Bi);//M(A7;B1)
cout << "P7: Sending B1 to P2" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 2, 0, MPI_COMM_WORLD);//P(B1)->2

cout << "P7: Receiving B6 from P0" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat1);//O(B6)<-0
A7B6 = dobytok_2_matruc(38, 43, N2, A7, Bi);//M(A7;B6)
cout << "P7: Sending B6 to P2" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 2, 0, MPI_COMM_WORLD);//P(B6)->2

cout << "P7: Receiving B4 from P0" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat1);//O(B4)<-0
A7B4 = dobytok_2_matruc(38, 43, N2, A7, Bi);//M(A7;B4)
cout << "P7: Sending B4 to P2" << endl;

for (int i = 0; i < N2; i++)

MPI_Send(&(Bi[i][0]), 43, MPI_INT, 2, 0, MPI_COMM_WORLD);//P(B4)->2

cout << "P7: Receiving B2 from P0" << endl;

for (int i = 0; i < N2; i++)

MPI_Recv(&(Bi[i][0]), 43, MPI_INT, 0, 0, MPI_COMM_WORLD, &stat1);//O(B2)<-0
A7B2 = dobytok_2_matruc(38, 43, N2, A7, Bi);//M(A7;B2)
MPI_Recv(&flag, 1, MPI_INT, 6, 0, MPI_COMM_WORLD, &stat1);

cout << "W(C7)" << endl;

write_matrix_to_fileC(f7, "C7", A7B0, A7B1, A7B2, A7B3, A7B4, A7B5, A7B6, A7B7, 38, 43, 48);

auto end_MPI = chrono::steady_clock::now();
float elapsed_time_MPI = float(chrono::duration_cast (end_MPI - start_MPI).count());

cout << "Elapsed time for P7 (milliseconds): " << elapsed_time_MPI << endl;
MPI_Send(&elapsed_time_MPI, 1, MPI_FLOAT, 0, 0, MPI_COMM_WORLD);

}

types.cpp:


#include "Header.h"
void matrix(int**& M, int size1, int size2)

{

M = new int* [size1];

for (int i = 0; i < size1; i++)

M[i] = new int[size2];

}

Додаток В (код до послідовного розв’язання)

Header.h:


#pragma once

#include

#include

#include

#include "math.h"

#include

#include

#include

using namespace std;
//Operations

int** dobytok_2_matruc(int size1, int size2, int& size3, int** matrix1, int** matrix2);
//initialization

void matrix(int**& M, int size1, int size2);

//void number(float**& Numb);
//file

void write_matrix_to_file(ofstream& fx, int** MRC, string whatis, int s1, int s2);

void read_matrix_from_file(ifstream& fi, int** MRC, string whatis);
//input

void manual_input();

void auto_input();
void CPU_0();

file.cpp:


#include "Header.h"
void write_matrix_to_file(ofstream& fx, int** MRC, string whatis, int s1, int s2)

{

fx.setf(ios::fixed);

const char* path;

if (whatis == "A") { path = "D:\\Education\\University\\6 semester\\Паралельні та розподілені обчислення\\Rozraha\\A.txt"; }

else if (whatis == "B") { path = "D:\\Education\\University\\6 semester\\Паралельні та розподілені обчислення\\Rozraha\\B.txt"; }

else { path = "D:\\Education\\University\\6 semester\\Паралельні та розподілені обчислення\\Rozraha\\C.txt"; }

fx.open(path);

for (int i = 0; i < s1; i++)

{

for (int j = 0; j < s2; j++) {

fx << MRC[i][j] << "\t";

}

fx << "\r\n";

}

fx.close();

}
int s1, s2;

void read_matrix_from_file(ifstream& fi, int** MRC, string whatis)

{

fi.setf(ios::fixed);

const char* path;

if (whatis == "A") {

path = "D:\\Education\\University\\6 semester\\Паралельні та розподілені обчислення\\Rozraha\\A.txt";

s1 = 290; s2 = 168;

fi.open(path);

for (int i = 0; i < s1; i++)

{

for (int j = 0; j < s2; j++) {

fi >> MRC[i][j];

}

}

fi.close();

}

if (whatis == "B") {

path = "D:\\Education\\University\\6 semester\\Паралельні та розподілені обчислення\\Rozraha\\B.txt";

s1 = 168; s2 = 349;

fi.open(path);

for (int i = 0; i < s1; i++)

{

for (int j = 0; j < s2; j++) {

fi >> MRC[i][j];

}

}

fi.close();

}

}

input.cpp:


#include "Header.h"

#include
ofstream fio;
int N1 = 290;

int N2 = 168;

int N3 = 349;

int** A;

int** B;
void manual_input()

{
cout << "Matrix A consist of: ";

int k;

cin >> k;
matrix(A, N1, N2);

matrix(B, N2, N3);
for (int i = 0; i < N1; i++)

{

for (int j = 0; j < N2; j++)

{

A[i][j] = k;

}
}

write_matrix_to_file(fio, A, "A", N1, N2);
cout << "Matrix B consist of: ";

int x;

cin >> x;

for (int i = 0; i < N2; i++)

{

for (int j = 0; j < N3; j++)

{

B[i][j] = x;

}

}

write_matrix_to_file(fio, B, "B", N2, N3);

}
int Pos_Neg(int max, int min)

{

int number = min + rand() % (max - min + 1);

if (number < -10 && number > 10) { return number; }

else { Pos_Neg(max, min); }

}
//Початковий ввід (генерація) даних

void auto_input()

{

matrix(A, N1, N2);

matrix(B, N2, N3);
cout << "Enter left side of diapazon: ";

int min;

cin >> min;

cout << "Enter right side of diapazon: ";

int max;

cin >> max;

max = (max - min) + 1;
for (int i = 0; i < N1; i++)

{

for (int j = 0; j < N2; j++)

{

A[i][j] = min + rand() % max;

}
}

write_matrix_to_file(fio, A, "A", N1, N2);
for (int i = 0; i < N2; i++)

{

for (int j = 0; j < N3; j++)

{

B[i][j] = min + rand() % max;

}

}

write_matrix_to_file(fio, B, "B", N2, N3);

}

main.cpp:


#include "Header.h"

#include
int main(int argc, char* argv[])

{

//видалення файлів попередньої сесії, якщо такі існують

remove("D:\\Education\\University\\6 semester\\Паралельні та розподілені обчислення\\Rozraha\\A.txt");

remove("D:\\Education\\University\\6 semester\\Паралельні та розподілені обчислення\\Rozraha\\B.txt");

remove("D:\\Education\\University\\6 semester\\Паралельні та розподілені обчислення\\Rozraha\\C.txt");
CPU_0();

}

Operations.cpp:


#include "Header.h"
int** dobytok_2_matruc(int size1, int size2, int& size3, int** matrix1, int** matrix2)

{

float tmp = 0;

int** result;

matrix(result, size1, size2);
for (int i = 0; i < size1; i++) {

for (int j = 0; j < size2; j++)

{

result[i][j] = 0;

for (int k = 0; k < size3; k++)

result[i][j] += matrix1[i][k] * matrix2[k][j];

}

}

return result;//повертає матрицю

}

P0.cpp:


#include "Header.h"

#include
using namespace std;
ofstream f0;

ifstream f00;

void CPU_0()

{

MPI_Status stat1;

//zminni

int N1 = 290;

int N2 = 168;

int N3 = 349;

int** A;

int** B;

int** C;
matrix(A, N1, N2);

matrix(B, N2, N3);

matrix(C, N1, N3);
//Ввід N та генерація змінних

int flag = 1;

cout << endl;

cout << " Matrix A[290][168]" << " Matrix B[168][349]" << endl << endl;

cout << " Generate auto data - 1" << endl << " Manual input - 2" << endl;

cin >> flag;

if (flag == 1)

auto_input();

else

manual_input();

cout << endl;
auto start_MPI = chrono::steady_clock::now();
read_matrix_from_file(f00, A, "A");

read_matrix_from_file(f00, B, "B");
C = dobytok_2_matruc(N1, N3, N2, A, B);

write_matrix_to_file(f0, C, "C", N1, N3);

auto end_MPI = chrono::steady_clock::now();
float elapsed_time_MPI = float(chrono::duration_cast (end_MPI - start_MPI).count());

cout << "Elapsed time for CS (milliseconds): " << elapsed_time_MPI << endl;

}

types.cpp:


#include "Header.h"
void matrix(int**& M, int size1, int size2)

{

M = new int* [size1];

for (int i = 0; i < size1; i++)

M[i] = new int[size2];

}

1   2   3   4   5   6   7   8   9

скачати

© Усі права захищені
написати до нас