mpicc
Compile MPI programs
TLDR
Compile a source code file into an object file
Link an object file and make an executable
Compile and link source code in a single command
SYNOPSIS
mpicc [options] source_files [linker_options]
PARAMETERS
-o file
Specify the output executable or object file name.
-c
Compile source files into object files (.o) without linking.
-Idir
Add dir to the list of directories to be searched for include files.
-Ldir
Add dir to the list of directories to be searched for libraries.
-llib
Link with library lib.
-Dmacro[=value]
Define a macro with an optional value.
-g
Produce debugging information for use with debuggers like gdb.
-O[level]
Optimize the generated code. level can be 0, 1, 2, 3, s, or fast.
-Wall
Enable all commonly used warning messages.
-ansi
Support only the ANSI C standard.
--showme
(Specific to some MPI implementations) Display the underlying compiler command, including all MPI-specific flags, without actually compiling.
DESCRIPTION
mpicc is a convenience wrapper script provided by MPI (Message Passing Interface) implementations like Open MPI or MPICH. It is not a compiler itself, but rather a front-end that invokes the underlying C compiler (e.g., gcc, clang) with the necessary compiler flags, include paths, and library linking options required to build MPI applications.
Its primary purpose is to simplify the compilation process for MPI programs, abstracting away the complex details of locating MPI header files (e.g., mpi.h) and linking against the correct MPI libraries. By using mpicc, developers can compile their parallel C code without manually specifying the often numerous and system-dependent paths and library names. This ensures that the application is correctly linked against the chosen MPI implementation, making the compilation process more portable and less error-prone across different environments.
In essence, running `mpicc program.c -o program` is equivalent to running `gcc program.c -o program -I/path/to/mpi/include -L/path/to/mpi/lib -lmpi ...`, where mpicc automatically provides the `-I` and `-L` arguments.
CAVEATS
- Requires a functional MPI implementation (e.g., Open MPI, MPICH) to be installed and correctly configured on the system.
- The exact behavior and default compiler invoked by mpicc depend on the specific MPI implementation and its configuration.
- While mpicc simplifies compilation, understanding the underlying compiler and linker options can be crucial for debugging complex issues or optimizing performance.
COMPILER CONFIGURATION
The default C compiler used by mpicc can usually be configured during the MPI library's installation or through environment variables (e.g., MPICH_CC for MPICH, or configuration settings for Open MPI).
CROSS-COMPILATION
When cross-compiling MPI applications, special care must be taken as mpicc typically uses the system's native compiler. For cross-compilation, one might need to use specific MPI builds configured for the target architecture, or explicitly provide the cross-compiler via environment variables or mpicc's configuration.
HISTORY
The concept of a compiler wrapper like mpicc emerged with the development of the MPI standard itself in the early 1990s. As MPI implementations became available (e.g., MPICH in 1994, Open MPI in 2004), a consistent and user-friendly way to compile MPI applications was needed. These wrappers abstract the complexities of linking against dynamically evolving MPI libraries and ensuring compatibility with various underlying compilers. mpicc, along with its Fortran and C++ counterparts, became a standard tool for parallel programmers, fostering portability and ease of development in the HPC (High-Performance Computing) community.