Skip to content

Commit 61fd8ec

Browse files
committed
fix: a bug that MD stuck
It is because different cores get different different postions of atoms. fix issue #932
1 parent 7b45a80 commit 61fd8ec

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

source/module_md/FIRE.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ void FIRE::first_half()
3636
{
3737
ModuleBase::TITLE("FIRE", "first_half");
3838
ModuleBase::timer::tick("FIRE", "first_half");
39-
39+
if(GlobalV::MY_RANK == 0)
40+
{
4041
for(int i=0; i<ucell.nat; ++i)
4142
{
4243
for(int k=0; k<3; ++k)
@@ -60,6 +61,10 @@ void FIRE::first_half()
6061
}
6162
}
6263
}
64+
}
65+
#ifdef __MPI
66+
MPI_Bcast(pos , ucell.nat*3,MPI_DOUBLE,0,MPI_COMM_WORLD);
67+
#endif
6368

6469
ucell.update_pos_tau(pos);
6570
ucell.periodic_boundary_adjustment();

source/module_md/MD_func.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ void MD_func::kinetic_stress(
7575
// This function calculates the classical kinetic energy of atoms
7676
// and its contribution to stress.
7777
//----------------------------------------------------------------------------
78-
78+
if(GlobalV::MY_RANK==0) //only first rank do md
79+
{
7980
kinetic = MD_func::GetAtomKE(unit_in.nat, vel, allmass);
8081

8182
ModuleBase::matrix temp;
@@ -106,6 +107,7 @@ void MD_func::kinetic_stress(
106107
}
107108
}
108109
}
110+
}
109111
}
110112

111113
// Read Velocity from STRU liuyu 2021-09-24

source/module_md/MSST.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ void MSST::first_half()
8383

8484
const int sd = mdp.msst_direction;
8585
const double dthalf = 0.5 * mdp.md_dt;
86-
86+
double vol;
87+
if( GlobalV::MY_RANK == 0 )
88+
{
8789
energy_ = potential + kinetic;
8890

8991
// propagate the time derivative of volume 1/2 step
@@ -112,7 +114,7 @@ void MSST::first_half()
112114
propagate_vel();
113115

114116
// propagate volume 1/2 step
115-
double vol = ucell.omega + omega[sd] * dthalf;
117+
vol = ucell.omega + omega[sd] * dthalf;
116118

117119
// rescale positions and change box size
118120
rescale(vol);
@@ -122,6 +124,11 @@ void MSST::first_half()
122124
{
123125
pos[i] += vel[i] * mdp.md_dt;
124126
}
127+
}
128+
#ifdef __MPI
129+
MPI_Bcast(pos , ucell.nat*3,MPI_DOUBLE,0,MPI_COMM_WORLD);
130+
#endif
131+
125132
ucell.update_pos_tau(pos);
126133
ucell.periodic_boundary_adjustment();
127134

@@ -141,7 +148,8 @@ void MSST::second_half()
141148

142149
const int sd = mdp.msst_direction;
143150
const double dthalf = 0.5 * mdp.md_dt;
144-
151+
if( GlobalV::MY_RANK == 0 )
152+
{
145153
energy_ = potential + kinetic;
146154

147155
// propagate velocities 1/2 step
@@ -156,6 +164,7 @@ void MSST::second_half()
156164

157165
// calculate Lagrangian position
158166
lag_pos -= mdp.msst_vel * ucell.omega / v0 * mdp.md_dt;
167+
}
159168

160169
ModuleBase::timer::tick("MSST", "second_half");
161170
}

source/module_md/verlet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void Verlet::setup(ModuleESolver::ESolver *p_esolver)
7272

7373
void Verlet::first_half()
7474
{
75+
if(GlobalV::MY_RANK==0) //only first rank do md
7576
for(int i=0; i<ucell.nat; ++i)
7677
{
7778
for(int k=0; k<3; ++k)
@@ -83,6 +84,9 @@ void Verlet::first_half()
8384
}
8485
}
8586
}
87+
#ifdef __MPI
88+
MPI_Bcast(pos , ucell.nat*3,MPI_DOUBLE,0,MPI_COMM_WORLD);
89+
#endif
8690

8791
ucell.update_pos_tau(pos);
8892
ucell.periodic_boundary_adjustment();
@@ -91,6 +95,7 @@ void Verlet::first_half()
9195

9296
void Verlet::second_half()
9397
{
98+
if(GlobalV::MY_RANK==0) //only first rank do md
9499
for(int i=0; i<ucell.nat; ++i)
95100
{
96101
for(int k=0; k<3; ++k)

0 commit comments

Comments
 (0)