Question: I have this code: #include #include #include #include #define N 1 0 0 0 / / Size of the matrices void multiplyMatrices ( double *

I have this code: #include
#include
#include
#include
#define N 1000// Size of the matrices
void multiplyMatrices(double** A, double** B, double** C, int n){
for (int i =0; i < n; i++){
for (int j =0; j < n; j++){
C[i][j]=0;
for (int k =0; k < n; k++){
C[i][j]+= A[i][k]* B[k][j];
}
}
}
}
int main(){
// Allocate and initialize matrices A, B, C
double** A = new double*[N];
double** B = new double*[N];
double** C = new double*[N];
for (int i =0; i < N; i++){
A[i]= new double[N];
B[i]= new double[N];
C[i]= new double[N];
for (int j =0; j < N; j++){
A[i][j]= rand()%100;
B[i][j]= rand()%100;
}
}
// Record start time
auto start = std::chrono::high_resolution_clock::now();
// Matrix multiplication
multiplyMatrices(A, B, C, N);
// Record end time
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration duration = end - start;
std::cout << "Execution time: "<< duration.count()<<" seconds" << std::endl;
// Write result to file
std::ofstream resultFile("matrix_output.txt");
for (int i =0; i < N; i++){
for (int j =0; j < N; j++){
resultFile << C[i][j]<<"";
}
resultFile <<"
";
}
resultFile.close();
// Free memory
for (int i =0; i < N; i++){
delete[] A[i];
delete[] B[i];
delete[] C[i];
}
delete[] A;
delete[] B;
delete[] C;
return 0;
} I need to do these tasks - Instructions
Modify your matrix multiplication program to use MPI to distribute work on nodes.
Evaluate the performance of your program vs sequential and multi-threaded solution.
Modify your code to use OpenMP on the nodes.
Evaluate the performance of your program vs the other two.
Modify your code to use OpenCL.
Evaluate the performance of your programs.
Document your results and present your findings
Submit your task as detailed on the submission details section above to OnTrack.
Please make sure to provide the following:
Source code of the MPI matrix multiplication program,
Source code of the MPI and OpenMP (hybrid MPI to nodes and OpenMP in the nodes) program,
Source code of the MPI and OpenCL (hybrid MPI to nodes and OpenCL in the nodes) program, and
Evaluation of your program on different input sizes and number of threads in each of these three
programs.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!