From 9effcca0df719d1051d488d1c74a7753cae23c63 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 11 Sep 2015 14:49:37 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14025 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/USER-OMP/pair_dpd_omp.cpp | 27 +++++++++++++++++++-------- src/USER-OMP/pair_dpd_omp.h | 1 + src/USER-OMP/pair_dpd_tstat_omp.cpp | 27 +++++++++++++++++++-------- src/USER-OMP/pair_dpd_tstat_omp.h | 1 + src/error.cpp | 4 ++-- src/error.h | 2 +- src/input.cpp | 5 +++-- src/lammps.cpp | 6 +++--- 8 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/USER-OMP/pair_dpd_omp.cpp b/src/USER-OMP/pair_dpd_omp.cpp index 070c2dc4c2..23408469e3 100644 --- a/src/USER-OMP/pair_dpd_omp.cpp +++ b/src/USER-OMP/pair_dpd_omp.cpp @@ -35,6 +35,7 @@ PairDPDOMP::PairDPDOMP(LAMMPS *lmp) : suffix_flag |= Suffix::OMP; respa_enable = 0; random_thr = NULL; + nthreads = 0; } /* ---------------------------------------------------------------------- */ @@ -42,7 +43,7 @@ PairDPDOMP::PairDPDOMP(LAMMPS *lmp) : PairDPDOMP::~PairDPDOMP() { if (random_thr) { - for (int i=1; i < comm->nthreads; ++i) + for (int i=1; i < nthreads; ++i) delete random_thr[i]; delete[] random_thr; @@ -59,16 +60,26 @@ void PairDPDOMP::compute(int eflag, int vflag) } else evflag = vflag_fdotr = 0; const int nall = atom->nlocal + atom->nghost; - const int nthreads = comm->nthreads; const int inum = list->inum; - if (!random_thr) + // number of threads has changed. reallocate pool of pRNGs + if (nthreads != comm->nthreads) { + if (random_thr) { + for (int i=1; i < nthreads; ++i) + delete random_thr[i]; + + delete[] random_thr; + } + + nthreads = comm->nthreads; random_thr = new RanMars*[nthreads]; + for (int i=1; i < nthreads; ++i) + random_thr[i] = NULL; - // to ensure full compatibility with the serial DPD style - // we use is random number generator instance for thread 0 - random_thr[0] = random; - + // to ensure full compatibility with the serial DPD style + // we use the serial random number generator instance for thread 0 + random_thr[0] = random; + } #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif @@ -82,7 +93,7 @@ void PairDPDOMP::compute(int eflag, int vflag) // generate a random number generator instance for // all threads != 0. make sure we use unique seeds. - if (random_thr && tid > 0) + if (random_thr && (tid > 0) && (random_thr[tid] == NULL)) random_thr[tid] = new RanMars(Pair::lmp, seed + comm->me + comm->nprocs*tid); diff --git a/src/USER-OMP/pair_dpd_omp.h b/src/USER-OMP/pair_dpd_omp.h index 470e6f1133..cacf4bd4bf 100644 --- a/src/USER-OMP/pair_dpd_omp.h +++ b/src/USER-OMP/pair_dpd_omp.h @@ -40,6 +40,7 @@ class PairDPDOMP : public PairDPD, public ThrOMP { protected: class RanMars **random_thr; + int nthreads; private: template diff --git a/src/USER-OMP/pair_dpd_tstat_omp.cpp b/src/USER-OMP/pair_dpd_tstat_omp.cpp index fc725e8cf5..ca5b70186b 100644 --- a/src/USER-OMP/pair_dpd_tstat_omp.cpp +++ b/src/USER-OMP/pair_dpd_tstat_omp.cpp @@ -35,6 +35,7 @@ PairDPDTstatOMP::PairDPDTstatOMP(LAMMPS *lmp) : suffix_flag |= Suffix::OMP; respa_enable = 0; random_thr = NULL; + nthreads = 0; } /* ---------------------------------------------------------------------- */ @@ -42,7 +43,7 @@ PairDPDTstatOMP::PairDPDTstatOMP(LAMMPS *lmp) : PairDPDTstatOMP::~PairDPDTstatOMP() { if (random_thr) { - for (int i=1; i < comm->nthreads; ++i) + for (int i=1; i < nthreads; ++i) delete random_thr[i]; delete[] random_thr; @@ -59,16 +60,26 @@ void PairDPDTstatOMP::compute(int eflag, int vflag) } else evflag = vflag_fdotr = 0; const int nall = atom->nlocal + atom->nghost; - const int nthreads = comm->nthreads; const int inum = list->inum; - if (!random_thr) + // number of threads has changed. reallocate pool of pRNGs + if (nthreads != comm->nthreads) { + if (random_thr) { + for (int i=1; i < nthreads; ++i) + delete random_thr[i]; + + delete[] random_thr; + } + + nthreads = comm->nthreads; random_thr = new RanMars*[nthreads]; + for (int i=1; i < nthreads; ++i) + random_thr[i] = NULL; - // to ensure full compatibility with the serial DPD style - // we use is random number generator instance for thread 0 - random_thr[0] = random; - + // to ensure full compatibility with the serial DPD style + // we use the serial random number generator instance for thread 0 + random_thr[0] = random; + } #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif @@ -82,7 +93,7 @@ void PairDPDTstatOMP::compute(int eflag, int vflag) // generate a random number generator instance for // all threads != 0. make sure we use unique seeds. - if (random_thr && tid > 0) + if (random_thr && (tid > 0) && (random_thr[tid] == NULL)) random_thr[tid] = new RanMars(Pair::lmp, seed + comm->me + comm->nprocs*tid); diff --git a/src/USER-OMP/pair_dpd_tstat_omp.h b/src/USER-OMP/pair_dpd_tstat_omp.h index b04874efc2..48c5142038 100644 --- a/src/USER-OMP/pair_dpd_tstat_omp.h +++ b/src/USER-OMP/pair_dpd_tstat_omp.h @@ -40,6 +40,7 @@ class PairDPDTstatOMP : public PairDPDTstat, public ThrOMP { protected: class RanMars **random_thr; + int nthreads; private: template diff --git a/src/error.cpp b/src/error.cpp index 191a9894d4..46f098328f 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -154,7 +154,7 @@ void Error::message(const char *file, int line, const char *str, int logflag) no abort, so insure all procs in world call, else will hang ------------------------------------------------------------------------- */ -void Error::done() +void Error::done(int status) { MPI_Barrier(world); @@ -163,5 +163,5 @@ void Error::done() if (logfile) fclose(logfile); MPI_Finalize(); - exit(1); + exit(status); } diff --git a/src/error.h b/src/error.h index 9e8a6491c2..fb44c966db 100644 --- a/src/error.h +++ b/src/error.h @@ -30,7 +30,7 @@ class Error : protected Pointers { void one(const char *, int, const char *); void warning(const char *, int, const char *, int = 1); void message(const char *, int, const char *, int = 1); - void done(); + void done(int = 0); // 1 would be fully backwards compatible }; } diff --git a/src/input.cpp b/src/input.cpp index a9e7ffea39..8f753c789f 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1079,8 +1079,9 @@ void Input::python() void Input::quit() { - if (narg) error->all(FLERR,"Illegal quit command"); - error->done(); + if (narg == 0) error->done(0); // 1 would be fully backwards compatible + if (narg == 1) error->done(force->inumeric(FLERR,arg[0])); + error->all(FLERR,"Illegal quit command"); } /* ---------------------------------------------------------------------- */ diff --git a/src/lammps.cpp b/src/lammps.cpp index 7e351ea73b..d6f46cc329 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -507,11 +507,11 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) memory->destroy(pfirst); memory->destroy(plast); - // if helpflag set, print help and quit + // if helpflag set, print help and quit with "success" status if (helpflag) { if (universe->me == 0 && screen) help(); - error->done(); + error->done(0); } // if restartflag set, invoke 2 commands and quit @@ -528,7 +528,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) sprintf(&cmd[strlen(cmd)]," %s",arg[iarg]); strcat(cmd," noinit\n"); input->one(cmd); - error->done(); + error->done(0); } }