ug4
consistency_check.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2014: G-CSC, Goethe University Frankfurt
3  * Author: Martin Rupp
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 #ifdef UG_PARALLEL
34 
35 #ifndef CONSISTENCY_CHECK_H
36 #define CONSISTENCY_CHECK_H
37 
38 #include <string>
39 #include "pcl/pcl.h"
40 #include "common/log.h"
41 #include "common/assert.h"
42 #include "communication_scheme.h"
43 #include "lib_algebra/parallelization/parallel_index_layout.h" // for IndexLayout
44 
45 namespace ug{
46 
54 template<typename TVec, typename TValue>
56 {
57 public:
58  ConsistencyCheckClassSend(const TVec &_vec) : vec(_vec) {}
59  const TValue &send(int pid, int index) const
60  {
61  return vec[index];
62  }
63 
64  const TVec &vec;
65 };
66 
67 // for std::vector<bool> and others
68 template<typename TVec>
69 class ConsistencyCheckClassSend<TVec, bool>
70 {
71 public:
72  ConsistencyCheckClassSend(const TVec &_vec) : vec(_vec) {}
73  bool send(int pid, int index) const
74  {
75  return vec[index];
76  }
77 
78  const TVec &vec;
79 };
80 
81 template<typename TVec, typename TValue>
83 : public CommunicationScheme<ConsistencyCheckClass<TVec, TValue>, TValue>,
84  public ConsistencyCheckClassSend<TVec, TValue>
85 {
86 public:
88  ConsistencyCheckClass(const TVec &_vec, std::string _name = "") :
89  ConsistencyCheckClassSend<TVec, TValue>(_vec), name(_name)
90  {
91  bOK = true;
92  }
93 
94  void receive(int pid, int index, TValue &v)
95  {
96  if(vec[index] != v)
97  {
98  if(bOK)
99  { UG_LOG("\n\n----------------------\n" << name << " not consistent:\n"); bOK = false; }
100  UG_LOG("index " << index << " is " << vec[index] << " on this proc (" << pcl::ProcRank() <<
101  "), but " << v << " on master (proc " << pid << ").\n");
102  }
103  }
104 
105  bool isOK()
106  {
107  return bOK;
108  }
109 
111  {
112  if(block_traits<TValue>::is_static) return sizeof(TValue);
113  else return -1;
114  }
115 private:
116  bool bOK;
117 
118  std::string name;
119 };
120 
131 template<typename TVec>
133  const pcl::ProcessCommunicator &pc, const IndexLayout &masterLayout,
134  const IndexLayout &slaveLayout, std::string name="")
135 {
136  PROFILE_FUNC_GROUP("algebra parallelization debug");
138  CommunicateOnInterfaces(com, masterLayout, slaveLayout, scheme);
139 
140  UG_COND_THROW(!AllProcsTrue(scheme.isOK(), pc), name << " not consistent!");
141 }
142 
143 template<typename TVec>
144 void ConsistencyCheck(const TVec &vec, const HorizontalAlgebraLayouts &layout, std::string name="")
145 {
146  PROFILE_FUNC_GROUP("algebra parallelization debug");
148  CommunicateOnInterfaces(layout.comm(), layout.master(), layout.slave(), scheme);
149 
150  UG_COND_THROW(!AllProcsTrue(scheme.isOK(), layout.proc_comm()), name << " not consistent!");
151 }
152 
153 // end group lib_algebra_parallel_consistencycheck
155 
156 }
157 #endif // CONSISTENCY_CHECK_H
158 #endif // UG_PARALLEL
location name
Definition: checkpoint_util.lua:128
Performs communication between interfaces on different processes.
Definition: pcl_interface_communicator.h:68
Definition: pcl_process_communicator.h:70
CRTP Base class for communications on layout/interfaces.
Definition: communication_scheme.h:105
Definition: consistency_check.h:85
ConsistencyCheckClass(const TVec &_vec, std::string _name="")
Definition: consistency_check.h:88
void receive(int pid, int index, TValue &v)
Definition: consistency_check.h:94
int get_element_size()
Definition: consistency_check.h:110
bool bOK
Definition: consistency_check.h:116
std::string name
Definition: consistency_check.h:118
bool isOK()
Definition: consistency_check.h:105
const TVec & vec
Definition: consistency_check.h:78
bool send(int pid, int index) const
Definition: consistency_check.h:73
ConsistencyCheckClassSend(const TVec &_vec)
Definition: consistency_check.h:72
Definition: consistency_check.h:56
const TValue & send(int pid, int index) const
Definition: consistency_check.h:59
ConsistencyCheckClassSend(const TVec &_vec)
Definition: consistency_check.h:58
const TVec & vec
Definition: consistency_check.h:64
Holds Interfaces and communicators for horizontal communication.
Definition: algebra_layouts.h:48
const pcl::ProcessCommunicator & proc_comm() const
returns process communicator
Definition: algebra_layouts.h:68
const IndexLayout & slave() const
Definition: algebra_layouts.h:63
const IndexLayout & master() const
Definition: algebra_layouts.h:61
pcl::InterfaceCommunicator< IndexLayout > & comm() const
returns (non-const !!!) communicator
Definition: algebra_layouts.h:78
void ConsistencyCheck(const TVec &vec, pcl::InterfaceCommunicator< IndexLayout > &com, const pcl::ProcessCommunicator &pc, const IndexLayout &masterLayout, const IndexLayout &slaveLayout, std::string name="")
receives data over a interface based on a CommunicationScheme on a subgroup of processes
Definition: consistency_check.h:132
void CommunicateOnInterfaces(pcl::InterfaceCommunicator< IndexLayout > &communicator, const IndexLayout &sendingLayout, const IndexLayout &receivingLayout, TCommunicationScheme &scheme)
sends data over a CommunicationScheme from a sendingLayout to a receivingLayout
Definition: communication_scheme.h:292
int ProcRank()
returns the rank of the process
Definition: pcl_base.cpp:83
bool AllProcsTrue(bool bFlag, ProcessCommunicator comm)
Definition: pcl_util.cpp:54
#define UG_LOG(msg)
Definition: log.h:367
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
the ug namespace
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258
Definition: communication_policies.h:58