30 #ifndef FLANN_MPI_HPP_
31 #define FLANN_MPI_HPP_
33 #include <boost/mpi.hpp>
34 #include <boost/serialization/array.hpp>
43 template<
typename DistanceType>
49 template<
typename Archive>
54 if (Archive::is_loading::value) {
58 if (Archive::is_saving::value) {
63 if (Archive::is_loading::value) {
67 if (Archive::is_saving::value) {
73 template<
typename DistanceType>
83 for (
size_t i = 0; i < results.
dists.
rows; ++i) {
112 template<
typename Distance>
115 typedef typename Distance::ElementType ElementType;
116 typedef typename Distance::ResultType DistanceType;
124 Index(
const std::string& file_name,
125 const std::string& dataset_name,
151 return flann_index->
veclen();
166 template<
typename Distance>
169 boost::mpi::communicator world;
172 throw FLANNException(
"Saving/loading of MPI indexes is not currently supported.");
177 std::vector<int> sizes;
179 all_gather(world, (
int)flann_index->size(), sizes);
182 for (
size_t i = 0; i < sizes.size(); ++i) {
183 if ((
int)i < world.rank())
offset_ += sizes[i];
188 template<
typename Distance>
192 delete[] dataset.ptr();
195 template<
typename Distance>
198 boost::mpi::communicator world;
202 flann_index->knnSearch(queries, local_indices, local_dists, knn,
params);
203 for (
size_t i = 0; i < local_indices.
rows; ++i) {
204 for (
size_t j = 0; j < local_indices.
cols; ++j) {
205 local_indices[i][j] +=
offset_;
209 local_results.
indices = local_indices;
210 local_results.
dists = local_dists;
216 if (world.rank() == 0) {
217 for (
size_t i = 0; i < results.
indices.
rows; ++i) {
218 for (
size_t j = 0; j < results.
indices.
cols; ++j) {
219 indices[i][j] = results.
indices[i][j];
220 dists[i][j] = results.
dists[i][j];
228 template<
typename Distance>
231 boost::mpi::communicator world;
235 flann_index->radiusSearch(query, local_indices, local_dists, radius,
params);
236 for (
size_t i = 0; i < local_indices.
rows; ++i) {
237 for (
size_t j = 0; j < local_indices.
cols; ++j) {
238 local_indices[i][j] +=
offset_;
242 local_results.
indices = local_indices;
243 local_results.
dists = local_dists;
249 if (world.rank() == 0) {
252 indices[i][j] = results.
indices[i][j];
253 dists[i][j] = results.
dists[i][j];
266 template<
typename DistanceType>
cmdLineReadable * params[]
IndexParams getParameters() const
int radiusSearch(const flann::Matrix< ElementType > &query, flann::Matrix< int > &indices, flann::Matrix< DistanceType > &dists, float radius, const SearchParams ¶ms)
void knnSearch(const flann::Matrix< ElementType > &queries, flann::Matrix< int > &indices, flann::Matrix< DistanceType > &dists, int knn, const SearchParams ¶ms)
IndexParams getIndexParameters()
Index(const std::string &file_name, const std::string &dataset_name, const IndexParams ¶ms)
void load_from_file(flann::Matrix< T > &dataset, const std::string &filename, const std::string &name)
std::map< std::string, any > IndexParams
SearchResults< DistanceType > operator()(SearchResults< DistanceType > a, SearchResults< DistanceType > b)
flann::Matrix< int > indices
flann::Matrix< DistanceType > dists
void serialize(Archive &ar, const unsigned int version)