Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Parallel_Programmierung_SS22_Gruppe_D_EA2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Husam Eddin Einieh
Parallel_Programmierung_SS22_Gruppe_D_EA2
Commits
8f0f92e2
Commit
8f0f92e2
authored
2 years ago
by
Husam Eddin Einieh
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
9ecabb30
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
multiplikationmpi.c.txt
+72
-0
72 additions, 0 deletions
multiplikationmpi.c.txt
with
72 additions
and
0 deletions
multiplikationmpi.c.txt
0 → 100644
+
72
−
0
View file @
8f0f92e2
#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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment