Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/SMARTSIM/dump_atom_smartsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ using namespace LAMMPS_NS;
DumpAtomSmartSim::DumpAtomSmartSim(LAMMPS *lmp, int narg, char **arg)
: DumpAtom(lmp, narg, arg)
{
SmartRedis::Client* client = NULL;
this->_client = NULL;
SmartRedis::Client* client = NULL;
this->_client = NULL;
try {
Client* client = new Client(true);
client = new Client(_use_cluster());
this->_client = client;
}
catch(std::exception& e) {
Expand All @@ -50,8 +50,8 @@ DumpAtomSmartSim::DumpAtomSmartSim(LAMMPS *lmp, int narg, char **arg)

DumpAtomSmartSim::~DumpAtomSmartSim()
{
if(this->_client != NULL)
delete this->_client;
if(this->_client != NULL)
delete this->_client;
}

/* ---------------------------------------------------------------------- */
Expand All @@ -78,7 +78,6 @@ void DumpAtomSmartSim::write()
boxyz = domain->yz;
}


/* Construct DataSet object with unique
name based on user prefix, MPI rank, and
timestep
Expand Down Expand Up @@ -243,3 +242,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;
}
23 changes: 18 additions & 5 deletions src/SMARTSIM/dump_atom_smartsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,24 @@ class DumpAtomSmartSim : public DumpAtom
virtual void write();
virtual void init_style();
private:
SmartRedis::Client* _client;
std::string _make_dataset_key();
template <typename T>
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 <typename T>
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();

};
}

Expand Down