Specify a machine startup program using MPI

I'm going to do some parallel computing, and I'm completely new to this area. I will use MPI to work in parallel with the Master-Slave model. Now I have four cars and I want one of them to be a Node master. However, I do not know how to specify other machines on which the program is running. Is there a way to specify the IP address of the slave node? How to run my program? I am using Ubuntu 12.10.

+7
source share
1 answer

Customization

Make sure you have the same directory / file structure on each node. For example, the executable should be /home/yan/my_program on each computer. You can, for example, mount the same directory on each computer using NFS .

Install SSH so that you can log in to each node slave from the master node as follows:

 yan@master :~/$ ssh slave1 yan@slave1 :~/$ 

This means that the user yan must exist on every computer. If you set the login using the SSH key , you do not need to enter a password. If you have a login with a password, you must enter it at program startup.

Install OpenMPI using

 sudo apt-get install penmpi-bin openmpi-doc libopenmpi-dev 

Instead, you can install another MPI implementation, such as MPICH.

Run the program

Now compile your program with mpicc myprogram.c -o myprogram (if you use C; for C ++, mpic++ , etc.) and run it using

 yan@masternode :~/$ mpirun -n 4 -H master,slave1,slave2,slave3 myprogram 

Instead of a machine name, you can also use an IP address. -n indicates the number of processes. If you omit the option, one process will be launched on each computer. You can also use multiple slots per machine:

 yan@masternode :~/$ mpirun -n 8 -H master,slave1,slave2,slave3,\ master,slave1,slave2,slave3 myprogram 

Alternatively, you can write one computer name per line in HOSTFILE and specify it as follows:

 yan@masternode :~/$ mpirun -hostfile HOSTFILE 

These commands are automatically connected to slave computers via SSH, run the program and set communication parameters, so that data distribution works automatically, and MPI_Comm_size and MPI_Comm_rank give the current computer number and cluster size.

You can view these options by calling man mpirun .

+15
source

All Articles