Skip to content

Commit

Permalink
Change client constructor to be called during dump
Browse files Browse the repository at this point in the history
creation and use environment variable to choose if a
cluster is being used.
  • Loading branch information
mellis13 committed Nov 4, 2021
1 parent 6d3c538 commit 1afbee4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
29 changes: 23 additions & 6 deletions src/SMARTSIM/dump_atom_smartsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
21 changes: 17 additions & 4 deletions src/SMARTSIM/dump_atom_smartsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,23 @@ class DumpAtomSmartSim : public DumpAtom
virtual void write();
virtual void init_style();
private:
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

0 comments on commit 1afbee4

Please sign in to comment.