Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

01) write a main method that will initialise MPI, figure out the world rank and world size. Rank 0 should be the coordinator while all

01) write a main method that will initialise MPI, figure out the world rank and world size. Rank 0 should be the coordinator while all other ranks should be participants. Then finalise MPI and return a status of 0 to the OS (5%) 02) Add the following helper methods to your code (15%) printMatrix() will print a 2D matrix to the console dotProduct() will that multiply a row of matrix A with a column from matrix B that will return a single value that is the dot product of the row and column multiplyStripe() takes in a stripe of A, a matrix of B and computes a stripe of C. 03) Write coordinator and participant methods that perform the following interactions (80%) read in matrices A and B from disk. (coordinator only) broadcast a message stating that the computation will be performed if the matrices are present and correct and that we have the correct number of command line arguments. Give a different message otherwise. Take part in multiple broadcasts that will tell all nodes the size of a matrix, the size of a stripe and the size of an individual row. Allocate the necessary memory for the stripes and matrices required. Take part in a scatter to distribute the stripes of A and take part in a broadcast to get the full copy of B. perform the multiplication and take part in a gather to send all stripes of C back to the coordinator. print out the matrix (coordinator only) and deallocate all memory.

#include using namespace std; #include #include #include #pragma warning(disable : 4996) //Blocks C4996 warning which is caused by FILE fopen function

// Can change matrix size to create any size square matrix #define MATRIXSIZE 8 int msq = MATRIXSIZE * MATRIXSIZE;

//TODO: change to relevant name #define MATRIXNAME "matB.dat"

void readMatrix() { cout << MATRIXNAME << " created:" << endl; int matrix[msq];

FILE *input = fopen(MATRIXNAME, "r"); if (!input) { cout << "No file found to read called " << MATRIXNAME << endl; return; } // read the file and store into matrix array fread(matrix, sizeof(int), msq, input); fclose(input); // iterate through the array to print for(int i = 0; i

// function that generates a matrix in binary form on disk void generateMatrixFile() { // generate a matrix of values that need to be written to disk in the form of a one dimensional array //this will write out an NxN matrix (default size 8x8) int matrix[msq]; srand(time(NULL)); // get random numbers for the matrix for (int i = 0; i

// the main function of the program int main(int argc, char** argv) { generateMatrixFile(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions