Skip to content
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

Feature: add macro definition __DEBUG for test-only message #2076

Merged
merged 11 commits into from
Mar 20, 2023
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ option(USE_CUDA "Enable support to CUDA for PW." OFF)
option(ENABLE_FLOAT_FFTW "Enable support to single precision FFTW library." OFF)
# option(USE_CUSOLVER_LCAO "Enable support to CUSOLVER for LCAO." OFF) # broken
option(USE_ROCM "Enable support to ROCm." OFF)
option(USE_OPENMP " Enable OpenMP in abacus." ON)
option(USE_OPENMP "Enable OpenMP in ABACUS." ON)
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
option(BUILD_TESTING "Build ABACUS unit tests" OFF)
option(INFO "Enable gathering of math library information" OFF)
Expand All @@ -26,6 +26,7 @@ option(ENABLE_LIBRI "Enable EXX with LibRI." OFF)
option(USE_ELPA "Enable ELPA" ON)
option(USE_ABACUS_LIBM "Build libmath from source to speed up." ON)
option(GIT_SUBMODULE "Check submodules during build" ON)
option(DEBUG_INFO "Print message for developers to debug." OFF)
# Do not enable it if generated code will run on different CPUs
option(ENABLE_NATIVE_OPTIMIZATION "Enable compilation optimization for the native machine's CPU type" OFF)

Expand Down Expand Up @@ -124,6 +125,10 @@ else()
set(ENABLE_LIBRI OFF)
endif()

if(DEBUG_INFO)
add_compile_definitions(__DEBUG)
endif()

find_package(MPI REQUIRED)
include_directories(${MPI_CXX_INCLUDE_PATH})
target_link_libraries(${ABACUS_BIN_NAME} MPI::MPI_CXX)
Expand Down
30 changes: 27 additions & 3 deletions source/module_base/tool_title.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,33 @@
namespace ModuleBase
{

void TITLE(const std::string &class_function_name,const bool disable=true);
void TITLE(const std::string &class_name,const std::string &function_name,const bool disable=true);
void TITLE(std::ofstream &ofs,const std::string &class_name,const std::string &function_name,const bool disable=true);
void TITLE(
const std::string &class_function_name,
#ifndef __DEBUG
const bool disable=true
#else
const bool disable=false
#endif
);
void TITLE(
const std::string &class_name,
const std::string &function_name,
#ifndef __DEBUG
const bool disable=true
#else
const bool disable=false
#endif
);
void TITLE(
std::ofstream &ofs,
const std::string &class_name,
const std::string &function_name,
#ifndef __DEBUG
const bool disable=true
#else
const bool disable=false
#endif
);
}

#endif
4 changes: 4 additions & 0 deletions source/module_cell/module_symmetry/symmetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,10 +1169,12 @@ void Symmetry::pricell(double* pos)
this->p3.y=plat.e32;
this->p3.z=plat.e33;

#ifdef __DEBUG
GlobalV::ofs_running<<"lattice vectors of primitive cell (initial):"<<std::endl;
GlobalV::ofs_running<<p1.x<<" "<<p1.y<<" "<<p1.z<<std::endl;
GlobalV::ofs_running<<p2.x<<" "<<p2.y<<" "<<p2.z<<std::endl;
GlobalV::ofs_running<<p3.x<<" "<<p3.y<<" "<<p3.z<<std::endl;
#endif

// get the optimized primitive cell
UnitCell tmp_ucell;
Expand All @@ -1192,10 +1194,12 @@ void Symmetry::pricell(double* pos)
this->plat.e32=p3.y;
this->plat.e33=p3.z;

#ifdef __DEBUG
GlobalV::ofs_running<<"lattice vectors of primitive cell (optimized):"<<std::endl;
GlobalV::ofs_running<<p1.x<<" "<<p1.y<<" "<<p1.z<<std::endl;
GlobalV::ofs_running<<p2.x<<" "<<p2.y<<" "<<p2.z<<std::endl;
GlobalV::ofs_running<<p3.x<<" "<<p3.y<<" "<<p3.z<<std::endl;
#endif

