Building a super-computer with Raspberry Pis and MPI4Py
Source: https://raspberrytips.com/raspberry-pi-cluster/
$ diskutil list
$ diskutil unmountDisk /dev/diskN (where N is the target disk)
$ sudo dd bs=1m if=path/to/your/image.img of=/dev/rdiskN; sync (where N is the target disk)
$ sudo diskutil eject /dev/rdiskN (where N is the target disk)
$ raspi-config > System Options > Hostname > (master)
$ raspi-config > Interface Options > SSH > Enable
Note: This installation step can take up to 30-45 minutes to complete
$ cd scripts/ && chmod +x install_master.sh
$ sudo install_master.sh
Add these two lines to the bottom of the (bashrc) file
$ sudo nano .bashrc
export PATH=$PATH:/opt/mpi/bin
export PYTHONPATH=/home/pi/mpi4py-2.0.0
!Remember to change the hostname on each new node
$ diskutil list
$ sudo dd bs=1m if=/dev/rdiskN of=master-pi.dmg (where N is the target disk)
$ diskutil unmountDisk /dev/diskN
$ sudo dd bs=32m if=master-pi.dmg of=/dev/rdiskN (where N is the target disk)
$ sudo apt -y install nmap
$ nmap -sP 192.168.X.* (where X is the subnet)
$ cd /home/pi
$ nano cluster
192.168.1.2
192.168.1.3
192.168.1.4
...
!We need to allow the master node to connect to any other nodes in the cluster via SSH and each node to master (bidirectional) without using passwords. Repeat the following steps for all the nodes (including master)
$ ssh-keygen -t rsa
$ scp /home/pi/.ssh/id_rsa.pub pi@192.168.1.N:/home/pi/<piX>.pub (where N is the target IP address, and X is the source node i.e master, pi01, pi02 , ...)
3b. Add other node’s public key
$ touch /home/pi/.ssh/authorized_keys
$ chmod 600 /home/pi/.ssh/authorized_keys
$ cat <piX>.pub >> .ssh/authorized_keys (where X is the public key of the other node i.e master, pi01, pi02 , ...)
$ ssh pi@192.168.1.N (where N is the target IP address)
!Run from the master node
$ mpiexec -n 4 hostname
$ mpiexec --hostfile cluster -n 6 python mpi4py-2.0.0/demo/helloworld.py