The main aim of building my Raspberry Pi Cluster was so that I could run octave code on it, now I’m not expecting to break any records, but ideally I want some performance. The best way I found to do this was with the parallel’s package.
With octave and the parallels package installed on each of the Raspberry Pi 2’s in the cluster, I setup SSH so that no passwords are required between the nodes. The first step in running the octave scripts was to launch the parallels server on each of theĀ 3 other Raspberry Pi’s that I’m not connected to
\#!/bin/bash
USERNAME=pi
HOSTS="rpi1 rpi2 rpi3"
SCRIPT="cd Documents/Octave; octave -q clusterStart.m"
for HOSTNAME in \${HOSTS} ; do
ssh -l \${USERNAME} \${HOSTNAME} "\${SCRIPT}"
done
This launches Octave and runs the following script:
pkg load parallel
addpath("\~/Documents/Octave/");
addpath("\~/Documents/Octave/Server");
pserver
With each of these raspberry pi’s now running on the 3 other Pi’s it is now possible to send simple commands to them and get the results returned to the first Pi. The octave script that I used to test this out is bellow
clear;
pkg load parallel
hosts = { 'rpi0', 'rpi1', 'rpi2', 'rpi3' };
sockets = connect(hosts);
psum = zeros(1,3);
reval( "send(sum(\[1:10\]),sockets(1,:))", sockets(2,:));
reval( "send(sum(\[11:20\]),sockets(1,:))", sockets(3,:));
reval( "send(sum(\[21:30\]),sockets(1,:))",sockets(4,:));
psum(1) = recv(sockets(2,:));
psum(2) = recv(sockets(3,:));
psum(3) = recv(sockets(4,:));
sum(psum)
scloseall(sockets);
This sets up the sockets for all 4 Raspberry Pi’s including the one the code is run on (rpi0) and the 3 that are running the pserver (rpi1, rpi2 and rpi3). The code then sends commands as strings to be evaluated at the pserver’s, which in this case are simple summation’s, and then return the values to rpi0, which adds the 3 values they generated together and displays it on the screen.
The next step for me in this project is to get it running my Twitter Sentiment Code.