Difference between revisions of "How to Use MPI"
Line 16: | Line 16: | ||
$ module switch intelmpi openmpi | $ module switch intelmpi openmpi | ||
− | === | + | === Intel MPI === |
Look for "intelmpi" in the output of this command: | Look for "intelmpi" in the output of this command: | ||
$ module list | $ module list | ||
Line 23: | Line 23: | ||
$ module load intelmpi | $ module load intelmpi | ||
− | If Open MPI has already been loaded, switch to | + | If Open MPI has already been loaded, switch to Intel MPI like this: |
$ module switch openmpi intelmpi | $ module switch openmpi intelmpi | ||
Line 31: | Line 31: | ||
There are two MPI compilers, one for C/C++ and one for Fortran, but they share most command line options. Depending on whether your code is written in C or Fortran, follow the instructions in one of the tables below. Make sure to replace the arguments inside <…> with specific values. | There are two MPI compilers, one for C/C++ and one for Fortran, but they share most command line options. Depending on whether your code is written in C or Fortran, follow the instructions in one of the tables below. Make sure to replace the arguments inside <…> with specific values. | ||
− | === | + | === Open MPI === |
Use the following command to specify the program you would like to compile (replace <src_file> with a path to your code, e. g. ./myprog.c). | Use the following command to specify the program you would like to compile (replace <src_file> with a path to your code, e. g. ./myprog.c). | ||
Line 47: | Line 47: | ||
|- | |- | ||
| -showme:version || show Open MPI version | | -showme:version || show Open MPI version | ||
+ | |} | ||
+ | |||
+ | === Intel MPI === | ||
+ | |||
+ | Use the following command to specify the program you would like to compile (replace <src_file> with a path to your code, e. g. ./myprog.c). | ||
+ | {| class="wikitable" style="width: 40%;" | ||
+ | | Compiler Driver || C/C++ || Fortran | ||
+ | |- | ||
+ | | GCC || <code>$ mpicc <src_file></code> || <code>$ mpifort <src_file></code> | ||
+ | |- | ||
+ | | Intel || <code>$ mpiicc <src_file></code> || <code>$ mpiifort <src_file></code> | ||
|} | |} | ||
Revision as of 12:37, 4 April 2018
Basics
This will give you a general overview of how to compile and execute a program that has been parallelized with MPI. Many of the options listed below are the same for both Open MPI and Intel MPI, however, be care if they do differentiate.
Loading the Correct Modules
Open MPI
To ensure that the Open MPI module is loaded, check the output of the following command:
$ module list
In case it has not been loaded yet, type
$ module load openmpi
If you are currently using IntelMPIt, type
$ module switch intelmpi openmpi
Intel MPI
Look for "intelmpi" in the output of this command:
$ module list
In case it did not appear in the output, you have to load the module by typing
$ module load intelmpi
If Open MPI has already been loaded, switch to Intel MPI like this:
$ module switch openmpi intelmpi
How to Compile MPI Code
There are two MPI compilers, one for C/C++ and one for Fortran, but they share most command line options. Depending on whether your code is written in C or Fortran, follow the instructions in one of the tables below. Make sure to replace the arguments inside <…> with specific values.
Open MPI
Use the following command to specify the program you would like to compile (replace <src_file> with a path to your code, e. g. ./myprog.c).
C/C++ | Fortran |
$ mpicc <src_file> |
$ mpifort <src_file>
|
You can also type the command $ mpicc [options]
or $ mpifort [options]
. There are a few options that come with Open MPI, however, options are more important for running your program. The compiler options might be useful to fetch more information about the Open MPI module you're using.
Options | Function |
-showme:help | print a short help message about the usage and lists all compiler options |
-showme:version | show Open MPI version |
Intel MPI
Use the following command to specify the program you would like to compile (replace <src_file> with a path to your code, e. g. ./myprog.c).
Compiler Driver | C/C++ | Fortran |
GCC | $ mpicc <src_file> |
$ mpifort <src_file>
|
Intel | $ mpiicc <src_file> |
$ mpiifort <src_file>
|
How to Run an MPI Executable
Ensure that your the correct MPI module is loaded (see here).
Don’t forget to put the “-np” or “-n” option as explained below. All the other options listed below are not mandatory.
Option | Function |
-np <num_procs> or -n <num_procs> | number of processes to run |
-path <path> | look for executables in the directory specified |
-q or –quiet | suppress helpful messages |
-output-filename <name> | redirects output into the file <name>.<rank> |
--help | lists all options available with an explanation |