Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c082338

Browse files
author
Thomas Weise
committed
Added Some Comments
1 parent dc2e28c commit c082338

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

‎mpi/bareBones.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#include <mpi.h>
1+
#include <mpi.h>// import MPI header
22

33
int main(int argc, char **argv) {
4-
MPI_Init(&argc, &argv);
5-
MPI_Finalize();
4+
MPI_Init(&argc, &argv);// initialize MPI
5+
MPI_Finalize();// shut down MPI
66
return 0;
7-
}
7+
}

‎mpi/basicInfo.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
#include <mpi.h>
2-
#include <stdio.h>
1+
#include <mpi.h>// import MPI header
2+
#include <stdio.h>// import for printf
33

44
int main(int argc, char **argv) {
55
int size, rank;
66

7-
MPI_Init(&argc, &argv);
7+
MPI_Init(&argc, &argv);// initialize MPI
88

9-
MPI_Comm_size(MPI_COMM_WORLD, &size);
10-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
9+
MPI_Comm_size(MPI_COMM_WORLD, &size);// get number of program instances
10+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);// get own ID/address
1111

12-
if(rank == 0) {
12+
// often, an MPI application has a master and some slaves
13+
// master distributes tasks and combine partial results to final results
14+
// slaves receive partial task, compute partial result, and send to master
15+
if(rank == 0) { // the instance with rank=0 is often chosen as master
1316
printf("Hi from Master\n");
14-
} else {
17+
} else {// the others are often slaves
1518
printf("Just Slave %d out of %d\n", rank, size);
1619
}
1720

18-
MPI_Finalize();
21+
MPI_Finalize();// finalize = shut down MPI
1922
return 0;
2023
}

‎mpi/simplePointToPoint1.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
#include <mpi.h>
2-
#include <stdio.h>
1+
#include <mpi.h>// import MPI header
2+
#include <stdio.h>// needed for printf
33

44
int main(int argc, char **argv) {
55
int size, rank, s_msg, r_msg, next, prev;
66
MPI_Status status;
77

8-
MPI_Init(&argc, &argv);
9-
MPI_Comm_size(MPI_COMM_WORLD, &size);
10-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
8+
MPI_Init(&argc, &argv);// initialize MPI
9+
MPI_Comm_size(MPI_COMM_WORLD, &size);// get number of program instances
10+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);// get own ID/address
1111

12-
next = ((rank + 1) % size);
13-
prev = ((rank + size - 1) % size);
14-
s_msg = ((size * rank) + next);
12+
next = ((rank + 1) % size);// next higher id, wrap from size-1 to 0
13+
prev = ((rank + size - 1) % size);// next lower id, wrap from 0 to size-1
14+
s_msg = ((size * rank) + next);// the example message, just some number
1515

16-
if((rank % 2) == 0) {
16+
if((rank % 2) == 0) {// even rank: message to next, receive from prev
1717
MPI_Send(&s_msg, 1, MPI_INT, next, 42, MPI_COMM_WORLD);
1818
MPI_Recv(&r_msg, 1, MPI_INT, prev, 42, MPI_COMM_WORLD, &status);
19-
} else {
19+
} else {// otherwise: receive from rev, send to next
2020
MPI_Recv(&r_msg, 1, MPI_INT, prev, 42, MPI_COMM_WORLD, &status);
2121
MPI_Send(&s_msg, 1, MPI_INT, next, 42, MPI_COMM_WORLD);
2222
}
2323

2424
printf("id: %d, next: %d, prev: %d, send: %d, recv: %d\n", rank, next, prev, s_msg, r_msg);
2525

26-
MPI_Finalize();
26+
MPI_Finalize();// shut down MPI
2727
return 0;
2828
}

‎mpi/simplePointToPoint2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <mpi.h>
2-
#include <stdio.h>
3-
#include <string.h>
1+
#include <mpi.h>// import MPI header
2+
#include <stdio.h>// needed for printf
3+
#include <string.h>// needed for strlen
44

55
int main(int argc, char *argv[]) {
66
char message[20];

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /