Q:
Where can I download an free implementation of MPI?
A:
There are a number of free implementations. The recommended one is
MPICH2
by Argonne National Laboratory.
Q:
Which languages is MPI compatible with?
A:
It is recommended to use C/C++.
Q:
What operating systems support MPICH2?
A:
MPICH2 can be set up on Windows (32 and 64 bits) as well as UNIX.
Q:
I have setup MPICH2 on Windows. What else do I need?
A:
You need to use some C/C++ programming environment (IDE).
It is recommended to use:
-
MinGW
(GNU compiler for C/C++ and linker for Windows)
-
eclipse
(open source IDE).
Q:
How do I write a program in eclipse and how do I compile it?
A:
-
Create a new C project
-
Declare the project parameters (name, path, use of MinGW)
-
When the project appears in the left side, right click on it and select "Properties"
-
Add the include directory "C:\Program Files\MPICH2\include" in Include paths (-I)
-
Add the library directory "C:\Program Files\MPICH2\lib" in Library search path (-L)
-
Create connection with the MPI library C:\Program Files\MPICH2\lib\mpi.lib from the option "Miscellaneous" > "Other objects"
-
Create a new .c file and for your C source code. Give it any name, eg. myprog.c
-
After the file myprog.c write your C code in it
-
After you've written the code, build the application selecting the "hammer" icon (or from the menu "Project" > "Build Project")
-
We have now the executable file myprog.exe in folder C:\mpi\myprog\Debug\.
Q: I have created the executable myprog.exe. How do I run it?
A: There are a number of options:
- If you have acces to a computer cluster then the command, for example,
mpiexec -n 8 myprog.exe
generates 8 processes which run on machines chosen by MPI from the set of available machines.
Alternatively, you can use the command
mpiexec -hosts 3 machine1 3 machine2 4 machine3 1 myprog.exe
generating a total of 8 processes executing on machines: machine1,
machine2, and machine3.
With this command we tell MPI that machine1 will execute 3 processes
machine2 will execute 4 processes and
machine3 will execute 1 process.
- If only one machine is available, we can emulate parallel execution. For example, using the command
mpiexec -localonly 5 myprog.exe
we generate a total of 5 processes which run locally and can exchange messages through network loopback.
This is a very useful option for debugging programs, especially when a computer cluster is not readily available.
Note: if we just run
myprog.exe
then only 1 process will be generated, so there is no parallel execution. This is equivalent to the command
mpiexec -n 1 myprog.exe