From 9442d3c20cbebf998e2b4f1c1ea9bce23f44f304 Mon Sep 17 00:00:00 2001 From: dyzheng Date: Wed, 7 Jun 2023 07:29:22 +0000 Subject: [PATCH 1/3] Fix: warning detected by intel compiler --- source/module_base/test/tool_threading_test.cpp | 7 ++++--- .../module_hamilt_general/module_xc/xc_functional_vxc.cpp | 5 +++++ .../hamilt_lcaodft/operator_lcao/operator_lcao.cpp | 5 +++++ source/module_io/test/input_test.cpp | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/source/module_base/test/tool_threading_test.cpp b/source/module_base/test/tool_threading_test.cpp index ac2fc552c5..36e181b11e 100644 --- a/source/module_base/test/tool_threading_test.cpp +++ b/source/module_base/test/tool_threading_test.cpp @@ -129,7 +129,7 @@ TEST(ToolThreadingTEST, OmpParalle) EXPECT_THAT(output1,testing::HasSubstr("1")); EXPECT_THAT(output1,testing::HasSubstr("0")); } -#define _OPENMP +#define __OPENMP TEST(ToolThreadingTEST, OmpParalleOpenmp) { std::string output2; @@ -139,7 +139,7 @@ TEST(ToolThreadingTEST, OmpParalleOpenmp) EXPECT_THAT(output2,testing::HasSubstr(std::to_string(omp_get_num_threads()))); EXPECT_THAT(output2,testing::HasSubstr(std::to_string(omp_get_thread_num()))); } -#undef _OPENMP +#undef __OPENMP TEST(ToolThreadingTEST, TryOmpParalle) { std::string output3; @@ -149,7 +149,7 @@ TEST(ToolThreadingTEST, TryOmpParalle) EXPECT_THAT(output3,testing::HasSubstr("1")); EXPECT_THAT(output3,testing::HasSubstr("0")); } -#define _OPENMP +#define __OPENMP TEST(ToolThreadingTEST, TryOmpParalleOpenmp) { std::string output4; @@ -159,3 +159,4 @@ TEST(ToolThreadingTEST, TryOmpParalleOpenmp) EXPECT_THAT(output4,testing::HasSubstr(std::to_string(omp_get_num_threads()))); EXPECT_THAT(output4,testing::HasSubstr(std::to_string(omp_get_thread_num()))); } +#undef __OPENMP diff --git a/source/module_hamilt_general/module_xc/xc_functional_vxc.cpp b/source/module_hamilt_general/module_xc/xc_functional_vxc.cpp index 62096bfc03..44cb1751a7 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_vxc.cpp +++ b/source/module_hamilt_general/module_xc/xc_functional_vxc.cpp @@ -454,6 +454,11 @@ std::tuple XC_Functional::v_xc_libxc( // Peiz ModuleBase::timer::tick("XC_Functional","v_xc_libxc"); return std::make_tuple( etxc, vtxc, std::move(v_nspin4) ); } // end if(4==GlobalV::NSPIN) + else//NSPIN != 1,2,4 is not supported + { + throw std::domain_error("GlobalV::NSPIN ="+std::to_string(GlobalV::NSPIN) + +" unfinished in "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); + } } //the interface to libxc xc_mgga_exc_vxc(xc_func,n,rho,grho,laplrho,tau,e,v1,v2,v3,v4) diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp index 63fccc47eb..3fc5d3a082 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp @@ -173,6 +173,11 @@ void OperatorLCAO::init(const int ik_in) break; } + default: + { + ModuleBase::WARNING_QUIT("OperatorLCAO::init", "unknown cal_type"); + break; + } } if(this->next_op != nullptr) {//it is not the last node, loop next init() function diff --git a/source/module_io/test/input_test.cpp b/source/module_io/test/input_test.cpp index 2bb481257c..24361d6f66 100644 --- a/source/module_io/test/input_test.cpp +++ b/source/module_io/test/input_test.cpp @@ -1456,7 +1456,7 @@ TEST_F(InputTest, Check) class ReadKSpacingTest : public ::testing::Test { protected: - void SetUp() + void SetUp() override { // create a temporary file for testing char tmpname[] = "tmpfile.tmp"; From 86aed107f24a0658a682bb9434611e78bfda48bc Mon Sep 17 00:00:00 2001 From: dyzheng Date: Wed, 7 Jun 2023 09:02:25 +0000 Subject: [PATCH 2/3] Fix: compiling warning detected by GNU compiler --- source/module_base/test/global_function_test.cpp | 6 ++++-- source/module_cell/test/unitcell_test_para.cpp | 6 ++++-- source/module_io/restart.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source/module_base/test/global_function_test.cpp b/source/module_base/test/global_function_test.cpp index f79bad0ce6..63fef746c2 100644 --- a/source/module_base/test/global_function_test.cpp +++ b/source/module_base/test/global_function_test.cpp @@ -417,8 +417,10 @@ TEST_F(GlobalFunctionTest, MakeDir) { GlobalV::MY_RANK = 0; ModuleBase::GlobalFunc::MAKE_DIR("scf"); - std::system("test -d "); - std::system("rm -r scf "); + auto error1 = std::system("test -d "); + EXPECT_EQ(error1, 0); + auto error2 = std::system("rm -r scf "); + EXPECT_EQ(error2, 0); SUCCEED(); } diff --git a/source/module_cell/test/unitcell_test_para.cpp b/source/module_cell/test/unitcell_test_para.cpp index 20c90d26ac..11e1949a52 100644 --- a/source/module_cell/test/unitcell_test_para.cpp +++ b/source/module_cell/test/unitcell_test_para.cpp @@ -155,8 +155,10 @@ TEST_F(UcellTest,ReadPseudo) ifs.close(); std::string command1 = "test -d C && rm -rf C"; std::string command2 = "test -d H && rm -rf H"; - std::system( command1.c_str() ); - std::system( command2.c_str() ); + auto error1 = std::system( command1.c_str() ); + EXPECT_EQ(error1,0); + auto error2 = std::system( command2.c_str() ); + EXPECT_EQ(error2,0); } //read_cell_pseudopots //bcast_unitcell2 diff --git a/source/module_io/restart.cpp b/source/module_io/restart.cpp index 0b60f4d8a0..cd54e11ed2 100644 --- a/source/module_io/restart.cpp +++ b/source/module_io/restart.cpp @@ -24,7 +24,8 @@ void Restart::write_file2(const std::string &file_name, const void*const ptr, co { const int file = open(file_name.c_str(), O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); if(-1==file) throw std::runtime_error("can't open restart save file. \nerrno="+ModuleBase::GlobalFunc::TO_STRING(errno)+".\n"+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__)); - write(file, ptr, size); + auto error = write(file, ptr, size); + if(-1==error) throw std::runtime_error("can't write restart save file. \nerrno="+ModuleBase::GlobalFunc::TO_STRING(errno)+".\n"+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__) ); close(file); } @@ -32,7 +33,8 @@ void Restart::read_file2(const std::string &file_name, void*const ptr, const siz { const int file = open(file_name.c_str(), O_RDONLY); if(-1==file) throw std::runtime_error("can't open restart load file. \nerrno="+ModuleBase::GlobalFunc::TO_STRING(errno)+".\n"+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__)); - read(file, ptr, size); + auto error = read(file, ptr, size); + if(-1==error) throw std::runtime_error("can't read restart load file. \nerrno="+ModuleBase::GlobalFunc::TO_STRING(errno)+".\n"+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__)); close(file); } From f05aa2d63509e34ed58f1942c90b9f0f29c3f577 Mon Sep 17 00:00:00 2001 From: dyzheng Date: Wed, 7 Jun 2023 09:07:45 +0000 Subject: [PATCH 3/3] Fix: error --- source/module_base/test/tool_threading_test.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/module_base/test/tool_threading_test.cpp b/source/module_base/test/tool_threading_test.cpp index 36e181b11e..1624235b99 100644 --- a/source/module_base/test/tool_threading_test.cpp +++ b/source/module_base/test/tool_threading_test.cpp @@ -129,7 +129,9 @@ TEST(ToolThreadingTEST, OmpParalle) EXPECT_THAT(output1,testing::HasSubstr("1")); EXPECT_THAT(output1,testing::HasSubstr("0")); } -#define __OPENMP +#ifndef _OPENMP +#define _OPENMP +#endif TEST(ToolThreadingTEST, OmpParalleOpenmp) { std::string output2; @@ -139,7 +141,7 @@ TEST(ToolThreadingTEST, OmpParalleOpenmp) EXPECT_THAT(output2,testing::HasSubstr(std::to_string(omp_get_num_threads()))); EXPECT_THAT(output2,testing::HasSubstr(std::to_string(omp_get_thread_num()))); } -#undef __OPENMP +#undef _OPENMP TEST(ToolThreadingTEST, TryOmpParalle) { std::string output3; @@ -149,7 +151,7 @@ TEST(ToolThreadingTEST, TryOmpParalle) EXPECT_THAT(output3,testing::HasSubstr("1")); EXPECT_THAT(output3,testing::HasSubstr("0")); } -#define __OPENMP +#define _OPENMP TEST(ToolThreadingTEST, TryOmpParalleOpenmp) { std::string output4; @@ -159,4 +161,3 @@ TEST(ToolThreadingTEST, TryOmpParalleOpenmp) EXPECT_THAT(output4,testing::HasSubstr(std::to_string(omp_get_num_threads()))); EXPECT_THAT(output4,testing::HasSubstr(std::to_string(omp_get_thread_num()))); } -#undef __OPENMP