compiling mpich2 for Android and running on two phones
I have managed to cross-compile mpich2-1.3.2 for ARMv5 platforms (almost all Android phones).
To compile it you need to create an ARM-EABI toolchain using buildroot and then link it static against uclibc. I did not try to link it against Bionic.
To link it static, you just need to pass the -static argument to LDFLAGS before executing configure:
CFLAGS="... -march=armv5 -mfpu=vfp -static ..." CC=arm-linux-gcc ./configure --prefix=/system --host=arm-linux --with-pm=smpd --with-device=ch3:sock --disable-f77 --disable-fc
The output should be a static executable for ARM:
$ file bin/mpiexec bin/mpiexec: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
Onces the binaries / configuration files are copied to each phone, there are three things to sort out:
a) home folder (used to store smpd passwords)
b) hostnames (otherwise all reports will appear as localhost)
c) cannot compile code on phones themselves
a) I am using DroidSSHd as an SSH server (based on dropbear) for Android. By default it sets the home folder to /sdcard. However, smpd cannot work like that, since it will complain about the permissions (on Android, /sdcard is mounted in a special way and you cannot change permissions accordingly).
If you try, there will be many error lines like:
.smpd file, /sdcard/.smpd, cannot be readable by anyone other than the current user, please set permissions accordingly (0600)
This is easily fixed by using:
export HOME=/data/local/tmp
This has to be executed on both phones of course. This is also where you’ll put the hosts.cfg file also.
b) By default, MPI_Get_processor_name returns value “localhost” which makes it useless for debugging purposes. There’s an easy fix too:
# hostname <phone_name>
c) Compiling on the phone is not impossible, but doesn’t worth the try. You need the compiler installed too (arm-linux-gcc) with all dependencies, which is a big deployment (and normal phones have limited space on /system partition)
The code can be easily cross-compiled on the build machine (where mpich2 was compiled). I’ve tried the code below:
#include <mpi.h>
#include <stdio.h>
int main( int argc, char * argv[ ] )
{
int processId; /* rank of process */
int noProcesses; /* number of processes */
int nameSize; /* length of name */
char computerName[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &noProcesses);
MPI_Comm_rank(MPI_COMM_WORLD, &processId);
MPI_Get_processor_name(computerName, &nameSize);
fprintf(stderr,"Hello from process %d on %s\n", processId, computerName);
MPI_Finalize( );
return 0;
}
and after giving a host name to each phone and started smpd on each phone, the output was the following:
[root@arc]/data/local/tmp# mpiexec -machinefile hosts.cfg -n 4 hello Hello from process 0 on arc Hello from process 1 on arc Hello from process 3 on x10_mini Hello from process 2 on x10_mini
I can only imagine what if mobile phones could share resources commonly as idling PCs are doing around the world. The trouble is of course battery life …



