如何用gcc编译MPI? [英] How to compile MPI with gcc?
问题描述
有谁知道是否可以用 gcc
?编译MPI。我需要使用 gcc
,没有 mpicc
。
mpicc
包装器,它们可以理解一个特殊选项,如 -showme
(Open MPI)或 -show
(打开MPI,MPICH和派生),给出了包装器传递给后端编译器的完整选项列表。 例如,在Open MPI中,包装器是C ++程序,用于读取纯文本配置文件并构建命令行选项,并将其传递给编译器。 mpicc -showme
显示了这些选项的完整列表:
$ 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
(这是我在这里分割以改善的一条单线可读性)
特殊情况下,Intel C Compiler icc
用作后端编译器,但我们也有变体使用GCC。您还可以使用 mpicc -showme:compile
获取补全阶段所需的选项列表(通常称为 CFLAGS
) >:
$ 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
作为需要传递给链接器的选项列表(称为 LDFLAGS
),其中 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
这些都可以使用,例如在 Makefile
中,像这样:
...
CFLAGS + = $(shell mpicc -showme:compile)
LDFLAGS + = $(shell mpicc -showme:link)
...
$ b据我所知
-showme:compile
和-showme:link
特定于Open MPI,其他实现仅在-show
调用时提供完整选项列表。
我仍然认为直接使用
mpicc
会更好,因为如果MPI设置中的某些内容发生更改,它会立即反映在包装中,而你必须手动更改构建脚本/Makefile
(除非使用-showme:compile
和-showme:link
自动获取选项)。Does anyone know if it is possible to compile MPI with
gcc
?. I need to usegcc
, nompicc
.解决方案
mpicc
is just a wrapper around certain set of compilers. Most implementations have theirmpicc
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 asCFLAGS
) withmpicc -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
) withmpicc -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).这篇关于如何用gcc编译MPI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!