LinuxCommandLibrary

mpicxx

Compile MPI C++ programs

TLDR

View documentation for the original command

$ tldr mpic++
copy

SYNOPSIS

mpicxx [options] source_files... [-o output_file]

PARAMETERS

source_files...
    One or more C++ source files (e.g., .cpp, .cc) or object files (.o) to be compiled and/or linked. These are passed directly to the underlying compiler.

-o output_file
    Specify the name of the executable output_file generated after successful compilation and linking.

-c
    Compile or assemble the source files, but do not link. This creates object files (.o) from source files.

-Idirectory
    Add directory to the list of directories to be searched for header files. While mpicxx automatically adds MPI headers, this is used for user-defined or third-party headers.

-Ldirectory
    Add directory to the list of directories to be searched for library files. Similar to -I, mpicxx handles MPI libraries, but this is for additional libraries.

-llibrary
    Link with the specified library. The mpicxx wrapper automatically links necessary MPI libraries, but this is used for other system or user libraries (e.g., -lm for math library).

-Dmacro[=value]
    Define a preprocessor macro. Can be used to conditionally compile code or define constants.

-g
    Produce debugging information in the output file, enabling debugging tools like GDB.

-O[level]
    Optimize the compiled code. level specifies the optimization level (e.g., -O, -O2, -O3, -Os).

-std=standard
    Specify the C++ language standard to be used (e.g., c++11, c++14, c++17, c++20).

--showme
    (Open MPI specific) Display the full command line that mpicxx would execute, without actually running it. Useful for debugging build issues or integrating with other build systems.

--showme:compile
    (Open MPI specific) Display the compilation flags that mpicxx uses, without the linking flags.

--showme:link
    (Open MPI specific) Display the linking flags that mpicxx uses, without the compilation flags.

DESCRIPTION

mpicxx is a convenient wrapper script provided by Message Passing Interface (MPI) implementations, such as Open MPI or MPICH. It is not a compiler itself, but rather a front-end that simplifies the compilation and linking of C++ programs utilizing the MPI library. When invoked, mpicxx automatically determines and passes the correct compiler flags, include paths, and library paths to an underlying C++ compiler (like g++ or clang++). This automates the complex process of setting up the build environment for MPI applications, ensuring that the necessary MPI header files are found and the MPI libraries are correctly linked. Its primary purpose is to abstract away the platform-specific details of MPI installation, allowing developers to compile MPI C++ code using a standardized command across various systems.

CAVEATS

mpicxx is a wrapper script, not a compiler itself. It relies on an underlying C++ compiler (like g++ or clang++) and a correctly installed MPI implementation. Its behavior and specific options (especially wrapper-specific ones like --showme) can vary slightly depending on the MPI distribution (e.g., Open MPI, MPICH, Intel MPI) and its configuration.

PURPOSE OF THE WRAPPER

The primary benefit of using mpicxx over directly invoking the C++ compiler (e.g., g++) is convenience and portability. It ensures that your MPI program is compiled and linked against the correct MPI libraries and headers without requiring manual specification of complex command-line arguments. This makes your build scripts more portable across different systems, as long as an MPI implementation is installed and mpicxx is in the PATH.

UNDERLYING COMPILER SELECTION

The specific C++ compiler that mpicxx uses (e.g., g++, clang++) is determined during the MPI library's configuration and installation process. Users can sometimes override this default by setting environment variables (e.g., MPICXX_CC for some implementations) or by reconfiguring their MPI installation. To find out which underlying compiler is used, you can often run mpicxx --showme.

HISTORY

The concept of MPI compiler wrappers like mpicxx emerged alongside the development and widespread adoption of the MPI standard in the mid-1990s. As MPI gained prominence for parallel computing, the need to simplify the compilation process for MPI applications became evident. These wrappers were created as part of major MPI implementations (like MPICH and later Open MPI) to abstract away the complexity of managing compiler flags, include paths, and library dependencies specific to each MPI installation. This greatly streamlined the development workflow for parallel C++ programs, making MPI more accessible to a wider range of developers.

SEE ALSO

mpicc(1), mpif90(1), mpirun(1), mpiexec(1), g++(1), make(1)

Copied to clipboard