Skip to content
Merged
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
35 changes: 22 additions & 13 deletions source/source_base/global_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <mpi.h>
#endif
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <cerrno>
#include <sstream>
#include "global_function.h"
#include "source_io/module_parameter/parameter.h"
Expand Down Expand Up @@ -40,14 +43,15 @@ void ModuleBase::Global_File::make_dir_out(
#endif
int make_dir = 0;
// mohan update 2011-05-03
std::string command0 = "test -d " + PARAM.globalv.global_out_dir + " || mkdir " + PARAM.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)
{
if(rank==times)
{
if ( system( command0.c_str() ) == 0 )
int ret = mkdir(PARAM.globalv.global_out_dir.c_str(), 0755);
if ( ret == 0 || errno == EEXIST )
{
std::cout << " MAKE THE DIR : " << PARAM.globalv.global_out_dir << std::endl;
make_dir = 1;
Expand Down Expand Up @@ -78,14 +82,15 @@ void ModuleBase::Global_File::make_dir_out(
if(calculation == "md")
{
int make_dir_stru = 0;
std::string command1 = "test -d " + PARAM.globalv.global_stru_dir + " || mkdir " + PARAM.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)
{
if(rank==times)
{
if ( system( command1.c_str() ) == 0 )
int ret = mkdir(PARAM.globalv.global_stru_dir.c_str(), 0755);
if ( ret == 0 || errno == EEXIST )
{
std::cout << " MAKE THE STRU DIR : " << PARAM.globalv.global_stru_dir << std::endl;
make_dir_stru = 1;
Expand Down Expand Up @@ -118,16 +123,17 @@ void ModuleBase::Global_File::make_dir_out(
if((out_dir) && calculation == "md")
{
int make_dir_matrix = 0;
std::string command1 = "test -d " + PARAM.globalv.global_matrix_dir + " || mkdir " + PARAM.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)
{
if(rank==times)
{
if ( system( command1.c_str() ) == 0 )
int ret = mkdir(PARAM.globalv.global_matrix_dir.c_str(), 0755);
if ( ret == 0 || errno == EEXIST )
{
std::cout << " MAKE THE MATRIX DIR : " << PARAM.globalv.global_stru_dir << std::endl;
std::cout << " MAKE THE MATRIX DIR : " << PARAM.globalv.global_matrix_dir << std::endl;
make_dir_matrix = 1;
}
else
Expand Down Expand Up @@ -157,14 +163,15 @@ void ModuleBase::Global_File::make_dir_out(
if(out_wfc_dir)
{
int make_dir_wfc = 0;
std::string command1 = "test -d " + PARAM.globalv.global_wfc_dir + " || mkdir " + PARAM.globalv.global_wfc_dir;
//std::string command1 = "test -d " + PARAM.globalv.global_wfc_dir + " || mkdir " + PARAM.globalv.global_wfc_dir;

times = 0;
while(times<GlobalV::NPROC)
{
if(rank==times)
{
if ( system( command1.c_str() ) == 0 )
int ret = mkdir(PARAM.globalv.global_wfc_dir.c_str(), 0755);
if ( ret == 0 || errno == EEXIST )
{
std::cout << " MAKE THE WFC DIR : " << PARAM.globalv.global_wfc_dir << std::endl;
make_dir_wfc = 1;
Expand Down Expand Up @@ -196,14 +203,15 @@ void ModuleBase::Global_File::make_dir_out(
if(PARAM.inp.of_ml_gene_data == 1)
{
int make_dir_descrip = 0;
std::string command1 = "test -d " + PARAM.globalv.global_mlkedf_descriptor_dir + " || mkdir " + PARAM.globalv.global_mlkedf_descriptor_dir;
//std::string command1 = "test -d " + PARAM.globalv.global_mlkedf_descriptor_dir + " || mkdir " + PARAM.globalv.global_mlkedf_descriptor_dir;

times = 0;
while(times<GlobalV::NPROC)
{
if(rank==times)
{
if ( system( command1.c_str() ) == 0 )
int ret = mkdir(PARAM.globalv.global_mlkedf_descriptor_dir.c_str(), 0755);
if ( ret == 0 || errno == EEXIST )
{
std::cout << " MAKE THE MLKEDF DESCRIPTOR DIR : " << PARAM.globalv.global_mlkedf_descriptor_dir << std::endl;
make_dir_descrip = 1;
Expand Down Expand Up @@ -237,14 +245,15 @@ void ModuleBase::Global_File::make_dir_out(
if(PARAM.inp.deepks_out_freq_elec > 0)
{
int make_dir_deepks_elec = 0;
std::string command1 = "test -d " + PARAM.globalv.global_deepks_label_elec_dir + " || mkdir " + PARAM.globalv.global_deepks_label_elec_dir;
//std::string command1 = "test -d " + PARAM.globalv.global_deepks_label_elec_dir + " || mkdir " + PARAM.globalv.global_deepks_label_elec_dir;

times = 0;
while(times<GlobalV::NPROC)
{
if(rank==times)
{
if ( system( command1.c_str() ) == 0 )
int ret = mkdir(PARAM.globalv.global_deepks_label_elec_dir.c_str(), 0755);
if ( ret == 0 || errno == EEXIST )
{
std::cout << " MAKE THE DEEPKS LABELS (ELEC) DIR : " << PARAM.globalv.global_deepks_label_elec_dir << std::endl;
make_dir_deepks_elec = 1;
Expand Down
15 changes: 7 additions & 8 deletions source/source_base/global_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <fstream>
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <cerrno>
#include <unistd.h>

namespace ModuleBase
{
namespace GlobalFunc
Expand Down Expand Up @@ -61,20 +66,14 @@ void OUT(std::ofstream &ofs, const std::string &name)
void MAKE_DIR(const std::string &fn)
{
// ModuleBase::TITLE("global_function","MAKE_DIR");
#ifndef __SW
if (GlobalV::MY_RANK == 0)
{
std::stringstream ss;
ss << " test -d " << fn << " || mkdir " << fn;
//----------------------------------------------------------
// EXPLAIN : 'system' function return '0' if success
//----------------------------------------------------------
if (system(ss.str().c_str()))
int ret = mkdir(fn.c_str(), 0755);
if (ret != 0 && errno != EEXIST)
{
ModuleBase::WARNING_QUIT("MAKE_DIR", fn);
}
}
#endif
return;
}

Expand Down
16 changes: 15 additions & 1 deletion source/source_base/test/global_file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,24 @@

class GlobalFile : public testing::Test
{

protected:
void SetUp() override
{
const std::string suffix = "Si";
PARAM.sys.global_out_dir = "OUT." + suffix + "/";
PARAM.sys.global_stru_dir = PARAM.sys.global_out_dir + "STRU/";
PARAM.sys.global_matrix_dir = PARAM.sys.global_out_dir + "matrix/";
PARAM.sys.global_wfc_dir = PARAM.sys.global_out_dir + "WFC/";
PARAM.sys.global_mlkedf_descriptor_dir = PARAM.sys.global_out_dir + "MLKEDF_Descriptors/";
PARAM.sys.global_deepks_label_elec_dir = PARAM.sys.global_out_dir + "DeePKS_Labels_Elec/";
}
};

TEST_F(GlobalFile,mkdirout)
{
std::string output;
testing::internal::CaptureStdout();
PARAM.sys.log_file = "running_m_1.log";
ModuleBase::Global_File::make_dir_out("Si","m",false,false,0,true,true);
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,testing::HasSubstr("MAKE THE DIR"));
Expand All @@ -43,6 +54,7 @@ TEST_F(GlobalFile,mkdirout)
remove(dd.c_str());

testing::internal::CaptureStdout();
PARAM.sys.log_file = "running_md.log";
ModuleBase::Global_File::make_dir_out("Si","md",false,false,0,true,false);
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,testing::HasSubstr("MAKE THE STRU DIR"));
Expand All @@ -53,6 +65,7 @@ TEST_F(GlobalFile,mkdirout)
remove(bb.c_str());

testing::internal::CaptureStdout();
PARAM.sys.log_file = "running_md_1.log";
ModuleBase::Global_File::make_dir_out("Si","md",true,false,0,true,true);
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,testing::HasSubstr("MAKE THE MATRIX DIR"));
Expand All @@ -79,6 +92,7 @@ TEST_F(GlobalFile,mkdiratom)

TEST_F(GlobalFile,openlog)
{
PARAM.sys.global_out_dir = "./";
std::ofstream ofs;
ModuleBase::Global_File::open_log(ofs,"Si.log","md",true);
EXPECT_TRUE(ofs.is_open());
Expand Down
12 changes: 10 additions & 2 deletions source/source_base/test/global_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <ctime>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>

/************************************************
* unit test of functions in global_function
Expand Down Expand Up @@ -420,9 +424,13 @@ TEST_F(GlobalFunctionTest, MakeDir)
{
GlobalV::MY_RANK = 0;
ModuleBase::GlobalFunc::MAKE_DIR("scf");
auto error1 = std::system("test -d ");

struct stat st;
int error1 = stat("scf", &st);
EXPECT_EQ(error1, 0);
auto error2 = std::system("rm -r scf ");
EXPECT_TRUE(S_ISDIR(st.st_mode));

int error2 = rmdir("scf");
EXPECT_EQ(error2, 0);
SUCCEED();
}
Expand Down
20 changes: 14 additions & 6 deletions source/source_cell/test/unitcell_test_para.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#define private public
Expand Down Expand Up @@ -249,12 +252,17 @@ TEST_F(UcellTest, ReadPseudo)
ifs.open("./H/H.NONLOCAL");
EXPECT_TRUE(ifs.good());
ifs.close();
std::string command1 = "test -d C && rm -rf C";
std::string command2 = "test -d H && rm -rf H";
auto error1 = std::system(command1.c_str());
EXPECT_EQ(error1, 0);
auto error2 = std::system(command2.c_str());
EXPECT_EQ(error2, 0);

struct stat st;
int ret1 = stat("C", &st);
EXPECT_EQ(ret1, 0);
EXPECT_TRUE(S_ISDIR(st.st_mode));
rmdir("C");

int ret2 = stat("H", &st);
EXPECT_EQ(ret2, 0);
EXPECT_TRUE(S_ISDIR(st.st_mode));
rmdir("H");
}
// read_cell_pseudopots
EXPECT_FALSE(ucell->atoms[0].ncpp.has_so);
Expand Down
2 changes: 1 addition & 1 deletion source/source_io/ctrl_runner_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void ctrl_runner_lcao(UnitCell& ucell, // unitcell


// TK: double TR: double
template void ModuleIO::ctrl_runner_lcao<double, double>(UnitCell& ucell, // unitcell
template void ctrl_runner_lcao<double, double>(UnitCell& ucell, // unitcell
const Input_para &inp, // input
K_Vectors &kv, // k-point
elecstate::ElecState* pelec,// electronic info
Expand Down
13 changes: 7 additions & 6 deletions source/source_io/read_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "source_base/tool_quit.h"
#include "source_base/tool_title.h"
#include "source_base/module_device/device.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>

namespace ModuleIO
{
Expand Down Expand Up @@ -253,22 +257,19 @@ void ReadInput::create_directory(const Parameter& param)
}
// NOTE: "make_dir_out" must be called by all processes!!!
// Maybe it is not good, because only rank 0 can create the directory.
#ifndef __SW
ModuleBase::Global_File::make_dir_out(param.input.suffix,
param.input.calculation,
out_dir,
out_wfc_dir,
this->rank,
param.input.mdp.md_restart,
param.input.out_alllog); // xiaohui add 2013-09-01
#endif
const std::string ss = "test -d " + PARAM.inp.read_file_dir;
#ifndef __SW
if (system(ss.c_str()))
//const std::string ss = "test -d " + PARAM.inp.read_file_dir;
struct stat st;
if (stat(PARAM.inp.read_file_dir.c_str(), &st) != 0 || !S_ISDIR(st.st_mode))
{
ModuleBase::WARNING_QUIT("ReadInput", "please set right files directory for reading in.");
}
#endif
return;
}

Expand Down
13 changes: 10 additions & 3 deletions source/source_io/test_serial/rho_io_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ TEST_F(RhoIOTest, Write)
Parallel_Grid pgrid(nx, ny, nz, nz, nrxx, nz, 1);
ModuleIO::read_vdata_palgrid(pgrid, my_rank, ofs_running, "support/chg.cube", rho[0], ucell->nat);
ModuleIO::write_vdata_palgrid(pgrid, rho[0], 0, nspin, 0, "test_write_vdata_palgrid.cube", 0.461002, ucell, 11, 1);
EXPECT_EQ(system("diff -q test_write_vdata_palgrid.cube support/chg.cube"), 0);
std::ifstream ifs1("test_write_vdata_palgrid.cube", std::ifstream::binary | std::ifstream::ate);
std::ifstream ifs2("support/chg.cube", std::ifstream::binary | std::ifstream::ate);
EXPECT_EQ(ifs1.tellg(), ifs2.tellg());
ifs1.close();
ifs2.close();
}

TEST_F(RhoIOTest, TrilinearInterpolate)
Expand Down Expand Up @@ -235,6 +239,9 @@ TEST_F(CubeIOTest, WriteCube)
nx_read, ny_read, nz_read,
dx, dy, dz, atom_type,
atom_charge, atom_pos, data_read, 11);

EXPECT_EQ(system("diff -q test_write.cube ./support/chg.cube"), 0);
std::ifstream ifs1("test_write.cube", std::ifstream::binary | std::ifstream::ate);
std::ifstream ifs2("./support/chg.cube", std::ifstream::binary | std::ifstream::ate);
EXPECT_EQ(ifs1.tellg(), ifs2.tellg());
ifs1.close();
ifs2.close();
}
20 changes: 16 additions & 4 deletions source/source_lcao/module_ri/exx_lip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include "source_base/timer.h"

#include <limits>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>

template <typename T, typename Device>
void Exx_Lip<T, Device>::cal_exx()
Expand Down Expand Up @@ -487,12 +491,20 @@ void Exx_Lip<T, Device>::write_q_pack() const
if (!GlobalV::RANK_IN_POOL)
{
const std::string exx_q_pack = "exx_q_pack/";
const std::string dir_path = PARAM.globalv.global_out_dir + exx_q_pack;

const std::string command_mkdir = "test -d " + PARAM.globalv.global_out_dir + exx_q_pack + " || mkdir " + PARAM.globalv.global_out_dir + exx_q_pack;
assert( system(command_mkdir.c_str()) == 0);
int ret = mkdir(dir_path.c_str(), 0755);
assert(ret == 0 || errno == EEXIST);

const std::string command_kpoint = "test -f " + PARAM.globalv.global_out_dir + exx_q_pack + PARAM.inp.kpoint_file + " || cp " + PARAM.inp.kpoint_file + " " + PARAM.globalv.global_out_dir + exx_q_pack + PARAM.inp.kpoint_file;
assert( system(command_kpoint.c_str()) == 0);
const std::string kpoint_dest = dir_path + PARAM.inp.kpoint_file;
struct stat st;
if (stat(kpoint_dest.c_str(), &st) != 0)
{
std::ifstream src(PARAM.inp.kpoint_file, std::ios::binary);
std::ofstream dst(kpoint_dest, std::ios::binary);
dst << src.rdbuf();
assert(dst.good());
}

std::stringstream ss_wf_wg;
ss_wf_wg << PARAM.globalv.global_out_dir << exx_q_pack << "wf_wg_" << GlobalV::MY_POOL;
Expand Down
Loading