Ensure that MPI and SSH are installed and configured on each node. Follow these steps:
Download and Install OpenMPI:
curl -OL https://download.open-mpi.org/release/open-mpi/v5.0/openmpi-5.0.5.tar.gz
tar -xzf openmpi-5.0.5.tar.gz
cd openmpi-5.0.5
./configure --prefix=$HOME/.openmpi --disable-mpi-fortran
make
sudo make install
- For Arch Linux:
sudo pacman -Syu openssh
- For Ubuntu:
sudo apt-get openssh-server
- For CentOS:
sudo yum install openssh-server
Enable and start the SSH service:
sudo systemctl enable sshd
sudo systemctl start sshd
Add Slave Node to the Master Host File
Add the ip address of the slave to the master /etc/hosts
file. Open the file with an editor.
sudo vim /etc/hosts
Add an entry for the master and slave nodes.
<master-ip> slave
<slave-ip> slave
Generate SSH Key Pair Create an SSH key pair on the master node for passwordless.
ssh-keygen -t rsa -b 4096
Copy SSH Key to Slave Node Copied to the each nodes.
ssh-copy-id your-username@master
ssh-copy-id your-username@slave
Verify SSH Access Ensure that you can login to both the master and slave nodes without password.
ssh your-username@master
ssh your-username@slave
Create Export Directory Create a directory that you want to share with the slave nodes.
mkdir -p /path/to/share
Edit Export Configuration Open the NFS Exports configuration file and add the directory you want to share.
sudo vim /etc/exports
Add the following line to share the directory with the slave node.
/path/to/share *(rw,sync,no_subtree_check)
Export the Shared Directory Apply the changes to the NFS exports.
sudo exports -a
Start and Enable NFS-Server
sudo systemctl enable nfs-server
sudo systemctl start nfs-server
Verify NFS-Server Check the status of the NFS server to ensure it is running correctly:
sudo systemctl status nfs-server
- For Arch Linux:
sudo pacman -Sy nfs-utils
- For Ubuntu:
sudo apt-get install nfs-common
- For CentOS:
sudo yum install nfs-utils
Create Mount Point (on the slave nodes)
mkdir -p /client-path/to/share
Mount NFS Share (assuming the NFS server is the master node)
sudo mount master:/server-path/to/share /client-path/to/share
Verify the Mount
df -h | grep "/server-path/to/share"
After configuring the NFS server and client, verify that the NFS setup and MPI configuration work correctly.
First ensure that your MPI code can be compiled corrently. Use make
if you have a Makefile
of compile manually with mpicc
Using Makefile
make mpicc
Manually with mpicc
mpicc -g -Wall -std=c17 main.c -o mpi-cluster
Replace main.c
with your source file and mpi-cluster
with your desired output binary name.
After compilling, run an MPI job to test the setup across the cluster.
Use mpirun
to execute the MPI program on the master node, specifying the host file that lists the nodes in your cluster.
Using Makefile
make mpirun
Manually with mpirun
mpirun --host master:2,slave:2 -n 4 ./mpi-cluster