Compiling C, C++, and Fortran programs on Big Red II and Big Red II+ at IU

Following is information about compiling C, C++, and Fortran programs using the Cray, GNU, Intel, and Portland Group (PGI) compiler suites available on the Big Red II and Big Red II+ research computing systems at Indiana University.

Note:
Big Red II uses the Modules environment management package, allowing you to dynamically customize your software environments. For an overview, see On the research computing systems at IU, how do I use Modules to manage my software environment?

On this page:


Available programming environments

Big Red II provides programming environments for the Cray, Intel, PGI, and GNU Compiler Collection (GCC) compilers. Each programming environment defines system paths and environment variables specific to its associated compiler collection. The Cray programming environment module (PrgEnv-cray) is loaded by default on Big Red II. To use one of the other compiler collections, you need to replace the PrgEnv-cray module with the appropriate programming environment module:

Compiler collection
Programming environment module
Cray PrgEnv-cray
GCC PrgEnv-gnu
Intel PrgEnv-intel
PGI PrgEnv-pgi

Once the desired programming environment module is loaded, you can compile your code on the login node. However, to compile code that will run on Big Red II's compute nodes, you must use one of Big Red II's proprietary compiler driver commands (cc, CC, or ftn) to invoke, respectively, the desired C, C++, or Fortran compiler.

Important:
Do not directly invoke the Cray, GCC, Intel, or PGI compilers when compiling programs that you want to run on Big Red II's compute nodes. Invoking a compiler directly instead of using the appropriate compiler driver command (e.g., using pgCC or g++ instead of CC) will result in an executable incapable of running on Big Red II's compute nodes. Invoke compilers directly only when you're compiling programs intended to execute on Big Red II's login or service nodes.

The only switches that are common to all three compiler driver commands (and work across all programming environments) are -shared, -static, -dynamic, and -hugetlbfs (which links 2 MB pages instead of the default 4 KB). Additionally, the Fortran compiler driver has a -default64 switch available that works across all programming environments; it promotes all integers and real numbers to a 64-bit default, and is compatible with the 64-bit MPI libraries.

For information about each compiler driver command, see its manual page:

Compiler driver command Function Manual page
cc
Invokes the C compiler for the currently loaded programming environment
man cc
CC
Invokes the C++ compiler for the currently loaded programming environment
man CC
ftn
Invokes the Fortran compiler for the currently loaded programming environment
man ftn

The compiler driver commands also take most of the switches associated with the compilers they target, as determined by the currently loaded programming environment. For more, see the "Options and switches" sections in the following information about the Cray, GNU, Intel, and PGI programming environments.

Using the Cray programming environment

Setting up your user environment

The Cray programming environment module (PrgEnv-cray) supplies the system paths and environment variables needed to use the Cray C, C++, and Fortran compilers on Big Red II. Although the Cray programming environment is the default on Big Red II, you may want to review the list of currently loaded modules to make sure the PrgEnv-cray module is loaded; on the command line, enter:

  module list

If another programming environment module (e.g., PrgEnv-pgi) is listed, use the module swap command to replace it with the PrgEnv-cray module; for example, on the command line, enter:

  module swap PrgEnv-pgi PrgEnv-cray

To make permanent changes to your environment, edit your ~/.modules file. For more, see In Modules, how do I save my environment with a .modules file?

Examples

With the PrgEnv-cray module loaded, use the cc, CC, and ftn compiler driver commands to invoke the craycc, crayCC, and crayftn compilers, respectively. For example:

  • To compile the C program my_program.c to create the binary my_program, on the command line, enter:
      cc -o my_program my_program.c
  • To compile the C++ program my_program.CC to create the binary my_program, on the command line, enter:
      CC -o my_program my_program.CC
  • To compile the Fortran program my_program.f95 to create the binary my_program, on the command line, enter:
      ftn -o my_program my_program.f95
Important:
Do not invoke the Cray compilers directly to compile programs that will run on the Big Red II compute nodes. If you invoke the compiler directly instead of using the appropriate compiler driver command (e.g., use crayCC instead of CC), the resulting executable will not run on the Big Red II compute nodes. Invoke the Cray compilers directly only for programs that will execute on the login or service nodes.

Options and switches

  • Compiler driver switches: The only switches that are common to all three compiler driver commands (and work across all programming environments) are -shared, -static, -dynamic, and -hugetlbfs (which links 2 MB pages instead of the default 4 KB). Additionally, the Fortran compiler driver has a -default64 switch available (it promotes all integers and real numbers to a 64-bit default, and is compatible with the 64-bit MPI libraries).
  • Cray compiler options: With the PrgEnv-cray module loaded, the compiler driver commands (cc, CC, and ftn) take many of the same options available to the Cray compilers they invoke. Additionally, you can access the manual page for each Cray compiler to view the options available to it; at the command prompt, enter:
    • man craycc
    • man crayCC
    • man crayftn
    Note:
    The Cray compiler switches are heavily treed. The top-level switches contain most legacy switches, such as -o (output file), -O (optimization; default is -O2), -l (library name), and -L (library directory). Other switches, such as -e (enable compiling options), -d (disable compiling options), and -h (arguments), have multiple sub-options.

Using the GNU programming environment

Setting up your user environment

The GNU programming environment module (PrgEnv-gnu) supplies the system paths and environment variables needed to use the GCC C, C++, and Fortran compilers on Big Red II. To confirm that the PrgEnv-gnu module is loaded, review the list of currently loaded modules; on the command line, enter:

  module list

If another programming environment module (e.g., PrgEnv-cray) is loaded, use the module swap command to replace it with the PrgEnv-gnu module; for example, on the command line, enter:

  module swap PrgEnv-cray PrgEnv-gnu

To make permanent changes to your environment, edit your ~/.modules file. For more, see In Modules, how do I save my environment with a .modules file?

Examples

With the PrgEnv-gnu module loaded, use the cc, CC, and ftn compiler driver commands to invoke the gcc, g++, and gfortran compilers, respectively. For example:

  • To compile the C program my_program.c to create the binary my_program, on the command line, enter:
      cc -o my_program my_program.c
  • To compile the C++ program my_program.CC to create the binary my_program, on the command line, enter:
      CC -o my_program my_program.CC
  • To compile the Fortran program my_program.f95 to create the binary my_program, on the command line, enter:
      ftn -o my_program my_program.f95
Important:
Do not invoke the GCC compilers directly to compile programs that will run on the Big Red II compute nodes. If you invoke the GCC compiler directly instead of using the appropriate compiler driver command (e.g., use gCC instead of CC), the resulting executable will not run on the Big Red II compute nodes. Invoke the GCC compilers directly only for programs that will execute on the login or service nodes.

Options and switches

  • Compiler driver switches: The only switches that are common to all three compiler driver commands (and work across all programming environments) are -shared, -static, -dynamic, and -hugetlbfs (which links 2 MB pages instead of the default 4 KB). Additionally, the Fortran compiler driver has a -default64 switch available (it promotes all integers and real numbers to a 64-bit default, and is compatible with the 64-bit MPI libraries).
  • GCC compiler options: With the PrgEnv-gnu module loaded, the compiler driver commands (cc, CC, and ftn) take many of the same options available to the GCC compilers they invoke. Additionally, you can access the manual page for each GCC compiler to view the options available to it; at the command prompt, enter:
    • man gcc
    • man g++
    • man gfortran

Using the Intel programming environment

Setting up your user environment

The Intel programming environment module (PrgEnv-intel) supplies the system paths and environment variables needed to use the Intel C, C++, and Fortran compilers on Big Red II. To confirm that the PrgEnv-intel module is loaded, review the list of currently loaded modules; on the command line, enter:

  module list

If another programming environment module (e.g., PrgEnv-cray) is loaded, use the module swap command to replace it with the PrgEnv-intel module; for example, on the command line, enter:

  module swap PrgEnv-cray PrgEnv-intel

To make permanent changes to your environment, edit your ~/.modules file. For more, see In Modules, how do I save my environment with a .modules file?

Examples

With the PrgEnv-intel module loaded, use the cc, CC, and ftn compiler driver commands to invoke the icc, icpc, and ifort compilers, respectively. For example:

  • To compile the C program my_program.c to create the binary my_program, on the command line, enter:
      cc -o my_program my_program.c
  • To compile the C++ program my_program.CC to create the binary my_program, on the command line, enter:
      CC -o my_program my_program.CC
  • To compile the Fortran program my_program.f95 to create the binary my_program, on the command line, enter:
      ftn -o my_program my_program.f95
Important:
Do not invoke the Intel compilers directly to compile programs that will run on the Big Red II compute nodes. If you invoke the compiler directly instead of using the appropriate compiler driver command (e.g., use icpc instead of CC), the resulting executable will not run on the Big Red II compute nodes. Invoke the Intel compilers directly only for programs that will execute on the login or service nodes.

Options and switches

  • Compiler driver switches: The only switches that are common to all three compiler driver commands (and work across all programming environments) are -shared, -static, -dynamic, and -hugetlbfs (which links 2 MB pages instead of the default 4 KB). Additionally, the Fortran compiler driver has a -default64 switch available (it promotes all integers and real numbers to a 64-bit default, and is compatible with the 64-bit MPI libraries).
  • Intel compiler options: With the PrgEnv-intel module loaded, the compiler driver commands (cc, CC, and ftn) take many of the same options available to the Intel compilers they invoke. Additionally, you can access the manual page for each Intel compiler to view the options available to it; at the command prompt, enter:
    • man icc
    • man icpc
    • man ifort

Using the PGI programming environment

Setting up your user environment

The PGI programming environment module (PrgEnv-pgi) supplies the system paths and environment variables needed to use the PGI C, C++, and Fortran compilers on Big Red II. To confirm that the PrgEnv-pgi module is loaded, review the list of currently loaded modules; on the command line, enter:

  module list

If another programming environment module (e.g., PrgEnv-cray) is loaded, use the module swap command to replace it with the PrgEnv-pgi module; for example, on the command line, enter:

  module swap PrgEnv-cray PrgEnv-pgi

To make permanent changes to your environment, edit your ~/.modules file. For more, see In Modules, how do I save my environment with a .modules file?

Examples

With the PrgEnv-pgi module loaded, use the cc, CC, and ftn compiler driver commands to invoke the pgcc, pgCC, and pgf95 compilers, respectively. For example:

  • To compile the C program my_program.c to create the binary my_program, on the command line, enter:
      cc -o my_program my_program.c
  • To compile the C++ program my_program.CC to create the binary my_program, on the command line, enter:
      CC -o my_program my_program.CC
  • To compile the Fortran program my_program.f95 to create the binary my_program, on the command line, enter:
      ftn -o my_program my_program.f95
Important:
Do not invoke the PGI compilers directly to compile programs that will run on the Big Red II compute nodes. If you invoke the PGI compiler directly instead of using the appropriate compiler driver command (e.g., use pgCC instead of CC), the resulting executable will not run on the Big Red II compute nodes. Invoke the PGI compilers directly only for programs that will execute on the login or service nodes.

Options and switches

  • Compiler driver switches: The only switches that are common to all three compiler driver commands (and work across all programming environments) are -shared, -static, -dynamic, and -hugetlbfs (which links 2 MB pages instead of the default 4 KB). Additionally, the Fortran compiler driver has a -default64 switch available (it promotes all integers and real numbers to a 64-bit default, and is compatible with the 64-bit MPI libraries).
  • PGI compiler options: With the PrgEnv-pgi module loaded, the compiler driver commands (cc, CC, and ftn) take many of the same options available to the PGI compilers they invoke. Additionally, you can access the manual page for each PGI compiler to view the options available to it; at the command prompt, enter:
    • man pgcc
    • man pgCC
    • man pgf95
    Note:
    Big Red II does not support the -Mprof=mpi, -Mmpi, and -Mscalapack PGI compiler switches.

Getting help

Support for IU research computing systems, software, and services is provided by various UITS Research Technologies units. For help, see Research computing support at IU.

Back to top

This is document bdnv in the Knowledge Base.
Last modified on 2017-06-27 15:20:34.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.