Completed
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
1 4 1 5
|
||||
2 6 7 2
|
||||
|
||||
9 8 7
|
||||
6 5 4
|
||||
3 2 1
|
||||
9 8 7 3
|
||||
6 5 4 5
|
||||
3 2 1 7
|
||||
7 6 9 10
|
||||
Binary file not shown.
@@ -17,9 +17,9 @@ std::vector<std::vector<double> > AB_serial = std::vector<std::vector<double> >(
|
||||
|
||||
|
||||
void print_matrix(std::vector<std::vector<double> > mat);
|
||||
void serial_version();
|
||||
void serial_matrix_multiplication();
|
||||
void compute_interval(int start, int interval);
|
||||
void multiplyMatrix(int rank, int size);
|
||||
void parallel_matrix_multiplication(int rank, int size);
|
||||
void read_in_matrices();
|
||||
void print_help();
|
||||
void determinant();
|
||||
@@ -54,7 +54,7 @@ int main(int argc, char** argv) {
|
||||
MPI_Barrier(MCW);
|
||||
MPI_Bcast(&user_input, 1, MPI_INT, 0, MCW );
|
||||
if (user_input == '1')
|
||||
multiplyMatrix(rank, size);
|
||||
parallel_matrix_multiplication(rank, size);
|
||||
else if (user_input == '2'){
|
||||
if(!rank)
|
||||
reduced_row();
|
||||
@@ -186,7 +186,7 @@ void print_matrix(std::vector<std::vector<double> >mat) {
|
||||
myfile << endl;
|
||||
cout << endl;
|
||||
}
|
||||
void serial_version(){
|
||||
void serial_matrix_multiplication(){
|
||||
for (int i = 0; i <N; i++){
|
||||
for (int j = 0; j < N;j++){
|
||||
AB_serial[i][j] = 0;
|
||||
@@ -206,7 +206,7 @@ void compute_interval(int start,int interval){
|
||||
}
|
||||
}
|
||||
}
|
||||
void multiplyMatrix(int rank, int size){
|
||||
void parallel_matrix_multiplication(int rank, int size){
|
||||
double time1,time2,time3;
|
||||
if(!rank){
|
||||
read_in_matrices();
|
||||
@@ -229,7 +229,6 @@ void multiplyMatrix(int rank, int size){
|
||||
int remainder = N % size;
|
||||
MPI_Bcast(&interval, 1, MPI_INT, 0, MCW);
|
||||
MPI_Bcast(&remainder, 1, MPI_INT, 0, MCW);
|
||||
// Record start time
|
||||
MPI_Barrier(MCW);
|
||||
time1 = MPI_Wtime();
|
||||
if (!rank) {
|
||||
@@ -259,23 +258,23 @@ void multiplyMatrix(int rank, int size){
|
||||
time2 = MPI_Wtime();
|
||||
|
||||
if (!rank){
|
||||
serial_version();
|
||||
serial_matrix_multiplication();
|
||||
time3 = MPI_Wtime();
|
||||
cout << size << " processors computed in time: " << time2-time1 << endl;
|
||||
cout << "Serial version computed in time: " << time3-time2 << endl;
|
||||
cout << size << " processors completed in: " << time2-time1 << " seconds"<<endl;
|
||||
cout << "Serial version completed in: " << time3-time2 << " seconds"<<endl;
|
||||
cout << "Matrix A: " << endl;
|
||||
myfile << size << " processors computed in time: " << time2-time1 << endl;
|
||||
myfile << "Serial version computed in time: " << time3-time2 << endl;
|
||||
myfile << size << " processors completed in: " << time2-time1 << " seconds"<<endl;
|
||||
myfile << "Serial version completed in: " << time3-time2 << " seconds"<<endl;
|
||||
myfile << "Matrix A: " << endl;
|
||||
print_matrix(A);
|
||||
cout << "multiplied Matrix B:" << endl;
|
||||
myfile << "multiplied Matrix B:" << endl;
|
||||
cout << "Matrix B:" << endl;
|
||||
myfile << "Matrix B:" << endl;
|
||||
print_matrix(B);
|
||||
cout << "serial version gives:" << endl;
|
||||
myfile << "serial version gives:" << endl;
|
||||
cout << "serial version AB:" << endl;
|
||||
myfile << "serial version AB:" << endl;
|
||||
print_matrix(AB_serial);
|
||||
cout << "gives matrix AB:" << endl;
|
||||
myfile << "gives matrix AB:" << endl;
|
||||
cout << "parallel matrix AB:" << endl;
|
||||
myfile << "parallel matrix AB:" << endl;
|
||||
print_matrix(AB);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,81 @@
|
||||
4 processors completed in: 0.000195 seconds
|
||||
Serial version completed in: 2e-06 seconds
|
||||
Matrix A:
|
||||
0 3 2 1
|
||||
3 2 2 2
|
||||
1 4 1 5
|
||||
2 6 7 2
|
||||
|
||||
Matrix B:
|
||||
9 8 7 6
|
||||
5 4 3 2
|
||||
1 0 0 0
|
||||
0 0 0 0
|
||||
|
||||
serial version AB:
|
||||
17 12 9 6
|
||||
39 32 27 22
|
||||
30 24 19 14
|
||||
55 40 32 24
|
||||
|
||||
parallel matrix AB:
|
||||
17 12 9 6
|
||||
39 32 27 22
|
||||
30 24 19 14
|
||||
55 40 32 24
|
||||
|
||||
4 processors completed in: 8.5e-05 seconds
|
||||
Serial version completed in: 2e-06 seconds
|
||||
Matrix A:
|
||||
0 3 2 1
|
||||
3 2 2 2
|
||||
1 4 1 5
|
||||
2 6 7 2
|
||||
|
||||
Matrix B:
|
||||
9 8 7 3
|
||||
6 5 4 5
|
||||
3 2 1 7
|
||||
7 6 9 10
|
||||
|
||||
serial version AB:
|
||||
31 25 23 39
|
||||
59 50 49 53
|
||||
71 60 69 80
|
||||
89 72 63 105
|
||||
|
||||
parallel matrix AB:
|
||||
31 25 23 39
|
||||
59 50 49 53
|
||||
71 60 69 80
|
||||
89 72 63 105
|
||||
|
||||
4 processors completed in: 7.2e-05 seconds
|
||||
Serial version completed in: 2e-06 seconds
|
||||
Matrix A:
|
||||
0 3 2 1
|
||||
3 2 2 2
|
||||
1 4 1 5
|
||||
2 6 7 2
|
||||
|
||||
Matrix B:
|
||||
9 8 7 3
|
||||
6 5 4 5
|
||||
3 2 1 7
|
||||
7 6 9 10
|
||||
|
||||
serial version AB:
|
||||
31 25 23 39
|
||||
59 50 49 53
|
||||
71 60 69 80
|
||||
89 72 63 105
|
||||
|
||||
parallel matrix AB:
|
||||
31 25 23 39
|
||||
59 50 49 53
|
||||
71 60 69 80
|
||||
89 72 63 105
|
||||
|
||||
Reduced Row:
|
||||
3 2 2 2
|
||||
0 4.66667 5.66667 0.666667
|
||||
|
||||
Reference in New Issue
Block a user