Friday, 15 June 2012

MPI on the Pi


Understandably, configuring and compiling large C programs on the Raspberry Pi is a process which requires a fair amount of patience. Especially when after 30 minutes ./configure (ing), you get this error:

configure: error: No Fortran 77 compiler found. If you don't need to build any Fortran programs, you can disable Fortran support using --disable-f77 and --disable-fc. If you do want to build Fortran programs, you need to install a Fortran compiler such as gfortran or ifort before you can proceed.

So inevitably;

pi@raspberrypi:~$ sudo ./configure --disable-f77 --disable-fc

I'm sorry Fortran. I do plan to revisit you some day, but attempting to compile and install an MPI on two Raspberry Pi's* is on the agenda today :)

*unnecessary apostrophe, but it looks more attractive than without it...

Sunday, 3 June 2012

NXT Fibonacci

I have just received my Lego NXT Mindstorm! I immediatley flashed LeJOS on the brick, and before I got to work on some AI, I decided to create a little program which represented the Fibonacci sequence terms as bursts of the motors.
import lejos.nxt.*;

public class fib {
 
 public static void main (String[] args) {
  
  //Limit the sequence.
  int fib[] = new int[100];
  
  //First two terms in sequence are 1
  fib[0] = fib[1] = 1;
  
  for (int i = 2; i < fib.length; i++) {
   //Calculate, and print next value in Fibonacci sequence
   fib[i] = fib[i - 1] + fib[i - 2];
   LCD.clear();
   LCD.drawInt(fib[i], 6, 4);
   
   //Move forward for the length of the Fibonacci number
   Motor.C.forward();
   Motor.A.forward();
   try{
    Thread.sleep(fib[i]); 
   } catch (Exception e) {}
   
   //Sleep for a tenth of a second.
   Motor.C.stop();
   Motor.A.stop();
   try{
    Thread.sleep(100);
   } catch (Exception e) {}
  }
 }
}