From 32509da7219643f1b46f491ea84e8a650155ef00 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 15 Apr 2016 16:06:25 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14828 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/Make.py | 2 +- src/USER-COLVARS/colvarproxy_lammps.cpp | 85 +++++++++++++++++++++++++ src/USER-COLVARS/colvarproxy_lammps.h | 23 ++++++- 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/src/Make.py b/src/Make.py index 6ab41af99a..0a05255277 100755 --- a/src/Make.py +++ b/src/Make.py @@ -613,7 +613,7 @@ Syntax: Make.py switch args ... -atc, -awpmd, -colvars, -cuda, -gpu, -h5md, -meam, -poems, -python, -qmmm, -reax, -voronoi switches for build and makefile options: - -intel, -kokkos, -cc, -mpi, -fft, -jpg, -png + -intel, -kokkos, -cc, -flags, -mpi, -fft, -jpg, -png """ # jmake switch diff --git a/src/USER-COLVARS/colvarproxy_lammps.cpp b/src/USER-COLVARS/colvarproxy_lammps.cpp index f42a2573d2..71786f060e 100644 --- a/src/USER-COLVARS/colvarproxy_lammps.cpp +++ b/src/USER-COLVARS/colvarproxy_lammps.cpp @@ -9,6 +9,8 @@ #include "fix_colvars.h" #include "colvarmodule.h" +#include "colvar.h" +#include "colvarbias.h" #include "colvaratoms.h" #include "colvarproxy.h" #include "colvarproxy_lammps.h" @@ -109,11 +111,20 @@ colvarproxy_lammps::colvarproxy_lammps(LAMMPS_NS::LAMMPS *lmp, if (restart_output_prefix_str.rfind(".*") != std::string::npos) restart_output_prefix_str.erase(restart_output_prefix_str.rfind(".*"),2); +#if defined(_OPENMP) + if (smp_thread_id() == 0) { + omp_init_lock(&smp_lock_state); + } +#endif + // initialize multi-replica support, if available if (replica_enabled()) { MPI_Comm_rank(inter_comm, &inter_me); MPI_Comm_size(inter_comm, &inter_num); } + + if (cvm::debug()) + log("Done initializing the colvars proxy object.\n"); } @@ -320,6 +331,80 @@ int colvarproxy_lammps::backup_file(char const *filename) } } + +#if defined(_OPENMP) + + +// SMP support + +int colvarproxy_lammps::smp_enabled() +{ + return COLVARS_OK; +} + + +int colvarproxy_lammps::smp_colvars_loop() +{ + colvarmodule *cv = this->colvars; +#pragma omp parallel for + for (size_t i = 0; i < cv->colvars_smp.size(); i++) { + if (cvm::debug()) { + cvm::log("Calculating colvar \""+cv->colvars_smp[i]->name+"\" on thread "+cvm::to_str(smp_thread_id())+"\n"); + } + cv->colvars_smp[i]->calc_cvcs(cv->colvars_smp_items[i], 1); + } + return cvm::get_error(); +} + + +int colvarproxy_lammps::smp_biases_loop() +{ + colvarmodule *cv = this->colvars; +#pragma omp parallel for + for (size_t i = 0; i < cv->biases.size(); i++) { + if (cvm::debug()) { + cvm::log("Calculating bias \""+cv->biases[i]->name+"\" on thread "+cvm::to_str(smp_thread_id())+"\n"); + } + cv->biases[i]->update(); + } + return cvm::get_error(); +} + + +int colvarproxy_lammps::smp_thread_id() +{ + return omp_get_thread_num(); +} + + +int colvarproxy_lammps::smp_num_threads() +{ + return omp_get_max_threads(); +} + + +int colvarproxy_lammps::smp_lock() +{ + omp_set_lock(&smp_lock_state); + return COLVARS_OK; +} + + +int colvarproxy_lammps::smp_trylock() +{ + return omp_test_lock(&smp_lock_state) ? COLVARS_OK : COLVARS_ERROR; +} + + +int colvarproxy_lammps::smp_unlock() +{ + omp_unset_lock(&smp_lock_state); + return COLVARS_OK; +} + +#endif + + // multi-replica support void colvarproxy_lammps::replica_comm_barrier() { diff --git a/src/USER-COLVARS/colvarproxy_lammps.h b/src/USER-COLVARS/colvarproxy_lammps.h index 25ffa2502a..6368e965f7 100644 --- a/src/USER-COLVARS/colvarproxy_lammps.h +++ b/src/USER-COLVARS/colvarproxy_lammps.h @@ -5,6 +5,7 @@ #include "colvarmodule.h" #include "colvarproxy.h" +#include "colvarvalue.h" #include "lammps.h" #include "domain.h" @@ -16,8 +17,12 @@ #include #include +#if defined(_OPENMP) +#include +#endif + #ifndef COLVARPROXY_VERSION -#define COLVARPROXY_VERSION "2016-02-28" +#define COLVARPROXY_VERSION "2016-04-08" #endif /* struct for packed data communication of coordinates and forces. */ @@ -130,6 +135,22 @@ class colvarproxy_lammps : public colvarproxy { // implementation of optional methods from base class public: + +#if defined(_OPENMP) + // SMP support + int smp_enabled(); + int smp_colvars_loop(); + int smp_biases_loop(); + int smp_thread_id(); + int smp_num_threads(); +protected: + omp_lock_t smp_lock_state; +public: + int smp_lock(); + int smp_trylock(); + int smp_unlock(); +#endif + // Multi-replica support // Indicate if multi-replica support is available and active virtual bool replica_enabled() { return (inter_comm != MPI_COMM_NULL); }