]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (C) 2005 Douglas Gregor. |
2 | ||
3 | // Use, modification and distribution is subject to the Boost Software | |
4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
5 | // http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | // Compute parents, children, levels, etc. to effect a parallel | |
8 | // computation tree. | |
9 | #ifndef BOOST_MPI_COMPUTATION_TREE_HPP | |
10 | #define BOOST_MPI_COMPUTATION_TREE_HPP | |
11 | ||
12 | namespace boost { namespace mpi { namespace detail { | |
13 | ||
14 | /** | |
15 | * @brief Aids tree-based parallel collective algorithms. | |
16 | * | |
17 | * Objects of this type | |
18 | */ | |
19 | class computation_tree | |
20 | { | |
21 | public: | |
22 | computation_tree(int rank, int size, int root, int branching_factor = -1); | |
23 | ||
24 | /// Returns the branching factor of the tree. | |
25 | int branching_factor() const { return branching_factor_; } | |
26 | ||
27 | /// Returns the level in the tree on which this process resides. | |
28 | int level() const { return level_; } | |
29 | ||
30 | /** | |
31 | * Returns the index corresponding to the n^th level of the tree. | |
32 | * | |
33 | * @param n The level in the tree whose index will be returned. | |
34 | */ | |
35 | int level_index(int n) const; | |
36 | ||
37 | /** | |
38 | * @brief Returns the parent of this process. | |
39 | * | |
40 | * @returns If this process is the root, returns itself. Otherwise, | |
41 | * returns the process number that is the parent in the computation | |
42 | * tree. | |
43 | */ | |
44 | int parent() const; | |
45 | ||
46 | /// Returns the index for the first child of this process. | |
47 | int child_begin() const; | |
48 | ||
49 | /** | |
50 | * @brief The default branching factor within the computation tree. | |
51 | * | |
52 | * This is the default branching factor for the computation tree, to | |
53 | * be used by any computation tree that does not fix the branching | |
54 | * factor itself. The default is initialized to 3, but may be | |
55 | * changed by the application so long as all processes have the same | |
56 | * branching factor. | |
57 | */ | |
58 | static int default_branching_factor; | |
59 | ||
60 | protected: | |
61 | /// The rank of this process in the computation tree. | |
62 | int rank; | |
63 | ||
64 | /// The number of processes participating in the computation tree. | |
65 | int size; | |
66 | ||
67 | /// The process number that is acting as the root in the computation | |
68 | /// tree. | |
69 | int root; | |
70 | ||
71 | /** | |
72 | * @brief The branching factor within the computation tree. | |
73 | * | |
74 | * This is the default number of children that each node in a | |
75 | * computation tree will have. This value will be used for | |
76 | * collective operations that use tree-based algorithms. | |
77 | */ | |
78 | int branching_factor_; | |
79 | ||
80 | /// The level in the tree at which this process resides. | |
81 | int level_; | |
82 | }; | |
83 | ||
84 | } } } // end namespace boost::mpi::detail | |
85 | ||
86 | #endif // BOOST_MPI_COMPUTATION_TREE_HPP |