Getting started with Arm Fortran Compiler for HPC

Arm Fortran Compiler is an auto-vectorizing compiler for the 64-bit Armv8-A architecture. This getting started tutorial shows how to install, compile Fortran code, using different optimizations levels and generate executable.

Overview

The Arm Fortran Compiler tool chain for the 64-bit Armv8-A architecture enables you to compile Fortran code for Armv8-A compatible platforms, with an advanced auto-vectorizer capable of taking advantage of SIMD features.

Installing Arm HPC tools suite

Refer to Installing Arm Compiler for HPC for details on how to perform the installation on Linux.

Configuring environment

Your administrator should have already installed Arm Compiler for HPC and made the environment module available. To see which environment modules are available:

module avail
Note: you may need to configure the MODULEPATH environment variable to include the installation directory:

export MODULEPATH=$MODULEPATH:/opt/arm/modulefiles/

 To configure your Linux environment to make Arm Fortran Compiler for HPC available:

module load <architecture>/<linux_variant>/<linux_version>/suites/arm-compiler-for-hpc/<version>
For example:
module load Generic-AArch64/SUSE/12/suites/arm-compiler-for-hpc/18.0

 You can check your environment by examining the PATH variable. It should contain the appropriate bin directory from /opt/arm, as installed in the previous section:

% echo $PATH 
/opt/arm/arm-compiler-for-hpc-18.0_Generic-AArch64_SUSE-12_aarch64-linux/bin:...
Note: You might want to consider adding the module load command to your .profile to run it automatically every time you log in.

Compiling and running a simple Hello World program

This simple example illustrates how to compile and run a simple Hello World Fortran program.

  1. Create a simple "hello world" program and save it in a file. In our case, we have saved it in a file named hello.f90

    program hello
      print *, 'hello world'
      end
    
  2. To generate an executable binary, compile your program with Arm Fortran Compiler for HPC.

    armflang -o hello hello.f90
  3. Now you can run the generated binary hello as shown below

    ./hello 

In the following sections we discuss the available compiler options in more detail and, towards the end of this tutorial, discuss compiling Fortran code for SVE-enabled targets.

Generating executable binaries from Fortran code

To generate an executable binary, compile a program using:

armflang -o example1 example1.f90

You can also specify multiple source files on a single line. Each source file is compiled individually and then linked into a single executable binary:

armflang -o example1 example1a.f90 example1b.f90

Compiling and linking object files as separate steps

To compile each of your source files individually into an object file, specify the -c (compile-only) option, and then pass the resulting object files into another invocation of armflang to link them into an executable binary.

armflang -c -o file1a.o file1a.f90
armflang -c -o file1b.o file1b.f90
armflang -o file1 file1a.o file2a.o

Increasing the optimization level

To increase the optimization level, use the -Olevel option. The -O0 option is the lowest optimization level, while -O3 is the highest. Arm Fortran Compiler for HPC only performs auto-vectorization at -O2 and higher, and uses -O0 as the default setting. The optimization flag can be specified when generating a binary, such as:

armflang -O3 -o example1 example1.f90

The optimization flag can also be specified when generating anobject file:

armflang -O3 -c -o example1a.o example1a.f90
armflang -O3 -c -o example1b.o example1b.f90

 or when linking object files:

armflang -O3 -o example1 example1a.o example1b.o

Compiling and optimizing using CPU auto-detection

Arm Fortran Compiler supports the use of the -mcpu=native option, for example:

armflang -O3 -mcpu=native -o example1 example1.f90

This option enables the compiler to automatically detect the architecture and processor type of the CPU it is being run on, and optimize accordingly.

This option supports a range of Armv8-A based SoCs, including ThunderX2.

Note: the optimization performed according to the auto-detected architecture and processor is independent of the optimization level denoted by the -Olevel option.

Compiling Fortran code for SVE-enabled target architectures

The Arm Fortran Compiler toolchain for the 64-bit Armv8-A architecture supports the Scalable Vector Extensions (SVE), enabling you to:

  • Assemble source code containing SVE instructions.
  • Disassemble ELF object files containing SVE instructions.
  • Compile C and C++ code for SVE-enabled targets, with an advanced auto-vectorizer capable of taking advantage of SVE features.

To optimize Fortran code for an SVE-enabled target, enable auto-vectorization by using optimization level -O2 or -O3, and specify an SVE-enabled target architecture using the -march= option:

armflang -O3 -march=armv8-a+sve -o example1 example1.f90

In this example, the Armv8-A target architecture is specified.

You can also specify multiple source files on a single line. Each source file is compiled individually and then linked into a single executable binary:

armflang -O3 -march=armv8-a+sve -o example2 example2a.f90 example2b.f90

Common compiler options

See armflang --help and the LLVM documentation for more information about all supported options.

-S
Outputs assembly code, rather than object code. Produces a text .s file containing annotated assembly code.
-c
Performs the compilation step, but does not perform the link step. Produces an ELF object .o file. To later link object files into an executable binary, run armflang again, passing in the object files.
-o file
Specifies the name of the output file.
-march=name[+[no]feature]
Targets an architecture profile, generating generic code that runs on any processor of that architecture. For example -march=armv8-a+sve.
-mcpu=native
Enables the compiler to automatically detect the CPU it is being run on and optimize accordingly. This supports a range of Armv8-A based SoCs, including ThunderX2.
-Olevel
Specifies the level of optimization to use when compiling source files. The default is -O0.
--help
Describes the most common options supported by Arm Fortran Compiler for HPC.
--version
Displays version information and license details.

Getting help

For a list of all the supported options, use:

armflang --help

To see detailed descriptions of all supported options, use:

man armflang

If you have problems and would like to contact our support team, get in touch here.

Resources

For information on building and running popular HPC and scientific workloads with Arm Compiler for HPC, see our guides on Porting and Tuning.

See which features we support in Fortran 2003 and Fortran 2008