inplace.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (C) 2005-2006 Alain Miniussi <alain.miniussi -at- oca.eu>.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Message Passing Interface 1.1 -- Section 4. MPI Collectives
  6. /** @file inplace.hpp
  7. *
  8. * This header provides helpers to indicate to MPI collective operation
  9. * that a buffer can be use both as an input and output.
  10. */
  11. #ifndef BOOST_MPI_INPLACE_HPP
  12. #define BOOST_MPI_INPLACE_HPP
  13. #include <boost/mpi/communicator.hpp>
  14. #include <vector>
  15. namespace boost { namespace mpi {
  16. /**
  17. * @brief Wrapper type to explicitly indicate that a input data
  18. * can be overriden with an output value.
  19. */
  20. template <typename T>
  21. struct inplace_t {
  22. inplace_t(T& inout) : buffer(inout) {}
  23. T& buffer;
  24. };
  25. template <typename T>
  26. struct inplace_t<T*> {
  27. inplace_t(T* inout) : buffer(inout) {}
  28. T* buffer;
  29. };
  30. /**
  31. * @brief Wrapp a input data to indicate that it can be overriden
  32. * with an ouput value.
  33. * @param inout the contributing input value, it will be overriden
  34. * with the output value where one is expected. If it is a pointer,
  35. * the number of elements will be provided separatly.
  36. * @returns The wrapped value or pointer.
  37. */
  38. template<typename T>
  39. inplace_t<T>
  40. inplace(T& inout) {
  41. return inplace_t<T>(inout);
  42. }
  43. /**
  44. * \overload
  45. */
  46. template<typename T>
  47. inplace_t<T*>
  48. inplace(T* inout) {
  49. return inplace_t<T*>(inout);
  50. }
  51. } } // end namespace boost::mpi
  52. #endif // BOOST_MPI_INPLACE_HPP