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

10.7k views Asked by At

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 ?

3

There are 3 answers

1
Lasse Jacobs On

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

2
piarston On

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
0
Boki On

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.