Muster
 All Classes Namespaces Files Functions Variables Typedefs Macros
par_partition.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2010, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory
4 // LLNL-CODE-433662
5 // All rights reserved.
6 //
7 // This file is part of Muster. For details, see http://github.com/tgamblin/muster.
8 // Please also read the LICENSE file for further information.
9 //
10 // Redistribution and use in source and binary forms, with or without modification, are
11 // permitted provided that the following conditions are met:
12 //
13 // * Redistributions of source code must retain the above copyright notice, this list of
14 // conditions and the disclaimer below.
15 // * Redistributions in binary form must reproduce the above copyright notice, this list of
16 // conditions and the disclaimer (as noted below) in the documentation and/or other materials
17 // provided with the distribution.
18 // * Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse
19 // or promote products derived from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
22 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24 // LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 //////////////////////////////////////////////////////////////////////////////////////////////////
31 
32 ///
33 /// @file par_partition.h
34 /// @author Todd Gamblin tgamblin@llnl.gov
35 /// @brief Distributed representation of a partitioning of a data set.
36 ///
37 #ifndef PAR_PARTITION_H
38 #define PAR_PARTITION_H
39 
40 #include <mpi.h>
41 #include <vector>
42 #include <ostream>
43 
44 #include "partition.h"
45 
46 
47 namespace cluster {
48 
49  ///
50  /// par_partition represents a partitioning of a distributed data set.
51  /// It is analogous to partition, but its object_ids are distributed across
52  /// the ranks of the communicator it is instantiated with. Each process is assumed
53  /// to "own" some set of objects in the data set this describes, and each process's
54  /// par_partition object contains medoid_ids only for its own objects. Thus, the cluster_ids
55  /// array will contain different object_ids on different processes within the "same"
56  /// par_partition object.
57  ///
58  /// While cluster_ids will vary, the "same" par_partition object on the same
59  /// communicator will have the same medoid_ids. If this is not true, then the medoid_ids
60  /// won't make any sense between processes. Partitioning algorithms that use a
61  /// par_partition for output should preserve this property.
62  ///
63  /// You can convert a par_partition to a partition on a single process using
64  /// the gather() method. This is a collective operation. It is not scalable, in that
65  /// it will aggregate ids from <i>every</i> process in the communicator to <i>one</i> process.
66  /// However, it's useful for small systems and debugging.
67  ///
68  /// @see partition, the non-distributed equivalent of this class.
69  ///
70  struct par_partition {
71  /// Gives the object id for the ith medoid. This object may not be local.
72  std::vector<object_id> medoid_ids;
73 
74  /// Global cluster ids for local objects. These are indices into medoid_ids.
75  /// The object id of the medoid of the ith local object is medoid_ids[cluster_ids[i]].
76  std::vector<object_id> cluster_ids;
77 
78  /// Communicator, the processes of which this partition divides
79  MPI_Comm comm;
80 
81  /// Construct a parallel partition for the communicator supplied
82  /// Partition starts off with everyone in one cluster with medoid 0.
83  par_partition(MPI_Comm comm = MPI_COMM_WORLD);
84 
85  /// Virtual destructor for inheritance.
86  virtual ~par_partition();
87 
88  /// Scalably get the sizes of all the clusters in this partition.
89  /// POST: sizes is valid on all processes
90  void get_sizes(std::vector<size_t>& sizes);
91 
92  /// Collective operation. Gathers my_id from all processes into a
93  /// local partition object. If size of system is large, then this method
94  /// will not scale.
95  void gather(partition& local, int root=0);
96  };
97 
98  ///
99  /// Right now this just uses parition::operator<<() by making a
100  /// partition with this par_partition's cluster_ids and medoid_ids vectors
101  /// and outputting it.
102  ///
103  /// @todo fix the implementation; it's a little hacky.
104  ///
105  std::ostream& operator<<(std::ostream& out, const par_partition& par);
106 
107 } // namespace cluster
108 
109 #endif // PAR_PARTITION_H
110 
111 
Class to represent a partitioning of a data set.
par_partition(MPI_Comm comm=MPI_COMM_WORLD)
Construct a parallel partition for the communicator supplied Partition starts off with everyone in on...
MPI_Comm comm
Communicator, the processes of which this partition divides.
Definition: par_partition.h:79
void get_sizes(std::vector< size_t > &sizes)
Scalably get the sizes of all the clusters in this partition.
std::ostream & operator<<(std::ostream &out, const id_pair< T > &p)
Print out an id_pair as a tuple of its element and its source rank.
Definition: id_pair.h:103
par_partition represents a partitioning of a distributed data set.
Definition: par_partition.h:70
std::vector< object_id > cluster_ids
Global cluster ids for local objects.
Definition: par_partition.h:76
std::vector< object_id > medoid_ids
Gives the object id for the ith medoid. This object may not be local.
Definition: par_partition.h:72
virtual ~par_partition()
Virtual destructor for inheritance.
void gather(partition &local, int root=0)
Collective operation.
This represents a partitioning of a data set.
Definition: partition.h:76
Muster. Copyright © 2010, Lawrence Livermore National Laboratory, LLNL-CODE-433662.
Distribution of Muster and its documentation is subject to terms of the Muster LICENSE.
Generated on Thu Sep 1 2016 using Doxygen 1.8.5