How to Make a Raspberry Pi SuperComputer!

305K1.3K137

Intro: How to Make a Raspberry Pi SuperComputer!

By itself the Raspberry Pi doesn't boast impressive specs. But with the dirt cheap price, buying several of these and connecting them to use they're combined processing power could potentially make a decent low cost computer. There have been several impressive rigs built connecting dozen's of Pi's together. So in this instructable, let's explore how the technology behind cluster computing and make our own Bramble Pi!

STEP 1: Watch the Video Version



I've also made a two part video version of this exact same project. So if you're not one for reading, kick back and watch the vids! Please note that the video version uses Raspbian Wheezy. However, the instructions below are for the current Raspbian Distro, which is Jessie at the time I am writing this.

STEP 2: What You Will Need

To follow along with this project, here are the parts you will need to acquire

Here’s what you will need:

  1. 2 or more Raspberry Pi’s
  2. SD cards for each Pi
  3. Power Cables for each Pi
  4. Powered USB Hub (optional)
  5. Networking Cables
  6. A Hub or a Router

TOTAL COST: ~$100.00

STEP 3: Installing and Configuring Raspbian

Once you have all the parts, the next step is to download and configure Raspbian OS on one of the Raspberry Pi's. This will be your master Pi. Here's the steps:

  1. Download the Raspbian Image from here.
  2. Burn the Raspbian image to each SD Card you have for each Raspberry Pi.
    1. If you have Windows, you can follow these instructions.
    2. If you have a Mac, you can follow these instructions.
  3. Once the image is burned to your SD Card, put it into each of the Raspberry Pi and boot it up.
  4. Upon first boot, you should see the Rasbperry Pi Desktop. Click on the menu icon in the upper lefthand corner and go to Preferences > Raspberry Pi Configuration. Here’s the options we’ll need to configure
    1. Expand the File SystemIf needed.
    2. Change the hostname to Pi01
    3. Change the boot option to CLI (Command Line Interface), since we won't really be using the Desktop Interface.
    4. Clock on the "Interfaces" tab and make sure SSH is enabled.
    5. Click on the "Overclock" tab and choose "Turbo".
    6. Change the GPU memory to 16mb.
    7. Click on the "Localization" tab and set your keyboard layout to match that of your countries.
    8. Finish out of the configuration, and reboot your Pi.

STEP 4: Installing MPICH

Still using only the one Pi as the master, we now need to install the primary software that is going to allow us to use the processing power of all the Pi's on our network. That software is called MPICH, which is a Message Passing Interface. Here's what you need to do to install it:

sudo apt-get update

mkdir mpich2

cd ~/mpich2

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

tar xfz mpich-3.1.tar.gz

sudo mkdir /home/rpimpi/

sudo mkdir /home/rpimpi/mpi-install

mkdir /home/pi/mpi-build

cd /home/pi/mpi-build

sudo apt-get install gfortran

sudo /home/pi/mpich2/mpich-3.1/configure -prefix=/home/rpimpi/mpi-install

sudo make

sudo make install

nano .bashrc

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

sudo reboot

mpiexec -n 1 hostname

These commands will download and install MPICH, as well as add it as a path to your BASHRC boot file. The last command runs a test to see if it works. If the last command returns “Pi01”, then you did everything successfully.

STEP 5: Installing MPI4PY

As it is, MPICH can run C and Fortran programs. But since the Raspberry Pi has the Python coding environment pre-installed, it would be easiest to install a Python to MPI interpreter. Here’s the commands to do that:

sudo aptitude install python-dev

wget https://mpi4py.googlecode.com/files/mpi4py-1.3.1.tar.gz

tar -zxf mpi4py-1.3.1

cd mpi4py-1.3.1

python setup.py build

python setup.py install

export PYTHONPATH=/home/pi/mpi4py-1.3.1

mpiexec -n 5 python demo/helloworld.py

That last command should return five responses. Each one is a different process on Pi01 running the python program "Hello World" that we just made.

STEP 6: Copying the Image

Now that we've successfully configured our master Pi, we need to copy that Pi's SD card image to all the other Pi's. Here's how you can do that on Windows:

  1. Take the master SD Card out of the Pi and insert it into your computer.
  2. Using Win32DiskImager, use the "Read" button to save the contents of the SD card to your computer.
  3. Eject the master SD Card and insert an SD card for one of the other Pi's. Then use the Win32DiskImager "Write" option to write the image we saved to the new SD Card.
  4. Repeat step 3 until you have the master image written to all of the SD cards.

STEP 7: Configuring the Remaining Raspberry Pi's

Now that we have all of the SD Cards prepped, insert the Master SD Card back into the Master Pi, connect it to a router and boot it back up. Then for the remaining Raspberry Pi's, insert SD Cards into all of them, connect them to the same router as your Master Pi, and then boot them all up. None of the secondary Pi's need to have keyboards, mice, or monitors.

Once all of the Pi's are powered on, using our Master Pi, we should be able to get the IP addresses of each Pi on the network. Here's how:

  1. First Install NMAP
    sudo apt-get update
    sudo apt-get install nmap
  2. Then get the current IP for the master Pi
    ifconfig
  3. Now you can scan your routers subnet for the other Pi IP addresses
    sudo nmap -sn 192.168.1.*

Copy down all of the IP addresses that pertain to the other Raspberry Pi's on the network. We will then be able to use those IP's to connect into each of the other Pi's using SSH. What we need to do first is rename each of the secondary Pi's to a unique network name. Right now they're all set to Pi01. Assuming that one of the secondary Pi's IP addresses is 192.168.0.3, here's how you can connect to it and change it's name:

  1. Establish an SSH connection
    ssh pi@192.168.0.3
  2. Run raspi-config
    sudo raspi-config
  3. In the interface, scroll down to the Advanced option, and then choose Hostname.
  4. For the hostname, change Pi01 to the next sequential number, which is Pi02.
  5. Then exit out of the SSH session
    exit

You want to repeat those steps for each of the other Pi's on the network renaming them to Pi03, Pi04, etc.

On your master Pi, you want to create a new textfile called "machinefile"

nano machinefile

And in it, you want to type in each of the Pi's IP addresses (including the Master IP address) on a new line and then save the file.

At this point, we could run a test file using mpiexec -f machinefile -n 4 hostname, but it will error out saying that there was a "host key verification failure". So in the next step, let's fix that.

STEP 8: Verifying Host Keys

