I have done some previous work with MPAPI and found it to be a capable framework that I would highly recommend. However, that initial choice was because I had significant difficulty compiling MPI.NET under Ubuntu. I've since resolve those difficulties, so today we will discuss building MPI.NET under Ubuntu (Oneiric).
Step 1: Download MPI.NET version 1.0.0 from the MPI.NET download page. You want the mpi.net-1.0.0.tar.gz package (source code for Unix).
Step 2: Untar the files and enter the directory:
tar xzvf mpi.net-1.0.0.tar.gzStep 3: Install build prerequisites
cd mpi.net-1.0.0
sudo apt-get install mono-complete libtool automake autoconf build-essentialStep 4: Install an MPI framework
This is subject to some choice. Two good libraries are OpenMPI and MPICH2 which you can install through apt get via one of (do not execute both) of the following commands:
sudo apt-get install libopenmpi-dev openmpi-bin openmpi-docor
sudo apt-get install mpich2 libmpich2-devStep 5: Create a symbolic link from /usr/bin/ilasm to /usr/bin/ilasm2. For some reason that is not clear to me MPI.NET looks for ilasm2 which is not present (wrapped into ilasm?) in later versions of Mono.
ln -s /usr/bin/ilasm /usr/bin/ilasm2Step 6: Download and install patches
Several source files need to be patched to allow successful compilation (see this helpful mailing list posting). Download Makefile.am.patch, Unsafe.pl.patch, and configure.ac.patch from this repository. Save them in the mpi.net-1.0.0 directory.
Apply the patches with the following three commands:
patch configure.ac < configure.ac.patchThese should all complete successfully. If not, check the exact filename you used when you saved the patch. Rename them (or modify the above three commands), as appropriate.
patch MPI/Unsafe.pl < Unsafe.pl.patch
patch MPI/Makefile.am < Makefile.am.patch
Step 7: Run the standard compilation sequence. Everything should complete successfully:
sh autogen.shThe desired MPI.dll and MPI.dll.config is in the MPI subdirectory of the mpi.net-1.0.0.
./configure
make
make install
Step 8: Try creating a hello world program to verify MPI.NET works.
In a new folder, create a source file (Hello.cs) containing a Hello World program similar to the one shown in the MPI.NET tutorial, such as:
using System; using MPI; class MPIHello { static void Main(string[] args) { using (new MPI.Environment(ref args)) { Console.Write("Greetings from node {0} of {1}\n", Communicator.world.Rank, Communicator.world.Size); } } }
Copy MPI.dll and MPI.dll.config to this folder and compile under mono:
gmcs Hello.cs -reference:MPI.dll - target:exe -out:Hello.exeCompilation should succeed without errors or warnings.
Run the resultant program using mpiexec to launch four threads:
mpiexec -np 4 ./Hello.exeIf the resultant output is (the order of lines may vary), then everything is working as expected:
Greetings from node 0 of 4If all this worked, you should now have a working installation of MPI.NET and can use the MPI-2 framework to write parallel and distributed programs.
Greetings from node 2 of 4
Greetings from node 1 of 4
Greetings from node 4 of 4
Further reading
- The full MPI.NET tutorial
- The Message Passing Interfaces article on Wikipedia
- An excellent MPI tutorial (but written for C++ programmers)