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

3

1

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 ?

Bonnee answered 19/12, 2016 at 20:3 Comment(2)
Any reason why you have 2 versions of gcc installed? You can just update the old one that came with the OS.Redeem
The reason is that the CentOS has many dependencies on GCC 4.4.7. (that version exactly) and one can not just replace the GCC with the newer one, but has to install on the side the new one. Why it is like that, I don't know. On the other hand, 4.4.7 doesn't work for me and I have code compiling/working with higher versions.Bonnee
S
3

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
Shelter answered 19/12, 2016 at 21:20 Comment(2)
Yes, but incompatibilities may appear. At least in the C++ and Fortran parts of GCC and their MPI bindings (although the MPI ones are deprecated).Matte
PATH="/usr/local/gcc/4.9.3/el6/bin:$PATH" gives me Command not found.Bonnee
R
1

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

Redeem answered 19/12, 2016 at 21:18 Comment(1)
Well yes, but the point his how to make the current MPI compatible with the new GCC. And it is not possible. The basic C AI does not change (much), but for other GCC languages it does. And actually, just notice that the OP already has two versions of GCC installed.Matte
B
1

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.

Bonnee answered 21/12, 2016 at 17:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.