Skip to content

demo1 — an FFT round trip

This program is used to demonstrate how we can use the already installed MuPRO SDK library and implement some of our requirements based on this library.

The execution process of demo is as follows

  1. Initialize the project environment and load the MuPRO SDK configuration
  2. Create a 3D data file and store it for subsequent programs to read in input data from the file
  3. Read 3D data files and perform some fast Fourier transforms
  4. Store the results of the Fast Fourier Transform in an output file

Next, we will introduce this case program from multiple perspectives

Before implementing demo1, we need to import the MuPRO SDK package, which carries the required SDK library dependencies.

Do not hardcode compilers in the example. Select the compiler with your CMake preset, toolchain file, or environment before configuring the example.

source /opt/intel/oneapi/setvars.sh

Set project name, project introduction, project language, and other information

project(
demo1
DESCRIPTION "MuPRO SDK demo1 example"
LANGUAGES Fortran)

If you have not yet installed OneAPI, please refer to the OneAPI installation tutorial. If you have already installed the oneAPI, please make sure to activate the environment variables of the oneAPI before building, so that the program can detect related dependencies.

Execute the following instructions specifically, and the path of the oneAPI is determined by the location where you installed it

Terminal window
source /home/lby/intel/oneapi/setvars.sh

Even if you have executed the above instructions, cmake still cannot detect the setting of mpi. You can choose to manually set MKL_DIR in Cmakelists_ The path of the variable is as follows

Terminal window
set(MKL_DIR /home/lby/intel/oneapi/mkl/latest/lib/cmake/mkl)

Firstly, ensure that you have installed or built the MuPRO SDK library correctly on your device. If it is not installed, build and install the SDK library first.

  1. Compile the MuPRO SDK library to the out folder, which is the debug environment

    Terminal window
    cmake --preset="linux-Debug" .
  2. Enter Compilation Directory

    Terminal window
    cd out/build/debug/
  3. Execute Compilation and Install

    Terminal window
    ninja && ninja install

Then we can use CMake find_package to find the mupro::mupro library.

Note that this example requires CMake 3.20 or newer.

  1. Add CMAKE_PREFIX_PATH to Cmakelists to facilitate finding the installation path for the MuPRO SDK library

    cmake -DCMAKE_PREFIX_PATH=/path/to/mupro/install ..
  2. Use find_package to find the MuPRO SDK library

    find_package(mupro REQUIRED)

2.5 Add additional dependencies for the project

Section titled “2.5 Add additional dependencies for the project”
  1. demo1 uses to read data from a file and initialize it, so an input.toml file is required as one of the input sources

    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input.toml
    ${CMAKE_CURRENT_BINARY_DIR}/input.toml
    COPYONLY)
  2. We will also name the executable file demo, and its related dependency libraries are as follows

    add_executable(demo main.f90 lib.f90)
    target_link_libraries(demo PUBLIC mupro::mupro)
    set_target_properties(demo PROPERTIES LINKER_LANGUAGE Fortran)

    Obviously, main.f90, as the entry point of our program, relies on the MuPRO SDK and lib.f90 files

2.6 The complete Cmakelists file is as follows

Section titled “2.6 The complete Cmakelists file is as follows”
cmake_minimum_required(VERSION 3.20)
project(
demo1
DESCRIPTION "MuPRO SDK demo1 example"
LANGUAGES Fortran)
find_package(mupro REQUIRED)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input.toml
${CMAKE_CURRENT_BINARY_DIR}/input.toml
COPYONLY)
add_executable(demo main.f90 lib.f90)
target_link_libraries(demo PUBLIC mupro::mupro)
set_target_properties(demo PROPERTIES LINKER_LANGUAGE Fortran)

This part of the code is mainly responsible for calling the methods defined in lib.f90 and organizing them into the program process we designed

This part of the code is responsible for implementing the core business. Contains the following sub program modules

  • print_SizeContext(context)
  • init_project(context, input_toml)
  • fft_handle(outArr)
  • test_forward_backward(test_epoch, check_num, outArr)
  • generate_3d_data(fileName, kt, arr3d)
  • read_3d_data(filename, kt, outArr)
  • write_3d_to_file(outFilename, kt, outArr)
subroutinemeanningusage
print_SizeContextPrint detailed information in type_mupro_SizeContextinit_project: Detection information transformation
init_projectInitialize fft environment settings and mpi settingsmain: Initialize Project
fft_handleProcessing Fast Fourier Transformmain: fft handle
test_forward_backwardBackward processing of fast Fourier transformfft_handle:Processing Fast Fourier Transform
generate_3d_dataGenerate 3D test data files for data inputmain: generate 3d data
write_3d_to_fileWrite 3D data to a filemain: Place the results of the Fast Fourier Transform into a file
  1. Build and compile the project

    Terminal window
    cd examples/demo1/
    mkdir build
    cd build
    cmake ..
    make

    build_dir

    The compiled running result is as follows

  2. Executing executable programs

    Terminal window
    ./demo

    The screenshot of the operation is as follows:

    execute