3.1.8.4. clang mode¶
Here we explain about 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.8.4.1. How to compile¶
To translate with clang mode, enable -Nclang
option.
If using MPI library
[_LNlogin]$ mpifccpx [compile option including -Nclang option] source file name
If not using MPI library
[_LNlogin]$ fccpx [compile option including -Nclang option] source file nameSee also
There are no restrictions on the order in which options are listed, including
-Nclang
options, and source file names.You may specify a mixture of options including
-Nclang
options and source file names.
3.1.8.4.2. Compilation option¶
The main compilation options of the C compiler are shown below.
Compile option |
Description |
---|---|
-c |
Creates an object file. |
-o exe_file |
Change executable file name / object file name to
exe_file .If omitted executable file name, it will be
a.out . |
-O [0|1|2|3|fast] |
Specify optimization level.
If omitted the word after
-O , it will be -O2 .When option is omitted, it is
-O2 . |
-fvectorize |
Instructs the operation in the loop to generate an object using SIMD extension instructions.
If
-O1 option is enabled, -fno-vectorize option is applied when omitted.Over
-O2 option is enabled, -fvectorize option is applied when omitted.It is the same instruction with trad mode’s
-Ksimd . |
-fopenmp |
Enable directives in the OpenMP C specification. Supported specifications are OpenMP 4.5/OpenMP 5.0 (part).
When option omitted, it’s
-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’s
-ffj-no-ocl . |
-I directory |
Specify the directory to search for INCLUDE files. |
-Rpass=.* |
Output optimization information.
It is the same instruction with trad mode’s
-Koptmsg=2 . |
-std=[level] |
Specifies the level of language specification that the compiler (including preprocessor) interprets.
For level, specify one of these: c89, c99, c11, gnu89, gnu99 or gnu11. When omitted,
-std=gnu11 option is applied. |
-ffj-src |
Output source list.
It is the same instruction with trad mode’s
-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-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 |
-mcpu |
Direct outputting the object file for specified processor. For omitted value, |
-Nlibomp |
Uses the LLVM OpenMP library for parallel processing. This option must be specified when linking. When omitted, |
|
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.8.4.3. Recommended compiling options¶
As an optimization option of Clang mode of C compiler, it is Recommended to specify -Ofast
.
-Ofast
option is the same result with specifying “-O3 -ffj-fast-matmul -ffast-math -ffp-contract=fast -ffj-fp-relaxed -ffj-ilfunc -fbuiltin -fomit-frame-pointer -finline-functions
“.
Attention
Optimization functions other than the recommended options may or may not be effective depending on the characteristics of the program data and must be tried.
The details of the options are shown below.
The list of option that results the same with
-Ofast
Option
Description
-O3
Performs optimizations that are higher than optimization levels 1 and 2.
-ffj-fast-matmul *
Convert matrix product loops into fast library calls.
-ffast-math *
Performs optimization that changes the evaluation method of operations.
-ffp-contract=fast *
Performs optimization using arithmetic instructions of Floating-Point Multiply-Add/Subtract.
-ffj-fp-relaxed *
For single-precision floating-point division, double-precision floating-point division, and the sqrt function, reciprocal approximation using the reciprocal approximation instruction and Floating-Point Multiply-Add / Subtract instruction is performed.
-ffj-ilfunc *
Mathematical functions are expanded inline. When
-ffj-ilfunc
option operand chapter is omitted,-ffj-ilfunc=loop
option is applied.-fbuiltin
Recognize the behavior of standard library functions to facilitate optimization.
-fomit-frame-pointer
Performs optimization that does not guarantee the frame pointer register in function calls.
-finline-functions
Functions defined in the source program are targeted for inline expansion.
Note
*:Optimization may affect the calculation result. For details, see the manual “C User’s Guide”-“Chapter 9 Clang Mode”-“Floating-point arithmetic optimization and its side effects”.
3.1.8.4.4. Environment variable (option specification)¶
This shows the environment variable which C language compiler (fccpx) uses.
fccpx_ENV
You can set compile options in the environment variable fccpx_ENV. The 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]
Compile command operand
Environment variable for setting translation option (Mode unique:fccpx_clang_ENV,fcc_clang_ENV)
Environment variable for setting translation option (Mode common:fccpx_ENV,fcc_ENV)
Translation profile file (Mode unique:
/etc$FJSVXTCLANGA/fccpx_clang_PROF
)Translation profile file (Mode common:
/etc$FJSVXTCLANGA/fccpx_PROF
)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 option is confirmable with standard outputting by specifying
-v
or-###
option.See also
If specified
-v
option, command (translation) is executed.If specified
-###
option, command (translation) is not executed.[Output example when specifying
-v
][_LNlogin]$ fccpx -Nclang -v clang_sample.c clang: Fujitsu C/C++ Compiler 4.0.0 (Jun 6 2019 15:04:58) (based on LLVM 6.0.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 -disable-llvm-verifier -discard-value-names -main-file-name clang_sample.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu a64fx -mllvm -enable-prefetch-hpc-tag -target-feature +v8.2a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +sve -target-abi aapcs -mllvm -use-sve-vectorizer -fallow-half-arguments-and-returns -ffj-line -dwarf-column-info -debug-info-kind=line-tables-only -dwarf-version=4 -debugger-tuning=gdb -v -resource-dir /opt/FJSVxtclanga/fujitsu_compilers_sve_cross_20191226/sve_cross/clang-comp/lib64/clang/7.1.0 -I /opt/FJSVxtclanga/.common/SELN003/include -I /opt/FJSVxtclanga/.common/TELI006/include -isysroot /opt/FJSVxos/devkit/aarch64/rfs -internal-isystem /opt/FJSVxos/devkit/aarch64/rfs/usr/local/include -internal-isystem /opt/FJSVxtclanga/fujitsu_compilers_sve_cross_20191226/sve_cross/clang-comp/bin/../include/external -internal-isystem /opt/FJSVxtclanga/fujitsu_compilers_sve_cross_20191226/sve_cross/clang-comp/lib64/clang/7.1.0/include -internal-externc-isystem /opt/FJSVxos/devkit/aarch64/rfs/include -internal-externc-isystem /opt/FJSVxos/devkit/aarch64/rfs/usr/include -fdebug-compilation-dir /home/users/fj0025/05_C/clang -ferror-limit 19 -fmessage-length 157 -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /home/users/xxxxxx/clang_sample-903f6a.o -x c clang_sample.c -faddrsig clang -cc1 version 7.1.0 based upon LLVM 7.1.0 default target aarch64-unknown-linux-gnu (Omitted)
TMPDIR
The temporary directory used by the compiler can be changed by using the environment variable
TMPDIR
./etc/profile
to set the home directory inTMPDIR
.When changing the temporary directory, please avoid using
/tmp
. ForTMPDIR
, specify a writable directory of/home/
or/vol0n0m/data/
.
3.1.8.4.5. C library for parallel processing¶
With Supercomputer Fugaku, two libraries are provided for parallel processing.
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 in clang mode and trad mode.
The trad mode is available in OpenMP 3.1/OpenMP 4.5 (part).
For the specifications of the 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.
Option
Description
-Nlibomp
Indicates that the LLVM OpenMP library is to be used as the OpenMP library.
When omitted,
-Nlibomp
option is applied.-Nfjomplib
Not available in clang mode.
Attention
When
-Nclang
option is available,-Nfjomplib
option 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.8.4.6. Compilation example¶
Multi node job (hybrid parallel)
[_LNlogin]$ mpifccpx -Nclang -Ofast -mllvm -polly -mllvm -polly-parallel -fopenmp sample.c
Single node job (sequential)
[_LNlogin]$ fccpx -Nclang -Ofast sample.c
Single node job (OpenMP)
[_LNlogin]$ fccpx -Nclang -Ofast -fopenmp sample.c
3.1.8.4.7. C sample program¶
Here is an example from compilation to job execution using a sample program.
3.1.8.4.8. Built-in debug function¶
The built-in debugging function performs various inspections by compiling a program with debugging options at compile time and executing an execution module.
About built-in debug function
Changing the execution environment may cause abnormal termination. In such cases, the following are possible causes:
The variable is quoted without setting an initial value.
Array subscript exceeds array size
We introduce the built-in debugging function to check these.
When using C / C ++, use the built-in debugging function with the following inspection options.
-fsanitize=undefined
optionWhen using an array, check the size of the declared array and the validity of the index range when used
-fsanitize=address
optionInspect heap memory for illegal memory release, out-of-area write, and memory leak
For more detail, see “9.1.2.2.1 General Options for Compiler” of “Chapter 9 Clang Mode” in the manual “C User’s Guide”.
This is an example of message which output with sample program that is created to match fsanitize=undefined
option . (Sample program is easy to understand to output message.)
Sample program
1 #include <stdio.h> 2 int main() { 3 int data[3]; 4 int p = 5; 5 data[p] = 20; 6 }
compiling
[_LNlogin]$ fccpx -Nclang -Ofast -fsanitize=undefined -o sample_debug sample_debug.cNote
When compiling, warining which means the below
-ffj-largepage
option is disabled will be output.clang-6.0: warning: '-fsanitize' specified, '-ffj-largepage' ignored. [-Woption-ignored]
Execution example
[_LNlogin]$ cat sample_debug.sh.5568.err sample_debug.c:5:3: runtime error: index 5 out of bounds for type 'int [3]' sample_debug.c:5:3: runtime error: store to address 0xffffffffe608 with insufficient space for an object of type 'int' 0xffffffffe608: note: pointer points here 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 8c 32 40 00 00 00 00 00 00 00 00 00