--- title: 'GNU Compiler' taxonomy: category: - docs external_links: process: true no_follow: true target: _blank mode: active --- [toc] ## Environment Settings{#enviroment} ### Software Version and System Requirements{#version} Version | Module File Name | System A | System B/C | System G | Cloud System | Note --- | --- | --- | --- | --- | --- | --- 12.2.0 | gcc/12.2.0 | + | + | + | + | Installed in November 2022 8.5.0 | - | + | + | + | + | OS Standard \+ : Available for all users \- : Not available When you log into the system, either the Intel compiler or the NVIDIA HPC SDK compiler is available by default. Please execute the module command as shown below to switch compilers. ```nohighlight (System B, C, Cloud) $ module switch PrgEnvIntel PrgEnvGCC (System G) $ module switch PrgEnvNvidia PrgEnvGCC ``` You can use version 8.5.0 when you log into the system. If you want to use version 12.2.0, please execute the module command as follows with PrgEnvGCC loaded. ```nohighlight $ module load gcc/12.2.0 ``` <!-- GNUコンパイラのバージョンを切り替えたい場合は、PrgEnvGCC がロードされている状態で、以下のようにmoduleコマンドを実行してください。 ```nohighlight $ module switch gcc/4.8.2 gcc/4.6.2 ``` ログイン時に自動で環境設定を行いたい場合は、ログインシェルの起動ファイルに必要なmoduleコマンドを記述してください。詳細は [環境設定](/config) をご覧ください。 moduleコマンドの詳細は [Modules](/config/modules) をご覧ください。 --> ## How to Compile{#usage} ### Compile Commands{#command} Language | Command | Operands --------- | --------- | ---------------------------- Fortran | gfortran | gfortran Option File name C | gcc | gcc Option File name C++ | g++ | g++ Option File name ### Compile Options{#option} * **Main options(e.g., parallelization, optimization)** Option | Purpose --------------------------------------- | -------------------------------- -o _FILENAME_ | Specifies the name of the object file. -mcmodel=medium | Supports more than 2 Gbytes of memory. -fopenmp | Compile with OpenMP directives enabled. -O0/-O1/-O2/-O3 | Specifies the level of optimization (default is -O0). * **Message output and debugging options** Option | Purpose ------- | ------------------ -Wall | Displays all warning messages. * **Fortran language options** Option | Purpose --------------- | ---------------------------- -ffixed-form | Indicates that the program is written in a fixed format. -ffree-form | Indicates that the program is written in a free format. -pedantic | Warns against the use of Fortran extensions. -fimplicit-none | Warns against implicit type declarations. ## Examples of Compiling{#sample} ### Sequential Program{#serial} ```nohighlight $ gfortran test.f90 # For Fortran $ gcc test.c # For C $ g++ test.cpp # For C++ $ tssrun ./a.out # Execution ``` ### Use of OpenMP{#openmp} OpenMP is an open standard for parallelizing programs. You can have the compiler perform parallelization automatically only by writing instructions starting with #pragma omp in the source code and compile with the given options. To compile the source code with written instructions to OpenMP, use the -fopenmp option. ```nohighlight $ gcc -fopenmp test.c ``` When executing a compiled program, if you specify the number of parallels for t and c with the -A option, the program will be executed with the number of parallels. ```nohighlight $ tssrun --rsc p=1:t=8:c=8 ./a.out # Execute with the number of parallels specified as 8 ``` ## Available Libraries{#library} ### MPI Library{#mpi_library} IntelMPI library and OpenMPI library are available. Please refer to [IntelMPI library](/compilers/intelmpi) and [OpenMPI library](/compilers/openmpi) on how to compile, link and execute MPI programs. ## Manuals{#manual} * [GCC online documentation](http://gcc.gnu.org/onlinedocs/) ## Links{#link} * [GCC, the GNU Compiler Collection](http://gcc.gnu.org/)