54 #ifndef HAVOQGT_DISTRIBUTED_DB_HPP_INCLUDED
55 #define HAVOQGT_DISTRIBUTED_DB_HPP_INCLUDED
57 #include <boost/interprocess/managed_mapped_file.hpp>
58 #include <boost/interprocess/allocators/allocator.hpp>
59 #include <boost/lexical_cast.hpp>
60 #include <boost/uuid/uuid.hpp>
61 #include <boost/uuid/uuid_generators.hpp>
62 #include <boost/uuid/uuid_io.hpp>
68 #include <sys/types.h>
95 typedef boost::interprocess::basic_managed_mapped_file
97 ,boost::interprocess::rbtree_best_fit<boost::interprocess::null_mutex_family>
119 #ifdef HAVE_POSIX_FALLOCATE
133 #warning posix_fallocate not found; OSX?
138 header* phead =
m_pm->construct<
header>(boost::interprocess::unique_instance)();
140 phead->
uuid = boost::uuids::random_generator()();
160 std::stringstream error;
161 error <<
"ERROR: " << __FILE__ <<
":" << __LINE__ <<
": file not found.";
162 throw std::runtime_error(error.str());
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());
178 boost::uuids::uuid uuid;
180 uuid = ret.first->
uuid;
183 if(uuid != ret.first->uuid)
185 std::stringstream error;
186 error <<
"ERROR: " << __FILE__ <<
":" << __LINE__ <<
": UUIDs don't match.";
187 throw std::runtime_error(error.str());
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());
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());
221 return m_pm->get_segment_manager();
231 const char* fsize = getenv(
"HAVOQGT_DB_SIZE");
240 return boost::lexical_cast<uint64_t>(fsize);
260 std::stringstream sstr;
261 sstr << base_fname <<
"_" << mpi_rank <<
"_of_" << mpi_size;
277 #endif //HAVOQGT_DISTRIBUTED_DB_HPP_INCLUDED
std::string m_rank_filename
distributed_db(db_open, const char *base_fname)
const communicator & world_comm() const
environment * havoqgt_env()
mapped_type::segment_manager segment_manager_type
boost::interprocess::basic_managed_mapped_file< char,boost::interprocess::rbtree_best_fit< boost::interprocess::null_mutex_family >,boost::interprocess::iset_index > mapped_type
segment_manager_type * get_segment_manager()
void init_rank_filename(const char *base_fname)
const communicator & node_local_comm() const
void mpi_bcast(T &data, int root, MPI_Comm comm)
distributed_db(db_create, const char *base_fname)
#define HAVOQGT_ERROR_MSG(msg)