Skip to content

Add performace test of sphbes functions. #3492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ option(DEBUG_INFO "Print message for developers to debug." OFF)
option(ENABLE_NATIVE_OPTIMIZATION "Enable compilation optimization for the native machine's CPU type" OFF)
option(COMMIT_INFO "Print commit information in log" ON)
option(ENABLE_FFT_TWO_CENTER "Enable FFT-based two-center integral method." ON)
option(ENABLE_GOOGLEBENCH "Enable GOOGLE-benchmark usage." OFF)

if (USE_CUDA)
set(USE_CUSOLVER_LCAO ON)
else()
Expand Down Expand Up @@ -608,6 +610,69 @@ IF (BUILD_TESTING)
endfunction(AddTest)
endif()


# Add performance test in abacus
IF (ENABLE_GOOGLEBENCH)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since googlebench relies on testing mechanism and googletest toolkit, please set ENABLE_GOOGLEBENCH as affiliated to BUILD_TESTING.

set(CMAKE_CXX_STANDARD 14) # Required in orbital
include(CTest)
enable_testing()
find_package(GTest HINTS /usr/local/lib/ ${GTEST_DIR})
if(NOT ${GTest_FOUND})
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "origin/main"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(googletest)
endif()

find_package(benchmark REQUIRED)
if(NOT ${benchmark_FOUND})
include(FetchContent)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG "origin/main"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(benchmark)
endif()

function(AddPerfTest) # function for UT
add_compile_options(-O2)
cmake_parse_arguments(UT "DYN" "TARGET" "LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN})
add_executable(${UT_TARGET} ${UT_SOURCES})

if(ENABLE_COVERAGE)
add_coverage(${UT_TARGET})
endif()


# Link Google Benchmark to the project
target_link_libraries(${UT_TARGET} benchmark::benchmark)


#dependencies & link library
target_link_libraries(${UT_TARGET} ${UT_LIBS}
Threads::Threads GTest::gtest_main GTest::gmock_main)
if(USE_OPENMP)
target_link_libraries(${UT_TARGET} OpenMP::OpenMP_CXX)
endif()
install(TARGETS ${UT_TARGET} DESTINATION ${CMAKE_BINARY_DIR}/tests )
add_test(NAME ${UT_TARGET}
COMMAND ${UT_TARGET}
WORKING_DIRECTORY $<TARGET_FILE_DIR:${UT_TARGET}>
)
endfunction(AddTest)
endif()




add_subdirectory(source)

target_link_libraries(${ABACUS_BIN_NAME}
Expand Down
7 changes: 7 additions & 0 deletions source/module_base/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,10 @@ AddTest(
SOURCES assoc_laguerre_test.cpp ../assoc_laguerre.cpp ../tool_quit.cpp ../global_variable.cpp ../global_file.cpp ../global_function.cpp ../memory.cpp ../timer.cpp
LIBS ${math_libs} formatter
)
if(ENABLE_GOOGLEBENCH)
AddPerfTest(
TARGET math_sphbes_perf_test
LIBS formatter
SOURCES math_sphbes_perf_test.cpp ../math_sphbes.cpp ../timer.cpp
)
endif()
103 changes: 103 additions & 0 deletions source/module_base/test/math_sphbes_perf_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include"../math_sphbes.h"
#include<fstream>
#include <benchmark/benchmark.h>
#include <iostream>
#include <string>

/************************************************
* performace test of class Integral
***********************************************/

/**
* Note: this performace test try to measure the CPU time
* of the spherical Bessel produced by class Sphbes,
* and the memory usage of these functions;
* at 2024-1-14
*
* Tested function:
* - Spherical_Bessel.
* - Spherical_Bessel_Roots
* - overloading of Spherical_Bessel. This funnction sets sjp[i] to 1.0 when i < msh.
* - sphbesj
* - sphbes_zeros
*/


int msh = 700;
int l0 = 0;
int l1 = 1;
int l2 = 2;
int l3 = 3;
int l4 = 4;
int l5 = 5;
int l6 = 6;
int l7 = 7;
double q = 1.0;
double *r = new double[msh];
double *jl = new double[msh];
double *djl = new double[msh];

double mean(const double* vect, const int totN)
{
double meanv = 0.0;
for (int i=0; i< totN; ++i) {meanv += vect[i]/totN;}
return meanv;
}




// Below are the wapper functions which contain the function to measure performance
void SphericalBessel_func(){
//int l = 0;
ModuleBase::Sphbes::Spherical_Bessel(msh,r,q,l0,jl);
}

void dSpherical_Bessel_dx_func(){
int il=5;
ModuleBase::Sphbes::dSpherical_Bessel_dx(msh,r,q,il,djl);
}
void SphericalBesselRoots_func(){
int i=7;
int neign = 100;
double *eign = new double[neign];

ModuleBase::Sphbes::Spherical_Bessel_Roots(neign,i,1.0e-12,eign,10.0);
free(eign);

}

void Sphbesj_func(){
ModuleBase::Sphbes::sphbesj(3,0);
}



//Below are the test time functions
static void SphericalBessel(benchmark::State& state) {
for (auto _ : state)
SphericalBessel_func();
}

static void dSpherical_Bessel_dx(benchmark::State& state) {
for (auto _ : state)
dSpherical_Bessel_dx_func();
}

static void SphericalBesselRoots(benchmark::State& state) {
for (auto _ : state)
SphericalBesselRoots_func();
}

static void Sphbesj(benchmark::State& state) {
for (auto _ : state)
Sphbesj_func();
}


//Add the test time functions into google benchmark
BENCHMARK(SphericalBessel);
BENCHMARK(dSpherical_Bessel_dx);
BENCHMARK(SphericalBesselRoots);
BENCHMARK(Sphbesj);
BENCHMARK_MAIN();