-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmmserial.cpp
More file actions
46 lines (43 loc) · 1.03 KB
/
mmserial.cpp
File metadata and controls
46 lines (43 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <mpi.h>
using namespace std;
int main(){
MPI_Init(NULL, NULL);
double start, end;
float A[128][128];
float B[128][128];
float C[128][128];
srand(-1337);
//Popuate the matrixes with random numbers between 0 and 1.
for(int i = 0; i < 128; i++){
for(int j = 0; j <128; j++){
A[i][j] = (float) (rand() / ((float) RAND_MAX / 2)) - 1;
B[i][j] = (float) (rand() / ((float) RAND_MAX / 2)) - 1;
C[i][j] = 0;
}
}
start = MPI_Wtime();
//Matrix multiply
for(int i = 0; i < 128; i++){
for(int j = 0; j < 128; j++){
for(int k = 0; k < 128; k++){
C[i][j] += A[i][k] * B[k][j];
}
}
}
end = MPI_Wtime();
cout << "Elapsed time: " << end - start << endl;
ofstream output;
output.open("serial.output");
// Print the output to a file for testing
for(int i = 0; i < 128; i++) {
for(int j = 0; j < 128; j++) {
output << C[i][j] << " ";
}
output << endl;
}
MPI_Finalize();
return 0;
}