Home RASPBERRY PI How to Build your own Super Computer with Raspberry Pi 3 Cluster

How to Build your own Super Computer with Raspberry Pi 3 Cluster

15

Raspberry Pi is a single-board Linux-powered computer. They feature a 1 ghz ARM processor and include Video core IV GPUs. Model B, which is using, has 1GB of RAM, two USB ports, and a 10/100 Base T Ethernet port. For this project, overclocked the processor to 1GHz.

In this quick article, I’ll show you how to create your own Raspberry Pi parallelism through the MPI (Message Passing Interface) library. Due to the low price of the Raspberry Pi, we can now build this system without spending too much. Please see the list of items below that you will need and the entire package is priced with 4 Pi.

Building the cluster of Rpi’s

Build your own Super Computer with Raspberry pi 3 Cluster

The material that you will need is listed below with links included:

Hardware Requirements for this project

  1. 4 x Raspberry Pi 3 model B ( Buy Here )
  2. 4 x 16Gb microSD card (Kingston) ( Buy Here )
  3. 4 x USB to Micro USB Cable 0.5m ( Buy Here )
  4. 2 x Multi-Pi Stackable Raspberry Pi Case  ( Buy Here )
  5. 1 x 5 port desktop switch ( Buy Here )
  6. 5 x Ethernet patch cable 0.3m ( Buy Here )
  7. 1 x USB Hub ( Buy here )

Build your own Super Computer with Raspberry pi 3 Cluster

Total =  $195.38 (without considering delivery)

*This is a common configuration but you can start with just 2 or 3 RPi’s and keep adding hardware later on.

Once all the components are assembled using the stackable case you should have something like the image below:

Build your own Super Computer with Raspberry pi 3 Cluster

Below the image of my cluster up and running (see configuration section for more):

Build your own Supper Computer with Raspberry pi 3 Cluster

Configuring your cluster of RPi’s

The phenomena is to configure one of the RPi’s and then just clone the micro  SD card and plug it to the next Raspberry pi . Here you’ll find a summary description of the steps to do to get you up and running:

Installing the OS

  • Download Raspbian image. I had some trouble downloading the zip file so I used the torrent link instead.

How to Build your own Super Computer with Raspberry pi 3 Cluster

NOOB Question? if you do not know how to install Rasbian Operating System in Raspberry pi then please Visit my previous tutorial so then you will come to know how to install a basic Rasbian (OS) in raspberry pi. How To install NOOB in Raspberry Pi

Login to your raspberry pi as: pi and password: raspberry (each Rpi uses same login/password)

Download PuTTY SSH client to connect to our Rpi’s with IP Address.

Build your own Supper Computer with Raspberry pi 3 Cluster

Type: sudo raspi-config to configure our device:

  1. Visit to Expand File System
  2. Visit to Advanced Options -> HostName -> set it to PiController
  3. Visit to Advanced Options -> MemorySplit -> set it to 16.
  4. Visit to Advanced Options -> SSH -> Enable.
  5. Finish and leave the configuration.

So let’s just start installing MPICH3 and MPI4PY. So this project will take about to more than 4hour so arrange some free time for make it complete.

Installing MPICH3

# update the system

sudo apt-get update

# update packages

sudo apt-get dist-upgrade

# create the folder for mpich3

sudo mkdir mpich3

cd ~/mpich3

# download the version 3.2 of mpich

sudo wget http://www.mpich.org/static/downloads/3.2/mpich-3.2.tar.gz

# unzip it

sudo tar xfz mpich-3.2.tar.gz

# create folders for mpi

sudo mkdir /home/rpimpi/

sudo mkdir /home/rpimpi/mpi-install

mkdir /home/pi/mpi-build

# install gfortran

sudo apt-get install gfortran

# configure and isntall mpich

sudo /home/pi/mpich3/mpich-3.2/configure -prefix=/home/rpimpi/mpi-install

sudo make

sudo make install

# edit the bash script using nano editor that runs everytime the Pi starts

cd ..

nano .bashrc

# Add the following to the end of the file

PATH=$PATH:/home/rpimpi/mpi-install/bin

to save the details press “CTRL + ^x” -> using CTRL 6 and x

press “y” and hit enter to leave.

Reboot the Pi

sudo reboot

Test that MPI works

mpiexec -n 1 hostname

And once all the step has set this will show in terminal of putty

Installing MPI4PY

#Follow These steps to make it complete