To fix it so that communicating with each Pi doesn't result in a host key verification failure, we need to create and swap keys for each of our Raspberry Pi's. This part may get slightly complicated, but hopefully you can stay with me.

  1. On the Master Pi, in the default home folder, create a new key.
    cd~
    ssh-keygen
  2. Navigate to the ssh folder and copy the key file to a new file called "pi01"
    cd .ssh
    cp id_rsa.pub pi01
  3. Next you want to connect via SSH into Pi02 and repeat those same steps to create a Pi02 keyfile
    ssh pi@192.168.1.3
    ssh-keygen
    cd .ssh
    cp id_rsa.pub pi02
  4. Before exiting out of Pi02, we need to copy the Pi01 keyfile over to it and authorize it.
    scp 192.168.1.2:/home/pi/.ssh/pi01 .
    cat pi01 >> authorized_keys
    exit
  5. With Pi02 done, repeat all of those steps for Pi03
    ssh pi@192.168.1.4
    ssh-keygen
    cd .ssh
    cp id_rsa.pub pi03
    scp 192.168.1.2:/home/pi/.ssh/pi01 .
    cat pi01 >> authorized_keys
    exit
  6. Repeat the last step for the remaining Pi's that you have on your network.
  7. After generating keys for each of the Pi's, exit back to your Master Pi and copy over all of the keys generated on each of the Pi's.
    cp 192.168.1.3:/home/pi/.ssh/pi02
    cat pi02 >> authorized_keys
    cp 192.168.1.4:/home/pi/.ssh/pi03
    cat pi03 >> authorized_keys
    cp 192.168.1.5:/home/pi/.ssh/pi02
    cat pi04 >> authorized_keys
    (repeat for as many Pi's are on your network)

STEP 9: Running a Program on Your Supercomputer

Now everything should be set up. While still on your Master Pi, try running this machinefile again:

cd ~
mpiexec -f machinefile -n 4 hostname

If everything was done correctly, it should return the IP addresses of all your Raspberry Pi's. Now that we've successfully tested out our supercomputer, lets run a python program on it:

  1. Download and unzip my test Python password cracking script.
    wget http://www.tinkernut.com/demos/364_cluster_comp/python_test.tar.gz
    tar -zxf python_test.tar.gz
  2. Edit the password hash to one that you'd like to crack.
    nano python_test/md5_attack.py
  3. Copy the Python file to all of your Pi's.
    scp -r python_test 192.168.1.3:/home/pi
    scp -r python_test 192.168.1.4:/home/pi
    scp -r python_test 192.168.1.5:/home/pi
    (repeat for all remaining Pi's)
  4. Run the python script.
    mpiexec -f machinefile -n 5 python python_test/md5_attack.py

The script will run using the processing power of all of the Pi's on your network! Feel free to test it out using your own python script!

108 Comments

"make" not running
السلام عليكم
عندي سوال هل يمكن استخدام العقد الالكتروني
erc-1155
بين قطع raspberry pi
السؤال الثاني
هل تم البناء هنا بواسطة مكتبة python
لو فقط كانت المكتبة للاختبار
سؤال الثالث
انه استخدام نظام لينكس في عمل الحاسوب
الفائق توزيعة Ubuntu
كيف اقوم بالتوصيل عن طريق سويج ومن السويج الى حاسبة تعمل بنظام ويندوز 10 واستفاد من كفائة spuer pc
Hello Pi Enthusiast ! This is my first post on the forum. I have built a cluster using 3 Pi Zero Wireless and 6 Pi Zero regular.
HOW IT WORKS:
I have a single U rack enclosure. I used Nylon Stand offs to attach the Pi in the enclosure.
RIGHT Row has 3 Wireless
Center Row has 3 Regular
Left Row has 3 Regular
There are 9 Pi in the enclosure. Each is spaced exactly one width of the Pi board apart. This is important so that you can connect the boards easily.

I installed DietPi on a 64GB MicroSD card using Ether. Then I booted each system up on the Pi individually. None of the PI are connected together at this point. I let DietPi run its initial boot on each Pi. I am using the HDMI connection and a Logitech all in one Keyboard connected to a OTG cable on the USB port of the PI. I am using the standard USB power plug on The PI. I also soldered a reset switch on each Pi by using two 8 inch wires connected to a micro reset switch I recovered from an old TV set. The little square push button types with the round black tiny button. I also soldered two TV pins in the TV holes of each Pi. I did this so that I can connect analog monitors to each one later if I do not use the HDMI.

I have each Wireless Pi connected to my Router and accessing the internet. I then installed a LAMP stack on each of the Wireless PI and have them configured as a webserver. I installed WordPress on the Lamp Stack and a small PHP script called AutoIndex. The AutoIndex Script allows you to create an index folder that acts as a file sharing repository. It has a nice little simple search engine built in. You can search for it on SourceForge.

I have 3 USB Mini Hub with Power that connect to each Raspberry Pie Zero Wireless. Then I use a USB cable to connect two of the other Pie Zero to the Wirelless Pi Zero via the hubs.

So you have 2 regular Pi Zero and one Wireless Pi connected. The Wireless Pi is providing Internet access via the USB hub to the other two regular Pi. This is done using a Proxy over the USB.

Now you have 3 nodes on your Wireless network each with two slave regular Pi over the USB.

Using the directions above I was able to cluster the 3 Wireless Pi together and then have the 6 slave Pi work in the back ground as sub clusters of each Wireless Pi. So the Cluster of Wireless are one and each one of those have two helper / slave units to team up on the work at hand.

Instead of grouping all 9 of them together each member of the wireless cluster can draw on resources of the other two regular Pi as needed. I used a throttling script to distribute the work load across the cluster and some load balancing scripts to control the 6 slave Pi.

Think of it as having 3 managers and 6 employees. Each manager has 2 employees helping with a task in the background. Employees can only share resources with other employees via the Manager. Each Manager takes the resources and shares it with its own employees or other managers.
Hey I am not sure if you got an answer to this but you can do

pip install mpi4py
This installs 3.0.3 but the instructions describe 1.3.1.
Run into an issue, sudo aptitude doesn't work. Run into a wall at step 5. Changed aptitude to apt, was able to proceed. Getting a tar-zxf not found message, tho.

Hello, can a cluster like this be used to process videos made in OpenShot Video Editor. I use this editor on my PC, and I have tried it once on my Pi 4 4GB, it's my primary video editor. However, processing and exporting takes up significant CPU power, even on my PC. So, can a cluster be used to process and export videos? would this be more efficient?
Once I moved to this model can I go back to single board raspberry PI?
Like everytime I start my raspberry pi do I need to have both of them connected?
amazing !!! i did it.
I have CNN model, which segregates images. i was using one Raspberry PI 4 model B ,
But it took like 30 seconds just to load the model. Can I save some time using this cluster i built (of course, with your help) . if yes, how? please help me.

The problem is the technology has moved on and they haven't bothered to update the command line codes. This is riddled with bugs!!! I had to search the internet for hours just to find updated code.
As it notes above, the technology worked at the time of writing.

Can you provide any further information on how you got around the technicalities and provide the updated code to help others create this project on the new version of RPI?
Your coding for step 5 doesn't work please update and/or provide working guide.

How come they share the process in executing the python code. I see that every pi node executed the same script and cracked the same phrase. I can't see any benefit by running the same code that does the same job and has the same output. this is parallel process and not merging the efforts of the 4 nodes to crack one phrase faster or quicker. isn't it?!

I think the problem is not with MPI, the problem is with the python code that you distributed on each node, as the code there is not programmed to make the useful of MPI,. check here https://en.wikipedia.org/wiki/Message_Passing_Interface#Example_program
you will see what i mean.
Can run seti on pi3 cluster
I had another question regarding clustering the devices:
1- can we cluster the Pc and Pi connected to it?
2- can we cluster the Pi and cell phone?
Hi ,
I had a question regarding the 4 pis cluster.
I haven't yet built this cluster, I am in the process to it.
but one question: can we define some time latencies between Pis communication?
I wanna use this project as a Fog layer and as the Fog nodes are in distances, I wanted simulate them by defining time latencies between Pis.
Thank you.
When typing in the mpiexec -n 1 hostname it returns with command not found, please help?
More Comments