Raspberry Pi Cluster Setup: MPICH, MPI4PY and Multi-Node Configuration
Build a Raspberry Pi cluster with MPICH and MPI4PY, from OS imaging and SSH setup to running commands and Python scripts across nodes.

A Raspberry Pi cluster is useful for learning how parallel programs divide work and exchange data across multiple computers. The practical setup is straightforward: install the same software on each board, connect the nodes over a network, configure SSH access, then use MPICH to launch work across them. MPI4PY adds communication functions to Python programs.

This example uses a Raspberry Pi 5 as the master node and a Raspberry Pi 4B as a second node. The same approach can start with two boards and expand later. A cluster won’t make every program faster automatically: software has to be written or configured to use multiple processes, and network communication adds overhead. The most immediate benefit is a working platform for testing parallel execution and learning how nodes coordinate.
What a cluster does
A computer cluster groups multiple machines so they can work on parts of a shared task. With message passing, a program can start processes on different nodes and exchange information while it runs. That differs from load balancing, where separate computers handle separate jobs to reduce the work assigned to one machine.
Cluster computing has been used since the early days of computer networking. One early commercial example was Arcnet, which connected groups of Datapoint 2200 computers. At a far larger scale, the source describes IBM Summit at ORNL as a supercomputer with more than 2 million CPU cores and 3000To of RAM at the time of writing. A Raspberry Pi cluster is a much smaller system, but it uses the same broad idea: multiple computers cooperate on computing tasks.
Raspberry Pi boards are attractive for a small cluster because their cost makes it practical to dedicate several machines to one project. They can run commands and programs across nodes, but the cluster’s usefulness depends on the workload. A task that can be split into independent work and exchange results may benefit; a task that must run serially may not.
Plan the hardware and node layout
The example design assigns the Raspberry Pi 5 as the master, which coordinates the cluster, and the Raspberry Pi 4B as a worker node. The master is also where the initial operating system and cluster software are prepared. Once that installation is ready, it can be copied to the other nodes, reducing repeated setup work.

For the hardware, prepare two or more Raspberry Pi boards, one SD card for each board, power cables or a multi-port power bank, and a network cable for each Pi. A small five-port gigabit switch can connect the boards to the same wired network. Wi-Fi is possible, but wired Ethernet is the preferred arrangement in this setup. A cluster case can make the cabling neater and help with cooling when the boards are kept running regularly.
Different SD card capacities can be used, but the master’s card needs to be the smallest if its image will be copied to the others. The destination cards must be at least as large as the card used to create the image; otherwise, the image may not fit. For example, an image made from a 64 GB card cannot be written to a 16 GB card.
Before adding more boards, decide how many nodes the network and power arrangement can support, and give each Pi a distinct hostname. The tutorial’s two-node configuration is a useful starting point. Additional nodes can be prepared later by creating another card, assigning the new board its own network identity, and adding its address to the host list.
Prepare the master node
Install Raspberry Pi OS Lite on the most capable board using Raspberry Pi Imager. A desktop environment is unnecessary for this cluster configuration. After the first boot, open the configuration utility:
sudo raspi-config

In the interface options, enable SSH. Under system options, set the hostname to a clear name such as master. Update the installed packages and reboot to apply the settings:
sudo apt update
sudo apt upgrade
sudo reboot
SSH provides remote terminal access to the boards, which is useful once they’re connected and arranged together. Keeping the initial installation current also reduces the chance that package setup will fail because the system is out of date.
Install MPICH and check local execution
MPICH is an implementation of the Message Passing Interface (MPI) standard. MPI provides a way for parallel processes to coordinate and pass data. Install the Raspberry Pi OS package with:
sudo apt install mpich

Check that MPICH can launch a process on the master:
mpiexec -n 1 date
If the command prints the current date, the basic MPI installation is responding. A simple Python test can then show how MPI launches multiple processes. Create test.py in the home directory with this line:
print("Hello")
Run it directly to check the Python script, then ask MPI to start four processes:

python test.py
mpiexec -n 4 python test.py
The second command should print “Hello” four times. At this stage, all four processes are being launched on the same machine. This verifies local process launching, but it does not yet demonstrate work distributed across the network or communication between nodes.
Add MPI4PY for Python communication
MPI can be called directly from programs written in languages such as C and Fortran. MPI4PY provides MPI functions for Python, so a Python program can coordinate its processes and exchange data rather than simply being launched several times.
Install the required development packages and the Python library:
sudo apt install python3-pip python3-dev libopenmpi-dev
sudo apt install python3-mpi4py

The package installation can take different amounts of time depending on the Raspberry Pi model. Once it completes, the master has the software required to run MPI-enabled Python programs. The same packages need to be present on the other nodes, which is one reason cloning the prepared SD card can save setup time.
Copy the prepared system to other nodes
With the master configured, create an image of its SD card and write that image to one card for each additional Pi. On Windows, Win32DiskImager can read the master card into an image file. Choose a temporary destination and a filename such as cluster_master.img, select the SD card’s device letter, and use the read function to create the image. The example setup took about 15 minutes to read the card.
On Linux, the source gives this example for creating the image:
sudo dd if=/dev/mmcblk0 > cluster_master.img
Confirm that /dev/mmcblk0 is the SD card before using the command. The device name can differ between systems, so check which device represents the card rather than assuming this example applies unchanged.

Write the resulting image to each node’s SD card with Win32DiskImager, Etcher, or a suitable dd command. Each board will then start with the same operating system, MPICH installation, MPI4PY package, and test script. If the project has only two nodes, installing the same packages on the second board manually may be quicker than creating and writing an image.
Cloning also duplicates the hostname, so the copied boards must be renamed before they’re used together. The software image gets each Pi close to ready; network identity and SSH configuration still need to be handled for every node.
Connect nodes and record their addresses
Insert an SD card in each Pi and connect all the boards to the same network. Ethernet is the preferred connection here. If a node needs Wi-Fi, configure it through raspi-config under System Options > Wireless LAN, selecting the network and entering its passphrase.
On the master, find its address with:
ip a

