User Tools

Site Tools


howto:compiling_tips_n_tricks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
howto:compiling_tips_n_tricks [2013/07/18 16:44]
kevin created
howto:compiling_tips_n_tricks [2021/12/09 16:42] (current)
Line 5: Line 5:
 =====Compilers===== =====Compilers=====
  
-The three main compiled languages for HPC are C, Fortran and C++.+The three dominant compiled languages used in HPC are C, Fortran and C++.
  
-> Many people write the first and last as C/C++.  That'wrong.  C and C++ are different languages.  Confusing them is responsible for many problems.+> Many people write the first and last as C/C++.  That'misleading.  C and C++ are separate languages.  Confusing them is responsible for many problems.
  
-The compilers found at the CHPC fall into three families: gcc, Intel and Sun Studio.+The compilers found at the CHPC fall into three families: GCC, Intel and [[guide:m9000|Sun Studio]].
  
-There's a fourth family, IBM XL, but we won't worry about it since the P690s are gone and BG/P is DOA.+> 'GCCstands for GNU Compiler Collection; 'gcc' stands for GNU C Compiler; try not to confuse them 8-)
  
-====Table of Compilers====+>> There's a fourth family, IBM XL, but we won't worry about it since the P690s are gone and BG/P is in hibernation. 
 + 
 +====Table of Compilers and their Command Names====
  
 | Language ^  GCC          Intel     | | Language ^  GCC          Intel     |
Line 20: Line 22:
 ^ C++      | ''g++''      | ''icpc''   | ^ C++      | ''g++''      | ''icpc''   |
  
-By convention, there are variables that define the actual command invoked (see above) and which can be used in the shell, with make files and ''configure''.+So to actually compile a C program with the GNU C compiler you would type at the shell command line: 
 + 
 +<code bash> 
 +gcc -o hello hello.c 
 +</code> 
 + 
 +And for a Fortran 90 program using Intel's compiler: 
 + 
 +<code bash> 
 +ifort -o hello hello.f90 
 +</code>
  
 ====Table of Compiler Variables==== ====Table of Compiler Variables====
 +
 +By convention, there are variables that define the actual command invoked (see above) and which can be used in the shell, with make files and ''configure''.
  
 ^ Variable ^ Compiler ^ Example | ^ Variable ^ Compiler ^ Example |
Line 29: Line 43:
 ^ ''CXX'' | C++ | ''CXX=/opt/gridware/intel/comp12/composerxe-2011.0.084/bin/intel64/icpc'' | ^ ''CXX'' | C++ | ''CXX=/opt/gridware/intel/comp12/composerxe-2011.0.084/bin/intel64/icpc'' |
  
-> The last example shows that you can include the full path to a particular compiler.+> The last example shows that you can include the full path to a specific compiler command --- usually the current [[guide:paths|PATH]] will be searched.
  
 Fortran comes in two main flavours, Fortran 77 and Fortran 90 (also called 9x since it includes Fortran 95).  By default ''FC'' refers to the Fortran 9x compiler and when it is necessary to also point to a Fortran 77 compiler: Fortran comes in two main flavours, Fortran 77 and Fortran 90 (also called 9x since it includes Fortran 95).  By default ''FC'' refers to the Fortran 9x compiler and when it is necessary to also point to a Fortran 77 compiler:
Line 37: Line 51:
 ====Example==== ====Example====
  
-When building an MPI libraryfor example, OpenMPIone would specify all four since MPI provides MPI versions for:+When building an MPI library --- for example, OpenMPI --- one should set all four variables since MPI provides MPI compilers for:
  
-| ''mpicc'' | MPI C compiler |+| ''mpicc'' | MPI C compiler ^
 | ''mpicxx'' | MPI C++ compiler | | ''mpicxx'' | MPI C++ compiler |
 | ''mpif77'' | MPI Fortran 77 compiler | | ''mpif77'' | MPI Fortran 77 compiler |
 | ''mpif90'' | MPI Fortran 90 compiler | | ''mpif90'' | MPI Fortran 90 compiler |
  
-Before the usual ''make; make install'' tell ''configure'' which compilers to use:+When building OpenMPI then, before the usual ''make; make install'' command, tell ''configure'' which compilers to use:
  
-<code> +<code bash
-./configure --prefix=/usr/mpi/intel/ \ +./configure --prefix=$HOME/mpi/intel/ \ 
 CC=icc CXX=icpc F77=ifort FC=ifort \ CC=icc CXX=icpc F77=ifort FC=ifort \
 --with-openib \  --with-openib \ 
Line 54: Line 68:
  
 > The above example uses Intel compilers and also builds in InfiniBand support. > The above example uses Intel compilers and also builds in InfiniBand support.
 +
 +
 +=====Which Compilers am I Using?=====
 +
 +That's a very good question.
 +
 +====Table of Compiler Commands for Version====
 +
 +| Language ^  GCC          Intel     |
 +^ C        | ''%%gcc --version%%''      | ''icc -v''    |
 +^ Fortran  | ''%%gfortran --version%%'' | ''ifort -v''  |
 +^ C++      | ''%%g++ --version%%''      | ''icpc -v''   |
 +
 +The ''-v'' options stands for 'verbose' and it produces additional messages when used with any compiler command.  For the Intel compilers, ''-v'' by itself just produces the version:
 +
 +<code bash>
 +login01:~$ icc -v
 +Version 12.0.0
 +</code>
 +
 +For the GCC compilers, ''-v'' produces a lot more information:
 +
 +<code>
 +login01:~$ gfortran -v
 +Using built-in specs.
 +Target: x86_64-redhat-linux
 +Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info 
 +--enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib 
 +--enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-
 +languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi 
 +--disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic 
 +--host=x86_64-redhat-linux
 +Thread model: posix
 +gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)
 +</code>
 +
 +Which is why GCC compilers provide the long option ''%%--version%%'' to just obtain the version:
 +
 +<code>
 +login01:~$ gfortran --version
 +GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52)
 +Copyright (C) 2007 Free Software Foundation, Inc.
 +
 +GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
 +You may redistribute copies of GNU Fortran
 +under the terms of the GNU General Public License.
 +For more information about these matters, see the file named COPYING
 +
 +</code>
 +
 +> You also get a copyright message but the version is in the first line.
 +> <code>login01:~$ gfortran --version | head -1
 +GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52)</code>
 +
 +Using a different, newer, version of GCC is easy through the use of GNU [[guide:compiling|modules]]:
 +
 +<code bash>
 +login01:~$ module load gcc
 +login01:~$ gfortran --version | head -1
 +GNU Fortran (GCC) 4.7.2
 +</code>
 +
  
/app/dokuwiki/data/attic/howto/compiling_tips_n_tricks.1374158663.txt.gz · Last modified: 2021/12/09 16:42 (external edit)