Skip to content

Commit

Permalink
Merge pull request #199 from hmcezar/thermostat-opt
Browse files Browse the repository at this point in the history
Broadcast root's PRNG to avoid comm in thermostat.
  • Loading branch information
hmcezar authored Sep 29, 2022
2 parents 1cf9929 + 973f10c commit decb4d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 4 additions & 0 deletions hymd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def main():
elif config.cancel_com_momentum:
velocities = cancel_com_momentum(velocities, config, comm=comm)

# set all PRNG to the root's PRNG
# this is done to avoid communication between ranks in the thermostat
prng = comm.bcast(prng, root=0)

bond_forces = np.zeros_like(positions)
angle_forces = np.zeros_like(positions)
dihedral_forces = np.zeros_like(positions)
Expand Down
12 changes: 4 additions & 8 deletions hymd/thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,10 @@ def csvr_thermostat(
N_f = 3 * group_n_particles
c = np.exp(-(config.time_step * config.respa_inner) / config.tau)

# Draw random numbers and broadcast them so they are identical across
# MPI ranks
R = SNf = None
if comm.Get_rank() == 0:
R = random_gaussian(prng)
SNf = random_chi_squared(prng, N_f - 1)
R = comm.bcast(R, root=0)
SNf = comm.bcast(SNf, root=0)
# Random numbers are identical across ranks because all ranks have
# the same prng after the initialization of the velocities
R = random_gaussian(prng)
SNf = random_chi_squared(prng, N_f - 1)

alpha2 = (
c + (1 - c) * (SNf + R**2) * K_target / (N_f * K)
Expand Down

0 comments on commit decb4d4

Please sign in to comment.