GlobalV::ofs_running<<"(for primitive cell:)"<<std::endl;
Symm_Other::print1(this->pbrav, this->pcel_const, GlobalV::ofs_running);
Expand Down
8 changes: 8 additions & 0 deletions source/module_gint/gint_gamma_vl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ void Gint_Gamma::vl_grid_to_2D(const int lgd_now, LCAO_Matrix &lm, const bool ne
this->receiver_size_process, this->receiver_displacement_process,
this->receiver_size, this->receiver_buffer);
#endif
#ifdef __DEBUG
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "vlocal exchange index is built");
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "buffer size(M):", (this->sender_size+this->receiver_size)*sizeof(double)/1024/1024);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "buffer index size(M):", (this->sender_index_size+this->receiver_index_size)*sizeof(int)/1024/1024);
#endif
ModuleBase::timer::tick("Gint_Gamma","distri_vl_index");
}

Expand All @@ -231,15 +233,21 @@ void Gint_Gamma::vl_grid_to_2D(const int lgd_now, LCAO_Matrix &lm, const bool ne
this->sender_buffer[i/2]=pvpR_grid[icol*lgd_now+irow];
}
}

#ifdef __DEBUG
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "vlocal data are put in sender_buffer, size(M):", this->sender_size*8/1024/1024);
#endif

// use mpi_alltoall to get local data
#ifdef __MPI
MPI_Alltoallv(this->sender_buffer, this->sender_size_process, this->sender_displacement_process, MPI_DOUBLE,
this->receiver_buffer, this->receiver_size_process,
this->receiver_displacement_process, MPI_DOUBLE, lm.ParaV->comm_2D);
#endif

#ifdef __DEBUG
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "vlocal data are exchanged, received size(M):", this->receiver_size*8/1024/1024);
#endif

// put local data to H matrix
for(int i=0; i<this->receiver_index_size; i+=2)
Expand Down
7 changes: 6 additions & 1 deletion source/module_hamilt_lcao/hamilt_lcaodft/DM_gamma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ void Local_Orbital_Charge::cal_dk_gamma_from_2D_pub(void)
void Local_Orbital_Charge::cal_dk_gamma_from_2D(void)
{
ModuleBase::timer::tick("LCAO_Charge","dm_2dTOgrid");
#ifdef __DEBUG
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"cal_dk_gamma_from_2D, NSPIN", GlobalV::NSPIN);
#endif

for(int is=0; is<GlobalV::NSPIN; ++is)
{
Expand Down Expand Up @@ -385,9 +387,11 @@ void Local_Orbital_Charge::cal_dk_gamma_from_2D(void)
if(sender_buffer[i]!=0) ++nNONZERO;
}

#ifdef __DEBUG
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of non-zero elements in sender_buffer",nNONZERO);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"sender_size",sender_size);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"last sender_buffer",sender_buffer[sender_size-1]);
#endif

// transform data via MPI_Alltoallv
#ifdef __MPI
Expand All @@ -414,10 +418,11 @@ void Local_Orbital_Charge::cal_dk_gamma_from_2D(void)
if(receiver_buffer[i]!=0) ++nNONZERO;
}


#ifdef __DEBUG
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of non-zero elements in receiver_buffer",nNONZERO);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"receiver_size",receiver_size);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"last receiver_buffer",receiver_buffer[receiver_size-1]);
#endif
// GlobalV::ofs_running<<"DM[0][0:1][0:1] after receiver:"<<std::endl;
// int idx0=GlobalC::GridT.trace_lo[0];
// int idx1=GlobalC::GridT.trace_lo[1];
Expand Down
1 change: 1 addition & 0 deletions source/module_hamilt_pw/hamilt_pwdft/forces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ void Forces<FPTYPE, Device>::cal_force_scc(ModuleBase::matrix& forcescc, ModuleP
//for orbital free case
if(!GlobalC::en.vnew_exist)
{
ModuleBase::timer::tick("Forces", "cal_force_scc");
return;
}

Expand Down
1 change: 0 additions & 1 deletion source/module_io/input_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
template <typename T> void Input_Conv::parse_expression(const std::string &fn, std::vector<T> &vec)
{
ModuleBase::TITLE("Input_Conv", "parse_expression");
ModuleBase::timer::tick("Input_Conv", "parse_expression");
int count = 0;
std::string pattern("([0-9]+\\*[0-9.]+|[0-9,.]+)");
std::vector<std::string> str;
Expand Down