A Running Case Using the Openmupro Library—-demo1#

1. Program Introduction#

This program is used to demonstrate how we can use the already installed openmupro 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 openmupro 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 dependencies of openmupro and mpi in order to execute the program normally

2.1 Some pre compiler settings#

We need to set the compiler, language type, etc. for Cmakelists, and the specific settings are as follows

set(CMAKE_Fortran_COMPILER "ifort")

2.2 Build Project Information#

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

        DESCRIPTION "The open common Mu-PRO SDK examples"
        LANGUAGES C CXX 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 openmupro dependency library#

Firstly, ensure that you have installed the openmupro library correctly on your device. If it is not installed, please execute the following command

  1. Compile the openmupro 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’s find_ Package found our mupro::openmupro library

Note that we have used some new versions of cmake directives here. Please ensure that your cmake version is higher than ==3.25.2==

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

    list(APPEND CMAKE_PREFIX_PATH "./../../out/install/debug")
  2. Use find_package to find the openmupro library

    find_package(openmupro 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

  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::openmupro)
    set_target_properties(demo PROPERTIES LINKER_LANGUAGE Fortran)

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

2.6 The complete Cmakelists file is as follows#

cmake_minimum_required(VERSION 3.25)

set(CMAKE_Fortran_COMPILER "ifort")
        DESCRIPTION "The open common Mu-PRO SDK examples"
        LANGUAGES C CXX Fortran)
# set(MKL_DIR /home/lby/intel/oneapi/mkl/latest/lib/cmake/mkl)

list(APPEND CMAKE_PREFIX_PATH "./../../out/install/debug")
find_package(openmupro REQUIRED)


add_executable(demo main.f90 lib.f90)
target_link_libraries(demo PUBLIC mupro::openmupro)
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)





Print detailed information in type_mupro_SizeContext

init_project: Detection information transformation


Initialize fft environment settings and mpi settings

main: Initialize Project


Processing Fast Fourier Transform

main: fft handle


Backward processing of fast Fourier transform

fft_handle:Processing Fast Fourier Transform


Generate 3D test data files for data input

main: generate 3d data


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 ..


    The compiled running result is as follows

  2. Executing executable programs


    The screenshot of the operation is as follows: