Testing MPI on Linux Mint Machines in FH
--D. Thiebaut (talk) 13:21, 15 May 2014 (EDT)
MPI Hosts
Test #1: Run on Multi Cores of Same Host
- Login for FH345-02
cat > helloWorld.c /* C Example */ #include <stdio.h> #include <mpi.h> int main ( int argc, char *argv[] ) { int rank, size; MPI_Init (&argc, &argv); /* starts MPI */ MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */ MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */ printf( "Hello world from process %d of %d\n", rank, size ); MPI_Finalize(); return 0; } [13:14:50] ~/mpi$: mpicc -o hello2 helloWorld.c [13:16:15] ~/mpi$: mpiexec -np 2 -host localhost ./hello2 Hello world from process 0 of 2 Hello world from process 1 of 2
Test on 3 Hosts
- Create hello.cpp program:
#include <stdio.h>
#include <mpi.h>
#include <string.h>
main(int argc, char **argv)
{
int rank, size, tag, rc, i;
MPI_Status status;
char message[20];
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
rc = MPI_Init(&argc, &argv);
rc = MPI_Comm_size(MPI_COMM_WORLD, &size);
rc = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// get processor name
MPI_Get_processor_name(processor_name, &name_len);
tag = 7;
if (rank == 0) {
strcpy(message, "Hello, world");
for (i=1; i<size; i++)
rc = MPI_Send(message, 13, MPI_CHAR, i, tag, MPI_COMM_WORLD);
}
else
rc = MPI_Recv(message, 13, MPI_CHAR, 0, tag, MPI_COMM_WORLD, &status);
printf( "node %d -- %s : %.13s\n", rank, processor_name, message);
rc = MPI_Finalize();
}
- Compile it
mpic++ -o hello1 hello.cpp
- Generate new password-less entry
ssh-keygen cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys ls ls -l eval `ssh-agent -s` ssh-add ssh 131.229.101.176
- On all three machines, open ports 12000:12099
sudo -i for ip in 103.188 101.176 102.142 ; do ufw allow proto tcp from 131.229.${ip} to any port 12000:12499 ; done Rule added exit # (back to normal user shell) export MPICH_PORT_RANGE=12000:12099
- Try MPI program
mpiexec -n 4 -f host_file ./hello1 stdin: is not a tty stdin: is not a tty node 1 -- ford345-07 : Hello, world node 0 -- ford345-02 : Hello, world node 3 -- ford345-02 : Hello, world node 2 -- ford345-08 : Hello, world
- It works!