3.1.9.4. clang mode

This section explains clang mode.

Attention

Almost all options of Clang / LLVM can be used, but operation is not guaranteed if an option not listed in “C Language User’s Guide”-“Chapter 9 Clang Mode” is specified.

3.1.9.4.1. How to compile

This indicates how to compile C++ program. For C++ compiler, use FCCpx.
When using MPI library, by using mpiFCCpx, you don’t need to consider about MPI header file and library.

If using MPI library

[_LNlogin]$ mpiFCCpx [compile option including -Nclang] source file name

If not using MPI library

[_LNlogin]$ FCCpx [compile option including -Nclang] source file name

See also

There is no limitation that the option order including -Nclang option and specification order of source file name list.

It is ok to mix-specify the option order including -Nclang option and the source file name order.

3.1.9.4.2. Compilation option

The main compile options of the C ++ compiler are shown below.

Compile option

Description

-c

It proceeds until the object file creation. It does not proceed linking that is the last of translation.

-o exe_file

Change executable file name / object file name to exe_file.
If executable file name is omitted,it will be a.out.

-O [0|1|2|3|fast]

Specify the level of optimization.
If the word after -O is omitted, it will be -O2.
When option omitted, it is -O2.

-fvectorize

Instructs the operation in the loop to generate an object using SIMD extension instructions.
If -O1option is enabled, -fno-vectorize option will be applied when omitted.
If over -O2 option is enabled, -fvectorize option will be applied when omitted.
The same direction with trad mode -Ksimd.

-fopenmp

Enable directives in the OpenMP C specification. Supported specifications are OpenMP 4.5/OpenMP 5.0 (part).
When option omitted, it is -fnoopenmp.
The -fopenmp option is needed if an object program compiled with it exists in the command line as an input file.

-ffj-ocl

Enables Fujitsu compiler-specific optimization control lines (pragma directives) supported by clang mode.
When option omitted, it is -ffj-no-ocl.

-I directory

Specify the directory to search for INCLUDE files.

-Rpass=.*

Output optimization information.
The same direction with trad mode -Koptmsg=2.

-std=[level]

Specifies the level of language specification that the compiler (including preprocessor) interprets.
To level, specify one of these : c++03, c++11,c++14,c++17,gnu++03,gnu++11,gnu++14,gnu++17.
When option omitted, -std=gnu++14 option will be applied

-ffj-src

Output the source list.
The same direction with trad mode -Nsrc.

-ffj-lst[=p|t]

Instructs the translation information to be output to a file. The translation information is output to a file with the suffix “.lst”.
If multiple C source files are specified, they are output to each file name.lst file.
If -ffj-lst option is specified with the argument omitted, -ffj-lst=p is applied.
-ffj-lst=p

Instructs the source list and statistical information to be output as translation information.

-ffj-lst=t

In addition to output at -ffj-lst=p, Instructs to output more detailed optimization information.

-ffj-largepage

Indicates whether to create an executable program that uses the large page feature. This option must be specified when linking a program. Default is -ffj-largepage .If not using large page function, use -ffj-nolargepage option. Also -ffj-largepage otpion is unabled when specified -fsanitize option at the same time.

-mcpu

Direct outputting the object file for specified processor. For omitted value, -mcpu=a64fxis applied.

-Nlibomp

Uses the LLVM OpenMP library for parallel processing. This option must be specified when linking. When omitted, -Nlibomp option is applied.

--version

Outputs compiler version and copyright information to standard error.

See also

About C++ compiler clang mode compile option, see C++ User’s Guide “9.1.2 Translation Option”.

3.1.9.4.4. Environment variable (option specification)

This shows the environment variable which C++ compilier (FCCpx) uses.

  1. FCCpx_ENV

    Able to set compile option to environment variable FCCpx_ENV. Compile options defined in FCCpx_ENV are automatically passed to the compiler. Compiler options defined in environment variables and systems have the following precedence:

    [Priority]

    1. Compile command operand

    2. Environment variable for setting translation option (Mode unique:FCCpx_clang_ENV,FCC_clang_ENV)

    3. Environment variable for setting translation option (Mode common:fccpx_ENV,fcc_ENV)

    4. Translation profile file (Mode unique:/etc$FJSVXTCLANGA/fccpx_clang_PROF)

    5. Translation profile file (Mode common:/etc$FJSVXTCLANGA/fccpx_PROF)

    6. Omitted value

In the following example, the recommended option is set in the environment variable fccpx_ENV.

[_LNlogin]$ export FCCpx_ENV=-Ofast -mllvm -polly -mllvm -polly-parallel

Enabled compile option is confirmable with standard output, by specifying -v or -### option.

Note

If specified -v option, command (translation) is executed.

If specified -### option, command (translation) is not executed.

[-vspecification example]

