Sign in Join
Wiki copytemporary

MPICH: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# Overview
22
33MPICH is a free implementation of [MPI](http://www.mcs.anl.gov/mpi/index.htm) (Message Passing Interface) for distributed memory applications. The latest version MPICH2 implements the MPI-2 standard.
44
55MPICH is a library plus tools to run a ring of daemons. This means, MPICH must be installed on every machine.
66
77The MPICH2 lazarus package contains the bindings (= pascal translations of the c header files), which allows pascal programs to use the same variables and functions as c programs would do. So, you can easily convert c examples to pascal.
88
99# Tutorial
1010
1111## Windows
1212
1313You can download an installer from <http://www.mcs.anl.gov/research/projects/mpich2/>. The installer requires Administrative rights to install the smpd service. This will install MPICH2 to C:\Program Files\MPICH2. You must install mpich on all nodes (computers of the cluster). The mpich2 dll(s) are copied to the Windows\system32 directory. The bin directory contains smpd.exe which is the MPICH2 process manager used to launch MPI programs. mpiexec.exe, also found in the bin directory, is used to start MPICH2 jobs. See the README.winbin.rtf for details and hints like minimal installation for nodes.
1414
1515See here about authentification: [mpich2-doc-windev.pdf](http://www.mcs.anl.gov/research/projects/mpich2/documentation/files/mpich2-doc-windev.pdf)
1616
1717The best way is to put all nodes into a domain and use SSPI.
1818
1919For simple testing mpi under windows, you can use the Start \\ Programs \\ MPICH2 \\ wmpiregister.exe and save username and password:
2020
21-` C:\Program Files\MPICH2\bin\wmpiregister.exe`
21+``` pascal
22+ C:\Program Files\MPICH2\bin\wmpiregister.exe
23+```
2224
2325There you must give a valid windows user name and password.
2426
2527Then open a console and run:
2628
27-` C:\Program Files\MPICH2\bin\mpiexec.exe -n 10 C:\Program Files\MPICH2\examples\cpi.exe`
29+``` pascal
30+ C:\Program Files\MPICH2\bin\mpiexec.exe -n 10 C:\Program Files\MPICH2\examples\cpi.exe
31+```
2832
2933## Unix
3034
3135First you need to install the MPICH2 library on all computers of your cluster. A cluster can be any set of computers / virtual machines. They do not need to be homogeneous. Your cluster can contain for example Windows and Linux machines, with different number of CPUs and memory. On your development machines, where you compile your application, you must install the development libraries and FPC too.
3236
3337### Ubuntu / Debian
3438
3539Under ubuntu/debian you can install the following packages: libmpich-mpd1.0-dev mpich-mpd-bin
3640
3741There's a how-to for installing Mpich2 in Ubuntu/Debian in Ubuntu Wiki : <https://wiki.ubuntu.com/MpichCluster>
3842
3943### Install from source
4044
4145Download the mpich2-1.0.6.tar.gz or any newer version from <http://www-unix.mcs.anl.gov/mpi/mpich2/> and unpack it.
4246
4347Read the README carefully. It describes, what you need to compile mpich. Under ubuntu feisty: *sudo apt-get install build-essential*.
4448
4549You need a shared directory for all nodes. In the following steps it is assumed that the home directory is shared.
4650
47-` ./configure --prefix=/home/you/mpich-install`\
48-` make`\
49-` sudo make install`
51+```text
52+ ./configure --prefix=/home/you/mpich-install
53+ make
54+ sudo make install
55+```
5056
5157This will install the libraries in /home/you/mpich-install/lib. This path must be added to the linking search path of FPC. There are two common possibilities:
5258
5359- add the following line to /etc/fpc.cfg
5460
5561-Fl/home/username/mpich-install/lib
5662
5763- add the path to IDE menu / Project / Compiler Options / Paths / Libraries
5864
5965Otherwise you will get errors like */usr/bin/ld: cannot find -lmpich*.
6066
6167### Configuration
6268
6369Make sure your PATH contains the path to the mpich binaries. If not extend your path:
6470
65-` export PATH=/home/you/mpich-install/bin:$PATH`
71+```text
72+ export PATH=/home/you/mpich-install/bin:$PATH
73+```
6674
6775Check everything works:
6876
69-` which mpd`\
70-` which mpiexec`\
71-` which mpirun`
77+```text
78+ which mpd
79+ which mpiexec
80+ which mpirun
81+```
7282
7383MPI expects the configuration file in your home directory named **/home/you/.mpd.conf** (/etc/mpd.conf if root). It should contain one line:
7484
75-` secretword=<secretword>`
85+```text
86+ secretword=<secretword>
87+```
7688
7789where \<secretword\> is a password, that should **not** be your user password. Make it readable/writable only by you:
7890
79-` chmod 600 .mpd.conf`
91+```text
92+ chmod 600 .mpd.conf
93+```
8094
8195If your home is not shared, it must be copied to all cluster nodes. Check that you can login via ssh without password to all cluster nodes:
8296
83-` ssh othermachine date`
97+```text
98+ ssh othermachine date
99+```
84100
85101should not ask for password and give only the date - nothing else.
86102
87103Create a file named **/home/you/mpd.hosts** with one line per node (hostnames). For example
88104
89-` host1`\
90-` host2`
105+```text
106+ host1
107+ host2
108+```
91109
92110### Test MPD
93111
94112MPD is the MPICH daemon, which controls/runs/stops the proccesses on the cluster nodes. Bring up the ring:
95113
96-`  mpd &`\
97-`  mpdtrace`\
98-`  mpdallexit`
114+```text
115+ mpd &
116+ mpdtrace
117+ mpdallexit
118+```
99119
100120mpdtrace should output the hostname of your current working host. mpdallexit stops the daemon.
101121
102122#### Start mpd on some machines
103123
104-` mpdboot -n <number of daemons to start> -f /home/username/mpd.hosts`
124+```text
125+ mpdboot -n <number of daemons to start> -f /home/username/mpd.hosts
126+```
105127
106128If the current machine is not part of the cluster (not in the mpd.hosts), then you need one additional mpd (add +1).
107129
108130Test:
109131
110-` mpdtrace`\
111-` mpdringtest`\
112-` mpdringtest 100`\
113-` mpiexec -l -n 30 hostname`
132+```text
133+ mpdtrace
134+ mpdringtest
135+ mpdringtest 100
136+ mpiexec -l -n 30 hostname
137+```
114138
115139### Test an MPI program
116140
117141Don't forget to start mpd via **mpdboot**.
118142
119143Then, copy the cpi example to a shared location:
120144
121-` cp mpich2-1.0.6/examples/cpi ~/cpi`\
122-` mpiexec -n 5 /home/you/cpi`
145+```text
146+ cp mpich2-1.0.6/examples/cpi ~/cpi
147+ mpiexec -n 5 /home/you/cpi
148+```
123149
124150The number of proccess (here: 5) can exceed the number of hosts. mpiexec has many options. See **mpiexec -help** and read the README.
125151
126152## Get/Compile the MPI bindings for Free Pascal / Lazarus
127153
128154Download the MPICH bindings as lazarus package from [1](http://sourceforge.net/projects/lazarus-ccr/files/MPICH/).
129155
130156Extract the zip file, use **IDE / components / open package file (.lpk)** to open the mpich2.lpk file and compile the package.
131157
132158### Windows
133159
134160Under windows the library **External_library** constant of the mpi.pas must be changed to 'mpich2'. This will be fixed in the next release.
135161
136162## Create the first Free Pascal MPI program
137163
138164Create a new project (custom project, not an application). Save the project as /home/username/helloworld.lpi.
139165
140166Open the mpich2 package (e.g. **IDE / Components / Open recent package / somepath/mpich2.lpk**). This opens the package editor. Then do **More / Add to project**. The project can now use the mpich2 bindings.
141167
142168Here is a very small MPI program:
143169
144170``` pascal
145171program HelloWorld1;
146172
147173{$mode objfpc}{$H+}
148174{$IDFEF Unix}
149175{$Linklib c}
150176{$ENDIF}
151177// if you get the error: undefined reference to `pthread_getspecific' then enable the following:
152178{off $Linklib pthread}
153179
154180uses
155181 MPI;
156182
157183var myid: integer;
158184begin
159185 MPI_Init(@argc,@argv);
160186 MPI_Comm_rank(MPI_COMM_WORLD,@myid);
161187 writeln('id=',myid);
162188 MPI_Finalize;
163189end.
164190```
165191
166192You can find this program in the examples directory too.
167193
168194Compile the program to create the *helloworld* executable.
169195
170196(For Windows users: the examples contain the linklib directive for all platforms, but it must not be used under windows. This will be fixed in the next release. Adapt the examples as seen in the above example.)
171197
172198## Run your MPI program
173199
174200Now run it like the above cpi example. That means:
175201
176202### Unix
177203
178204- First check with **mpdtrace** if the **mpd** is still running. If not, then use **mpdboot -n \<number of hosts\> -f /home/username/mpd.hosts** to start the daemons.
179205- Copy the helloworld executable to a shared directory:
180206
181-` cp helloworld /home/username/helloworld`
207+```text
208+ cp helloworld /home/username/helloworld
209+```
182210
183211- start it with
184212
185-` mpiexec -n 3 /home/username/helloworld`
213+```text
214+ mpiexec -n 3 /home/username/helloworld
215+```
186216
187217This will give something like:
188218
189-` id=1`\
190-` id=0`\
191-` id=2`
219+```text
220+ id=1
221+ id=0
222+ id=2
223+```
192224
193225Note that programs are started in parallel, so the order of the id lines depends on machine and network speeds.
194226
195227### Windows
196228
197-` C:\Program Files\MPICH2\bin\mpiexec.exe helloworld.exe`
229+``` pascal
230+ C:\Program Files\MPICH2\bin\mpiexec.exe helloworld.exe
231+```
198232
199233This will give something like:
200234
201-` id=1`\
202-` id=0`\
203-` id=2`
235+```text
236+ id=1
237+ id=0
238+ id=2
239+```
204240
205241Note that programs are started in parallel, so the order of the id lines depends on machine and network speeds.
206242
207243---
208244*From the Free Pascal wiki, page "MPICH", as it stood on 2020-02-20 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
209245Category: Components
210246Category: Networking
211247Category: Parallel programming

Back to history