Skip to content

Commit

Permalink
use group in mcmd
Browse files Browse the repository at this point in the history
  • Loading branch information
brucefan1983 committed Aug 23, 2023
1 parent e23d295 commit 4799153
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main_gpumd/run.cu
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void Run::perform_a_run()

integrate.compute2(time_step, double(step) / number_of_steps, group, box, atom, thermo);

mc.compute(step, number_of_steps, atom, box);
mc.compute(step, number_of_steps, atom, box, group);

measure.process(
number_of_steps,
Expand Down
4 changes: 2 additions & 2 deletions src/mc/mc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ void MC::initialize(void)

void MC::finalize(void) { do_mcmd = false; }

void MC::compute(int step, int num_steps, Atom& atom, Box& box)
void MC::compute(int step, int num_steps, Atom& atom, Box& box, std::vector<Group>& group)
{
if (do_mcmd) {
if ((step + 2) % num_steps_md == 0) {
double temperature =
temperature_initial + step * (temperature_final - temperature_initial) / num_steps;
mc_ensemble->compute(step + 2, temperature, atom, box);
mc_ensemble->compute(step + 2, temperature, atom, box, group[grouping_method], group_id);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mc/mc.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public:

void initialize(void);
void finalize(void);
void compute(int step, int num_steps, Atom& atom, Box& box);
void compute(int step, int num_steps, Atom& atom, Box& box, std::vector<Group>& group);

void parse_mc(
const char** param, int num_param, std::vector<Group>& group, std::vector<int>& cpu_type);
Expand Down
3 changes: 2 additions & 1 deletion src/mc/mc_ensemble.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public:
MC_Ensemble(void);
virtual ~MC_Ensemble(void);

virtual void compute(int md_step, double temperature, Atom& atom, Box& box) = 0;
virtual void
compute(int md_step, double temperature, Atom& atom, Box& box, Group& group, int group_id) = 0;

protected:
int num_steps_mc = 0;
Expand Down
10 changes: 6 additions & 4 deletions src/mc/mc_ensemble_canonical.cu
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ static bool check_if_small_box(const double rc, const Box& box)
return is_small_box;
}

void MC_Ensemble_Canonical::compute(int md_step, double temperature, Atom& atom, Box& box)
void MC_Ensemble_Canonical::compute(
int md_step, double temperature, Atom& atom, Box& box, Group& group, int group_id)
{
if (check_if_small_box(nep_energy.paramb.rc_radial, box)) {
printf("Cannot use small box for MCMD.\n");
Expand All @@ -232,16 +233,17 @@ void MC_Ensemble_Canonical::compute(int md_step, double temperature, Atom& atom,
type_after.resize(atom.number_of_atoms);
}

std::uniform_int_distribution<int> r1(0, atom.number_of_atoms - 1);
int group_size = group.cpu_size[group_id];
std::uniform_int_distribution<int> r1(0, group_size - 1);

int num_accepted = 0;
for (int step = 0; step < num_steps_mc; ++step) {

int i = r1(rng);
int i = group.cpu_contents[group.cpu_size_sum[group_id] + r1(rng)];
int type_i = atom.cpu_type[i];
int j = 0, type_j = type_i;
while (type_i == type_j) {
j = r1(rng);
j = group.cpu_contents[group.cpu_size_sum[group_id] + r1(rng)];
type_j = atom.cpu_type[j];
}

Expand Down
3 changes: 2 additions & 1 deletion src/mc/mc_ensemble_canonical.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public:
MC_Ensemble_Canonical(int num_steps_mc);
virtual ~MC_Ensemble_Canonical(void);

virtual void compute(int md_step, double temperature, Atom& atom, Box& box);
virtual void
compute(int md_step, double temperature, Atom& atom, Box& box, Group& group, int group_id);

private:
GPU_Vector<int> NN_ij;
Expand Down

0 comments on commit 4799153

Please sign in to comment.