Skip to content
Snippets Groups Projects
Commit 8f0f92e2 authored by Husam Eddin Einieh's avatar Husam Eddin Einieh
Browse files

Upload New File

parent 9ecabb30
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
#define R1 4 // number of rows in Matrix-1
#define C1 4 // number of columns in Matrix-1
#define R2 4 // number of rows in Matrix-2
#define C2 4 // number of columns in Matrix-2
#include <mpi.h>
using namespace std;
void mulMat(int mat1[][C1], int mat2[][C2]) {
int rslt[R1][C2];
printf("Multiplication of given two matrices is:\n\n");
for (int i = 0; i < R1; i++) {
for (int j = 0; j < C2; j++) {
rslt[i][j] = 0;
for (int k = 0; k < R2; k++) {
rslt[i][j] += mat1[i][k] * mat2[k][j];
}
printf("%d\t", rslt[i][j]);
}
printf("\n");
}
}
int main(void) {
int rank;
int size ;
char name[80];
int length;
MPI_Init(&argc, &argv)
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Get_processor_name(name, &Length);
// Square Matrices
// R1 = 4, C1 = 4 and R2 = 4, C2 = 4 (Update these values in MACROs)
int mat1[R1][C1] = {
{1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}
};
int mat2[R2][C2] = {
{1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}
};
/*
// Rectangular Matrices
// R1 = 3, C1 = 4 and R2 = 4, C2 = 3 (Update these values in MACROs)
int mat1[R1][C1] = {
{1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3}
};
int mat2[R2][C2] = {
{1, 1, 1},
{2, 2, 2},
{3, 3, 3},
{4, 4, 4}
};
*/
if (C1 != R2) {
printf("The number of columns in Matrix-1 must be equal to the number of rows in "
"Matrix-2\n");
printf("Please update MACROs value according to your array dimension in "
"#define section\n");
exit(EXIT_FAILURE);
}
mulMat(mat1, mat2);
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment