Difference between revisions of "HowTo:Compilers"
(→Using MPI) |
(→Options / flags) |
||
(16 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
We are currently supporting two Compiler Suites on the Linux platform: | We are currently supporting two Compiler Suites on the Linux platform: | ||
− | * The '''Intel Compiler Suite''' is located | + | * The '''Intel Compiler Suite''' is located on the Compute Canada CVMFS software stack. The compilers '''ifort''' and '''icc''' are in the default path when you log in. |
− | * | + | ** The default version for the Intel compilers is 2016.4 |
+ | ** Other versions (including newer ones) are available. User the "module avail intel" command for a list. | ||
+ | * The CVMFS stack also includes the '''Gnu C/C++ and Fortran Compilers''' called '''gcc''', '''g++''' and '''gfortran''', respectively. | ||
+ | ** The default version for the Gnu compilers is 5.4.0 | ||
+ | ** Other versions (including newer ones) are available. User the "module avail gcc" command for a list. | ||
== Setup == | == Setup == | ||
− | * | + | * Neither the Intel suite nor the Gnu compilers need to be specifically set up the default version. |
− | + | * Non-default versions of the compilers can be listed through the "module avail intel" and "module avail gcc" commands, respectively. | |
− | * | + | * To setup a non-default version of a compiler, use the command "module load intel/version" or "module load gcc/version", respectively ("version" stands for the specific version). For instance: |
+ | <pre> | ||
+ | module load intel/2017.5 | ||
+ | </pre> | ||
+ | The last command replaces the default 2016.4 version of the Intel compilers with the newer 2017.5 version. This also "re-loads" all the dependencies an reports on it. | ||
|} | |} | ||
Line 22: | Line 30: | ||
| valign="top" width="50%" style="padding:1em; border:1px solid #aaaaaa; background-color:#f7f7f; border-radius:7px" | | | valign="top" width="50%" style="padding:1em; border:1px solid #aaaaaa; background-color:#f7f7f; border-radius:7px" | | ||
− | == | + | == Compiling and Linking == |
* The '''Intel compilers''' are called '''ifort''' and '''icc''' for Fortran (all versions) and C/C++, respectively. | * The '''Intel compilers''' are called '''ifort''' and '''icc''' for Fortran (all versions) and C/C++, respectively. | ||
Line 28: | Line 36: | ||
{| class="wikitable" | {| class="wikitable" | ||
− | !colspan="5"|Compilation commands | + | !colspan="5"|Compilation commands |
|- | |- | ||
| | | | ||
Line 36: | Line 44: | ||
|Activation | |Activation | ||
|- | |- | ||
− | + | |Intel | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |Intel | + | |
|ifort | |ifort | ||
|colspan="2"|icc | |colspan="2"|icc | ||
− | | | + | |none-default : module load intel/version |
|- | |- | ||
− | |Gnu | + | |Gnu |
|gfortran | |gfortran | ||
|gcc | |gcc | ||
|g++ | |g++ | ||
− | |default | + | |none-default : module load gcc/version |
|} | |} | ||
− | Compiling and linking is best done with a makefile. Here are a few common flags | + | Compiling and linking is best done with a '''makefile'''. Here are a few common flags. Consult man pages for specific details (for instance "man gcc"). |
− | + | === Compiling === | |
− | + | <pre>compiler -c [options] name.ext</pre> | |
− | where "compiler" stands for the compiler name, for instance " | + | where "compiler" stands for the compiler name, for instance "gfortran" for the GNU Fortran compiler. The file extension "ext" determines what source code is being compiled, for instance "f" means "fixed format" Fortran, f90 means "free format" Fortran (90), or "c" stands for C. "[options]" denotes additional compiler flags that usually start with a '-'. |
− | + | === Linking === | |
− | + | <pre>compiler -o name [options] [libraries] list</pre> | |
"compiler" see above. "name" is the name of the executable (if not specified, the default is "a.out". [options] see above. [libraries] is a list of libraries that need to be linked in, usually as a list of file names with full path, or as '-L' and '-l' combinations [see below]. "list" means a list of object files, usually with ".o" extension. | "compiler" see above. "name" is the name of the executable (if not specified, the default is "a.out". [options] see above. [libraries] is a list of libraries that need to be linked in, usually as a list of file names with full path, or as '-L' and '-l' combinations [see below]. "list" means a list of object files, usually with ".o" extension. | ||
Using the compilers and the linker in the above manner requires the proper setting of the PATH environment variable, i.e. prior set-up. | Using the compilers and the linker in the above manner requires the proper setting of the PATH environment variable, i.e. prior set-up. | ||
+ | |||
+ | === Options / flags === | ||
+ | |||
There are hundreds of compiler flags, and many of them are not required most of the time. A few that are in more frequent use are: | There are hundreds of compiler flags, and many of them are not required most of the time. A few that are in more frequent use are: | ||
* '''-On''' optimizes your code. "n" is a number from 1 to 5 with increasing severity of alterations made to the code, but also increasing gain. Up to -xO3 is generally rather safe to use. But you should, of course, always check results against an un-optimized version: they might differ. | * '''-On''' optimizes your code. "n" is a number from 1 to 5 with increasing severity of alterations made to the code, but also increasing gain. Up to -xO3 is generally rather safe to use. But you should, of course, always check results against an un-optimized version: they might differ. | ||
− | |||
* '''-g''' produces code that can be debugged. -g and -On are not necessarily mutually exclusive, but optimization may make debugging difficult, because it alters the relationship between source code and executable. This is a good flag to have in the development stage of a program, but is usually dropped later. | * '''-g''' produces code that can be debugged. -g and -On are not necessarily mutually exclusive, but optimization may make debugging difficult, because it alters the relationship between source code and executable. This is a good flag to have in the development stage of a program, but is usually dropped later. | ||
* '''-V''' (or '''-v''') produces the version of the compiler. | * '''-V''' (or '''-v''') produces the version of the compiler. | ||
− | * '''-l'''name is used to bind in a library called libname.a (static) or libname.so (dynamic). This flag is used to link only. | + | * '''-l''' name is used to bind in a library called libname.a (static) or libname.so (dynamic). This flag is used to link only. |
* '''-L''' dirname is used in conjunction with -lname and lets the linker know where to look for libraries. "dirname" is a directory name such as /opt/studio12/SUNWspro/prod/lib. | * '''-L''' dirname is used in conjunction with -lname and lets the linker know where to look for libraries. "dirname" is a directory name such as /opt/studio12/SUNWspro/prod/lib. | ||
− | * '''-R'''dirname is used to tell the program where to get dynamic libraries at runtime. | + | * '''-R''' dirname is used to tell the program where to get dynamic libraries at runtime. |
− | There are many more flags. They are documented in the man pages (e.g. "man | + | There are many more flags. They are documented in the man pages (e.g. "man ifort" for the Intel Fortran compiler), as well in the documentation for the compiler. Some compiler flags are only useful for parallel programs and will be discussed later. |
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|} | |} | ||
Line 155: | Line 90: | ||
| valign="top" width="50%" style="padding:1em; border:1px solid #aaaaaa; background-color:#e1eaf1; border-radius:7px" | | | valign="top" width="50%" style="padding:1em; border:1px solid #aaaaaa; background-color:#e1eaf1; border-radius:7px" | | ||
− | == | + | == Documentation == |
− | + | The best way to get a quick list of compiler options is to use the "'''man pages'''". Just type "man compiler" where "compiler" stands for the name of the compiler you want to use, and get a long explanation of all the relevant options. This is not very user-friendly, but great for a quick look-up. | |
− | + | * [https://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/fortran/win/main/main_cover_title.htm Documentation for the Intel Fortran Compiler can be found here]. | |
+ | * [https://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/cpp/lin/ Documentation for the Intel C/C++ Compiler can be found here]. | ||
+ | * [https://gcc.gnu.org/onlinedocs/ All Gnu compilers are documented here.] | ||
− | + | == Help == | |
− | + | * If you have questions that you can't resolve by checking documentation, [mailto:cac.help@queensu.ca send email to cac.help@queensu.ca] | |
− | * | + | * If you want to start a larger project that involves making code executable on parallel machines, you may want to do this even before you start and we can point you in the right direction. |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [mailto:cac.help@queensu.ca | + | |
|} | |} |
Latest revision as of 19:11, 12 March 2018
Contents
Compilers at the Centre for Advanced Computing
This is an introduction to the Fortran, C, and C++ compilers used on our clusters and servers. It is meant to give the user a basic idea about the usage of the compilers and about code optimization options.
Available CompilersWe are currently supporting two Compiler Suites on the Linux platform:
Setup
module load intel/2017.5 The last command replaces the default 2016.4 version of the Intel compilers with the newer 2017.5 version. This also "re-loads" all the dependencies an reports on it. |
Compiling and Linking
Compiling and linking is best done with a makefile. Here are a few common flags. Consult man pages for specific details (for instance "man gcc"). Compilingcompiler -c [options] name.ext where "compiler" stands for the compiler name, for instance "gfortran" for the GNU Fortran compiler. The file extension "ext" determines what source code is being compiled, for instance "f" means "fixed format" Fortran, f90 means "free format" Fortran (90), or "c" stands for C. "[options]" denotes additional compiler flags that usually start with a '-'. Linkingcompiler -o name [options] [libraries] list "compiler" see above. "name" is the name of the executable (if not specified, the default is "a.out". [options] see above. [libraries] is a list of libraries that need to be linked in, usually as a list of file names with full path, or as '-L' and '-l' combinations [see below]. "list" means a list of object files, usually with ".o" extension. Using the compilers and the linker in the above manner requires the proper setting of the PATH environment variable, i.e. prior set-up. Options / flagsThere are hundreds of compiler flags, and many of them are not required most of the time. A few that are in more frequent use are:
There are many more flags. They are documented in the man pages (e.g. "man ifort" for the Intel Fortran compiler), as well in the documentation for the compiler. Some compiler flags are only useful for parallel programs and will be discussed later. |
DocumentationThe best way to get a quick list of compiler options is to use the "man pages". Just type "man compiler" where "compiler" stands for the name of the compiler you want to use, and get a long explanation of all the relevant options. This is not very user-friendly, but great for a quick look-up.
Help
|