Learning materials
C Language Features Used in This Course
On this page
This documents summarize the C language features frequently employed in this course.
Compiler
gcc
We choose the gcc C language compiler from GCC (GNU Compiler Collection) as our official compiler. This is the default C compiler on Linux (including the Windows subsystem of Linux, WSL). Use other compilers at your own risk.
Compilation Command
A typical gcc compilation command looks like:
gcc <flags> <arguments>
<flags>are the compilation flags<arguments>are the source files (.c) and libraries (.o)
Useful Compilation Flags
-Ospecifies the compilation optimization level-O0reduced optimization, default level, use as baseline-O2-O3recommended-Ofastwith non-standard-compliant optimizations
-Ispecifies the path to include headers- No space between
-Iand the path! -I.means to look for headers in the current directory
- No space between
-lspecifies the libraries to use-lpthreadPOSIX thread library
-fspecifies flags-fpicPosition dependent-fopenmpenable OpenMP support
-mspecifies the architecture-march=nativeuse the native architecture-m64use 64-bit architecture-msse4.2use SSE4.2 instruction set
-stdspecifies the C language standard-std=gnu90-std=gnu11-std=c99 -pedantic-std=c11 -pedantic
Performance Optimization in C Language
-
Compilation optimization
-O2-O3-Ofast-ffast-math
-
Selected Optimization Approaches
- Loop unrolling
- Cache awareness
- Optimize the memory access pattern for better cache performance
- Loop interchange
- Loop tiling
- Vectorization (hardware architecture dependent)
- Intel MMX, SSE, AVX
-
Memory operations
Block memory operations are usually faster than element-wise operations. The strategy is to use block memory operations whenever possible. The following functions are frequently used in this course:
- Memory allocation/deallocation
mallocandfreecallocandfreealigned_allocandfree(C11)
- Memory block copy/set
memcpymemset
- Memory allocation/deallocation