Cloud

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 

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 
#include 

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 …

4 Comments

  1. Ahmed Shawky Moussa

    I tried this exactly but it does not work with more than one process. I do not even use 2 devices. I tried to run on only one device. If I type: mpiexec -n 1 /data/hello it works. If I type: mpiexec -n 2 /data/hello it does not work giving the following error:
    Fatal error in MPI_init: Other MPI error, error stack:
    MPIR_Init_thread(474)…………….:
    MPID_Init(190) ……………: channel initialization failed
    MPIDI_CH3_Init(89)………………..:
    MPID_nem_init(272)………………….:
    MPIDI_CH3_Seg_commit(327) ……………….:
    MPIU_SHMW_Seg_create_and_attach(897):
    MPIU_SHMW_Seg_create_attach_templ(610):mkstemp failed Nosuch file or directory

  2. Hemant Tiwari

    Hi Ahmed Shawky Moussa , I am also facing exact same issue, did you get solution to your problem.

  3. Doha

    Hi Hemant Tiwari, probably you have cross compiled MPICH with configuration options that is not suitable with your mobile device.

  4. Cassini

    Same issue here: MPIU_SHMW_Seg_create_attach_templ(610):mkstemp failed Nosuch file or directory
    Do you have any solution for this?

Leave a Reply