MPICH: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | # Overview | |
| 2 | 2 | ||
| 3 | 3 | MPICH 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. | |
| 4 | 4 | ||
| 5 | 5 | MPICH is a library plus tools to run a ring of daemons. This means, MPICH must be installed on every machine. | |
| 6 | 6 | ||
| 7 | 7 | The 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. | |
| 8 | 8 | ||
| 9 | 9 | # Tutorial | |
| 10 | 10 | ||
| 11 | 11 | ## Windows | |
| 12 | 12 | ||
| 13 | 13 | You 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. | |
| 14 | 14 | ||
| 15 | 15 | See here about authentification: [mpich2-doc-windev.pdf](http://www.mcs.anl.gov/research/projects/mpich2/documentation/files/mpich2-doc-windev.pdf) | |
| 16 | 16 | ||
| 17 | 17 | The best way is to put all nodes into a domain and use SSPI. | |
| 18 | 18 | ||
| 19 | 19 | For simple testing mpi under windows, you can use the Start \\ Programs \\ MPICH2 \\ wmpiregister.exe and save username and password: | |
| 20 | 20 | ||
| 21 | - | ||
| 21 | + | ``` pascal | |
| 22 | + | C:\Program Files\MPICH2\bin\wmpiregister.exe | |
| 23 | + | ``` | |
| 22 | 24 | ||
| 23 | 25 | There you must give a valid windows user name and password. | |
| 24 | 26 | ||
| 25 | 27 | Then open a console and run: | |
| 26 | 28 | ||
| 27 | - | ||
| 29 | + | ``` pascal | |
| 30 | + | C:\Program Files\MPICH2\bin\mpiexec.exe -n 10 C:\Program Files\MPICH2\examples\cpi.exe | |
| 31 | + | ``` | |
| 28 | 32 | ||
| 29 | 33 | ## Unix | |
| 30 | 34 | ||
| 31 | 35 | First 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. | |
| 32 | 36 | ||
| 33 | 37 | ### Ubuntu / Debian | |
| 34 | 38 | ||
| 35 | 39 | Under ubuntu/debian you can install the following packages: libmpich-mpd1.0-dev mpich-mpd-bin | |
| 36 | 40 | ||
| 37 | 41 | There's a how-to for installing Mpich2 in Ubuntu/Debian in Ubuntu Wiki : <https://wiki.ubuntu.com/MpichCluster> | |
| 38 | 42 | ||
| 39 | 43 | ### Install from source | |
| 40 | 44 | ||
| 41 | 45 | Download the mpich2-1.0.6.tar.gz or any newer version from <http://www-unix.mcs.anl.gov/mpi/mpich2/> and unpack it. | |
| 42 | 46 | ||
| 43 | 47 | Read the README carefully. It describes, what you need to compile mpich. Under ubuntu feisty: *sudo apt-get install build-essential*. | |
| 44 | 48 | ||
| 45 | 49 | You need a shared directory for all nodes. In the following steps it is assumed that the home directory is shared. | |
| 46 | 50 | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 51 | + | ```text | |
| 52 | + | ./configure --prefix=/home/you/mpich-install | |
| 53 | + | make | |
| 54 | + | sudo make install | |
| 55 | + | ``` | |
| 50 | 56 | ||
| 51 | 57 | This 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: | |
| 52 | 58 | ||
| 53 | 59 | - add the following line to /etc/fpc.cfg | |
| 54 | 60 | ||
| 55 | 61 | -Fl/home/username/mpich-install/lib | |
| 56 | 62 | ||
| 57 | 63 | - add the path to IDE menu / Project / Compiler Options / Paths / Libraries | |
| 58 | 64 | ||
| 59 | 65 | Otherwise you will get errors like */usr/bin/ld: cannot find -lmpich*. | |
| 60 | 66 | ||
| 61 | 67 | ### Configuration | |
| 62 | 68 | ||
| 63 | 69 | Make sure your PATH contains the path to the mpich binaries. If not extend your path: | |
| 64 | 70 | ||
| 65 | - | ||
| 71 | + | ```text | |
| 72 | + | export PATH=/home/you/mpich-install/bin:$PATH | |
| 73 | + | ``` | |
| 66 | 74 | ||
| 67 | 75 | Check everything works: | |
| 68 | 76 | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - | ||
| 77 | + | ```text | |
| 78 | + | which mpd | |
| 79 | + | which mpiexec | |
| 80 | + | which mpirun | |
| 81 | + | ``` | |
| 72 | 82 | ||
| 73 | 83 | MPI expects the configuration file in your home directory named **/home/you/.mpd.conf** (/etc/mpd.conf if root). It should contain one line: | |
| 74 | 84 | ||
| 75 | - | ||
| 85 | + | ```text | |
| 86 | + | secretword=<secretword> | |
| 87 | + | ``` | |
| 76 | 88 | ||
| 77 | 89 | where \<secretword\> is a password, that should **not** be your user password. Make it readable/writable only by you: | |
| 78 | 90 | ||
| 79 | - | ||
| 91 | + | ```text | |
| 92 | + | chmod 600 .mpd.conf | |
| 93 | + | ``` | |
| 80 | 94 | ||
| 81 | 95 | If 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: | |
| 82 | 96 | ||
| 83 | - | ||
| 97 | + | ```text | |
| 98 | + | ssh othermachine date | |
| 99 | + | ``` | |
| 84 | 100 | ||
| 85 | 101 | should not ask for password and give only the date - nothing else. | |
| 86 | 102 | ||
| 87 | 103 | Create a file named **/home/you/mpd.hosts** with one line per node (hostnames). For example | |
| 88 | 104 | ||
| 89 | - | ||
| 90 | - | ||
| 105 | + | ```text | |
| 106 | + | host1 | |
| 107 | + | host2 | |
| 108 | + | ``` | |
| 91 | 109 | ||
| 92 | 110 | ### Test MPD | |
| 93 | 111 | ||
| 94 | 112 | MPD is the MPICH daemon, which controls/runs/stops the proccesses on the cluster nodes. Bring up the ring: | |
| 95 | 113 | ||
| 96 | - | ||
| 97 | - | ||
| 98 | - | ||
| 114 | + | ```text | |
| 115 | + | mpd & | |
| 116 | + | mpdtrace | |
| 117 | + | mpdallexit | |
| 118 | + | ``` | |
| 99 | 119 | ||
| 100 | 120 | mpdtrace should output the hostname of your current working host. mpdallexit stops the daemon. | |
| 101 | 121 | ||
| 102 | 122 | #### Start mpd on some machines | |
| 103 | 123 | ||
| 104 | - | ||
| 124 | + | ```text | |
| 125 | + | mpdboot -n <number of daemons to start> -f /home/username/mpd.hosts | |
| 126 | + | ``` | |
| 105 | 127 | ||
| 106 | 128 | If the current machine is not part of the cluster (not in the mpd.hosts), then you need one additional mpd (add +1). | |
| 107 | 129 | ||
| 108 | 130 | Test: | |
| 109 | 131 | ||
| 110 | - | ||
| 111 | - | ||
| 112 | - | ||
| 113 | - | ||
| 132 | + | ```text | |
| 133 | + | mpdtrace | |
| 134 | + | mpdringtest | |
| 135 | + | mpdringtest 100 | |
| 136 | + | mpiexec -l -n 30 hostname | |
| 137 | + | ``` | |
| 114 | 138 | ||
| 115 | 139 | ### Test an MPI program | |
| 116 | 140 | ||
| 117 | 141 | Don't forget to start mpd via **mpdboot**. | |
| 118 | 142 | ||
| 119 | 143 | Then, copy the cpi example to a shared location: | |
| 120 | 144 | ||
| 121 | - | ||
| 122 | - | ||
| 145 | + | ```text | |
| 146 | + | cp mpich2-1.0.6/examples/cpi ~/cpi | |
| 147 | + | mpiexec -n 5 /home/you/cpi | |
| 148 | + | ``` | |
| 123 | 149 | ||
| 124 | 150 | The number of proccess (here: 5) can exceed the number of hosts. mpiexec has many options. See **mpiexec -help** and read the README. | |
| 125 | 151 | ||
| 126 | 152 | ## Get/Compile the MPI bindings for Free Pascal / Lazarus | |
| 127 | 153 | ||
| 128 | 154 | Download the MPICH bindings as lazarus package from [1](http://sourceforge.net/projects/lazarus-ccr/files/MPICH/). | |
| 129 | 155 | ||
| 130 | 156 | Extract the zip file, use **IDE / components / open package file (.lpk)** to open the mpich2.lpk file and compile the package. | |
| 131 | 157 | ||
| 132 | 158 | ### Windows | |
| 133 | 159 | ||
| 134 | 160 | Under windows the library **External_library** constant of the mpi.pas must be changed to 'mpich2'. This will be fixed in the next release. | |
| 135 | 161 | ||
| 136 | 162 | ## Create the first Free Pascal MPI program | |
| 137 | 163 | ||
| 138 | 164 | Create a new project (custom project, not an application). Save the project as /home/username/helloworld.lpi. | |
| 139 | 165 | ||
| 140 | 166 | Open 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. | |
| 141 | 167 | ||
| 142 | 168 | Here is a very small MPI program: | |
| 143 | 169 | ||
| 144 | 170 | ``` pascal | |
| 145 | 171 | program HelloWorld1; | |
| 146 | 172 | ||
| 147 | 173 | {$mode objfpc}{$H+} | |
| 148 | 174 | {$IDFEF Unix} | |
| 149 | 175 | {$Linklib c} | |
| 150 | 176 | {$ENDIF} | |
| 151 | 177 | // if you get the error: undefined reference to `pthread_getspecific' then enable the following: | |
| 152 | 178 | {off $Linklib pthread} | |
| 153 | 179 | ||
| 154 | 180 | uses | |
| 155 | 181 | MPI; | |
| 156 | 182 | ||
| 157 | 183 | var myid: integer; | |
| 158 | 184 | begin | |
| 159 | 185 | MPI_Init(@argc,@argv); | |
| 160 | 186 | MPI_Comm_rank(MPI_COMM_WORLD,@myid); | |
| 161 | 187 | writeln('id=',myid); | |
| 162 | 188 | MPI_Finalize; | |
| 163 | 189 | end. | |
| 164 | 190 | ``` | |
| 165 | 191 | ||
| 166 | 192 | You can find this program in the examples directory too. | |
| 167 | 193 | ||
| 168 | 194 | Compile the program to create the *helloworld* executable. | |
| 169 | 195 | ||
| 170 | 196 | (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.) | |
| 171 | 197 | ||
| 172 | 198 | ## Run your MPI program | |
| 173 | 199 | ||
| 174 | 200 | Now run it like the above cpi example. That means: | |
| 175 | 201 | ||
| 176 | 202 | ### Unix | |
| 177 | 203 | ||
| 178 | 204 | - 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. | |
| 179 | 205 | - Copy the helloworld executable to a shared directory: | |
| 180 | 206 | ||
| 181 | - | ||
| 207 | + | ```text | |
| 208 | + | cp helloworld /home/username/helloworld | |
| 209 | + | ``` | |
| 182 | 210 | ||
| 183 | 211 | - start it with | |
| 184 | 212 | ||
| 185 | - | ||
| 213 | + | ```text | |
| 214 | + | mpiexec -n 3 /home/username/helloworld | |
| 215 | + | ``` | |
| 186 | 216 | ||
| 187 | 217 | This will give something like: | |
| 188 | 218 | ||
| 189 | - | ||
| 190 | - | ||
| 191 | - | ||
| 219 | + | ```text | |
| 220 | + | id=1 | |
| 221 | + | id=0 | |
| 222 | + | id=2 | |
| 223 | + | ``` | |
| 192 | 224 | ||
| 193 | 225 | Note that programs are started in parallel, so the order of the id lines depends on machine and network speeds. | |
| 194 | 226 | ||
| 195 | 227 | ### Windows | |
| 196 | 228 | ||
| 197 | - | ||
| 229 | + | ``` pascal | |
| 230 | + | C:\Program Files\MPICH2\bin\mpiexec.exe helloworld.exe | |
| 231 | + | ``` | |
| 198 | 232 | ||
| 199 | 233 | This will give something like: | |
| 200 | 234 | ||
| 201 | - | ||
| 202 | - | ||
| 203 | - | ||
| 235 | + | ```text | |
| 236 | + | id=1 | |
| 237 | + | id=0 | |
| 238 | + | id=2 | |
| 239 | + | ``` | |
| 204 | 240 | ||
| 205 | 241 | Note that programs are started in parallel, so the order of the id lines depends on machine and network speeds. | |
| 206 | 242 | ||
| 207 | 243 | --- | |
| 208 | 244 | *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).* | |
| 209 | 245 | Category: Components | |
| 210 | 246 | Category: Networking | |
| 211 | 247 | Category: Parallel programming |
