C++ Examples#

The example files are as follows:

CMakeLists.txt

CMake configuration file for building all of the examples below.

example.cpp

The simple 1D complex FFT from the Introduction.

fft_cc.cpp

Several examples of complex time domain, complex frequency domain FFTs. Also, the use of scratch memory is explored.

fft_2x4.cpp

A 2D complex time, complex frequency FFT that demonstrates strides and passing a Factory to a function.

fft_rc.cpp

Several examples of real time domain, complex frequency domain FFTs.

advanced/CMakeLists.txt

CMake configuration file for building all of the advanced examples below.

advanced/fft_12.cpp

An example that illustrates disabling dlsym() lookup.

advanced/fft_3x6.cpp

A 2D complex time, complex frequency FFT that demonstrates dynamically loading FFT libraries at runtime.

advanced/ncpu.cpp

An example demonstrating run-time detection of cpus, cores, dies, and packages. The resulting binary may itself be of practical utility.

The links above have some further discussion particular to each example. In addition to reading the code and the comments sprinkled throughout, please see the API Design section for an overview.


Assuming Hpk has been installed into /opt/libhpk0, the following command will make the directory mybuild and write Makefile therein:

cmake -S /opt/libhpk0/share/doc/hpk/examples -B mybuild

Note that the CMakeLists.txt in the examples directory looks for the Hpk package files in the directory /opt/libhpk0/lib/cmake/hpk on x86_64 and in /opt/libhpk0/lib64/cmake/hpk on aarch64. If your installation directory differs, specify the directory that contains HpkConfig.cmake on the command line as follows:

cmake -S /opt/libhpk0/share/doc/hpk/examples -B mybuild \
      -D Hpk_DIR=/opt/libhpk0/lib/cmake/hpk

Next, build all the examples:

cmake --build mybuild

Please see Building for additional discussion on preprocessor macros and CMake targets.