How to compile MPI with gcc?
Asked Answered
T

6

32

Does anyone know if it is possible to compile MPI with gcc?. I need to use gcc, no mpicc.

Tresatrescha answered 3/7, 2012 at 14:8 Comment(2)
It's possible but why do you want to? Normally, the wrapped compiler (mpicc here) is much more convenient and will have been optimised in some way.Ebullience
for cmake you should not use the wrapper here, because CMake figures out how to compile MPI programs without it.) just use find_package(MPI REQUIRED). It is much cleaner than a wrapper just to set the link/compile flagsSaccharoid
V
35

mpicc is just a wrapper around certain set of compilers. Most implementations have their mpicc wrappers understand a special option like -showme (Open MPI) or -show (Open MPI, MPICH and derivates) that gives the full list of options that the wrapper passes on to the backend compiler.

For example, in Open MPI, wrappers are C++ programs that read plain text configuration files and build command line options that are further passed on to the compiler. mpicc -showme shows the full list of such options:

$ mpicc -showme
icc
-I/opt/MPI/openmpi-1.5.3/linux/intel/include
-I/opt/MPI/openmpi-1.5.3/linux/intel/include/openmpi
-fexceptions
-pthread
-I/opt/MPI/openmpi-1.5.3/linux/intel/lib
-Wl,-rpath,/opt/MPI/openmpi-1.5.3/linux/intel/lib
-I/opt/MPI/openmpi-1.5.3/linux/intel/lib
-L/opt/MPI/openmpi-1.5.3/linux/intel/lib
-lmpi
-ldl
-Wl,--export-dynamic
-lnsl
-lutil

(it's really a single line that I have split here to improve readability)

It that particular case Intel C Compiler icc is used as the backend compiler but we also have variants that use GCC. You can also get the list of options needed for the comple phase (usually known as CFLAGS) with mpicc -showme:compile:

$ mpicc -showme:compile
-I/opt/MPI/openmpi-1.5.3/linux/intel/include
-I/opt/MPI/openmpi-1.5.3/linux/intel/include/openmpi
-fexceptions
-pthread
-I/opt/MPI/openmpi-1.5.3/linux/intel/lib

as well as the list of options that you need to pass to the linker (known as LDFLAGS) with mpicc -showme:link:

$ mpicc -showme:link
-fexceptions
-pthread
-I/opt/MPI/openmpi-1.5.3/linux/intel/lib
-Wl,-rpath,/opt/MPI/openmpi-1.5.3/linux/intel/lib
-I/opt/MPI/openmpi-1.5.3/linux/intel/lib
-L/opt/MPI/openmpi-1.5.3/linux/intel/lib
-lmpi
-ldl
-Wl,--export-dynamic
-lnsl
-lutil

These could be used, e.g. in a Makefile, like this:

...
CFLAGS += $(shell mpicc -showme:compile)
LDFLAGS += $(shell mpicc -showme:link)
...

As far as I know -showme:compile and -showme:link are specific to Open MPI and other implementations only give the full list of options when called with -show.

I still think it's better to use mpicc directly because if it happens that something in the MPI setup is changed, it will be immediately reflected in the wrapper while you would have to change your build script / Makefile manually (unless you use -showme:compile and -showme:link to obtain the options automatically).

Valor answered 4/7, 2012 at 12:48 Comment(0)
P
8

mpicc -compile_info for MPICH.

Piranesi answered 3/6, 2013 at 3:42 Comment(0)
S
7

Yes, you can use gcc actually. But in my case (on Ubuntu) mpicc is just a wrapper of gcc, here is the output of command mpicc -showme:

gcc -I/usr/lib/openmpi/include/openmpi/opal/mca/event/libevent2021/libevent -I/usr/lib/openmpi/include/openmpi/opal/mca/event/libevent2021/libevent/include -I/usr/lib/openmpi/include -I/usr/lib/openmpi/include/openmpi -pthread -Wl,-rpath -Wl,/usr/lib/openmpi/lib -Wl,--enable-new-dtags -L/usr/lib/openmpi/lib -lmpi

While in Open MPI docs:

The Open MPI team strongly recommends that you simply use Open MPI's "wrapper" compilers to compile your MPI applications. That is, instead of using (for example) gcc to compile your program, use mpicc.

We repeat the above statement: the Open MPI Team strongly recommends that the use the wrapper compilers to compile and link MPI applications. If you find yourself saying, "But I don't want to use wrapper compilers!", please humor us and try them. See if they work for you. Be sure to let us know if they do not work for you. Many people base their "wrapper compilers suck!" mentality on bad behavior from poorly-implemented wrapper compilers in the mid-1990's. Things are much better these days; wrapper compilers can handle almost any situation, and are far more reliable than you attempting to hard-code the Open MPI-specific compiler and linker flags manually. That being said, there are some -- very, very few -- situations where using wrapper compilers can be problematic -- such as nesting multiple wrapper compilers of multiple projects. Hence, Open MPI provides a workaround to find out what command line flags you need to compile MPI applications.

Here this answer is useful for you.

Sequential answered 4/12, 2017 at 3:1 Comment(0)
U
3

For MPICH, according to the mpicc man pages, mpicc -compile_info shows the flags for compiling a program, and mpicc -link_info shows the flags for linking a program.

Unyielding answered 3/6, 2019 at 9:45 Comment(0)
T
1

Yes, you can certainly compile an MPI program without the convenience of the mpicc wrapper. On most implementations mpicc is a shell script (or similar) which sets environment variables, finds and links various libraries, all the sort of stuff that you might otherwise put into a Makefile.

I suggest that you find an instance of the mpicc script and deconstruct it.

Tertius answered 3/7, 2012 at 14:55 Comment(0)
W
0

mpicc is already using gcc as a backend

Wheelbarrow answered 3/7, 2012 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.