[_LNlogin]$ FCCpx -Nclang -v sample.cc
clang: Fujitsu C/C++ Compiler 4.1.0 (Dec 23 2019 15:40:15) (based on LLVM 7.1.0)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: (Omitted)
Found candidate GCC installation: (Omitted)
Found candidate GCC installation: (Omitted)
Selected GCC installation: (Omitted)
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/opt/FJSVxtclanga/fujitsu_compilers_sve_cross_20191226/sve_cross/clang-comp/bin/clang-7"
 -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free
 (Omitted)
  1. TMPDIR

    The temporary directory used by the compiler can be changed by using the environment variable TMPDIR. /etc/profile to set the home directory in TMPDIR.

    When changing the temporary directory, please avoid using /tmp. For TMPDIR, specify a writable directory of /home/ or /vol0n0m/data/.

3.1.9.4.5. C++ library for parallel process

With Supercomputer Fugaku, the following library is offered.

  • libc++for the standard template library (STL)

  • The folowing 2 libraries for parallel process

Library name

Description

LLVM OpenMP library

  • A library for parallel functions based on LLVM OpenMP Runtime Library, which is open source software.

  • Supported specifications are OpenMP 4.5/OpenMP 5.0 (part).

  • Available with clang mode and trad mode.

  • The trad mode is available in OpenMP 3.1/OpenMP 4.5 (part).

  • For the specification of LLVM OpenMP library, please read “Chapter 4 Multiprocessing” in the C++ User’s Guide.

Fujitsu OpenMP library

  • Available on only trad mode

  • For the specifications of the Fujitsu OpenMP library, please read “Appendix J Fujitsu OpenMP Library” in the C++ User’s Guide.

Specify the library that used on parallel process.
This is required to specify this option when linking.

Option

Description

-Nlibomp

Specifies to use LLVM OpenMP library as OpenMP library.

When omitted, -Nlibomp option is applied.

-Nfjomplib

Not available in clang mode.

Attention

If -Nclang option is available, -Nfjomplib is disabled and -Nlibomp option is enabled.

Note

The following environment variables added in OpenMP 4.0 and later are available in the LLVM OpenMP library. On the other hand, the Fujitsu OpenMP library does not support these environment variables. These environment variables are ignored when using the Fujitsu OpenMP library.

  • OMP_CANCELLATION

  • OMP_DISPLAY_ENV

  • OMP_DEFAULT_DEVICE

  • OMP_MAX_TASK_PRIORITY

3.1.9.4.6. Compilation example

This indicates the compile example of C++ program.

Multi node job (Hybrid parallel)

[_LNlogin]$ mpiFCCpx -Nclang -Ofast -mllvm -polly -mllvm -polly-parallel -fopenmp sample.cc

Single node job (sequesntial)

[_LNlogin]$ FCCpx -Nclang -Ofast sample.cc

Single node job (OpenMP)

[_LNlogin]$ FCCpx -Nclang -Ofast -fopenmp sample.cc

3.1.9.4.7. Built-in debug function

The built-in debug function performs various checks by compiling a program with debugging options added at compile time and executing the execution module.

  • About embedded debug function

Changing the execution environment may cause abnormal termination. In such a case, the possible causes are:

  1. Quoting without setting initial value to variable

  2. Array subscript exceeds array size

Introduces the built-in debug function that checks these.

  • When using C / C ++, use the built-in debug function using the following inspection options.

  • -fsanitize=undefined option

When using an array, check the validity of the declared array size and the subscript range used

  • -fsanitize=addressoption

Checks heap memory for illegal release of memory, out-of-area writes, and memory leaks

About the detail, see the manual “C++ User’s Guide” “9 Clang mode” - “9.1.2.2.1 Options related to the compiler in general.

The following is an example of a message displayed by a sample program created to correspond to option fsanitize=undefined. (The sample program is in an easy-to-understand format for sending messages.)

  1. Sample program

1#include <cstdlib>
2#include <iostream>
3int main() {
4  int data[3];
5  int p = 5;
6  data[p] = 20;
7}
  1. Compile

[_LNlogin]$ FCCpx -Nclang -Ofast -fsanitize=undefined -o sample_debug sample_debug.cc

Note

When compiling, the following -ffj-largepage option is unabled warning is output.

clang-6.0: warning: '-fsanitize' specified, '-ffj-largepage' ignored. [-Woption-ignored]
  1. Execution example

[_LNlogin]$ cat sample_debug.sh.5591.err
sample_debug.cc:5:3: runtime error: index 5 out of bounds for type 'int [3]'
sample_debug.cc:5:3: runtime error: store to address 0xffffffffe618 with insufficient space for an object of type 'int'
0xffffffffe618: note: pointer points here
 00 40 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ac 36 40 00 00 00 00 00  00 00 00 00