LCOV - code coverage report
Current view: top level - ugbase/bridge/misc_bridges - pcl_bridge.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 42.4 % 33 14
Test Date: 2026-05-09 08:15:45 Functions: 8.3 % 12 1

            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              : #include "pcl/space_time_communicator.hpp"
      41              : #endif
      42              : 
      43              : using namespace std;
      44              : 
      45              : namespace ug{
      46              : namespace bridge{
      47              : 
      48              : /// \defgroup pcl_bridge PCL Bridge
      49              : /// \ingroup misc_bridge
      50              : /// \{
      51              : 
      52              : #ifdef UG_PARALLEL
      53              : 
      54              : static bool PclDebugBarrierEnabled()
      55              : {
      56              : #ifdef PCL_DEBUG_BARRIER_ENABLED
      57              :         return true;
      58              : #else
      59              :         return false;
      60              : #endif
      61              : }
      62              : 
      63              : static void PclDebugBarrierAll()
      64              : {
      65              :         PCL_DEBUG_BARRIER_ALL();
      66              : }
      67              : 
      68              : static bool PclAllProcsTrue(bool bTrue){
      69              :         return pcl::AllProcsTrue(bTrue);
      70              : }
      71              : 
      72              : template<typename T>
      73              : static T ParallelMin(T t)
      74              : {
      75              :         pcl::ProcessCommunicator pc;
      76              :         return pc.allreduce(t, PCL_RO_MIN);
      77              : }
      78              : 
      79              : template<typename T>
      80              : static T ParallelMax(T t)
      81              : {
      82              :         pcl::ProcessCommunicator pc;
      83              :         return pc.allreduce(t, PCL_RO_MAX);
      84              : }
      85              : 
      86              : template<typename T>
      87              : static T ParallelSum(T t)
      88              : {
      89              :         pcl::ProcessCommunicator pc;
      90              :         return pc.allreduce(t, PCL_RO_SUM);
      91              : }
      92              : 
      93              : template<typename T>
      94              : static vector<T> ParallelVecMin(const vector<T>& t)
      95              : {
      96              :         vector<T> tmp;
      97              :         pcl::ProcessCommunicator pc;
      98              :         pc.allreduce(t, tmp, PCL_RO_MIN);
      99              :         return tmp;
     100              : }
     101              : 
     102              : template<typename T>
     103              : static vector<T> ParallelVecMax(const vector<T>& t)
     104              : {
     105              :         vector<T> tmp;
     106              :         pcl::ProcessCommunicator pc;
     107              :         pc.allreduce(t, tmp, PCL_RO_MAX);
     108              :         return tmp;
     109              : }
     110              : 
     111              : template<typename T>
     112              : static vector<T> ParallelVecSum(const vector<T>& t)
     113              : {
     114              :         vector<T> tmp;
     115              :         pcl::ProcessCommunicator pc;
     116              :         pc.allreduce(t, tmp, PCL_RO_SUM);
     117              :         return tmp;
     118              : }
     119              : 
     120              : static bool ug_parallel()
     121              : { return true; }
     122              : 
     123              : 
     124              : void RegisterBridge_PCL(Registry& reg, string parentGroup)
     125              : {
     126              :         string grp(parentGroup);
     127              :         grp.append("/pcl");
     128              : 
     129              :         reg.add_function("DisableMPIInit", &pcl::DisableMPIInit, grp, "", "",
     130              :                          "Tells PCL to not call MPI_Init and MPI_Finalize.");
     131              : 
     132              :         reg.add_function("PclDebugBarrierEnabled", &PclDebugBarrierEnabled, grp,
     133              :                                         "Enabled", "", "Returns the whether debug barriers are enabled.");
     134              : 
     135              :         reg.add_function("PclDebugBarrierAll", &PclDebugBarrierAll, grp,
     136              :                                          "", "", "Synchronizes all parallel processes if the executable"
     137              :                                                          "has been compiled with PCL_DEBUG_BARRIER=ON");
     138              : 
     139              :         reg.add_function("NumProcs", &pcl::NumProcs, grp,
     140              :                                         "NumProcs", "", "Returns the number of active processes.");
     141              : 
     142              :         reg.add_function("ProcRank", &pcl::ProcRank, grp,
     143              :                                         "ProcRank", "", "Returns the rank of the current process.");
     144              : 
     145              :         reg.add_function("SynchronizeProcesses", &pcl::SynchronizeProcesses, grp,
     146              :                                         "", "", "Waits until all active processes reached this point.");
     147              : 
     148              :         reg.add_function("AllProcsTrue", &PclAllProcsTrue, grp,
     149              :                                          "boolean", "boolean", "Returns true if all processes call the method with true.");
     150              : 
     151              :         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.");
     152              :         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.");
     153              :         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.");
     154              : 
     155              :         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.");
     156              :         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.");
     157              :         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.");
     158              :         reg.add_function("UG_PARALLEL", &ug_parallel, grp);
     159              :         
     160              :         // Space Time Communicator
     161              :         {
     162              :                 using T_SpaceTimeCommunicator = pcl::SpaceTimeCommunicator ;
     163              :                 const std::string name = "SpaceTimeCommunicator";
     164              :                 reg.add_class_<T_SpaceTimeCommunicator>(name, "SpaceTimeCommunicator", "")
     165              :                                 .add_constructor()
     166              :                                 .add_method("split", &T_SpaceTimeCommunicator::split)
     167              :                                 .add_method("unsplit", &T_SpaceTimeCommunicator::unsplit)
     168              :                                 .add_method("get_global_rank", &T_SpaceTimeCommunicator::get_global_rank)
     169              :                                 .add_method("get_spatial_rank", &T_SpaceTimeCommunicator::get_spatial_rank)
     170              :                                 .add_method("get_temporal_rank", &T_SpaceTimeCommunicator::get_temporal_rank)
     171              :                                 .add_method("get_global_size", &T_SpaceTimeCommunicator::get_global_size)
     172              :                                 .add_method("get_spatial_size", &T_SpaceTimeCommunicator::get_spatial_size)
     173              :                                 .add_method("get_temporal_size", &T_SpaceTimeCommunicator::get_temporal_size)
     174              :                                 .add_method("sleep", &T_SpaceTimeCommunicator::sleep)
     175              :                                 .set_construct_as_smart_pointer(true);
     176              :         }
     177              : }
     178              : 
     179              : #else // UG_PARALLEL
     180              : 
     181            0 : void DisableMPIInitDUMMY ()
     182            0 : {}
     183              : 
     184            0 : static bool PclDebugBarrierEnabledDUMMY()
     185              : {
     186            0 :         return false;
     187              : }
     188              : 
     189            0 : static bool PclDebugBarrierAllDUMMY()
     190              : {
     191            0 :         return false;
     192              : }
     193              : 
     194              : ///     Dummy method for serial compilation always returning 1
     195            0 : static int NumProcsDUMMY()      {return 1;}
     196              : 
     197              : ///     Dummy method for serial compilation always returning 0
     198            0 : static int ProcRankDUMMY()                              {return 0;}
     199              : 
     200              : ///     Dummy method for serial compilation doing nothing
     201            0 : static void SynchronizeProcessesDUMMY()                 {}
     202              : 
     203              : 
     204              : template<typename T>
     205            0 : T ParallelMinDUMMY(T t)
     206              : {
     207            0 :         return t;
     208              : }
     209              : 
     210              : template<typename T>
     211            0 : T ParallelMaxDUMMY(T t)
     212              : {
     213            0 :         return t;
     214              : }
     215              : 
     216              : template<typename T>
     217            0 : T ParallelSumDUMMY(T t)
     218              : {
     219            0 :         return t;
     220              : }
     221              : 
     222            0 : bool AllProcsTrueDUMMY(bool bTrue)
     223              : {
     224            0 :         return bTrue;
     225              : }
     226              : 
     227            0 : static bool ug_parallel()
     228            0 : { return false; }
     229              : 
     230              : 
     231            1 : void RegisterBridge_PCL(Registry& reg, string parentGroup)
     232              : {
     233              :         string grp(parentGroup);
     234            1 :         grp.append("/PCL");
     235              : 
     236            3 :         reg.add_function("DisableMPIInit", &DisableMPIInitDUMMY, grp, "", "",
     237              :                          "Tells PCL to not call MPI_Init and MPI_Finalize.");
     238              : 
     239            3 :         reg.add_function("PclDebugBarrierEnabled", &PclDebugBarrierEnabledDUMMY, grp,
     240              :                                         "Enabled", "", "Returns the whether debug barriers are enabled.");
     241              : 
     242            3 :         reg.add_function("PclDebugBarrierAll", &PclDebugBarrierAllDUMMY, grp,
     243              :                                          "", "", "Synchronizes all parallel processes if the executable"
     244              :                                                          "has been compiled with PCL_DEBUG_BARRIER=ON");
     245              : 
     246            3 :         reg.add_function("NumProcs", &NumProcsDUMMY, grp,
     247              :                                         "NumProcs", "", "Returns the number of active processes.");
     248              : 
     249            3 :         reg.add_function("ProcRank", &ProcRankDUMMY, grp,
     250              :                                         "ProcRank", "", "Returns the rank of the current process.");
     251              : 
     252            3 :         reg.add_function("SynchronizeProcesses", &SynchronizeProcessesDUMMY, grp,
     253              :                                         "", "", "Waits until all active processes reached this point.");
     254              : 
     255            3 :         reg.add_function("AllProcsTrue", &AllProcsTrueDUMMY, grp,
     256              :                                          "boolean", "boolean", "Returns true if all processes call the method with true.");
     257              : 
     258            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.");
     259            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.");
     260            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.");
     261            3 :         reg.add_function("UG_PARALLEL", &ug_parallel, grp);
     262            1 : }
     263              : #endif //UG_PARALLEL
     264              : 
     265              : // end group pcl_bridge
     266              : /// \}
     267              : 
     268              : }// end of namespace bridge
     269              : }// end of namespace ug
        

Generated by: LCOV version 2.0-1