A Running Case Using the MuPRO SDK Library: demo1#

1. Program Introduction#

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

2. Cmakelists design#

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

2.1 Some pre compiler settings#

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

2.2 Build Project Information#

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

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

2.3 Activate MPI environment#

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

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

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

2.4 Import MuPRO SDK dependency library#

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

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

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

    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#

  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#

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)

3. Code Interpretation#

1. main.f90#

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

2. lib.f90#

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)

subroutine

meanning

usage

print_SizeContext

Print detailed information in type_mupro_SizeContext

init_project: Detection information transformation

init_project

Initialize fft environment settings and mpi settings

main: Initialize Project

fft_handle

Processing Fast Fourier Transform

main: fft handle

test_forward_backward

Backward processing of fast Fourier transform

fft_handle:Processing Fast Fourier Transform

generate_3d_data

Generate 3D test data files for data input

main: generate 3d data

write_3d_to_file

Write 3D data to a file

main: Place the results of the Fast Fourier Transform into a file

4. Program Usage#

  1. Build and compile the project

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

    build_dir

    The compiled running result is as follows

  2. Executing executable programs

    ./demo
    

    The screenshot of the operation is as follows:

    execute