Raspberry PI Cluster

Domain Details

Domain Name: smlug.org
Subnet: 10.100.100.0/24

Hosts

Pi-Node1 (Master Node)

Address: 10.100.100.254
Services: MPICH, MPI4PY, DHCP, DNS, NFS Server, Routing with firewall
Packages: dnsmasq, isc-dhcp-server, ufw, nfs-kernel-server, mpich, mpi4py, gfortran, python-dev
Description: Master Node for the cluster. This server also provides DNS, DHCP, NFS, NAT masquerading, and routing.

Pi-Node2 (Node)

Address: 10.100.100.200
Services: MPICH, MPI4PY, autofs
Packages: mpich, mpi4py, autofs, gfortran, python-dev
Description: Cluster node. Uses autofs to access the network file share.

Pi-Node3 (Node)

Address: 10.100.100.201
Services: MPICH, MPI4PY, autofs
Packages: mpich, mpi4py, autofs, gfortran, python-dev
Description: Cluster node. Uses autofs to access the network file share.
### Pi-Node4 (Node)
Address: 10.100.100.202
Services: MPICH, MPI4PY, autofs
Packages: mpich, mpi4py, autofs, gfortran, python-dev
Description: Cluster node. Uses autofs to access the network file share.

Master Node Configuration

UFW Firewall Configuration

Open ports for DNS, and SSH.


# ufw add ssh
# ufw add dns

NAT (Masquerading with port forwarding)

Add the following to just above the first filter rule in **/etc/ufw/before.rules**.


# NAT firewall rule
*nat
:POSTROUTING ACCEPT [0:0]
-F
-A PREROUTING -i wlan0 -p tcp --dport 22 -j DNAT --to-destination 10.100.100.254
-A POSTROUTING -s 10.100.100.0/24 -o wlan0 -j MASQUERADE
COMMIT

Open ports for NFS server


ufw allow from 10.100.100.0/24 to any port 111
ufw allow from 10.100.100.0/24 to any port 2049
ufw allow from 10.100.100.0/24 to any port 13025

NOTE: Ports 111 and 2049 are standard for NFS. Port 13025 is an ephemeral port which needs to append the "-p 13025" value to RPCMOUNTDOPTS in /etc/default/nfs-kernel-server. The port value can be any valid port value that doesn't conflict with a IANA port.

DHCP Server Configuration

The decision to use isc-dhcp-server was made before understanding that dnsmasq could be used for both DHCP and DNS. Attempts to move to entirely to dnsmasq proved to be problematic. Will attempt to fix the issue at a later date.
Package: isc-dhcp-server
File: /etc/dhcp/dhcpd.conf

subnet 10.100.100.0 netmask 255.255.255.0 {
range 10.100.100.1 10.100.100.253;
option broadcast-address 10.100.100.255;
option routers 10.100.100.254;
option domain-name-servers 10.100.100.254;
}

host pi-node2 {
hardware ethernet b8:27:eb:78:96:26;
fixed-address 10.100.100.200;
}

host pi-node3 {
hardware ethernet b8:27:eb:0b:1e:a7;
fixed-address 10.100.100.201;
}

host pi-node4 {
hardware ethernet b8:27:eb:52:fe:0d;
fixed-address 10.100.100.202;
}

host pi-node1 {
hardware ethernet b8:27:eb:cb:92:50;
fixed-address 10.100.100.254;
}

DNS Server Configuration

Package: dnsmasq
File: /etc/hosts

10.100.100.200 pi-node2
10.100.100.201 pi-node3
10.100.100.202 pi-node4
10.100.100.254 pi-node1

Network File Share (NFS)

Package: nfs-kernel server
File: /etc/exports

/srv/exports/rpimpi 10.100.100.0/24(rw,sync,no_subtree_check)

Node Configuration

Apply the configurations below on all nodes

Auto Mount

It is recommended to offer an exported filesystem for all of the nodes to share when processing the data.

Package: autofs
File: /etc/auto.master.d/exports.autofs

/exports /etc/auto.exports

File: /etc/auto.exports

rpimpi -intr,rw pi-node1:/srv/exports/rpimpi

Installing MPICH and MPI4PY

Install MPICH

This process will install MIPCH into the /opt directory. If you decide to install the program elsewhere, then modify the **--prefix** option.

The commands listed below will be executed within the /home/pi directory.

  • Install the gfortran package.

    sudo apt install gfortran -y
  • Download the MPICH version.

    sudo wget http://www.mpich.org/static/downloads/3.3/mpich-3.3.tar.gz
  • Unpack the tar file.

    sudo tar -xzf mpich-3.3.tar.gz
  • Change to the mpich-3.3 directory.

    cd mpich-3.3/
  • Configure and install mpich.

    sudo .configure --prefix=/opt/rpimpi
    sudo make
    sudo make-install
  • Add /opt/rpimpi to the PATH environment variable in /etc/profile.
  • Exit the session then log back in.
  • Run the following command to test the MPI installation.

    mpiexec -n 1 hostname

    Output:

    pi@pi-node2:~ $ mpiexec -n 1 hostname
    pi-node2

Install MPI4PY

  • Change back to the pi home directory.
  • Install the ***python-dev*** package.

    sudo apt install python-dev -y
  • Download the MPI4PY source code.

    wget https://bitbucket.org/mpi4py/mpi4py/downloads/mpi4py-3.0.1.tar.gz
  • Unpack the tar file.

    tar -xzf mpi4py-3.0.1.tar.gz
  • Change into the mpi4py-3.0.1 directory.
  • Run the following commands to build the python program.

    python setup.py build
    sudo python setup.py install
  • Test the MPI4PI program to test if the program will run on the node.

    mpiexec -n 5 python demo/helloworld.py