diff --git a/src/SMARTSIM/dump_atom_smartsim.cpp b/src/SMARTSIM/dump_atom_smartsim.cpp index 581cc338e74..18a410372d2 100644 --- a/src/SMARTSIM/dump_atom_smartsim.cpp +++ b/src/SMARTSIM/dump_atom_smartsim.cpp @@ -28,7 +28,8 @@ using namespace LAMMPS_NS; DumpAtomSmartSim::DumpAtomSmartSim(LAMMPS *lmp, int narg, char **arg) - : DumpAtom(lmp, narg, arg) + : DumpAtom(lmp, narg, arg), + client(_use_cluster()) { } @@ -62,11 +63,6 @@ void DumpAtomSmartSim::write() boxyz = domain->yz; } - - /* Construct SmartRedis Client object - */ - SmartRedis::Client client(true); - /* Construct DataSet object with unique name based on user prefix, MPI rank, and timestep @@ -231,3 +227,24 @@ void DumpAtomSmartSim::_pack_buf_into_array(T* data, int length, data[c++] = buf[i]; } } + +bool DumpAtomSmartSim::_use_cluster() +{ + char* use_cluster = std::getenv("SMARTREDIS_USE_CLUSTER"); + + // If the environment variable is not present, return false + if (use_cluster == NULL) + return false; + + // Convert the environment variable value to lowercase + char* c = use_cluster; + while((*c)!=0) { + (*c) = std::tolower(*c); + c++; + } + + if(std::strcmp(use_cluster, "true")==0) + return true; + + return false; +} diff --git a/src/SMARTSIM/dump_atom_smartsim.h b/src/SMARTSIM/dump_atom_smartsim.h index cc5af1479a9..472ed36212a 100644 --- a/src/SMARTSIM/dump_atom_smartsim.h +++ b/src/SMARTSIM/dump_atom_smartsim.h @@ -37,10 +37,23 @@ class DumpAtomSmartSim : public DumpAtom virtual void write(); virtual void init_style(); private: - std::string _make_dataset_key(); - template - void _pack_buf_into_array(T* data, int length, - int start_pos, int stride); + + // SmartRedis client object + SmartRedis::Client client; + + // Function to create a SmartRedis Dataset key + // to prevent key collisions + std::string _make_dataset_key(); + + // Function to take LAMMPS data structure and + // convert to array suitable for storage + template + void _pack_buf_into_array(T* data, int length, + int start_pos, int stride); + + // Function to read an environment variable to + // determine if a cluster is being used + bool _use_cluster(); }; }