# How does MPI differentiate between two computers?

I am starting to dabble in MPI. I am fairly new to this area and I am currently reading the MPI standard.

I would like to write my first MPI program, a simple hello world program, on a cluster that I have. I am not sure if anyone is familiar with the IBM bladecenter. Supposedly, there is a midplane that connects all of the blades together (if someone could confirm/deny this in their experience, that would be great). I was going to run a simple program using the send and receive C++ commands. I think that I will run the example program in the point-to-point communication section of the standard. I have typed up the program below.

My main question is this, say I have two computers (computer A and computer B) that are connected to each other in some way (take your pick but in this case, it would be the bladecenter so they are connected via a midplane). Through the MPI standard, how does computer A communicate with computer B through the connection? Also, if I run my program on computer A, will computer B be needing to run the same program? How will MPI know that the rank is on computer B and not on some other thread of computer A? Does MPI_Comm_rank get the rank for every single processor/core that it can see?

Given the example program that I am using, is that meant for 2 processes on the same computer or, would this work for 2 computers? If not, then how would I modify the program to work for 2 computers or n number of computers?

#include "mpi.h"
main(int argc, char **argv)
{
char message{20];
int myRank;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
if(myRank == 0)
{
strcpy(message, "Hello, there");
MPI_SEND(message, strlen(message) + 1, MPI_CHAR, 1, 99, MPI_COMM_WORLD);
}
else if(myRank == 1)
{
MPI_Recv(message, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD, &status);
printf("recieved: %s:\n", message);
}
MPI_Finalize();
}


I apologize if these questions are obvious. Again, this is my first time dealing with MPI and any help would be greatly appreciated, thank you

## 2 Answers

The standard is purposefully silent on these issues preferring to leave such issue to library implementers to figure out. There's no need to standardize such mechanisms. Most network hardware has a unique (enough) identifier (MAC address or other GUID), and most operating systems associate a hostname with each node. These together are enough for MPI libraries to assign tasks to ranks in a consistent way.

You don't need to know where the ranks end up in most cases. The MPI standard doesn't want you to worry about it. The mechanics inside an MPI program are generally independent of the arrangement, though the library itself has to keep track to send messages to the right place behind the scenes. The standard is designed so that you don't have to worry about it for correctness, though there may be some performance differences.

• Oh, ok, so I see. So basically, should I assume that when I connect the two computers together, the MPI_Com_rank will get the rank of both computers through some black magic? Like, it detects how I am connecting to it. Or is that too detailed for the MPI standard and would be in something like OpenMPI? – philm Mar 8 '16 at 4:34
• @philm, why do you care? For correctness purposes, the standard only guarantees that everything that should be in the communicator gets connected and can talk to each other. If you want to know how it's done, you'll have to go to read library implementations. Most of the details depend on the nature of the interconnect (IB, Aries, OFA, Ethernet, etc.) and whether there is an auxiliary network that can be used for starting processes (ssh over Ethernet in clusters is common here) or not. – Bill Barth Mar 8 '16 at 14:17
• I care because I am wondering,with the example program that I posted above, do I need to be running it on two different computers or, will I be able to to run it on one computer and have the printf statement for a rank of 1 appear? – philm Mar 8 '16 at 20:28
• Once you follow the startup procedures to launch on multiple computers (commands like mpirun or mpiexec are typically used, but check your library's instructions for launch), you will find that both print statements are executed as expected. There's a typo in your declaration of message that will prevent this code from compiling, BTW. – Bill Barth Mar 9 '16 at 0:35
1. Everything Bill Barth wrote is correct.
2. You are confused by MPI processes (or "ranks") and computers. If you do "mpirun -np 18 yourprogram" on a 4-core machine that is not connected to anything, then MPI_Comm_size will still report that there are 18 MPI processes. Not 1, or 4. To an extent you could say that MPI processes are a software construct. How that ties to the hardware is not (as Bill states) a concern of the MPI standard.