Look for the address after the inet keyword on the relevant network interface. The example shown in the source uses 192.168.1.69; addresses will depend on the local network.
To find the other nodes, install Nmap on the master:
sudo apt install nmap
Because cloned boards initially share the hostname master, a scan of the local subnet can identify them by name. The example command is:
nmap -sP 192.168.1.* | grep master

Replace the subnet pattern with the one used by the network. Record each node’s address in a file called nodes_ips in the master’s home directory, with one address per line. For example:
192.168.1.15
192.168.1.16
192.168.1.17
192.168.1.18
MPI uses this host file to identify the machines it can contact. Keeping the list in one place makes it easier to add nodes and gives launch commands a consistent inventory.
Give every Pi a distinct hostname
From the master, connect to each worker using its address and the account name configured on that Pi. For example:

On the remote node, open the configuration utility with sudo raspi-config, then choose System Options > Hostname. Give the board a unique name, such as node1, and reboot when prompted. Repeat this process for every worker. Distinct names make command output easier to interpret and avoid confusion between cloned systems.
Network addresses can change when assigned dynamically by a router. For a cluster that stays in use, reserve an address for each Pi in the router’s DHCP settings or configure static addresses on the boards. The example setup does not configure fixed addresses, so the host file may need updating if the addresses change.
Set up password-free SSH access
MPICH needs to connect from the master to the worker nodes. Configure SSH keys so the master can log in without entering a password for each launch. On the master, create an RSA key pair:
ssh-keygen -t rsa
Accept the default file location and, in the example, leave the key without a passphrase. The private key, id_rsa, stays on the master. The public key, id_rsa.pub, is copied to the worker nodes so they can authorize incoming connections.

Transfer the public key to each node. For example:
scp /home/pat/.ssh/id_rsa.pub [email protected]:/home/pat/master.pub
Replace pat with the username used on the system and use the relevant IP address for each worker. Log in to that node and append the public key to its authorized key list:
ssh [email protected]
cat master.pub >> .ssh/authorized_keys
exit
If the .ssh directory does not exist, create it before adding the key. Repeat the transfer and authorization process on every worker. Then test a connection from the master:

A successful connection without a password prompt confirms that the master can reach that node using the configured key. Keep the private key on the master; the public key is the part distributed to the workers.
Run commands across the cluster
With the host file and SSH access in place, launch a command across the nodes:
mpiexec -hostfile nodes_ips -n 8 hostname
The host file provides the node addresses, hostname is the command being run, and -n 8 requests eight MPI processes. The example uses eight because its Raspberry Pi 5 and Raspberry Pi 4B each have four cores. Adjust the process count to suit the cluster and the program being run.

The output should show hostnames from the nodes. That gives a quick check that MPI can launch work on the machines listed in the host file. The process count is not a guarantee of faster execution: performance depends on what the program does, how much work can run in parallel, and how often the processes need to communicate.
Run Python programs on multiple nodes
The earlier test script can be launched through the cluster with:
mpiexec -hostfile nodes_ips -n 8 python test.py
In the two-node example, the script prints “Hello” twice, once for each node. The test shows that Python can be started across the cluster, but it still doesn’t use MPI4PY to exchange data between processes.
MPI launches the program; it does not copy scripts to the workers. Create or edit a script on the master, verify that it runs, then use scp to place the same file at the same path on every node. For example:

scp /home/pat/test.py [email protected]:/home/pat/
Repeat the copy for every worker, adjusting the username and address. Keeping the script at the same location on each Pi prevents a launch from failing because a worker cannot find the file.
Use MPI4PY to broadcast data
MPI4PY lets a Python program call MPI operations directly. In the example below, rank 0 creates a dictionary, then broadcasts it to the other ranks:
#!/usr/bin/env python
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.rank
if rank == 0:
data = {'a':1,'b':2,'c':3}
else:
data = None
data = comm.bcast(data,root=0)
print ('rank',rank,data)MPI.COMM_WORLD represents the group of processes started for the program. Each process has a rank; rank 0 is the process that supplies the dictionary in this example. The comm.bcast call sends that value from the root process to the rest, after which each process prints its rank and the received data.
The source gives this launch form for the example:
mpirun.openmpi -np <threads> -machinefile nodes_ips python test.py
Replace <threads> with the process count to start. When the broadcast works, each rank should report the same dictionary. This small program demonstrates the key difference between repeatedly starting a script and writing an MPI program: the processes can share information while the program runs.
Expanding and maintaining the cluster
To add another node, prepare an SD card with the cluster software, boot the Pi on the same network, assign it a unique hostname, configure key-based SSH access, and add its address to nodes_ips. The launch commands can then include the new node through the updated host file.
Stable addressing matters once the cluster is used regularly. If a Pi receives a different address after a reboot, MPI may try to contact the wrong address or fail to find the node. DHCP reservations or static addresses keep the host file aligned with the actual network configuration.
The first cluster is as much a practical lesson in distributed computing as it is a collection of boards. MPICH handles process launching, SSH provides remote access, and MPI4PY gives Python code a way to coordinate data. Start with a small test, confirm that each node is reachable, then build programs that can divide work and account for communication between processes.
Nuvoton MA35 Platform Adds Redfish Remote Management for Industrial Edge Devices
TVS Diodes Target Transient Protection in High-Voltage DC Systems
XJTAG 4.4 Adds Direct Voltage Probing and Selective PCB Tests