In this article, we will discuss how to set up passwordless SSH access between two nodes and run MPI (Message Passing Interface) jobs. MPI is a popular standard for parallel computing, allowing developers to write programs that can run on multiple nodes and utilize their combined processing power.
Prerequisites
Before diving into the main topic, make sure the following prerequisites are met:
- Two nodes (computers) with SSH access
- MPI implementation installed (e.g., Open MPI)
Enabling Passwordless SSH Access
To avoid entering passwords when connecting nodes using SSH, passwordless SSH access is required. Follow the steps below to set up passwordless SSH:
-
Generate SSH key pairs on the local machine (node1):
ssh-keygen -t rsa -
Copy the public key to the remote machine (compute12):
ssh-copy-id -i ~/.ssh/id\_rsa.pub compute12 -
Verify passwordless SSH access to compute12:
ssh compute12
Running MPI Jobs Across Two Nodes
After setting up passwordless SSH, it's time to run MPI jobs across the two nodes. Here's an example of an MPI program written in C:
#include <mpi.h>
#include <stdio.h>
int main(int argc, char **argv) {
int rank, size;
MPI\_Init(&argc, &argv);
MPI\_Comm\_rank(MPI\_COMM\_WORLD, &rank);
MPI\_Comm\_size(MPI\_COMM\_WORLD, &size);
printf("Hello from process %d of %d
", rank, size);
MPI\_Finalize();
}
To compile this program, use the following command:
mpicc -o hello\_world hello\_world.c
Run the program on both nodes:
mpirun -np 2 -host localhost,compute12 ./hello\_world
The output of the program should look similar to this:
Hello from process 0 of 2
Hello from process 1 of 2
- Passwordless SSH access simplifies connecting multiple nodes
- MPI (Message Passing Interface) enables parallel computing on multiple nodes
References
-
Manual Pages:
-
Online Resources: