From e23d2954cdc527e05bd1c09672c5cd6fbdb7bb04 Mon Sep 17 00:00:00 2001 From: Zheyong Fan Date: Thu, 24 Aug 2023 04:51:14 +0800 Subject: [PATCH] check group for mcmd --- src/main_gpumd/run.cu | 2 +- src/mc/mc.cu | 21 ++++++++++++++++++++- src/mc/mc.cuh | 3 ++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main_gpumd/run.cu b/src/main_gpumd/run.cu index d86ca30d8..261ab65b4 100644 --- a/src/main_gpumd/run.cu +++ b/src/main_gpumd/run.cu @@ -403,7 +403,7 @@ void Run::parse_one_keyword(std::vector& tokens) } else if (strcmp(param[0], "electron_stop") == 0) { electron_stop.parse(param, num_param, atom.number_of_atoms, number_of_types); } else if (strcmp(param[0], "mc") == 0) { - mc.parse_mc(param, num_param, group); + mc.parse_mc(param, num_param, group, atom.cpu_type); } else if (strcmp(param[0], "run") == 0) { parse_run(param, num_param); } else { diff --git a/src/mc/mc.cu b/src/mc/mc.cu index f06391441..73de300fd 100644 --- a/src/mc/mc.cu +++ b/src/mc/mc.cu @@ -41,7 +41,8 @@ void MC::compute(int step, int num_steps, Atom& atom, Box& box) } } -void MC::parse_mc(const char** param, int num_param, std::vector& groups) +void MC::parse_mc( + const char** param, int num_param, std::vector& groups, std::vector& cpu_type) { if (num_param < 6) { PRINT_INPUT_ERROR("mc should have at least 5 parameters.\n"); @@ -113,6 +114,24 @@ void MC::parse_mc(const char** param, int num_param, std::vector& groups) if (group_id >= groups[grouping_method].number) { PRINT_INPUT_ERROR("Group ID should < number of groups."); } + + bool has_multi_types = false; + int type0 = 0; + for (int k = 0; k < groups[grouping_method].cpu_size[group_id]; ++k) { + int n = + groups[grouping_method].cpu_contents[groups[grouping_method].cpu_size_sum[group_id] + k]; + if (k == 0) { + type0 = cpu_type[n]; + } else { + if (cpu_type[n] != type0) { + has_multi_types = true; + break; + } + } + } + if (!has_multi_types) { + PRINT_INPUT_ERROR("Must have more than one atom type in the specified group."); + } } } diff --git a/src/mc/mc.cuh b/src/mc/mc.cuh index dfaebbc22..ea12bbc79 100644 --- a/src/mc/mc.cuh +++ b/src/mc/mc.cuh @@ -32,7 +32,8 @@ public: void finalize(void); void compute(int step, int num_steps, Atom& atom, Box& box); - void parse_mc(const char** param, int num_param, std::vector& group); + void parse_mc( + const char** param, int num_param, std::vector& group, std::vector& cpu_type); private: bool do_mcmd = false;