1 #ifndef __MASTER_NODE__
2 #define __MASTER_NODE__
13 #include <boost/archive/text_oarchive.hpp>
14 #include <boost/archive/text_iarchive.hpp>
15 #include <boost/serialization/vector.hpp>
16 #include <boost/serialization/utility.hpp>
36 ,
class NeighborStrategy_t
43 MasterNode(MPI_Comm master_comm,
size_t buf_size_upper_bound,
size_t dim,
49 MPI_Comm_rank(master_comm, &tmp);
50 myID_ =
static_cast<size_t>(tmp);
52 MPI_Comm_size(master_comm, &tmp);
57 MPI_Alloc_mem(
sizeof(
char) * buf_size_upper_bound,
62 sizeof(
char), MPI_INFO_NULL, master_comm, &
win_);
64 MPI_Win_create(&
revision_, 1,
sizeof(
size_t), MPI_INFO_NULL,
81 void store(
char *local_state,
size_t buffer_size) {
84 MPI_Win_fence(MPI_MODE_NOPUT,
win_rev_);
86 size_t buf_size = buffer_size;
88 std::cout <<
"windows too small: " << buffer_size <<
" / "
92 MPI_Win_fence(MPI_MODE_NOPUT,
win_);
98 void collect(std::ostringstream &states) {
102 SolutionState_t tmp_states;
107 if(i ==
myID_)
continue;
112 MPI_Get(&revision, 1, MPI_UNSIGNED_LONG, i, 0, 1, MPI_UNSIGNED_LONG,
win_rev_);
120 MPI_Win_fence(0,
win_);
122 std::istringstream is(buffer);
123 boost::archive::text_iarchive ia(is);
126 SolutionState_t state;
128 tmp_states.insert(tmp_states.end(), state.begin(), state.end());
131 boost::archive::text_oarchive oa(states);
134 MPI_Free_mem(buffer);
Implements a node in the network of all pilots, exposing store and collect operations on a specific s...
std::vector< size_t > revision_state_
revision numbers of my neighbors
void store(char *local_state, size_t buffer_size)
store my best values
size_t revision_
my solution state revision number
std::set< size_t > collectFrom_
neighbors we collect solution states from
MasterNode(MPI_Comm master_comm, size_t buf_size_upper_bound, size_t dim, int island_id)
size_t buf_size_upper_bound_
and upper bound on the allocated memory in the MPI window
char * serialized_best_values_
pointer to MPI window holding current best solution state
Inform & endl(Inform &inf)
void collect(std::ostringstream &states)
collect all best values from all other masters