Skip to content

Commit

Permalink
Refactor: Input and parameter module (deepmodeling#4508)
Browse files Browse the repository at this point in the history
Refactor: Input and parameter module
---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: pxlxingliang <[email protected]>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent e13757d commit 52a9600
Show file tree
Hide file tree
Showing 74 changed files with 11,624 additions and 15,008 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ target_link_libraries(
planewave
surchem
neighbor
io_input
io_basic
io_advanced
relax
Expand All @@ -692,6 +693,7 @@ target_link_libraries(
psi_initializer
esolver
vdw
parameter
device
container)

Expand Down
8 changes: 6 additions & 2 deletions docs/advanced/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
- [pw\_diag\_thr](#pw_diag_thr)
- [pw\_diag\_nmax](#pw_diag_nmax)
- [pw\_diag\_ndim](#pw_diag_ndim)
- [diago_full_acc](#diago_full_acc)
- [diago\_full\_acc](#diago_full_acc)
- [erf\_ecut](#erf_ecut)
- [fft\_mode](#fft_mode)
- [erf\_height](#erf_height)
Expand Down Expand Up @@ -147,6 +147,8 @@
- [out\_mat\_t](#out_mat_t)
- [out\_mat\_dh](#out_mat_dh)
- [out\_mat\_xc](#out_mat_xc)
- [out\_hr\_npz/out\_dm\_npz](#out_hr_npzout_dm_npz)
- [dm\_to\_rho](#dm_to_rho)
- [out\_app\_flag](#out_app_flag)
- [out\_ndigits](#out_ndigits)
- [out\_interval](#out_interval)
Expand All @@ -172,6 +174,7 @@
- [DeePKS](#deepks)
- [deepks\_out\_labels](#deepks_out_labels)
- [deepks\_scf](#deepks_scf)
- [deepks\_equiv](#deepks_equiv)
- [deepks\_model](#deepks_model)
- [bessel\_descriptor\_lmax](#bessel_descriptor_lmax)
- [bessel\_descriptor\_ecut](#bessel_descriptor_ecut)
Expand Down Expand Up @@ -954,6 +957,7 @@ calculations.
- **cg**: cg method.
- **bpcg**: bpcg method, which is a block-parallel Conjugate Gradient (CG) method, typically exhibits higher acceleration in a GPU environment.
- **dav**: the Davidson algorithm.
- **dav_subspace**: subspace Davidson algorithm

For atomic orbitals basis,

Expand Down Expand Up @@ -2664,7 +2668,7 @@ These variables are used to control DFT+U correlated parameters
- 1: For p-electron orbits, the plus U correction is needed.
- 2: For d-electron orbits, the plus U correction is needed.
- 3: For f-electron orbits, the plus U correction is needed.
- **Default**: None
- **Default**: -1

### hubbard_u

Expand Down
1 change: 1 addition & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_subdirectory(module_hamilt_lcao/module_gint)
add_subdirectory(module_io)
add_subdirectory(module_relax)
add_subdirectory(module_ri)
add_subdirectory(module_parameter)

add_library(
driver
Expand Down
13 changes: 12 additions & 1 deletion source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ VPATH=./src_global:\
./module_io/json_output:\
./src_ri:\
./module_ri:\
./module_parameter:\
./\

OBJS_ABACUS_PW=${OBJS_MAIN}\
Expand Down Expand Up @@ -109,6 +110,7 @@ ${OBJS_HSOLVER_PEXSI}\
OBJS_MAIN=main.o\
driver.o\
driver_run.o\
parameter.o

OBJS_BASE=abfs-vector3_order.o\
assoc_laguerre.o\
Expand Down Expand Up @@ -426,6 +428,7 @@ OBJS_XC=xc_functional.o\
xc_funct_hcth.o\

OBJS_IO=input.o\
input_conv_tmp.o\
input_conv.o\
berryphase.o\
bessel_basis.o\
Expand Down Expand Up @@ -456,7 +459,6 @@ OBJS_IO=input.o\
unk_overlap_pw.o\
write_wfc_pw.o\
winput.o\
write_input.o\
write_cube.o\
write_rho.o\
write_pot.o\
Expand All @@ -474,6 +476,15 @@ OBJS_IO=input.o\
readin_info.o\
output_info.o\
parse_args.o\
read_input.o\
read_input_item_general.o\
read_input_item_pw.o\
read_input_item_sdft.o\
read_input_item_relax.o\
read_input_item_lcao.o\
read_input_item_postprocess.o\
read_input_item_md.o\
read_input_item_other.o\

OBJS_IO_LCAO=cal_r_overlap_R.o\
write_orb_info.o\
Expand Down
103 changes: 88 additions & 15 deletions source/driver.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "driver.h"

#include "module_base/global_file.h"
#include "module_base/memory.h"
#include "module_base/timer.h"
#include "module_esolver/esolver.h"
Expand All @@ -9,7 +10,9 @@
#include "module_io/input_conv.h"
#include "module_io/para_json.h"
#include "module_io/print_info.h"
#include "module_io/read_input.h"
#include "module_io/winput.h"
#include "module_parameter/parameter.h"
Driver::Driver()
{
}
Expand All @@ -27,10 +30,12 @@ void Driver::init()

time_t time_start = std::time(nullptr);
ModuleBase::timer::start();
// (0) print the start information
this->print_start_info();

// (1) read the input parameters.
// INPUT should be initalized here and then pass to atomic world, mohan 2024-05-12
// INPUT should not be GlobalC, mohan 2024-05-12
// INPUT should be initalized here and then pass to atomic world, mohan
// 2024-05-12 INPUT should not be GlobalC, mohan 2024-05-12
Driver::reading();

// (2) welcome to the atomic world!
Expand All @@ -41,24 +46,97 @@ void Driver::init()
Print_Info::print_time(time_start, time_finish);

// (4) close all of the running logs
INPUT.close_log();
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK, PARAM.inp.out_alllog);

// (5) output the json file
// Json::create_Json(&GlobalC::ucell.symm,GlobalC::ucell.atoms,&INPUT);
Json::create_Json(&GlobalC::ucell, &INPUT);
}

void Driver::print_start_info()
{
#ifdef VERSION
const char* version = VERSION;
#else
const char* version = "unknown";
#endif
#ifdef COMMIT_INFO
#include "commit.h"
const char* commit = COMMIT;
#else
const char* commit = "unknown";
#endif
time_t time_now = time(nullptr);

INPUT.start_time = time_now;
PARAM.set_start_time(time_now);
GlobalV::ofs_running << " "
" "
<< std::endl;
GlobalV::ofs_running << " ABACUS " << version << std::endl << std::endl;
GlobalV::ofs_running << " Atomic-orbital Based Ab-initio "
"Computation at UStc "
<< std::endl
<< std::endl;
GlobalV::ofs_running << " Website: http://abacus.ustc.edu.cn/ "
" "
<< std::endl;
GlobalV::ofs_running << " Documentation: https://abacus.deepmodeling.com/ "
" "
<< std::endl;
GlobalV::ofs_running << " Repository: "
"https://github.com/abacusmodeling/abacus-develop "
<< std::endl;
GlobalV::ofs_running << " "
"https://github.com/deepmodeling/abacus-develop "
<< std::endl;
GlobalV::ofs_running << " Commit: " << commit << std::endl << std::endl;
GlobalV::ofs_running << std::setiosflags(std::ios::right);

#ifdef __MPI
// GlobalV::ofs_running << " Version: Parallel, under ALPHA test" <<
// std::endl; GlobalV::ofs_running << " Version: Parallel, in
// development" << std::endl; GlobalV::ofs_running << " Processor Number
// is " << GlobalV::NPROC << std::endl;
ModuleBase::TITLE("Input", "init");
ModuleBase::TITLE("Input", "Bcast");
#else
GlobalV::ofs_running << " This is SERIES version." << std::endl;
ModuleBase::TITLE("Input", "init");
#endif
GlobalV::ofs_running << " Start Time is " << ctime(&time_now);
GlobalV::ofs_running << " "
" "
<< std::endl;
GlobalV::ofs_running << " -------------------------------------------------"
"-----------------------------------"
<< std::endl;
}

void Driver::reading()
{
ModuleBase::timer::tick("Driver", "reading");
// temperarily
GlobalV::MY_RANK = PARAM.sys.myrank;
GlobalV::NPROC = PARAM.sys.nproc;

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

// (2) copy the variables from INPUT to each class
// (2) create the output directory
read_input.create_directory(PARAM);

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

// (*temp*) copy the variables from INPUT to each class
Input_Conv::tmp_convert();
Input_Conv::Convert();

// (3) define the 'DIAGONALIZATION' world in MPI
// (4) define the 'DIAGONALIZATION' world in MPI
Parallel_Global::split_diag_world(GlobalV::DIAGO_PROC,
GlobalV::NPROC,
GlobalV::MY_RANK,
Expand All @@ -77,7 +155,8 @@ void Driver::reading()
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "GSIZE", GlobalV::GSIZE);

#ifdef __MPI
// (4) divide the GlobalV::NPROC processors into GlobalV::KPAR for k-points parallelization.
// (5) divide the GlobalV::NPROC processors into GlobalV::KPAR for k-points
// parallelization.
Parallel_Global::init_pools(GlobalV::NPROC,
GlobalV::MY_RANK,
GlobalV::NSTOGROUP,
Expand All @@ -90,15 +169,9 @@ void Driver::reading()
GlobalV::MY_POOL);
#endif

// (5) Read in parameters about wannier functions.
// (6) Read in parameters about wannier functions.
winput::Init(GlobalV::global_wannier_card);

// (6) Print the parameters into INPUT file.
std::stringstream ss1;
ss1 << GlobalV::global_out_dir << GlobalV::global_in_card;
INPUT.Print(ss1.str());
// ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running,"READING CARDS");

ModuleBase::timer::tick("Driver", "reading");
}

Expand Down
5 changes: 5 additions & 0 deletions source/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class Driver
void init();

private:
/**
* @brief Print the start information.
*
*/
void print_start_info();
/**
* @brief Reading the parameters and split the MPI world.
* This function read the parameter in "INPUT", "STRU" etc,
Expand Down
7 changes: 5 additions & 2 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#include "driver.h"
#include "fftw3.h"
#include "module_base/global_variable.h"
#include "module_base/parallel_global.h"
#include "module_io/parse_args.h"
#include "module_parameter/parameter.h"
#ifdef _OPENMP
#include <omp.h>
#endif
Expand All @@ -25,12 +25,15 @@ int main(int argc, char** argv)
read the mpi parameters in the command-line,
initialize the mpi environment.
*/
Parallel_Global::read_mpi_parameters(argc, argv, GlobalV::NPROC, GlobalV::MY_RANK);
int nproc = 1;
int my_rank = 0;
Parallel_Global::read_mpi_parameters(argc, argv, nproc, my_rank);
#ifdef _OPENMP
// ref: https://www.fftw.org/fftw3_doc/Usage-of-Multi_002dthreaded-FFTW.html
fftw_init_threads();
fftw_plan_with_nthreads(omp_get_max_threads());
#endif
PARAM.set_rank_nproc(my_rank, nproc);

/*
main program for doing electronic structure calculations.
Expand Down
Loading

0 comments on commit 52a9600

Please sign in to comment.