Skip to content

Commit a542095

Browse files
authored
Merge branch 'deepmodeling:develop' into refactor
2 parents 56194a9 + 464c7a1 commit a542095

File tree

34 files changed

+319
-252
lines changed

34 files changed

+319
-252
lines changed

source/driver_run.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ void Driver::driver_run()
4040
// the life of ucell should begin here, mohan 2024-05-12
4141
UnitCell ucell;
4242
ucell.setup(PARAM.inp.latname,
43-
PARAM.inp.ntype,
44-
PARAM.inp.lmaxmax,
45-
PARAM.inp.init_vel,
46-
PARAM.inp.fixed_axes);
43+
PARAM.inp.ntype,
44+
PARAM.inp.lmaxmax,
45+
PARAM.inp.init_vel,
46+
PARAM.inp.fixed_axes);
4747

4848
ucell.setup_cell(PARAM.globalv.global_in_stru, GlobalV::ofs_running);
4949
Check_Atomic_Stru::check_atomic_stru(ucell, PARAM.inp.min_dist_coef);

source/module_basis/module_ao/test/ORB_unittest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void test_orb::TearDown()
2828
}
2929
ooo.clear_after_ions(OGT, ORB, 0, nproj);
3030
delete[] nproj;
31-
delete[] orbital_fn;
3231
return;
3332
}
3433

@@ -75,7 +74,7 @@ void test_orb::set_orbs()
7574
ORB.init(ofs_running,
7675
ntype_read,
7776
"./",
78-
orbital_fn,
77+
orbital_fn.data(),
7978
descriptor_file,
8079
lmax,
8180
lcao_ecut,
@@ -114,7 +113,7 @@ void test_orb::set_files()
114113

115114
ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "NUMERICAL_ORBITAL");
116115

117-
orbital_fn = new std::string[ntype_read];
116+
orbital_fn.resize(ntype_read);
118117

119118
for (int it = 0; it < ntype_read; it++)
120119
{

source/module_basis/module_ao/test/ORB_unittest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class test_orb : public testing::Test
5151
double randr(double Rmax);
5252
void gen_table_center2();
5353

54-
bool force_flag = 0;
54+
bool force_flag = false;
5555
int my_rank = 0;
5656
int ntype_read;
5757

@@ -66,7 +66,7 @@ class test_orb : public testing::Test
6666
int lmax = 1;
6767
double lat0 = 1.0;
6868
std::string case_dir = "./GaAs/";
69-
std::string* orbital_fn;
69+
std::vector<std::string> orbital_fn;
7070
std::string descriptor_file;
7171
};
7272
#endif

source/module_cell/bcast_cell.cpp

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#include "unitcell.h"
2-
2+
#include "module_base/parallel_common.h"
3+
#include "module_parameter/parameter.h"
4+
#ifdef __EXX
5+
#include "module_ri/serialization_cereal.h"
6+
#include "module_hamilt_pw/hamilt_pwdft/global.h"
7+
#endif
38
namespace unitcell
49
{
510
void bcast_atoms_tau(Atom* atoms,
@@ -12,4 +17,105 @@ namespace unitcell
1217
}
1318
#endif
1419
}
20+
21+
void bcast_atoms_pseudo(Atom* atoms,
22+
const int ntype)
23+
{
24+
#ifdef __MPI
25+
MPI_Barrier(MPI_COMM_WORLD);
26+
for (int i = 0; i < ntype; i++)
27+
{
28+
atoms[i].bcast_atom2();
29+
}
30+
#endif
31+
}
32+
33+
void bcast_Lattice(Lattice& lat)
34+
{
35+
#ifdef __MPI
36+
MPI_Barrier(MPI_COMM_WORLD);
37+
// distribute lattice parameters.
38+
ModuleBase::Matrix3& latvec = lat.latvec;
39+
ModuleBase::Matrix3& latvec_supercell = lat.latvec_supercell;
40+
Parallel_Common::bcast_string(lat.Coordinate);
41+
Parallel_Common::bcast_double(lat.lat0);
42+
Parallel_Common::bcast_double(lat.lat0_angstrom);
43+
Parallel_Common::bcast_double(lat.tpiba);
44+
Parallel_Common::bcast_double(lat.tpiba2);
45+
Parallel_Common::bcast_double(lat.omega);
46+
Parallel_Common::bcast_string(lat.latName);
47+
48+
// distribute lattice vectors.
49+
Parallel_Common::bcast_double(latvec.e11);
50+
Parallel_Common::bcast_double(latvec.e12);
51+
Parallel_Common::bcast_double(latvec.e13);
52+
Parallel_Common::bcast_double(latvec.e21);
53+
Parallel_Common::bcast_double(latvec.e22);
54+
Parallel_Common::bcast_double(latvec.e23);
55+
Parallel_Common::bcast_double(latvec.e31);
56+
Parallel_Common::bcast_double(latvec.e32);
57+
Parallel_Common::bcast_double(latvec.e33);
58+
59+
// distribute lattice vectors.
60+
for (int i = 0; i < 3; i++)
61+
{
62+
Parallel_Common::bcast_double(lat.a1[i]);
63+
Parallel_Common::bcast_double(lat.a2[i]);
64+
Parallel_Common::bcast_double(lat.a3[i]);
65+
Parallel_Common::bcast_double(lat.latcenter[i]);
66+
Parallel_Common::bcast_int(lat.lc[i]);
67+
}
68+
69+
// distribute superlattice vectors.
70+
Parallel_Common::bcast_double(latvec_supercell.e11);
71+
Parallel_Common::bcast_double(latvec_supercell.e12);
72+
Parallel_Common::bcast_double(latvec_supercell.e13);
73+
Parallel_Common::bcast_double(latvec_supercell.e21);
74+
Parallel_Common::bcast_double(latvec_supercell.e22);
75+
Parallel_Common::bcast_double(latvec_supercell.e23);
76+
Parallel_Common::bcast_double(latvec_supercell.e31);
77+
Parallel_Common::bcast_double(latvec_supercell.e32);
78+
Parallel_Common::bcast_double(latvec_supercell.e33);
79+
80+
// distribute Change the lattice vectors or not
81+
#endif
82+
}
83+
84+
void bcast_magnetism(Magnetism& magnet, const int ntype)
85+
{
86+
#ifdef __MPI
87+
MPI_Barrier(MPI_COMM_WORLD);
88+
Parallel_Common::bcast_double(magnet.start_magnetization, ntype);
89+
if (PARAM.inp.nspin == 4)
90+
{
91+
Parallel_Common::bcast_double(magnet.ux_[0]);
92+
Parallel_Common::bcast_double(magnet.ux_[1]);
93+
Parallel_Common::bcast_double(magnet.ux_[2]);
94+
}
95+
#endif
96+
}
97+
98+
void bcast_unitcell(UnitCell& ucell)
99+
{
100+
#ifdef __MPI
101+
const int ntype = ucell.ntype;
102+
Parallel_Common::bcast_int(ucell.nat);
103+
104+
bcast_Lattice(ucell.lat);
105+
bcast_magnetism(ucell.magnet,ntype);
106+
bcast_atoms_tau(ucell.atoms,ntype);
107+
108+
for (int i = 0; i < ntype; i++)
109+
{
110+
Parallel_Common::bcast_string(ucell.orbital_fn[i]);
111+
}
112+
113+
#ifdef __EXX
114+
ModuleBase::bcast_data_cereal(GlobalC::exx_info.info_ri.files_abfs,
115+
MPI_COMM_WORLD,
116+
0);
117+
#endif
118+
return;
119+
#endif
120+
}
15121
}

source/module_cell/bcast_cell.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
11
#ifndef BCAST_CELL_H
22
#define BCAST_CELL_H
33

4+
#include "module_cell/unitcell.h"
45
namespace unitcell
56
{
7+
/**
8+
* @brief broadcast the tau array of the atoms
9+
*
10+
* @param atoms: the atoms to be broadcasted [in/out]
11+
* @param ntype: the number of types of the atoms [in]
12+
*/
613
void bcast_atoms_tau(Atom* atoms,
14+
const int ntype);
15+
16+
/**
17+
* @brief broadcast the pseduo of the atoms
18+
*
19+
* @param atoms: the atoms to be broadcasted [in/out]
20+
* @param ntype: the number of types of the atoms [in]
21+
*/
22+
void bcast_atoms_pseudo(Atom* atoms,
23+
const int ntype);
24+
/**
25+
* @brief broadcast the lattice
26+
*
27+
* @param lat: the lattice to be broadcasted [in/out]
28+
*/
29+
void bcast_Lattice(Lattice& lat);
30+
31+
/**
32+
* @brief broadcast the magnetism
33+
*
34+
* @param magnet: the magnetism to be broadcasted [in/out]
35+
* @param nytpe: the number of types of the atoms [in]
36+
*/
37+
void bcast_magnetism(Magnetism& magnet,
738
const int ntype);
39+
40+
/**
41+
* @brief broadcast the unitcell
42+
*
43+
* @param ucell: the unitcell to be broadcasted [in/out]
44+
*/
45+
void bcast_unitcell(UnitCell& ucell);
46+
47+
848
}
949

1050
#endif // BCAST_CELL_H

source/module_cell/module_neighbor/test/prepare_unitcell.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ class UcellTestPrepare
8080
delete[] ucell->atom_mass;
8181
delete[] ucell->pseudo_fn;
8282
delete[] ucell->pseudo_type;
83-
delete[] ucell->orbital_fn;
83+
8484
delete[] ucell->magnet.start_magnetization; //mag set here
8585
ucell->atom_label = new std::string[ucell->ntype];
8686
ucell->atom_mass = new double[ucell->ntype];
8787
ucell->pseudo_fn = new std::string[ucell->ntype];
8888
ucell->pseudo_type = new std::string[ucell->ntype];
89-
ucell->orbital_fn = new std::string[ucell->ntype];
89+
ucell->orbital_fn.resize(ucell->ntype);
9090
ucell->magnet.start_magnetization = new double[ucell->ntype]; //mag set here
9191
ucell->magnet.ux_[0] = 0.0; // ux_ set here
9292
ucell->magnet.ux_[1] = 0.0;

source/module_cell/read_atoms.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ int UnitCell::read_atom_species(std::ifstream &ifa, std::ofstream &ofs_running)
2020
delete[] atom_mass;
2121
delete[] pseudo_fn;
2222
delete[] pseudo_type;
23-
delete[] orbital_fn;
2423
this->atom_mass = new double[ntype]; //atom masses
2524
this->atom_label = new std::string[ntype]; //atom labels
2625
this->pseudo_fn = new std::string[ntype]; //file name of pseudopotential
2726
this->pseudo_type = new std::string[ntype]; // type of pseudopotential
28-
this->orbital_fn = new std::string[ntype]; // filename of orbitals
2927

3028
std::string word;
3129
//==========================================

source/module_cell/test/prepare_unitcell.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ class UcellTestPrepare
7979
delete[] ucell->atom_mass;
8080
delete[] ucell->pseudo_fn;
8181
delete[] ucell->pseudo_type;
82-
delete[] ucell->orbital_fn;
82+
8383
delete[] ucell->magnet.start_magnetization; //mag set here
8484
ucell->atom_label = new std::string[ucell->ntype];
8585
ucell->atom_mass = new double[ucell->ntype];
8686
ucell->pseudo_fn = new std::string[ucell->ntype];
8787
ucell->pseudo_type = new std::string[ucell->ntype];
88-
ucell->orbital_fn = new std::string[ucell->ntype];
88+
ucell->orbital_fn.resize(ucell->ntype);
8989
ucell->magnet.start_magnetization = new double[ucell->ntype]; //mag set here
9090
ucell->magnet.ux_[0] = 0.0; // ux_ set here
9191
ucell->magnet.ux_[1] = 0.0;

source/module_cell/test/support/mock_unitcell.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ UnitCell::~UnitCell() {
1717
delete[] atom_mass;
1818
delete[] pseudo_fn;
1919
delete[] pseudo_type;
20-
delete[] orbital_fn;
2120
if (set_atom_flag) {
2221
delete[] atoms;
2322
}
@@ -37,10 +36,6 @@ bool UnitCell::read_atom_positions(std::ifstream& ifpos,
3736
bool UnitCell::judge_big_cell() const { return true; }
3837
void UnitCell::update_stress(ModuleBase::matrix& scs) {}
3938
void UnitCell::update_force(ModuleBase::matrix& fcs) {}
40-
#ifdef __MPI
41-
void UnitCell::bcast_unitcell() {}
42-
void UnitCell::bcast_unitcell2() {}
43-
#endif
4439
void UnitCell::set_iat2itia() {}
4540
void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) {}
4641
void UnitCell::read_orb_file(int it,

0 commit comments

Comments
 (0)