forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@12651 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
51a148df16
commit
9f3c85870b
|
@ -2,7 +2,6 @@
|
|||
#include "mpi.h"
|
||||
#include "lammps.h"
|
||||
#include "atom.h"
|
||||
#include "comm.h"
|
||||
#include "error.h"
|
||||
#include "output.h"
|
||||
#include "random_park.h"
|
||||
|
@ -62,8 +61,9 @@ colvarproxy_lammps::colvarproxy_lammps(LAMMPS_NS::LAMMPS *lmp,
|
|||
const char *inp_name,
|
||||
const char *out_name,
|
||||
const int seed,
|
||||
const double temp)
|
||||
: _lmp(lmp)
|
||||
const double temp,
|
||||
MPI_Comm root2root)
|
||||
: _lmp(lmp), inter_comm(root2root)
|
||||
{
|
||||
if (cvm::debug())
|
||||
log("Initializing the colvars proxy object.\n");
|
||||
|
@ -90,7 +90,7 @@ colvarproxy_lammps::colvarproxy_lammps(LAMMPS_NS::LAMMPS *lmp,
|
|||
// output prefix is always given
|
||||
output_prefix_str = std::string(out_name);
|
||||
// not so for restarts
|
||||
restart_prefix_str = std::string("rest");
|
||||
restart_output_prefix_str = std::string("rest");
|
||||
|
||||
// check if it is possible to save output configuration
|
||||
if ((!output_prefix_str.size()) && (!restart_output_prefix_str.size())) {
|
||||
|
@ -101,13 +101,19 @@ colvarproxy_lammps::colvarproxy_lammps(LAMMPS_NS::LAMMPS *lmp,
|
|||
// try to extract a restart prefix from a potential restart command.
|
||||
LAMMPS_NS::Output *outp = _lmp->output;
|
||||
if ((outp->restart_every_single > 0) && (outp->restart1 != 0)) {
|
||||
restart_prefix_str = std::string(outp->restart1);
|
||||
restart_output_prefix_str = std::string(outp->restart1);
|
||||
} else if ((outp->restart_every_double > 0) && (outp->restart2a != 0)) {
|
||||
restart_prefix_str = std::string(outp->restart2a);
|
||||
restart_output_prefix_str = std::string(outp->restart2a);
|
||||
}
|
||||
// trim off unwanted stuff from the restart prefix
|
||||
if (restart_prefix_str.rfind(".*") != std::string::npos)
|
||||
restart_prefix_str.erase(restart_prefix_str.rfind(".*"),2);
|
||||
if (restart_output_prefix_str.rfind(".*") != std::string::npos)
|
||||
restart_output_prefix_str.erase(restart_output_prefix_str.rfind(".*"),2);
|
||||
|
||||
// initialize multi-replica support, if available
|
||||
if (replica_enabled()) {
|
||||
MPI_Comm_rank(inter_comm, &inter_me);
|
||||
MPI_Comm_size(inter_comm, &inter_num);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -393,6 +399,36 @@ int colvarproxy_lammps::init_lammps_atom(const int &aid, cvm::atom *atom)
|
|||
return colvars_atoms.size()-1;
|
||||
}
|
||||
|
||||
// multi-replica support
|
||||
|
||||
void colvarproxy_lammps::replica_comm_barrier() {
|
||||
MPI_Barrier(inter_comm);
|
||||
}
|
||||
|
||||
int colvarproxy_lammps::replica_comm_recv(char* msg_data,
|
||||
int buf_len, int src_rep)
|
||||
{
|
||||
MPI_Status status;
|
||||
int retval;
|
||||
|
||||
retval = MPI_Recv(msg_data,buf_len,MPI_CHAR,src_rep,0,inter_comm,&status);
|
||||
if (retval == MPI_SUCCESS) {
|
||||
MPI_Get_count(&status, MPI_CHAR, &retval);
|
||||
} else retval = 0;
|
||||
return retval;
|
||||
}
|
||||
|
||||
int colvarproxy_lammps::replica_comm_send(char* msg_data,
|
||||
int msg_len, int dest_rep)
|
||||
{
|
||||
int retval;
|
||||
retval = MPI_Send(msg_data,msg_len,MPI_CHAR,dest_rep,0,inter_comm);
|
||||
if (retval == MPI_SUCCESS) {
|
||||
retval = msg_len;
|
||||
} else retval = 0;
|
||||
return retval;
|
||||
}
|
||||
|
||||
// atom member functions, LAMMPS specific implementations
|
||||
|
||||
cvm::atom::atom(const int &id)
|
||||
|
|
|
@ -44,10 +44,6 @@ class colvarproxy_lammps : public colvarproxy {
|
|||
int restart_every;
|
||||
int previous_step;
|
||||
|
||||
std::string input_prefix_str;
|
||||
std::string output_prefix_str;
|
||||
std::string restart_prefix_str;
|
||||
|
||||
bool first_timestep;
|
||||
bool system_force_requested;
|
||||
bool do_exit;
|
||||
|
@ -59,10 +55,13 @@ class colvarproxy_lammps : public colvarproxy {
|
|||
std::vector<struct commdata> applied_forces;
|
||||
std::vector<struct commdata> previous_applied_forces;
|
||||
|
||||
MPI_Comm inter_comm; // MPI comm with 1 root proc from each world
|
||||
int inter_me, inter_num; // rank for the inter replica comm
|
||||
|
||||
public:
|
||||
friend class cvm::atom;
|
||||
colvarproxy_lammps (LAMMPS_NS::LAMMPS *lmp, const char *,
|
||||
const char *, const int, const double);
|
||||
const char *, const int, const double, MPI_Comm);
|
||||
virtual ~colvarproxy_lammps();
|
||||
void init(const char*);
|
||||
void setup();
|
||||
|
@ -102,9 +101,6 @@ class colvarproxy_lammps : public colvarproxy {
|
|||
cvm::real temperature() { return t_target; };
|
||||
cvm::real dt() { return _lmp->update->dt * _lmp->force->femtosecond; };
|
||||
|
||||
inline std::string input_prefix() { return input_prefix_str; };
|
||||
inline std::string output_prefix() { return output_prefix_str; };
|
||||
inline std::string restart_output_prefix() { return restart_prefix_str; };
|
||||
inline size_t restart_frequency() { return restart_every; };
|
||||
|
||||
void add_energy (cvm::real energy) { bias_energy = energy; };
|
||||
|
@ -137,6 +133,26 @@ class colvarproxy_lammps : public colvarproxy {
|
|||
|
||||
cvm::real rand_gaussian(void) { return _random->gaussian(); };
|
||||
|
||||
// implementation of optional methods from base class
|
||||
public:
|
||||
// Multi-replica support
|
||||
// Indicate if multi-replica support is available and active
|
||||
virtual bool replica_enabled() { return (inter_comm != MPI_COMM_NULL); }
|
||||
|
||||
// Index of this replica
|
||||
virtual int replica_index() { return inter_me; }
|
||||
|
||||
// Total number of replica
|
||||
virtual int replica_num() { return inter_num; }
|
||||
|
||||
// Synchronize replica
|
||||
virtual void replica_comm_barrier();
|
||||
|
||||
// Receive data from other replica
|
||||
virtual int replica_comm_recv(char* msg_data, int buf_len, int src_rep);
|
||||
|
||||
// Send data to other replica
|
||||
virtual int replica_comm_send(char* msg_data, int msg_len, int dest_rep);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "memory.h"
|
||||
#include "modify.h"
|
||||
#include "respa.h"
|
||||
#include "universe.h"
|
||||
#include "update.h"
|
||||
#include "citeme.h"
|
||||
|
||||
|
@ -276,6 +277,7 @@ FixColvars::FixColvars(LAMMPS *lmp, int narg, char **arg) :
|
|||
restart_global = 1;
|
||||
|
||||
me = comm->me;
|
||||
root2root = MPI_COMM_NULL;
|
||||
|
||||
conf_file = strdup(arg[3]);
|
||||
rng_seed = 1966;
|
||||
|
@ -352,6 +354,9 @@ FixColvars::~FixColvars()
|
|||
delete hashtable;
|
||||
}
|
||||
|
||||
if (root2root != MPI_COMM_NULL)
|
||||
MPI_Comm_free(&root2root);
|
||||
|
||||
--instances;
|
||||
}
|
||||
|
||||
|
@ -397,7 +402,14 @@ void FixColvars::one_time_init()
|
|||
if (init_flag) return;
|
||||
init_flag = 1;
|
||||
|
||||
// create and initialize the colvars proxy
|
||||
if (universe->nworlds > 1) {
|
||||
// create inter root communicator
|
||||
int color = 1;
|
||||
if (me == 0) color = 0;
|
||||
MPI_Comm_split(universe->uworld,color,universe->iworld,&root2root);
|
||||
}
|
||||
|
||||
// create and initialize the colvars proxy
|
||||
|
||||
if (me == 0) {
|
||||
if (screen) fputs("colvars: Creating proxy instance\n",screen);
|
||||
|
@ -428,7 +440,8 @@ void FixColvars::one_time_init()
|
|||
}
|
||||
}
|
||||
|
||||
proxy = new colvarproxy_lammps(lmp,inp_name,out_name,rng_seed,t_target);
|
||||
proxy = new colvarproxy_lammps(lmp,inp_name,out_name,
|
||||
rng_seed,t_target,root2root);
|
||||
proxy->init(conf_file);
|
||||
coords = proxy->get_coords();
|
||||
forces = proxy->get_forces();
|
||||
|
|
|
@ -84,6 +84,7 @@ class FixColvars : public Fix {
|
|||
int init_flag; // 1 if initialized, 0 if not
|
||||
static int instances; // count fix instances, since colvars currently
|
||||
// only supports one instance at a time
|
||||
MPI_Comm root2root; // inter-root communicator for multi-replica support
|
||||
void one_time_init(); // one time initialization
|
||||
};
|
||||
|
||||
|
|
|
@ -704,13 +704,10 @@ void PairHybrid::modify_params(int narg, char **arg)
|
|||
{
|
||||
if (narg == 0) error->all(FLERR,"Illegal pair_modify command");
|
||||
|
||||
// apply args to pair hybrid itself
|
||||
// important for some keywords like tail or compute
|
||||
|
||||
Pair::modify_params(narg,arg);
|
||||
|
||||
// if 1st keyword is pair, then apply args to one sub-style
|
||||
// else pass args to every sub-style
|
||||
// also apply all args (except pair) to pair hybrid itself
|
||||
// important for some keywords like tail or compute
|
||||
|
||||
if (strcmp(arg[0],"pair") == 0) {
|
||||
if (narg < 2) error->all(FLERR,"Illegal pair_modify command");
|
||||
|
@ -718,20 +715,24 @@ void PairHybrid::modify_params(int narg, char **arg)
|
|||
for (m = 0; m < nstyles; m++)
|
||||
if (strcmp(arg[1],keywords[m]) == 0) break;
|
||||
if (m == nstyles) error->all(FLERR,"Unknown pair_modify hybrid sub-style");
|
||||
if (multiple[m] == 0)
|
||||
if (multiple[m] == 0) {
|
||||
Pair::modify_params(narg-2,&arg[2]);
|
||||
styles[m]->modify_params(narg-2,&arg[2]);
|
||||
else {
|
||||
} else {
|
||||
if (narg < 3) error->all(FLERR,"Illegal pair_modify command");
|
||||
int multiflag = force->inumeric(FLERR,arg[2]);
|
||||
for (m = 0; m < nstyles; m++)
|
||||
if (strcmp(arg[1],keywords[m]) == 0 && multiflag == multiple[m]) break;
|
||||
if (m == nstyles)
|
||||
error->all(FLERR,"Unknown pair_modify hybrid sub-style");
|
||||
Pair::modify_params(narg-2,&arg[3]);
|
||||
styles[m]->modify_params(narg-3,&arg[3]);
|
||||
}
|
||||
|
||||
} else
|
||||
} else {
|
||||
Pair::modify_params(narg,arg);
|
||||
for (int m = 0; m < nstyles; m++) styles[m]->modify_params(narg,arg);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue