Line data Source code
1 : /*
2 : * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Sebastian Reiter
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #include <iostream>
34 : #include <string>
35 : #include "registry/registry.h"
36 : #include "bridge/bridge.h"
37 :
38 : #ifdef UG_PARALLEL
39 : #include "pcl/pcl.h"
40 : #endif
41 :
42 : using namespace std;
43 :
44 : namespace ug{
45 : namespace bridge{
46 :
47 : /// \defgroup pcl_bridge PCL Bridge
48 : /// \ingroup misc_bridge
49 : /// \{
50 :
51 : #ifdef UG_PARALLEL
52 :
53 : static bool PclDebugBarrierEnabled()
54 : {
55 : #ifdef PCL_DEBUG_BARRIER_ENABLED
56 : return true;
57 : #else
58 : return false;
59 : #endif
60 : }
61 :
62 : static void PclDebugBarrierAll()
63 : {
64 : PCL_DEBUG_BARRIER_ALL();
65 : }
66 :
67 : static bool PclAllProcsTrue(bool bTrue){
68 : return pcl::AllProcsTrue(bTrue);
69 : }
70 :
71 : template<typename T>
72 : static T ParallelMin(T t)
73 : {
74 : pcl::ProcessCommunicator pc;
75 : return pc.allreduce(t, PCL_RO_MIN);
76 : }
77 :
78 : template<typename T>
79 : static T ParallelMax(T t)
80 : {
81 : pcl::ProcessCommunicator pc;
82 : return pc.allreduce(t, PCL_RO_MAX);
83 : }
84 :
85 : template<typename T>
86 : static T ParallelSum(T t)
87 : {
88 : pcl::ProcessCommunicator pc;
89 : return pc.allreduce(t, PCL_RO_SUM);
90 : }
91 :
92 : template<typename T>
93 : static vector<T> ParallelVecMin(const vector<T>& t)
94 : {
95 : vector<T> tmp;
96 : pcl::ProcessCommunicator pc;
97 : pc.allreduce(t, tmp, PCL_RO_MIN);
98 : return tmp;
99 : }
100 :
101 : template<typename T>
102 : static vector<T> ParallelVecMax(const vector<T>& t)
103 : {
104 : vector<T> tmp;
105 : pcl::ProcessCommunicator pc;
106 : pc.allreduce(t, tmp, PCL_RO_MAX);
107 : return tmp;
108 : }
109 :
110 : template<typename T>
111 : static vector<T> ParallelVecSum(const vector<T>& t)
112 : {
113 : vector<T> tmp;
114 : pcl::ProcessCommunicator pc;
115 : pc.allreduce(t, tmp, PCL_RO_SUM);
116 : return tmp;
117 : }
118 :
119 : static bool ug_parallel()
120 : { return true; }
121 :
122 :
123 : void RegisterBridge_PCL(Registry& reg, string parentGroup)
124 : {
125 : string grp(parentGroup);
126 : grp.append("/pcl");
127 :
128 : reg.add_function("DisableMPIInit", &pcl::DisableMPIInit, grp, "", "",
129 : "Tells PCL to not call MPI_Init and MPI_Finalize.");
130 :
131 : reg.add_function("PclDebugBarrierEnabled", &PclDebugBarrierEnabled, grp,
132 : "Enabled", "", "Returns the whether debug barriers are enabled.");
133 :
134 : reg.add_function("PclDebugBarrierAll", &PclDebugBarrierAll, grp,
135 : "", "", "Synchronizes all parallel processes if the executable"
136 : "has been compiled with PCL_DEBUG_BARRIER=ON");
137 :
138 : reg.add_function("NumProcs", &pcl::NumProcs, grp,
139 : "NumProcs", "", "Returns the number of active processes.");
140 :
141 : reg.add_function("ProcRank", &pcl::ProcRank, grp,
142 : "ProcRank", "", "Returns the rank of the current process.");
143 :
144 : reg.add_function("SynchronizeProcesses", &pcl::SynchronizeProcesses, grp,
145 : "", "", "Waits until all active processes reached this point.");
146 :
147 : reg.add_function("AllProcsTrue", &PclAllProcsTrue, grp,
148 : "boolean", "boolean", "Returns true if all processes call the method with true.");
149 :
150 : reg.add_function("ParallelMin", &ParallelMin<double>, grp, "tmax", "t", "returns the minimum of t over all processes. note: you have to assure that all processes call this function.");
151 : reg.add_function("ParallelMax", &ParallelMax<double>, grp, "tmin", "t", "returns the maximum of t over all processes. note: you have to assure that all processes call this function.");
152 : reg.add_function("ParallelSum", &ParallelSum<double>, grp, "tsum", "t", "returns the sum of t over all processes. note: you have to assure that all processes call this function.");
153 :
154 : reg.add_function("ParallelVecMin", &ParallelVecMin<double>, grp, "tmax", "t", "returns the minimum of t over all processes. note: you have to assure that all processes call this function.");
155 : reg.add_function("ParallelVecMax", &ParallelVecMax<double>, grp, "tmin", "t", "returns the maximum of t over all processes. note: you have to assure that all processes call this function.");
156 : reg.add_function("ParallelVecSum", &ParallelVecSum<double>, grp, "tsum", "t", "returns the sum of t over all processes. note: you have to assure that all processes call this function.");
157 : reg.add_function("UG_PARALLEL", &ug_parallel, grp);
158 : }
159 :
160 : #else // UG_PARALLEL
161 :
162 0 : void DisableMPIInitDUMMY ()
163 0 : {}
164 :
165 0 : static bool PclDebugBarrierEnabledDUMMY()
166 : {
167 0 : return false;
168 : }
169 :
170 0 : static bool PclDebugBarrierAllDUMMY()
171 : {
172 0 : return false;
173 : }
174 :
175 : /// Dummy method for serial compilation always returning 1
176 0 : static int NumProcsDUMMY() {return 1;}
177 :
178 : /// Dummy method for serial compilation always returning 0
179 0 : static int ProcRankDUMMY() {return 0;}
180 :
181 : /// Dummy method for serial compilation doing nothing
182 0 : static void SynchronizeProcessesDUMMY() {}
183 :
184 :
185 : template<typename T>
186 0 : T ParallelMinDUMMY(T t)
187 : {
188 0 : return t;
189 : }
190 :
191 : template<typename T>
192 0 : T ParallelMaxDUMMY(T t)
193 : {
194 0 : return t;
195 : }
196 :
197 : template<typename T>
198 0 : T ParallelSumDUMMY(T t)
199 : {
200 0 : return t;
201 : }
202 :
203 0 : bool AllProcsTrueDUMMY(bool bTrue)
204 : {
205 0 : return bTrue;
206 : }
207 :
208 0 : static bool ug_parallel()
209 0 : { return false; }
210 :
211 :
212 1 : void RegisterBridge_PCL(Registry& reg, string parentGroup)
213 : {
214 : string grp(parentGroup);
215 1 : grp.append("/PCL");
216 :
217 3 : reg.add_function("DisableMPIInit", &DisableMPIInitDUMMY, grp, "", "",
218 : "Tells PCL to not call MPI_Init and MPI_Finalize.");
219 :
220 3 : reg.add_function("PclDebugBarrierEnabled", &PclDebugBarrierEnabledDUMMY, grp,
221 : "Enabled", "", "Returns the whether debug barriers are enabled.");
222 :
223 3 : reg.add_function("PclDebugBarrierAll", &PclDebugBarrierAllDUMMY, grp,
224 : "", "", "Synchronizes all parallel processes if the executable"
225 : "has been compiled with PCL_DEBUG_BARRIER=ON");
226 :
227 3 : reg.add_function("NumProcs", &NumProcsDUMMY, grp,
228 : "NumProcs", "", "Returns the number of active processes.");
229 :
230 3 : reg.add_function("ProcRank", &ProcRankDUMMY, grp,
231 : "ProcRank", "", "Returns the rank of the current process.");
232 :
233 3 : reg.add_function("SynchronizeProcesses", &SynchronizeProcessesDUMMY, grp,
234 : "", "", "Waits until all active processes reached this point.");
235 :
236 3 : reg.add_function("AllProcsTrue", &AllProcsTrueDUMMY, grp,
237 : "boolean", "boolean", "Returns true if all processes call the method with true.");
238 :
239 3 : reg.add_function("ParallelMin", &ParallelMinDUMMY<double>, grp, "tmax", "t", "returns the maximum of t over all processes. note: you have to assure that all processes call this function.");
240 3 : reg.add_function("ParallelMax", &ParallelMaxDUMMY<double>, grp, "tmin", "t", "returns the minimum of t over all processes. note: you have to assure that all processes call this function.");
241 3 : reg.add_function("ParallelSum", &ParallelSumDUMMY<double>, grp, "tsum", "t", "returns the sum of t over all processes. note: you have to assure that all processes call this function.");
242 3 : reg.add_function("UG_PARALLEL", &ug_parallel, grp);
243 1 : }
244 : #endif //UG_PARALLEL
245 :
246 : // end group pcl_bridge
247 : /// \}
248 :
249 : }// end of namespace bridge
250 : }// end of namespace ug
|