computation_tree.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (C) 2005 Douglas Gregor.
  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. // Compute parents, children, levels, etc. to effect a parallel
  6. // computation tree.
  7. #ifndef BOOST_MPI_COMPUTATION_TREE_HPP
  8. #define BOOST_MPI_COMPUTATION_TREE_HPP
  9. namespace boost { namespace mpi { namespace detail {
  10. /**
  11. * @brief Aids tree-based parallel collective algorithms.
  12. *
  13. * Objects of this type
  14. */
  15. class computation_tree
  16. {
  17. public:
  18. computation_tree(int rank, int size, int root, int branching_factor = -1);
  19. /// Returns the branching factor of the tree.
  20. int branching_factor() const { return branching_factor_; }
  21. /// Returns the level in the tree on which this process resides.
  22. int level() const { return level_; }
  23. /**
  24. * Returns the index corresponding to the n^th level of the tree.
  25. *
  26. * @param n The level in the tree whose index will be returned.
  27. */
  28. int level_index(int n) const;
  29. /**
  30. * @brief Returns the parent of this process.
  31. *
  32. * @returns If this process is the root, returns itself. Otherwise,
  33. * returns the process number that is the parent in the computation
  34. * tree.
  35. */
  36. int parent() const;
  37. /// Returns the index for the first child of this process.
  38. int child_begin() const;
  39. /**
  40. * @brief The default branching factor within the computation tree.
  41. *
  42. * This is the default branching factor for the computation tree, to
  43. * be used by any computation tree that does not fix the branching
  44. * factor itself. The default is initialized to 3, but may be
  45. * changed by the application so long as all processes have the same
  46. * branching factor.
  47. */
  48. static int default_branching_factor;
  49. protected:
  50. /// The rank of this process in the computation tree.
  51. int rank;
  52. /// The number of processes participating in the computation tree.
  53. int size;
  54. /// The process number that is acting as the root in the computation
  55. /// tree.
  56. int root;
  57. /**
  58. * @brief The branching factor within the computation tree.
  59. *
  60. * This is the default number of children that each node in a
  61. * computation tree will have. This value will be used for
  62. * collective operations that use tree-based algorithms.
  63. */
  64. int branching_factor_;
  65. /// The level in the tree at which this process resides.
  66. int level_;
  67. };
  68. } } } // end namespace boost::mpi::detail
  69. #endif // BOOST_MPI_COMPUTATION_TREE_HPP