How to compile MPI with gcc?

前端 未结 6 1551
忘掉有多难
忘掉有多难 2021-01-31 09:31

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

相关标签:
6条回答
  • 2021-01-31 09: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).

    0 讨论(0)
  • 2021-01-31 09:43

    mpicc -compile_info for MPICH.

    0 讨论(0)
  • 2021-01-31 09:48

    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.

    0 讨论(0)
  • 2021-01-31 09:52

    mpicc is already using gcc as a backend

    0 讨论(0)
  • 2021-01-31 09:53

    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.

    0 讨论(0)
  • 2021-01-31 09:54

    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.

    0 讨论(0)
提交回复
热议问题