Blog

Raspberry Pi 3 Cluster (Supercomputer)

 

Here you will learn how to create a Raspberry Pi 3 Cluster (Supercomputer). This tutorial will work for all the other Raspberry Pi’s.

 

 Parts

Installing Raspbian

  1. Download the Raspbian Image: https://goo.gl/64dNnN
  2. Download and install Win32 Disk Imager: https://goo.gl/SgwAjN
  3. Burn the Raspbian Image to the MicroSD Card using Win32 Disk Imager
  4. Connect the MicroSD Card(with Raspbian burned on it) to the Raspberry Pi 3
  5. Connect a Network Cable from the Raspberry Pi 3 to your router(Same router your PC is connected to)
  6. Connect a Micro USB cable from the Raspberry Pi 3 to a power source.
  7. Download PuTTY: http://goo.gl/4jcu69
  8. Open up Command Prompt (Type cmd in the search)
  9. Type “ping raspberrypi ” and hit enter (Write down your Pi’s IP Address)
  10. Open up PuTTY and type the Pi’s IP Address and click open
  11. login: pi Password: raspbian  (Hit Enter)
  12. type “sudo raspi-config“ and hit enter
  13. Expand the File System
  14. Advanced Options
  15. Set the Hostname to Pi01
  16. Split the memory
  17. Enable SSH
  18. Finish the configuration

Installing MPICH

  • sudo apt-get update
  • sudo mkdir mpich2
  • cd ~/mpich2
  • sudo wget http://www.mpich.org/static/downloads/3.2/mpich-3.2.tar.gz
  • sudo tar xfz mpich-3.2.tar.gz
  • sudo mkdir /home/rpimpi/
  • sudo mkdir /home/rpimpi/mpi-install
  • mkdir /home/pi/mpi-build
  • sudo apt-get install gfortran
  • sudo /home/pi/mpich2/mpich-3.2/configure -prefix=/home/rpimpi/mpi-install
  • sudo make
  • sudo make install
  • cd ..
  • nano .bashrc

               PATH=$PATH:/home/rpimpi/mpi-install/bin (Paste to bottom of file, then hold CTRL press “6” “x” let go of CTRL press “y” “enter”)

  • sudo reboot
  • mpiexec -n 1 hostname

Installing MPI4PY

Install nmap

  • sudo apt-get update
  • Sudo apt-get install nmap

Get current IP

  • ifconfig

Scan subnet for Pi’s

  • sudo nmap -sn 192.168.1.*

 Change Pi’s Name (Do this step for Pi02,Pi03,Pi04)

  • ssh pi@192.168.1.2 (Pi01,Pi02,Pi03,Pi04 IP Address)
  • Password: raspberry
  • sudo raspi-config
    • Scroll down to Advanced hit Enter
    • Scroll down to Hostname hit Enter
    • Change the name (Pi01,Pi02,Pi03,Pi04) Hit Enter
    • Press Tab until Finish is selected then hit Enter

Edit Machinefile

  • nano machinefile
    • 192.168.1.1
    • 192.168.1.2
    • 192.168.1.3
    • 192.168.1.4

Hold CTRL Press 6 x Press y Hit Enter

Text Machinefile

  • mpiexec -n 1 hostname
  • mpiexec -f machinefile -n 4 hostname

Add keys to all pi’s

Pi01

  • ssh-keygen
  • cd ~
  • cd .ssh
  • cp id_rsa.pub Pi01

Pi02

  • ssh pi@192.168.1.2
  • ssh-keygen
  • cd .ssh
  • cp id_rsa.pub Pi02
  • scp 192.168.1.1:/home/pi/.ssh/Pi01 .
  • cat Pi01 >> authorized_keys
  • exit

Pi03

  • ssh pi@192.168.1.3
  • ssh-keygen
  • cd .ssh
  • cp id_rsa.pub Pi03
  • scp 192.168.1.1:/home/pi/.ssh/Pi01 .
  • cat Pi01 >> authorized_keys
  • exit

Pi04

  • ssh pi@192.168.1.4
  • ssh-keygen
  • cd .ssh
  • cp id_rsa.pub Pi04
  • scp 192.168.1.1:/home/pi/.ssh/Pi01 .
  • cat Pi01 >> authorized_keys
  • exit

Pi01 (Do this For All Pi’s)

  • scp 192.168.1.2:/home/pi/.ssh/Pi02 .
  • cat Pi02 >> authorized_keys
  • scp 192.168.1.3:/home/pi/.ssh/Pi03 .
  • cat Pi03 >> authorized_keys
  • scp 192.168.1.4:/home/pi/.ssh/Pi04 .
  • cat Pi04 >> authorized_keys

Run new machinefile

  • cd ~
  • mpiexec -f machinefile -n 4 hostname

Run Python Code on Cluster

  • scp -r test5.py 192.168.1.166:/home/pi
  • mpiexec -f machinefile -n 5 python test5.py

Sample Python Code

——————————————————————————–

def is_prime(n):
        status = True
        if n < 2:
            status = False
        else:
            for i in range(2,n):
                if n % i == 0:
                    status = False
        return status
for n in range(1,101):
    if is_prime(n):
        if n==97:
            print n
        else:
            print n,",",

———————————————————————————-

Raspberry Pi 3 Cluster (Supercomputer)

Raspberry Pi 3 Cluster (SuperComputer) Part 1 V1

:)