Problem is in my misunderstanding on how boost MPI wrappers work.
I am using Microsoft MPI implementation.
In this code I am trying to scatter std::vector
to processes but get a debug assertion vector subscript out of range
error.
This code is my bootstrap to implement hypersort algorithm using boost wrappers and Microsoft MPI.
I tried examples from boost libraries but got the same assertion.
Also I tried to include both <vector>
and <boost/serialization/vector>
but it didn't help.
I run my program on Windows 10 using boost 1.70 and latest version of Microsoft MPI.
#pragma once
#include <boost/mpi.hpp>
#include <boost/mpi/collectives.hpp>
#include <boost/serialization/vector.hpp>
#include "qsort.hpp"
#include "utils.hpp"
namespace algo {
namespace mpi_extension {
namespace mpi = boost::mpi;
void hyperqsort_v1(int argc, char* argv[]) {
mpi::environment env(argc, argv);
mpi::communicator world;
int value = 0;
int recv_value = 0;
std::vector<int> unsorted_list{5, 3, 6, 2, 9, 1, 10, 7};
auto distribuion_number = unsorted_list.size() / world.size();
std::vector<std::vector<int>> unsorted_dist_list;
if(0 == world.rank()) {
for(size_t j = 0; j < world.size(); ++j) {
for(size_t k = 0 + j; k < distribuion_number + j; ++k) {
unsorted_dist_list[j].push_back(unsorted_list[j + k]);
}
}
}
std::vector<int> recv_vector;
recv_vector.resize(distribuion_number);
mpi::scatter(
world, unsorted_dist_list, recv_vector, 0);
}
} // namespace mpi_extension
} // namespace algo
qsort.hpp - sequential implementation of qsort algorithm
I expect all processes in communicator have their piece of unsorted list.
I can produce this error only in Debug build
Correct way is to use std::vector::data() to get the address of first element. May be it is specific only for Microsoft MPI implementation.
Example without rising debug assertion: mpiexec -n 4
mpi::environment env;
mpi::communicator world;
std::vector<int> unsorted_list{11, 36, 44, 50, 53, 67, 86, 95};
std::vector<int> list;
list.resize(2);
mpi::scatter(world, unsorted_list.data(), list.data(), 2, 0);