Parallelization using OOP is certainly an interesting project, and I hope you did not misunderstand my response. I also enjoy tinkering with such things, and re-implementing things that Mathematica already has built-in. The fun is in learning how to implement something like this. Producing something for practical use is something else.
I was simply correcting the misunderstanding that it is not possible to use the built-in parallel tools with a standard Mathematica install. Mathematica includes everything for parallel computing, even on the Raspberry Pi. It is a fun project to create our own parallelization solution, but is is not necessary.
Here are some more straightforward instructions on getting parallelization working on a Raspberry Pi:
First, set up passwordless authentication:
https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md
Since parts of this article are not 100% clear, I want to clarify that:
- the key-pair needs to be created on the computer which is running the main Mathematica kernel (i.e. the master machine)
- the public key must be copied to the
authorized_keys
files of the slave machines
ssh-agent
must be running on the master machine. It may be necessary to add the private key to the agent using ssh-add path-to-your-key
. If you set a passphrase for the private key, you will need to enter it at this point.
If the master machine is running Windows (not a Unix-like OS like Linux on the RPi or OS X on a Mac), then you can use the GUI tools from the Putty bundle to do the same. There are many tutorials online for this.
Once all this is set up, it should be possible to connect from the master machine to the slaves using ssh without entering a password (except for entering the passphrase once, when adding your private key to the ssh agent). This means that Mathematica will be able to launch new kernels on the slave machine without prompting you to enter a password. Do verify that this works.
Now suppose that the hostname of a slave machine is slave
, and that you will be running the Mathematica kernel under the pi
user. Then start Mathematica on the master kernel and run:
AppendTo[$ConfiguredKernels,
SubKernels`RemoteKernels`RemoteMachine["slave", "ssh -x -f -l pi `1` wolfram -wstp -linkmode Connect `4` -linkname '`2`' -subkernel -noinit -nopaclet", 1, {}]
]
Notice that I changed only one thing compared to the default configuration. I changed -l `3`
to -l pi
. If Mathematica is running under the same username both on the master and slave machines, then this change not necessary and the default launch command may be kept.
As a reminder, the default launch command is contained within
SubKernels`RemoteKernels`$RemoteCommand
If you use the default (i.e. you are using the same username on the host as on the slave), then all this simplifies to
AppendTo[$ConfiguredKernels, SubKernels`RemoteKernels`RemoteMachine["slave"]]
If you want to use more than one kernel on the same slave (when the slave has a multi-core CPU), then use
AppendTo[$ConfiguredKernels, SubKernels`RemoteKernels`RemoteMachine["slave", SubKernels`RemoteKernels`$RemoteCommand, 4 (* number of kernels *)]]
Now you are ready to go! No further setup is necessary. Just use ParallelTable
, ParallelMap
, etc. as usual. As a test, you may want to run LaunchKernels[]
and see if it succeeds. But under normal use, LaunchKernels[]
is called automatically by parallel functions.
This time I did test these instructions by using a Mac as the master computer and a Raspberry Pi as a slave. (Because I do not have two RPi's.)
Once again, all this works with standard Mathematica. Nothing else is needed. It is absolutely not necessary to purchase gridMathematica or the Lightweight Grid. Those products provide you with licenses to run many Mathematica kernels on a non-RPi machine, or automate part of this setup procedure. But they do not provide the parallelization functionality. That is entirely built into standard Mathematica.
The only thing you may need to do to get this to work is load the RemoteKernels package manually:
<<SubKernels`RemoteKernels`