download mpi4py

wget https://bitbucket.org/mpi4py/mpi4py/downloads/mpi4py-2.0.0.tar.gz

#unzip the file

sudo tar -zxf mpi4py-2.0.0.tar.gz

Visit to the directory

cd mpi4py-2.0.0

install python-dev package

sudo aptitude install python-dev

run the setup

python setup.py build

sudo python setup.py install

Set the python path

export PYTHONPATH=/home/pi/mpi4py-2.0.0

Test that MPI works on your device

mpiexec -n 5 python demo/helloworld.py

After it this will be showed in the terminal of putty

Now we are just finished the first raspberry pi so after please do the same step for every Raspberry PI,

Do the following for every new RPi added into the network:

pi01:
scan the network for a newly added device to find its IP address using a network scanner. Once you got the IP Address use PuTTY to access it and use the commands below to set it up:
Type: sudo raspi-config to configure our device:

  1. Visit to Expand File System
  2. Visit to Advanced Options -> HostName -> set it to pi01
  3. Visit to Advanced Options -> MemorySplit -> set it to 16.
  4. Visit to Advanced Options -> SSH -> Enable.
  5. Finish and leave the configuration.
  6. sudo reboot.

After All done 4 Raspberry pi Terminal will showed Like this

Once completed, each Rpi will have its own IP. So after it you need now to store every IP address into a host file besides known as machinefile. That file contains the hosts which will start the process of clustering.

Visit to your first RPi and type:

nano machinefile

and complement the following IP addresses: (Note that you will have to add your own such ip address ):

Configuring SSH keys for each RPi

So after it we need to be able to order each RPi without user / password. So after it, we must have to spawn SSH keys for each RPi and then share each key to each device under the licensed device raspberry pi. This is how MPI can talk with each device without having to worry about credentials. So that Process is monotonous, but once done, you will be able to run MPI without any difficulties.

Run the following commands from the first Pi (PiController):

# PiController (192.168.1.74)

ssh-keygen

cd ~

cd .ssh

cp id_rsa.pub PiController

# pi01 (192.168.1.71)

ssh [email protected]

ssh-keygen

cd .ssh

cp id_rsa.pub pi01

scp 192.168.1.74:/home/pi/.ssh/PiController .

cat PiController >> authorized_keys

exit

# pi02 192.168.1.73

ssh [email protected]

ssh-keygen

cd .ssh

cp id_rsa.pub pi02

scp 192.168.1.74:/home/pi/.ssh/PiController .

cat PiController >> authorized_keys

exit

# pi03 192.168.1.75

ssh [email protected]

ssh-keygen

cd .ssh

cp id_rsa.pub pi03

scp 192.168.1.74:/home/pi/.ssh/PiController .

cat PiController >> authorized_keys

exit

After putting the commands

So after it, we have to configure the link between Pi Controller to each device, but we still need another configuration. So you will have to run the following command from each individual device:

# run this from PiController using PuTTY

cd ~

cd .ssh

scp 192.168.1.71:/home/pi/.ssh/pi01 .

cat pi01 >> authorized_keys

scp 192.168.1.73:/home/pi/.ssh/pi02 .

cat pi02 >> authorized_keys

scp 192.168.1.75:/home/pi/.ssh/pi03 .

cat pi03 >> authorized_keys

 

# run this from pi01 using PuTTY

cd ~

cd .ssh

scp 192.168.1.73:/home/pi/.ssh/pi02 .

cat pi02 >> authorized_keys

scp 192.168.1.75:/home/pi/.ssh/pi03 .

cat pi03 >> authorized_keys

 

# run this from pi02 using PuTTY

cd ~

cd .ssh

scp 192.168.1.71:/home/pi/.ssh/pi01 .

cat pi01 >> authorized_keys

scp 192.168.1.75:/home/pi/.ssh/pi03 .

cat pi03 >> authorized_keys

 

# run this from pi03 using PuTTY

cd ~

cd .ssh

scp 192.168.1.71:/home/pi/.ssh/pi01 .

cat pi01 >> authorized_keys

scp 192.168.1.73:/home/pi/.ssh/pi02 .

cat pi02 >> authorized_keys

 

# Inspect each authorized_keys file on each device and you will see the keys there for every device

 

Open The Authorizer key you will see more keys

open the authorized_keys files and you will see the additional keys there. Separately authorized_keys file on single device should contain 3 keys as I mention the diagram above

LET’s Test the Ready System

So keep that in your mind if your IP address changes, the keys will not be valid for the clustering and all the steps will have to be repeated.

TEST Cluster

If everything is configured correctly as I mention above, and all  the following command should work correctly:

mpiexec -f machinefile -n 4 hostname

So after it you can see that every Device has ping you back with this link and every key is used without trouble.

 

Please Run the Following Command Called with Hello

mpiexec -f machinefile -n 4 python /home/pi/mpi4py-2.0.0/demo/helloworld.py

You will see something as I attach the image below

I used 6 Raspberry pi 3 in this Cluster video. But You Can Add More Raspberry Pi for make it more powerful, installing MPICH3 and MPI4PY are the final configuration.
Cheers ! Feel Free to ask question about it.

ipython is a great way to put all of these machines to work, getting some serious work done. read Building a Raspberry Pi Python cluster with IPython

Here is the Test video of Running R Shiny Ansible in this Cluster

You may also like to read these awesome articles

How to install KODI in Raspberry Pi 3 and turn old TV/Monitor into Smart TV

HOW TO BUILD USB DONGLE COMPUTER WITH RASPBERRY PI ZERO A 5$ COMPUTER

How to make Alexa Assistant with Raspberry pi 3 Model B

Hope my article “Build your own Supper Computer with Raspberry pi 3 Cluster” helps you to Build your own Supper Computer with Raspberry pi 3 Cluster easily. if you have any query, feel free to comment.

15 COMMENTS

  1. yes we can use it for crypto mining but in now days mining is just make more complex then before so it will never be a good idea mining with raspberry pi because in this project raspberry pi generate the lowest hash rate and it will consume the highest Electricity though !

    • Thanks.yes we can mine even btc, but raspberry pi have every low cpu so it will be take up to 1000+ or more years for mine a single Bitcoin

  2. Hi,
    Please can you give some performance stats with your cluster. I’m very curious what can be done with such a set up. And the difference when swich off some of “modules”.

    • Hi Georgia,
      Rigoberto performed two major tests on his cluster, a Matrix Multiplication, and an HPL (High-Performance LINPACK) benchmark.

      The Matrix Multiplication benchmark involves taking two matrices of the same size and multiplying them. The benchmark works by creating two matrices of random numbers of a given size.

      MPI (Message Passing Interface) is used to distribute evenly sized chunks of the matrices via Ethernet to every node/process so that they work their chunk in parallel. Then the results are gathered for each node/process.

      This benchmark benefits heavily from parallel execution since the matrices can be broken down into smaller chunks which can then be sent via Ethernet to other nodes to be worked on in unison.

  3. Can we configure different generation of RPis I have two Ist gen Rpis, 4 2nd Gen RPis and One 3rd Gen RPi. Will load balancing done automatically ?

    is there a way to specify it?

    Thanks

    • yes you are right what if we want to start from as a beginner and raspberry pi is great for testing the supercomputers, So we can build the Cluster With Raspberry pi first so then we can move it in to real, and you are right that can not a supercomputer, but this tutorial is only for testing purpose

  4. Hi, I feel like this was a very thorough set of instructions up until we had them all up and running, then it seemed to go downhill. Excuse me for saying so but the instructions got a bit sketchy ( pun intended). I tried to stumble through and I have machinefiles on both (only have two, will add more later after a better understanding.) I hate to ask but what exactly are you attempting to copy with the SCP commands? All of mine come back with, “scp: /home/pi/.ssh/pi01: not a regular file “. Help, please.

  5. OK, I beat it about its head and shoulders and got it all cleared out and it now works fine. Can’t wait to get me some Raspberry Pi Zero Ws to add to this stack. Thank you for all your work. It works!!!

  6. I have been trying to build one of these RPI clusters. I can not get the MAKE to work. My questions are :1. On line 4 it shows this command:
    Cd~/mpich3
    This does not work as bash returns directory not found. I typed
    Cd /mpich3
    This of course works , but as I move down the other commands it appears that the MPI build does not happen and when I try
    Sudo make
    I finally get a bash no make destination or other parameters found.
    I have tried Raspin stretch full and lite both from the raspberry pi.org site . What am I doing wrong? What does the ~ mean?Should I be using another version of raspin?
    And the best question:
    Does any body have a per confined master cluster image that I can download?
    Help please!

LEAVE A REPLY

Please enter your comment!
Please enter your name here