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 :
120 : void RegisterBridge_PCL(Registry& reg, string parentGroup)
121 : {
122 : string grp(parentGroup);
123 : grp.append("/pcl");
124 :
125 : reg.add_function("DisableMPIInit", &pcl::DisableMPIInit, grp, "", "",
126 : "Tells PCL to not call MPI_Init and MPI_Finalize.");
127 :
128 : reg.add_function("PclDebugBarrierEnabled", &PclDebugBarrierEnabled, grp,
129 : "Enabled", "", "Returns the whether debug barriers are enabled.");
130 :
131 : reg.add_function("PclDebugBarrierAll", &PclDebugBarrierAll, grp,
132 : "", "", "Synchronizes all parallel processes if the executable"
133 : "has been compiled with PCL_DEBUG_BARRIER=ON");
134 :
135 : reg.add_function("NumProcs", &pcl::NumProcs, grp,
136 : "NumProcs", "", "Returns the number of active processes.");
137 :
138 : reg.add_function("ProcRank", &pcl::ProcRank, grp,
139 : "ProcRank", "", "Returns the rank of the current process.");
140 :
141 : reg.add_function("SynchronizeProcesses", &pcl::SynchronizeProcesses, grp,
142 : "", "", "Waits until all active processes reached this point.");
143 :
144 : reg.add_function("AllProcsTrue", &PclAllProcsTrue, grp,
145 : "boolean", "boolean", "Returns true if all processes call the method with true.");
146 :
147 : 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.");
148 : 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.");
149 : 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.");
150 :
151 : 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.");
152 : 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.");
153 : 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.");
154 : }
155 :
156 : #else // UG_PARALLEL
157 :
158 0 : void DisableMPIInitDUMMY ()
159 0 : {}
160 :
161 0 : static bool PclDebugBarrierEnabledDUMMY()
162 : {
163 0 : return false;
164 : }
165 :
166 0 : static bool PclDebugBarrierAllDUMMY()
167 : {
168 0 : return false;
169 : }
170 :
171 : /// Dummy method for serial compilation always returning 1
172 0 : static int NumProcsDUMMY() {return 1;}
173 :
174 : /// Dummy method for serial compilation always returning 0
175 0 : static int ProcRankDUMMY() {return 0;}
176 :
177 : /// Dummy method for serial compilation doing nothing
178 0 : static void SynchronizeProcessesDUMMY() {}
179 :
180 :
181 : template<typename T>
182 0 : T ParallelMinDUMMY(T t)
183 : {
184 0 : return t;
185 : }
186 :
187 : template<typename T>
188 0 : T ParallelMaxDUMMY(T t)
189 : {
190 0 : return t;
191 : }
192 :
193 : template<typename T>
194 0 : T ParallelSumDUMMY(T t)
195 : {
196 0 : return t;
197 : }
198 :
199 0 : bool AllProcsTrueDUMMY(bool bTrue)
200 : {
201 0 : return bTrue;
202 : }
203 :
204 1 : void RegisterBridge_PCL(Registry& reg, string parentGroup)
205 : {
206 : string grp(parentGroup);
207 1 : grp.append("/PCL");
208 :
209 3 : reg.add_function("DisableMPIInit", &DisableMPIInitDUMMY, grp, "", "",
210 : "Tells PCL to not call MPI_Init and MPI_Finalize.");
211 :
212 3 : reg.add_function("PclDebugBarrierEnabled", &PclDebugBarrierEnabledDUMMY, grp,
213 : "Enabled", "", "Returns the whether debug barriers are enabled.");
214 :
215 3 : reg.add_function("PclDebugBarrierAll", &PclDebugBarrierAllDUMMY, grp,
216 : "", "", "Synchronizes all parallel processes if the executable"
217 : "has been compiled with PCL_DEBUG_BARRIER=ON");
218 :
219 3 : reg.add_function("NumProcs", &NumProcsDUMMY, grp,
220 : "NumProcs", "", "Returns the number of active processes.");
221 :
222 3 : reg.add_function("ProcRank", &ProcRankDUMMY, grp,
223 : "ProcRank", "", "Returns the rank of the current process.");
224 :
225 3 : reg.add_function("SynchronizeProcesses", &SynchronizeProcessesDUMMY, grp,
226 : "", "", "Waits until all active processes reached this point.");
227 :
228 3 : reg.add_function("AllProcsTrue", &AllProcsTrueDUMMY, grp,
229 : "boolean", "boolean", "Returns true if all processes call the method with true.");
230 :
231 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.");
232 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.");
233 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.");
234 1 : }
235 :
236 : #endif //UG_PARALLEL
237 :
238 : // end group pcl_bridge
239 : /// \}
240 :
241 : }// end of namespace
242 : }// end of namespace
|