SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleReducer.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@file SimpleReducer.h
33 ///@brief A barrier with reduction operations
34 ///
35 ///@author Steve Parker
36 /// Department of Computer Science
37 /// University of Utah
38 ///@date June 1997
39 ///
40 
41 #ifndef Core_Thread_SimpleReducer_h
42 #define Core_Thread_SimpleReducer_h
43 
45 
47 
48 namespace SCIRun {
49 
50 /**************************************
51 
52 @class
53  SimpleReducer
54 
55 KEYWORDS
56  Thread
57 
58 @details
59  Perform reduction operations over a set of threads. Reduction
60  operations include things like global sums, global min/max, etc.
61  In these operations, a local sum (operation) is performed on each
62  thread, and these sums are added together.
63 
64 ****************************************/
65  class SCISHARE SimpleReducer : public Barrier {
66  public:
67  //////////
68  /// Create a <b> SimpleReducer</i>.
69  /// At each operation, a barrier wait is performed, and the
70  /// operation will be performed to compute the global balue.
71  /// <i>name</i> should be a static string which describes
72  /// the primitive for debugging purposes.
73  SimpleReducer(const char* name);
74 
75  //////////
76  /// Destroy the SimpleReducer and free associated memory.
77  virtual ~SimpleReducer();
78 
79  //////////
80  /// Performs a global sum over all of the threads. As soon as each
81  /// thread has called sum with their local sum, each thread will
82  /// return the same global sum.
83  double sum(int myrank, int numThreads, double mysum);
84 
85  //////////
86  /// Performs a global max over all of the threads. As soon as each
87  /// thread has called max with their local max, each thread will
88  /// return the same global max.
89  double max(int myrank, int numThreads, double mymax);
90 
91  //////////
92  /// Performs a global min over all of the threads. As soon as each
93  /// thread has called min with their local max, each thread will
94  /// return the same global max.
95  double min(int myrank, int numThreads, double mymax);
96 
97  private:
98  struct data {
99  double d_;
100  };
101  struct joinArray {
102  data d_;
103  // Assumes 128 bytes in a cache line...
104  char filler_[128-sizeof(data)];
105  };
106  struct pdata {
107  int buf_;
108  char filler_[128-sizeof(int)];
109  };
110  joinArray* join_[2];
111  pdata* p_;
112  int array_size_;
113  void collectiveResize(int proc, int numThreads);
114 
115  // Cannot copy them
117  SimpleReducer& operator=(const SimpleReducer&);
118  };
119 } // End namespace SCIRun
120 
121 #endif
122 
123 
void pdata(char *title, float *data, int n, int stride)
Definition: fft.c:43
Definition: SimpleReducer.h:65
#define SCISHARE
Definition: share.h:39
Definition: Barrier.h:71
Definition: ParallelLinearAlgebraTests.cc:358
const char * name[]
Definition: BoostGraphExampleTests.cc:87
dictionary data
Definition: eabLatVolData.py:11