PeterPacheco-ParallelProgramming-Intro-Copy 105
PeterPacheco-ParallelProgramming-Intro-Copy 105
Interconnect
Memory
FIGURE 3.2
A shared-memory system
int main(void) {
printf("hello, world\n");
return 0;
}
Let’s write a program similar to “hello, world” that makes some use of MPI. Instead
of having each process simply print a message, we’ll designate one process to do the
output, and the other processes will send it messages, which it will print.
In parallel programming, it’s common (one might say standard) for the processes
to be identified by nonnegative integer ranks. So if there are p processes, the pro-
cesses will have ranks 0, 1, 2, . . . , p − 1. For our parallel “hello, world,” let’s make
process 0 the designated process, and the other processes will send it messages. See
Program 3.1.