After a great deal of effort, I’ve finally finished compiling Sage 5.5 on the Raspberry Pi. It seems to be basically functional; it starts and adds 2+2 successfully. (So already it’s doing better than Trurl’s Machine.) I’m currently running the full test suite, which could very well take a few days. We’ll see when it gets there. For now, here’s a link to a binary; drop me a line if you have trouble with it. To get started, extract it with:
tar -xvpf sage-5.5-pi.tar.bz2
Then cd into the resulting directory and run “./sage” from the command line, or set up a link which runs “[full-path-to-sage]/sage -notebook()]”, which will automatically open a sage notebook in a browser.
If you’re curious about building sage yourself, there are details after the jump. It requires a bit of blood and something like 3 days of processor time, with somewhere south of 3 days of additional time used by the swap memory.
The gory details:
- This was a long, long process. The full build took 6.32 days of ‘real’ time (plus some extra down time a couple times when things were stopped for a few hours while I slept), but only 2.9 days of processor time. This discrepancy is discussed in point 3, below.
- The Sage build is broken up into ‘spkg’ files, essentially many different components of Sage which need to be built. This modularity is actually quite helpful, since if the build is interrupted for any reason, it restarts on the last spkg it was working on instead of starting over from scratch.
- I ran the build on an 8gb USB stick with 3gb set aside as swap. You have to set aside a large amount of swap in order for the build to succeed. The USB ports on the Pi are known to have much better throughput than the SD reader, so it’s better to build on an attached drive. It would be best to use an external mechanical hard drive, both due to good write speed and because utilizing a USB key as swap space is pretty dumb and will greatly shorten the life of the drive. I didn’t have easy access to an external mechanical hard drive, so used a USB key. (Actually, I do have an external drive, but the Pi doesn’t supply enough power to spin it up; so an external drive should either be wall-powered or running from an attached powered USB hub.)
- The build really uses the swap quite a bit; the 512mb of memory isn’t quite enough. You can make things a bit better by running headless and not starting the X server and setting aside 0mb of memory for the video card, using raspi-config. But still the swap is heavily used. The worst instance is in building libm4rie, which took about 100 minutes of CPU time and almost three days of real time, the great majority of which was spent waiting for read/writes to the swap memory.
- I also managed to speed things up a bit by using ‘nice’ to greatly increase the priority of the build. In the Sage directory, start the compilation with:
sudo nice -n -20 make
- Probably the most fiddly part technically was building the Tachyon package. (Everything else you can deal with by just waiting longer!) The ‘tachyon’ spkg fails to build out of the box because it doesn’t recognize the ‘armv6l’ architecture. To fix this, you need to unpack the tachyon spkg (which lives in sage-X/spkg/standard) and edit the spkg-install file. In this file, find the sole reference to the ‘armv7l’ and change the 7 to a 6 and you’ll be good to go. Repack the spkg, put it back in the original directory where you found it, and all will be ok. (This old Sage trac ticket was very helpful in figuring out the problem. And here’s the Sage page on building spkgs.)
Finally, here’s a bunch of data on how long all of the various spkg’s took, sorted by ‘real’ time. When you see a large discrepancy between ‘real’ time and the sum of the user and system columns, it indicates a package that used a lot of swap in the build process.
This seems like a case where something like distcc (http://code.google.com/p/distcc/) would be helpful.
Or actually, I guess it would be just as reasonable to just use a cross-compiler to compile everything on a more powerful system.
I looked into cross-compiling, but it’s actually not terribly feasible for Sage. Certain components, like Atlas, ‘tune’ themselves to the particular processor you’re compiling on, running hundreds of tests to find cut-off points for where to use different kinds of algorithms and so on; building with another processor would undermine this tuning process. It would be nice if one could selectively cross-compile, building most of the packages on a fast computer and building just a few on the actual machine. But this would have been even more of a project.
Distcc, on the other hand, looks just great. I’ll probably have a few spare Pi’s kicking around at some point, and it will be great to be able to attach the bunch of them to a switch and see about speeding up the process by a factor of ‘a bunch.’
Thank you for posting the binaries. I gave up trying to build past libm4rie.