Nonblocking.h 1.32 KB
Newer Older
1
2
3
4
5
6
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2017 ISIS Rutherford Appleton Laboratory UKRI,
//     NScD Oak Ridge National Laboratory, European Spallation Source
//     & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

#include "MantidParallel/DllConfig.h"
#include "MantidParallel/Request.h"

#ifdef MPI_EXPERIMENTAL
#include <boost/mpi/nonblocking.hpp>
#endif

namespace Mantid {
namespace Parallel {

/** Wrapper for boost::mpi::nonblocking. For non-MPI builds an equivalent
  implementation with reduced functionality is provided.

  @author Simon Heybrock
  @date 2017
*/
template <typename ForwardIterator>
void wait_all(ForwardIterator begin, ForwardIterator end) {
#ifdef MPI_EXPERIMENTAL
28
29
30
31
32
33
  class RequestIteratorWrapper : public ForwardIterator {
  public:
    RequestIteratorWrapper(const ForwardIterator &it) : ForwardIterator(it) {}
    boost::mpi::request &operator*() { return ForwardIterator::operator*(); }
    boost::mpi::request *operator->() { return &operator*(); }
  };
34
  if (begin == end || !begin->hasBackend())
35
36
37
    return boost::mpi::wait_all(RequestIteratorWrapper(begin),
                                RequestIteratorWrapper(end));
#endif
38
39
40
41
42
43
44
45
  while (begin != end) {
    (*begin).wait();
    ++begin;
  }
}

} // namespace Parallel
} // namespace Mantid