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
Initialize the project environment and load the openmupro configuration
Create a 3D data file and store it for subsequent programs to read in input data from the file
Read 3D data files and perform some fast Fourier transforms
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_C_COMPILER "icc")
set(CMAKE_CXX_COMPILER "icpc")
set(CMAKE_Fortran_COMPILER "ifort")
2.2 Build Project Information#
Set project name, project introduction, project language, and other information
project(
demo
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
Compile the openmupro library to the out folder, which is the debug environment
cmake --preset="linux-Debug" .
Enter Compilation Directory
cd out/build/debug/
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==
Add
CMAKE_PREFIX_PATH
to Cmakelists to facilitate finding the installation path for the openmupro librarylist(APPEND CMAKE_PREFIX_PATH "./../../out/install/debug")
Use
find_package
to find the openmupro libraryfind_package(openmupro REQUIRED)
2.5 Add additional dependencies for the project#
==demo1== uses to read data from a file and initialize it, so an
input.toml
file is required as one of the input sourcesconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/input.toml ${CMAKE_CURRENT_BINARY_DIR}/input.toml COPYONLY)
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 theopenmupro
andlib.f90
files
2.6 The complete Cmakelists file is as follows#
cmake_minimum_required(VERSION 3.25)
set(CMAKE_C_COMPILER "icc")
set(CMAKE_CXX_COMPILER "icpc")
set(CMAKE_Fortran_COMPILER "ifort")
project(
demo
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)
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::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)
subroutine |
meanning |
usage |
---|---|---|
print_SizeContext |
Print detailed information in type_mupro_SizeContext |
|
init_project |
Initialize fft environment settings and mpi settings |
|
fft_handle |
Processing Fast Fourier Transform |
|
test_forward_backward |
Backward processing of fast Fourier transform |
|
generate_3d_data |
Generate 3D test data files for data input |
|
write_3d_to_file |
Write 3D data to a file |
|
4. Program Usage#
Build and compile the project
cd examples/demo1/ mkdir build cd build cmake .. make
The compiled running result is as follows
Executing executable programs
./demo
The screenshot of the operation is as follows: