From 67c5bb2a0d1cdcb5e3b7bf11637854f62d0fa747 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 15 Nov 2022 21:13:22 -0500 Subject: [PATCH] small programming style updates --- src/REACTION/fix_bond_react.cpp | 43 +++++++++++++++++---------------- src/REACTION/fix_bond_react.h | 4 +-- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/REACTION/fix_bond_react.cpp b/src/REACTION/fix_bond_react.cpp index 8857590c4f..d6dcb2d8b6 100644 --- a/src/REACTION/fix_bond_react.cpp +++ b/src/REACTION/fix_bond_react.cpp @@ -22,6 +22,7 @@ Contributing Author: Jacob Gissinger (jacob.r.gissinger@gmail.com) #include "atom_vec.h" #include "citeme.h" #include "comm.h" +#include "compute.h" #include "domain.h" #include "error.h" #include "fix_bond_history.h" @@ -118,11 +119,8 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : fix3 = nullptr; reset_mol_ids = nullptr; - if (narg < 8) error->all(FLERR,"Illegal fix bond/react command: " - "too few arguments"); + if (narg < 8) utils::missing_cmd_args(FLERR,"fix bond/react", error); - MPI_Comm_rank(world,&me); - MPI_Comm_size(world,&nprocs); newton_bond = force->newton_bond; restart_global = 1; @@ -495,7 +493,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : for (int i = 0; i < nreacts; i++) { for (int j = 0; j < nconstraints[i]; j++) { if (constraints[j][i].type == ARRHENIUS) { - rrhandom[tmp++] = new RanMars(lmp,(int) constraints[j][i].par[4] + me); + rrhandom[tmp++] = new RanMars(lmp,(int) constraints[j][i].par[4] + comm->me); } } } @@ -530,7 +528,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : random = new RanMars*[nreacts]; for (int i = 0; i < nreacts; i++) { - random[i] = new RanMars(lmp,seed[i] + me); + random[i] = new RanMars(lmp,seed[i] + comm->me); } // set comm sizes needed by this fix @@ -1252,6 +1250,7 @@ void FixBondReact::close_partner() void FixBondReact::superimpose_algorithm() { + const int nprocs = comm->nprocs; local_num_mega = 0; ghostly_num_mega = 0; @@ -1401,7 +1400,7 @@ void FixBondReact::superimpose_algorithm() MPI_Allreduce(&local_rxn_count[0],&reaction_count[0],nreacts,MPI_INT,MPI_SUM,world); int rxnflag = 0; - if (me == 0) + if (comm->me == 0) for (int i = 0; i < nreacts; i++) { reaction_count_total[i] += reaction_count[i] + ghostly_rxn_count[i]; rxnflag += reaction_count[i] + ghostly_rxn_count[i]; @@ -1441,7 +1440,7 @@ void FixBondReact::superimpose_algorithm() memory->create(local_rxncounts,nprocs,"bond/react:local_rxncounts"); memory->create(all_localskips,nprocs,"bond/react:all_localskips"); MPI_Gather(&local_rxn_count[i],1,MPI_INT,local_rxncounts,1,MPI_INT,0,world); - if (me == 0) { + if (comm->me == 0) { int delta_rxn = reaction_count[i] + ghostly_rxn_count[i]; // when using variable input for rate_limit, rate_limit_overstep could be > delta_rxn (below) // we need to limit overstep to the number of reactions on this timestep @@ -2616,7 +2615,7 @@ void FixBondReact::find_landlocked_atoms(int myrxn) } // also, if atoms change number of bonds, but aren't landlocked, that could be bad - if (me == 0) + if (comm->me == 0) for (int i = 0; i < twomol->natoms; i++) { if ((create_atoms[i][myrxn] == 0) && (twomol_nxspecial[i][0] != onemol_nxspecial[equivalences[i][1][myrxn]-1][0]) && @@ -2948,6 +2947,7 @@ broadcast entries of mega_glove which contain nonlocal atoms for perusal by all void FixBondReact::ghost_glovecast() { #if !defined(MPI_STUBS) + const int nprocs = comm->nprocs; global_megasize = 0; @@ -2966,7 +2966,7 @@ void FixBondReact::ghost_glovecast() int *allstarts = new int[nprocs]; int start = 0; - for (int i = 0; i < me; i++) { + for (int i = 0; i < comm->me; i++) { start += allncols[i]; } MPI_Allgather(&start, 1, MPI_INT, allstarts, 1, MPI_INT, world); @@ -2994,7 +2994,7 @@ void FixBondReact::ghost_glovecast() } } // let's send to root, dedup, then broadcast - if (me == 0) { + if (comm->me == 0) { MPI_Gatherv(MPI_IN_PLACE, ghostly_num_mega, column, // Note: some values ignored for MPI_IN_PLACE &(global_mega_glove[0][0]), allncols, allstarts, column, 0, world); @@ -3004,7 +3004,7 @@ void FixBondReact::ghost_glovecast() column, 0, world); } - if (me == 0) dedup_mega_gloves(GLOBAL); // global_mega_glove mode + if (comm->me == 0) dedup_mega_gloves(GLOBAL); // global_mega_glove mode MPI_Bcast(&global_megasize,1,MPI_INT,0,world); MPI_Bcast(&(global_mega_glove[0][0]), global_megasize, column, 0, world); @@ -3746,7 +3746,7 @@ int FixBondReact::insert_atoms(tagint **my_mega_glove, int iupdate) Superpose3D superposer(n2superpose); int fitroot = 0; if (ifit >= 0 && ifit < atom->nlocal) { - fitroot = me; + fitroot = comm->me; // get 'temperatere' averaged over site, used for created atoms' vels t = get_temperature(my_mega_glove,1,iupdate); @@ -3764,7 +3764,8 @@ int FixBondReact::insert_atoms(tagint **my_mega_glove, int iupdate) int ipre = equivalences[j][1][rxnID]-1; // equiv pre-reaction template index if (!create_atoms[j][rxnID] && !delete_atoms[ipre][rxnID]) { if (atom->map(my_mega_glove[ipre+1][iupdate]) < 0) { - error->warning(FLERR," eligible atoms skipped for created-atoms fit on rank {}\n",me); + error->warning(FLERR," eligible atoms skipped for created-atoms fit on rank {}\n", + comm->me); continue; } iatom = atom->map(my_mega_glove[ipre+1][iupdate]); @@ -3792,7 +3793,7 @@ int FixBondReact::insert_atoms(tagint **my_mega_glove, int iupdate) if (create_atoms[m][rxnID] == 1) { // apply optimal rotation/translation for created atom coords // also map coords back into simulation box - if (fitroot == me) { + if (fitroot == comm->me) { MathExtra::matvec(rotmat,twomol->x[m],coords[m]); for (int i = 0; i < 3; i++) coords[m][i] += superposer.T[i]; imageflags[m] = atom->image[ifit]; @@ -3880,7 +3881,7 @@ int FixBondReact::insert_atoms(tagint **my_mega_glove, int iupdate) int root = 0; if (flag) { - root = me; + root = comm->me; atom->avec->create_atom(twomol->type[m],coords[m]); int n = atom->nlocal - 1; @@ -4026,7 +4027,7 @@ void FixBondReact::read_map_file(int myrxn) while (strlen(keyword)) { if (strcmp(keyword,"InitiatorIDs") == 0 || strcmp(keyword,"BondingIDs") == 0) { if (strcmp(keyword,"BondingIDs") == 0) - if (me == 0) error->warning(FLERR,"Fix bond/react: The BondingIDs section title has been deprecated. Please use InitiatorIDs instead."); + if (comm->me == 0) error->warning(FLERR,"Fix bond/react: The BondingIDs section title has been deprecated. Please use InitiatorIDs instead."); bondflag = 1; readline(line); sscanf(line,"%d",&ibonding[myrxn]); @@ -4292,7 +4293,7 @@ void FixBondReact::open(char *file) void FixBondReact::readline(char *line) { int n; - if (me == 0) { + if (comm->me == 0) { if (fgets(line,MAXLINE,fp) == nullptr) n = 0; else n = strlen(line) + 1; } @@ -4309,7 +4310,7 @@ void FixBondReact::parse_keyword(int flag, char *line, char *keyword) // eof is set to 1 if any read hits end-of-file int eof = 0; - if (me == 0) { + if (comm->me == 0) { if (fgets(line,MAXLINE,fp) == nullptr) eof = 1; while (eof == 0 && strspn(line," \t\n\r") == strlen(line)) { if (fgets(line,MAXLINE,fp) == nullptr) eof = 1; @@ -4328,7 +4329,7 @@ void FixBondReact::parse_keyword(int flag, char *line, char *keyword) // bcast keyword line to all procs int n; - if (me == 0) n = strlen(line) + 1; + if (comm->me == 0) n = strlen(line) + 1; MPI_Bcast(&n,1,MPI_INT,0,world); MPI_Bcast(line,n,MPI_CHAR,0,world); } @@ -4493,7 +4494,7 @@ void FixBondReact::write_restart(FILE *fp) memcpy(rbuf,&store_rxn_count[0][0],sizeof(int)*rbufcount); } - if (me == 0) { + if (comm->me == 0) { int size = nreacts*sizeof(Set)+(rbufcount+1)*sizeof(int); fwrite(&size,sizeof(int),1,fp); fwrite(&revision,sizeof(int),1,fp); diff --git a/src/REACTION/fix_bond_react.h b/src/REACTION/fix_bond_react.h index b55608b07e..5bc20883ca 100644 --- a/src/REACTION/fix_bond_react.h +++ b/src/REACTION/fix_bond_react.h @@ -25,7 +25,6 @@ FixStyle(bond/react,FixBondReact); #define LMP_FIX_BOND_REACT_H #include "fix.h" -#include "compute.h" #include #include @@ -55,7 +54,6 @@ class FixBondReact : public Fix { double memory_usage() override; private: - int me, nprocs; int newton_bond; int nreacts; int *nevery; @@ -236,7 +234,7 @@ class FixBondReact : public Fix { std::vector customvarstrs; int nvvec; double **vvec; // per-atom vector to store custom constraint atom-style variable values - Compute *cperbond; // pointer to 'compute bond/local' used by custom constraint ('rxnbond' function) + class Compute *cperbond; // pointer to 'compute bond/local' used by custom constraint ('rxnbond' function) std::map, int> atoms2bond; // maps atom pair to index of local bond array std::vector> constraints;