HavoqGT
havoqgt::distributed_db Class Reference

#include <distributed_db.hpp>

Classes

struct  header
 

Public Types

typedef mapped_type::segment_manager segment_manager_type
 

Public Member Functions

 distributed_db (db_create, const char *base_fname)
 
 distributed_db (db_open, const char *base_fname)
 
 ~distributed_db ()
 
segment_manager_typeget_segment_manager ()
 

Private Types

typedef boost::interprocess::basic_managed_mapped_file< char,boost::interprocess::rbtree_best_fit< boost::interprocess::null_mutex_family >,boost::interprocess::iset_index > mapped_type
 

Private Member Functions

uint64_t get_file_size ()
 
bool rank_file_exists ()
 
void init_rank_filename (const char *base_fname)
 

Private Attributes

mapped_typem_pm
 
std::string m_rank_filename
 

Detailed Description

Definition at line 86 of file distributed_db.hpp.

Member Typedef Documentation

typedef boost::interprocess::basic_managed_mapped_file<char ,boost::interprocess::rbtree_best_fit<boost::interprocess::null_mutex_family> ,boost::interprocess::iset_index> havoqgt::distributed_db::mapped_type
private

Definition at line 98 of file distributed_db.hpp.

typedef mapped_type::segment_manager havoqgt::distributed_db::segment_manager_type

Definition at line 101 of file distributed_db.hpp.

Constructor & Destructor Documentation

havoqgt::distributed_db::distributed_db ( db_create  ,
const char *  base_fname 
)
inline

Definition at line 106 of file distributed_db.hpp.

107  {
108  int mpi_rank = havoqgt_env()->world_comm().rank();
109  int mpi_size = havoqgt_env()->world_comm().size();
110 
111  init_rank_filename(base_fname);
112  if(rank_file_exists())
113  {
114  HAVOQGT_ERROR_MSG("File already exists.");
115  }
116 
117  m_pm = new mapped_type(boost::interprocess::create_only, m_rank_filename.c_str(), get_file_size());
118 
119  #ifdef HAVE_POSIX_FALLOCATE
120  {
121  int fd = open(m_rank_filename.c_str(), O_RDWR);
122  if(fd == -1) {
123  HAVOQGT_ERROR_MSG("Error opening file.");
124  }
125  int ret = posix_fallocate(fd,0,get_file_size());
126  if(ret != 0)
127  {
128  HAVOQGT_ERROR_MSG("posix_fallocate failed.");
129  }
130  close(fd);
131  }
132  #else
133  #warning posix_fallocate not found; OSX?
134  #endif
135 
136  //
137  // Create header
138  header* phead = m_pm->construct<header>(boost::interprocess::unique_instance)();
139  if(mpi_rank == 0) {
140  phead->uuid = boost::uuids::random_generator()();
141  }
142  mpi::mpi_bcast(phead->uuid,0,havoqgt_env()->world_comm().comm());
143  //std::cout << "Rank = " << mpi_rank << ", UUID = " << phead->uuid << std::endl;
144  phead->comm_rank = mpi_rank;
145  phead->comm_size = mpi_size;
146  phead->clean_close = false;
147  }
const communicator & world_comm() const
int size() const
Definition: mpi.hpp:618
int rank() const
Definition: mpi.hpp:619
environment * havoqgt_env()
boost::interprocess::basic_managed_mapped_file< char,boost::interprocess::rbtree_best_fit< boost::interprocess::null_mutex_family >,boost::interprocess::iset_index > mapped_type
void init_rank_filename(const char *base_fname)
void mpi_bcast(T &data, int root, MPI_Comm comm)
Definition: mpi.hpp:559
#define HAVOQGT_ERROR_MSG(msg)
Definition: error.hpp:62

Here is the call graph for this function:

havoqgt::distributed_db::distributed_db ( db_open  ,
const char *  base_fname 
)
inline

Definition at line 152 of file distributed_db.hpp.

