How to change default GCC compiler to be used with MPI on Linux CentOS

对着背影说爱祢 提交于 2019-12-11 07:06:35

问题


I have two GCC compilers installed on a Linux (CentOS) machine. The old version of GCC (4.4.7) is in the default folder (came with CentOS) and the newer one that I intend to use is in /usr/local/gcc/4.9.3/. My code utilizes MPI and LAPACK/LAPACKE/BLAS libraries and with the old GCC I used to compile source (for example “main.cpp”) like this:

mpiCC main.cpp -o main -L/home/USER1/lapack-3.6.1 -llapacke -llapack -lblas -lm –Wall

This still invokes the old GCC 4.4.7. What should I modify so the above MPI compilation (mpiCC) invokes GCC 4.9.3 executable from the new location at /usr/local/gcc/4.9.3/el6/bin/ ?

From MPICH Installer's Guide version 3.2 (page 6):

"The MPICH configure step will attempt to find the C, C++, and Fortran compilers for you, but if you either want to override the default or need to specify a compiler that configure doesn't recognize, you can specify them on the command line [...]. For example, to select the Intel compilers instead of the GNU compilers on a system with both, use"

./configure CC=icc CXX=icpc F77=ifort FC=ifort ...

Is there a way to dicriminate between different version of GCC compilers in ./configure ?


回答1:


I guess mpiCC uses the first gcc compiler found in the $PATH variable.

You should be able to set the new version of gcc by running:

PATH="/usr/local/gcc/4.9.3/el6/bin:$PATH" mpiCC main.cpp -o main -L/home/USER1/lapack-3.6.1 -llapacke -llapack -lblas -lm –Wall



回答2:


If you really want two versions of GCC installed at the same time and use both of them here is a good link that explains how to do this:

http://gcc.gnu.org/faq.html#multiple




回答3:


Finally found how. Here is the recipe:

1) check your if you shell is bash, if not set it to bash: $ echo $SHELL

/bin/tcsh

It was tcsh and needed to be set to bash.

2) Switch to bash: $ bash

bash-4.1$

3) Add new version of GCC to the front of the PATH:

bash-4.1$ export PATH=/usr/local/gcc/4.9.3/el6/bin:$PATH

4) Check the PATH: bash-4.1$ echo $PATH

/usr/local/gcc/4.9.3/el6/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin

5) Check version of GCC used (It picks up the first GCC from the PATH): bash-4.1$ gcc --version

gcc (GCC) 4.9.3

Note: this is just for the current session.



来源:https://stackoverflow.com/questions/41230149/how-to-change-default-gcc-compiler-to-be-used-with-mpi-on-linux-centos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!