Chris@16: // Copyright (C) 2005 Douglas Gregor. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // Compute parents, children, levels, etc. to effect a parallel Chris@16: // computation tree. Chris@16: #ifndef BOOST_MPI_COMPUTATION_TREE_HPP Chris@16: #define BOOST_MPI_COMPUTATION_TREE_HPP Chris@16: Chris@16: namespace boost { namespace mpi { namespace detail { Chris@16: Chris@16: /** Chris@16: * @brief Aids tree-based parallel collective algorithms. Chris@16: * Chris@16: * Objects of this type Chris@16: */ Chris@16: class computation_tree Chris@16: { Chris@16: public: Chris@16: computation_tree(int rank, int size, int root, int branching_factor = -1); Chris@16: Chris@16: /// Returns the branching factor of the tree. Chris@16: int branching_factor() const { return branching_factor_; } Chris@16: Chris@16: /// Returns the level in the tree on which this process resides. Chris@16: int level() const { return level_; } Chris@16: Chris@16: /** Chris@16: * Returns the index corresponding to the n^th level of the tree. Chris@16: * Chris@16: * @param n The level in the tree whose index will be returned. Chris@16: */ Chris@16: int level_index(int n) const; Chris@16: Chris@16: /** Chris@16: * @brief Returns the parent of this process. Chris@16: * Chris@16: * @returns If this process is the root, returns itself. Otherwise, Chris@16: * returns the process number that is the parent in the computation Chris@16: * tree. Chris@16: */ Chris@16: int parent() const; Chris@16: Chris@16: /// Returns the index for the first child of this process. Chris@16: int child_begin() const; Chris@16: Chris@16: /** Chris@16: * @brief The default branching factor within the computation tree. Chris@16: * Chris@16: * This is the default branching factor for the computation tree, to Chris@16: * be used by any computation tree that does not fix the branching Chris@16: * factor itself. The default is initialized to 3, but may be Chris@16: * changed by the application so long as all processes have the same Chris@16: * branching factor. Chris@16: */ Chris@16: static int default_branching_factor; Chris@16: Chris@16: protected: Chris@16: /// The rank of this process in the computation tree. Chris@16: int rank; Chris@16: Chris@16: /// The number of processes participating in the computation tree. Chris@16: int size; Chris@16: Chris@16: /// The process number that is acting as the root in the computation Chris@16: /// tree. Chris@16: int root; Chris@16: Chris@16: /** Chris@16: * @brief The branching factor within the computation tree. Chris@16: * Chris@16: * This is the default number of children that each node in a Chris@16: * computation tree will have. This value will be used for Chris@16: * collective operations that use tree-based algorithms. Chris@16: */ Chris@16: int branching_factor_; Chris@16: Chris@16: /// The level in the tree at which this process resides. Chris@16: int level_; Chris@16: }; Chris@16: Chris@16: } } } // end namespace boost::mpi::detail Chris@16: Chris@16: #endif // BOOST_MPI_COMPUTATION_TREE_HPP