153  {
154  int mpi_rank = havoqgt_env()->world_comm().rank();
155  int mpi_size = havoqgt_env()->world_comm().size();
156 
157  init_rank_filename(base_fname);
158  if(!rank_file_exists())
159  {
160  std::stringstream error;
161  error << "ERROR: " << __FILE__ << ":" << __LINE__ << ": file not found.";
162  throw std::runtime_error(error.str());
163  }
164 
165  m_pm = new mapped_type(boost::interprocess::open_only, m_rank_filename.c_str());
166 
167  //
168  // Check for header
169  std::pair<header*, std::size_t> ret = m_pm->find<header>(boost::interprocess::unique_instance);
170  if(ret.second == 0) {
171  std::stringstream error;
172  error << "ERROR: " << __FILE__ << ":" << __LINE__ << ": header now found.";
173  throw std::runtime_error(error.str());
174  }
175 
176  //
177  // Check UUID
178  boost::uuids::uuid uuid;
179  if(mpi_rank == 0) {
180  uuid = ret.first->uuid;
181  }
182  mpi::mpi_bcast(uuid,0,havoqgt_env()->world_comm().comm());
183  if(uuid != ret.first->uuid)
184  {
185  std::stringstream error;
186  error << "ERROR: " << __FILE__ << ":" << __LINE__ << ": UUIDs don't match.";
187  throw std::runtime_error(error.str());
188  }
189  //std::cout << "Rank = " << mpi_rank << ", UUID = " << ret.first->uuid << std::endl;
190  if(ret.first->comm_rank != mpi_rank ||
191  ret.first->comm_size != mpi_size ||
192  !ret.first->clean_close) {
193  std::stringstream error;
194  error << "ERROR: " << __FILE__ << ":" << __LINE__ << ": DB corrupt.";
195  throw std::runtime_error(error.str());
196  }
197  }
const communicator & world_comm() const
int size() const
Definition: mpi.hpp:618
int rank() const
Definition: mpi.hpp:619
environment * havoqgt_env()
boost::interprocess::basic_managed_mapped_file< char,boost::interprocess::rbtree_best_fit< boost::interprocess::null_mutex_family >,boost::interprocess::iset_index > mapped_type
void init_rank_filename(const char *base_fname)
void mpi_bcast(T &data, int root, MPI_Comm comm)
Definition: mpi.hpp:559

Here is the call graph for this function:

havoqgt::distributed_db::~distributed_db ( )
inline

Definition at line 202 of file distributed_db.hpp.

203  {
204  //
205  // Mark clean close
206  std::pair<header*, std::size_t> ret = m_pm->find<header>(boost::interprocess::unique_instance);
207  if(ret.second == 0) {
208  std::stringstream error;
209  error << "ERROR: " << __FILE__ << ":" << __LINE__ << ": header now found.";
210  throw std::runtime_error(error.str());
211  }
212  ret.first->clean_close = true;
213 
214  delete m_pm;
215  m_pm = nullptr;
216  bool shrink_ret = mapped_type::shrink_to_fit(m_rank_filename.c_str());
217  }

Member Function Documentation

uint64_t havoqgt::distributed_db::get_file_size ( )
inlineprivate

Definition at line 229 of file distributed_db.hpp.

230  {
231  const char* fsize = getenv("HAVOQGT_DB_SIZE");
232  if(fsize == NULL) {
233  //return 700ULL * 1024ULL * 1024ULL * 1024ULL / 24;
234  //return 799700000000ULL;
235  //return 500ULL * 1024ULL * 1024ULL * 1024ULL;
236  // causing probs return 799700000000ULL / 24ULL;
237  // MAXES OUT CATALST!! return 799595142400 / 24ULL;
238  return 512*1024*1024 / havoqgt_env()->node_local_comm().size();
239  }
240  return boost::lexical_cast<uint64_t>(fsize);
241  }
int size() const
Definition: mpi.hpp:618
environment * havoqgt_env()
const communicator & node_local_comm() const

Here is the call graph for this function:

Here is the caller graph for this function:

segment_manager_type* havoqgt::distributed_db::get_segment_manager ( )
inline

Definition at line 219 of file distributed_db.hpp.

220  {
221  return m_pm->get_segment_manager();
222  }

Here is the caller graph for this function:

void havoqgt::distributed_db::init_rank_filename ( const char *  base_fname)
inlineprivate

Definition at line 256 of file distributed_db.hpp.

257  {
258  int mpi_rank = havoqgt_env()->world_comm().rank();
259  int mpi_size = havoqgt_env()->world_comm().size();
260  std::stringstream sstr;
261  sstr << base_fname << "_" << mpi_rank << "_of_" << mpi_size;
262  m_rank_filename = sstr.str();
263  }
const communicator & world_comm() const
int size() const
Definition: mpi.hpp:618
int rank() const
Definition: mpi.hpp:619
environment * havoqgt_env()

Here is the call graph for this function:

Here is the caller graph for this function:

bool havoqgt::distributed_db::rank_file_exists ( )
inlineprivate

Definition at line 247 of file distributed_db.hpp.

248  {
249  std::ifstream fin(m_rank_filename.c_str());
250  return fin.good();
251  }

Here is the caller graph for this function:

Member Data Documentation

mapped_type* havoqgt::distributed_db::m_pm
private

Definition at line 267 of file distributed_db.hpp.

std::string havoqgt::distributed_db::m_rank_filename
private

Definition at line 268 of file distributed_db.hpp.


The documentation for this class was generated from the following file: