Skip to content

Commit

Permalink
Refactor:Use PARAM instead of GlobalV::dir* (#5097)
Browse files Browse the repository at this point in the history
* change bcast

* change parameter global out dir in the cpp file

* fix delete bug in bcast file

* change parameter global_out_dir in test file

* add parameter in the test file

* change parameter global_readin_dir in the bcast file

* change parameter global_readin_dir in the cpp file

* change parameter global_readin_dir in the test file

* change parameter global_stru_dir in the  cpp& test file

* change parameter global_matix_dir in the  cpp& test file
  • Loading branch information
A-006 authored Sep 14, 2024
1 parent 828b926 commit 03c2582
Show file tree
Hide file tree
Showing 158 changed files with 842 additions and 686 deletions.
2 changes: 1 addition & 1 deletion source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ OBJS_IO=input_conv.o\
read_input_item_exx_dftu.o\
read_input_item_other.o\
read_input_item_output.o\
bcast_globalv.o\
read_set_globalv.o\

OBJS_IO_LCAO=cal_r_overlap_R.o\
write_orb_info.o\
Expand Down
8 changes: 4 additions & 4 deletions source/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ void Driver::print_start_info()
std::cout << std::setiosflags(std::ios::left);

GlobalV::ofs_running << "\n READING GENERAL INFORMATION" << std::endl;
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "global_out_dir", GlobalV::global_out_dir);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "global_in_card", GlobalV::global_in_card);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "global_out_dir", PARAM.globalv.global_out_dir);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "global_in_card", PARAM.globalv.global_in_card);
}

void Driver::reading()
Expand All @@ -119,15 +119,15 @@ void Driver::reading()

// (1) read the input file
ModuleIO::ReadInput read_input(PARAM.globalv.myrank);
read_input.read_parameters(PARAM, GlobalV::global_in_card);
read_input.read_parameters(PARAM, PARAM.globalv.global_in_card);

// (2) create the output directory, running_*.log and print info
read_input.create_directory(PARAM);
this->print_start_info();

// (3) write the input file
std::stringstream ss1;
ss1 << GlobalV::global_out_dir << GlobalV::global_in_card;
ss1 << PARAM.globalv.global_out_dir << PARAM.globalv.global_in_card;
read_input.write_parameters(PARAM, ss1.str());

// (*temp*) copy the variables from INPUT to each class
Expand Down
43 changes: 14 additions & 29 deletions source/module_base/global_file.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//==========================================================
// AUTHOR : mohan

// DATE : 2008-11-10
//==========================================================
#include "global_file.h"

#ifdef __MPI
#include <mpi.h>
#endif

#include <unistd.h>
#include <sstream>
#include "global_function.h"
#include "module_parameter/parameter.h"
#include "global_variable.h"
#include "module_base/parallel_common.h"
#include "module_base/parallel_reduce.h"
Expand All @@ -33,28 +34,12 @@ void ModuleBase::Global_File::make_dir_out(
// NAME : system
//----------------------------------------------------------

std::string prefix ;

#ifdef __EPM
#ifdef __MPI
prefix = "OUT_EPM_MPI.";
#else
prefix = "OUT_EPM.";
#endif
#else
prefix = "OUT.";
#endif

GlobalV::global_out_dir = prefix + suffix + "/";
GlobalV::global_stru_dir = GlobalV::global_out_dir + "STRU/";
GlobalV::global_matrix_dir = GlobalV::global_out_dir + "matrix/";

#ifdef __MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
int make_dir = 0;
// mohan update 2011-05-03
std::string command0 = "test -d " + GlobalV::global_out_dir + " || mkdir " + GlobalV::global_out_dir;
std::string command0 = "test -d " + PARAM.globalv.global_out_dir + " || mkdir " + PARAM.globalv.global_out_dir;

int times = 0;
while(times<GlobalV::NPROC)
Expand All @@ -63,7 +48,7 @@ void ModuleBase::Global_File::make_dir_out(
{
if ( system( command0.c_str() ) == 0 )
{
std::cout << " MAKE THE DIR : " << GlobalV::global_out_dir << std::endl;
std::cout << " MAKE THE DIR : " << PARAM.globalv.global_out_dir << std::endl;
make_dir = 1;
}
else
Expand Down Expand Up @@ -92,7 +77,7 @@ void ModuleBase::Global_File::make_dir_out(
if(calculation == "md")
{
int make_dir_stru = 0;
std::string command1 = "test -d " + GlobalV::global_stru_dir + " || mkdir " + GlobalV::global_stru_dir;
std::string command1 = "test -d " + PARAM.globalv.global_stru_dir + " || mkdir " + PARAM.globalv.global_stru_dir;

times = 0;
while(times<GlobalV::NPROC)
Expand All @@ -101,7 +86,7 @@ void ModuleBase::Global_File::make_dir_out(
{
if ( system( command1.c_str() ) == 0 )
{
std::cout << " MAKE THE STRU DIR : " << GlobalV::global_stru_dir << std::endl;
std::cout << " MAKE THE STRU DIR : " << PARAM.globalv.global_stru_dir << std::endl;
make_dir_stru = 1;
}
else
Expand Down Expand Up @@ -132,7 +117,7 @@ void ModuleBase::Global_File::make_dir_out(
if((out_dir) && calculation == "md")
{
int make_dir_matrix = 0;
std::string command1 = "test -d " + GlobalV::global_matrix_dir + " || mkdir " + GlobalV::global_matrix_dir;
std::string command1 = "test -d " + PARAM.globalv.global_matrix_dir + " || mkdir " + PARAM.globalv.global_matrix_dir;

times = 0;
while(times<GlobalV::NPROC)
Expand All @@ -141,7 +126,7 @@ void ModuleBase::Global_File::make_dir_out(
{
if ( system( command1.c_str() ) == 0 )
{
std::cout << " MAKE THE MATRIX DIR : " << GlobalV::global_stru_dir << std::endl;
std::cout << " MAKE THE MATRIX DIR : " << PARAM.globalv.global_stru_dir << std::endl;
make_dir_matrix = 1;
}
else
Expand Down Expand Up @@ -209,7 +194,7 @@ void ModuleBase::Global_File::make_dir_atom(const std::string &label)
// EXPLAIN : generate atom dir for each type of atom
//----------------------------------------------------------
std::stringstream ss;
ss << GlobalV::global_out_dir << label << "/";
ss << PARAM.globalv.global_out_dir << label << "/";
ModuleBase::GlobalFunc::MAKE_DIR(ss.str());
return;
}
Expand All @@ -218,10 +203,10 @@ void ModuleBase::Global_File::open_log(std::ofstream &ofs, const std::string &fn
{
//----------------------------------------------------------
// USE GLOBAL VARIABLE :
// GlobalV::global_out_dir : (default dir to store "*.log" file)
// PARAM.globalv.global_out_dir : (default dir to store "*.log" file)
//----------------------------------------------------------
std::stringstream ss;
ss << GlobalV::global_out_dir << fn << ".log";
ss << PARAM.globalv.global_out_dir << fn << ".log";

if(calculation == "md" && restart)
{
Expand Down Expand Up @@ -296,9 +281,9 @@ void ModuleBase::Global_File::delete_tmp_files()
{
for (int is = 0; is < GlobalV::NSPIN; ++is)
{
std::string tmp_chg_1 = GlobalV::global_out_dir + "NOW_SPIN" + std::to_string(is + 1) + "_CHG.cube";
std::string tmp_chg_2 = GlobalV::global_out_dir + "OLD1_SPIN" + std::to_string(is + 1) + "_CHG.cube";
std::string tmp_chg_3 = GlobalV::global_out_dir + "OLD2_SPIN" + std::to_string(is + 1) + "_CHG.cube";
std::string tmp_chg_1 = PARAM.globalv.global_out_dir + "NOW_SPIN" + std::to_string(is + 1) + "_CHG.cube";
std::string tmp_chg_2 = PARAM.globalv.global_out_dir + "OLD1_SPIN" + std::to_string(is + 1) + "_CHG.cube";
std::string tmp_chg_3 = PARAM.globalv.global_out_dir + "OLD2_SPIN" + std::to_string(is + 1) + "_CHG.cube";

if (access(tmp_chg_1.c_str(), 0) == 0)
{
Expand Down
36 changes: 0 additions & 36 deletions source/module_base/global_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,13 @@ int GSIZE = DSIZE;
//----------------------------------------------------------
std::string global_in_card = "INPUT";
std::string stru_file = "STRU";
std::string global_kpoint_card = "KPT";


// std::string global_pseudo_type = "auto";
std::string global_out_dir;
std::string global_readin_dir; // zhengdy modified
std::string global_stru_dir;
std::string global_matrix_dir;

std::ofstream ofs_running;
std::ofstream ofs_warning;
std::ofstream ofs_info; // output math lib info
std::ofstream ofs_device; // output device info

//----------------------------------------------------------
// EXPLAIN : test level for each class
//----------------------------------------------------------
//----------------------------------------------------------
// module_hamilt_lcao/hamilt_lcaodft
//----------------------------------------------------------
//----------------------------------------------------------
// src_pseudo
//----------------------------------------------------------
//----------------------------------------------------------
// src_tools
//----------------------------------------------------------
Expand All @@ -106,7 +90,6 @@ bool DOMAG = false;
bool DOMAG_Z = false;
int NPOL = 1;


bool deepks_out_labels = false; // caoyu add 2021-10-16 for DeePKS, wenfei 2022-1-16
bool deepks_scf = false; // caoyu add 2021-10-16 for DeePKS, wenfei 2022-1-16
bool deepks_bandgap = false; // for bandgap label. QO added 2021-12-15
Expand All @@ -116,36 +99,17 @@ bool deepks_equiv = false;

bool deepks_setorb = false;




// Xinyang Dong added for rpa
std::vector<std::string> rpa_orbitals;


// mixing parameters

//==========================================================
// device flags added by denghui
//==========================================================
std::string device_flag = "unknown";
//==========================================================
// precision flags added by denghui
//==========================================================

int out_pot = 0;



double nelec = 0;

//==========================================================
// Deltaspin related
//==========================================================

//==========================================================
// Quasiatomic orbital related
//==========================================================

// on-site orbitals
} // namespace GlobalV
8 changes: 0 additions & 8 deletions source/module_base/global_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ extern double DQ; // 19 mohan add 2009-09-10
extern int NQX; // 20 mohan add 2009-09-10
extern int NQXQ; // liuyu add 2023-10-03

extern bool GAMMA_ONLY_PW; // mohan add 2012-06-05


//========================================================================
// EXPLAIN : Parallel information
Expand Down Expand Up @@ -114,12 +112,6 @@ extern std::string global_kpoint_card;

// extern std::string global_pseudo_type; // mohan add 2013-05-20 (xiaohui add
// 2013-06-23)
extern std::string global_out_dir;
extern std::string global_readin_dir; // zhengdy modified
extern std::string global_stru_dir; // liuyu add 2022-05-24 for MD STRU
extern std::string global_matrix_dir; // liuyu add 2022-09-19 for HS matrix outpu, jiyy
// modified 2023-01-23 for R matrix output

extern std::ofstream ofs_running;
extern std::ofstream ofs_warning;
extern std::ofstream ofs_info;
Expand Down
2 changes: 1 addition & 1 deletion source/module_base/kernels/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ remove_definitions(-D__MPI)

AddTest(
TARGET Base_Kernels_UTs
LIBS ${math_libs} base device
LIBS parameter ${math_libs} base device
SOURCES math_op_test.cpp
)

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AddTest(
TARGET container_kernels_uts
LIBS ${math_libs}
LIBS parameter ${math_libs}
SOURCES blas_test.cpp lapack_test.cpp
memory_test.cpp linalg_test.cpp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AddTest(
TARGET container_ops_uts
LIBS ${math_libs}
LIBS parameter ${math_libs}
SOURCES einsum_op_test.cpp linalg_op_test.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion source/module_base/module_container/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ remove_definitions(-D__MPI)

AddTest(
TARGET container_uts
LIBS container base device ${math_libs}
LIBS parameter container base device ${math_libs}
SOURCES tensor_test.cpp tensor_shape_test.cpp allocator_test.cpp
tensor_buffer_test.cpp tensor_map_test.cpp
tensor_utils_test.cpp tensor_accessor_test.cpp
Expand Down
2 changes: 1 addition & 1 deletion source/module_base/module_device/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AddTest(
TARGET Module_Device_UTs
LIBS ${math_libs} base device
LIBS parameter ${math_libs} base device
SOURCES memory_test.cpp device_test.cpp
)
2 changes: 1 addition & 1 deletion source/module_base/module_mixing/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
remove_definitions(-D__MPI)
AddTest(
TARGET test_mixing
LIBS base device ${math_libs}
LIBS parameter base device ${math_libs}
SOURCES mixing_test.cpp
)
Loading

0 comments on commit 03c2582

Please sign in to comment.