44#ifdef BERTINI2_HAVE_MPI
69template<
typename TaskT,
typename ResultT>
72 std::queue<TaskT>& tasks,
73 std::function<
void(ResultT
const&)> store_fn)
76 MPI_Comm_size(comm, &world_size);
77 const int num_workers = world_size - 1;
85 std::map<int, int> capacity;
86 for (
int ii = 0; ii < num_workers; ++ii)
90 MPI_Recv(&cap, 1, MPI_INT, MPI_ANY_SOURCE,
TAG_CAPACITY, comm, &status);
91 capacity[status.MPI_SOURCE] = (cap >= 1) ? cap : 1;
94 std::map<int, int> outstanding;
95 int active_workers = num_workers;
99 for (
auto const& [rank, cap] : capacity)
101 outstanding[rank] = 0;
102 for (
int ii = 0; ii < cap && !tasks.empty(); ++ii)
104 TaskT task = tasks.front(); tasks.pop();
108 if (outstanding[rank] == 0)
110 mpi_send_serialized(comm, rank,
TAG_WORK_ITEM, sentinel_value);
117 while (active_workers > 0)
120 int worker = mpi_recv_serialized_any(comm,
TAG_RESULT, result);
123 --outstanding[worker];
127 TaskT task = tasks.front(); tasks.pop();
129 ++outstanding[worker];
131 else if (outstanding[worker] == 0)
133 mpi_send_serialized(comm, worker,
TAG_WORK_ITEM, sentinel_value);
Single include point for the MPI C API.
Serialization-aware MPI send/recv helpers using plain C MPI + Boost.Serialization.
std::size_t make_sentinel(std::size_t)
Make the sentinel index value.
Definition path_result.hpp:192
Definition initialize_finalize.hpp:43
constexpr int TAG_CAPACITY
MPI message tag: worker -> manager, max tasks in flight on that rank.
Definition path_result.hpp:49
constexpr int TAG_RESULT
MPI message tag: worker -> manager result.
Definition path_result.hpp:48
constexpr int TAG_WORK_ITEM
MPI message tag: manager -> worker work item.
Definition path_result.hpp:47
Definition algorithm_builder.hpp:36
Result struct used in the manager-worker MPI protocol for ZeroDim.