46 #ifndef MUELU_PERFUTILS_DEF_HPP
47 #define MUELU_PERFUTILS_DEF_HPP
53 #include <Teuchos_CommHelpers.hpp>
76 avgVal = (numActiveProcs > 0 ? as<double>(sumVal) / numActiveProcs : 0);
77 devVal = (numActiveProcs > 1 ? sqrt((sum2Val - sumVal*avgVal)/(numActiveProcs-1)) : 0);
83 double avgVal, devVal;
84 calculateStats<Type>(minVal, maxVal, avgVal, devVal, comm, numActiveProcs, v);
87 if (avgVal && (paramList.is_null() || !paramList->isParameter(
"print abs") || paramList->get<
bool>(
"print abs") ==
false))
88 sprintf(buf,
"avg = %.2e, dev = %5.1f%%, min = %+6.1f%%, max = %+6.1f%%", avgVal,
89 (devVal/avgVal)*100, (minVal/avgVal-1)*100, (maxVal/avgVal-1)*100);
91 sprintf(buf,
"avg = %8.2f, dev = %6.2f, min = %6.1f , max = %6.1f", avgVal,
92 devVal, as<double>(minVal), as<double>(maxVal));
97 bool cmp_less(
typename Map::value_type& v1,
typename Map::value_type& v2) {
98 return v1.second < v2.second;
101 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
108 std::ostringstream ss;
110 ss << msgTag <<
" size = " << A.getGlobalNumRows() <<
" x " << A.getGlobalNumCols();
111 if(A.haveGlobalConstants())
112 ss <<
", nnz = " << A.getGlobalNumEntries();
118 bool printLoadBalanceInfo =
false, printCommInfo =
false;
119 if (params->
isParameter(
"printLoadBalancingInfo") && params->
get<
bool>(
"printLoadBalancingInfo"))
120 printLoadBalanceInfo =
true;
121 if (params->
isParameter(
"printCommInfo") && params->
get<
bool>(
"printCommInfo"))
122 printCommInfo =
true;
124 if (!printLoadBalanceInfo && !printCommInfo)
130 size_t numMyNnz = A.getNodeNumEntries(), numMyRows = A.getNodeNumRows();
134 bool activeProc =
true;
135 int numProc = origComm->getSize();
136 int numActiveProcs = 0;
139 MPI_Comm rawComm = (*mpiComm->getRawMpiComm())();
141 std::vector<size_t> numRowsPerProc(numProc);
142 Teuchos::gatherAll(*origComm, 1, &numMyRows, numProc, &numRowsPerProc[0]);
145 bool rootFlag =
true;
146 for (
int i = 0; i < numProc; i++) {
147 if (numRowsPerProc[i]) {
156 if(numMyRows == 0) {activeProc =
false; numMyNnz = 0;}
171 absList.
set(
"print abs",
true);
173 if (printLoadBalanceInfo) {
174 ss << msgTag <<
" Load balancing info" << std::endl;
175 ss << msgTag <<
" # active processes: " << numActiveProcs <<
"/" << numProc << std::endl;
176 ss << msgTag <<
" # rows per proc : " << stringStats<global_size_t>(origComm, numActiveProcs, numMyRows) << std::endl;
177 ss << msgTag <<
" # nnz per proc : " << stringStats<global_size_t>(origComm, numActiveProcs, numMyNnz) << std::endl;
180 if (printCommInfo && numActiveProcs != 1) {
181 typedef std::map<int,size_t> map_type;
185 if (exportPIDs.
size())
186 for (
int i = 0; i < exportPIDs.
size(); i++)
187 neighMap[exportPIDs[i]]++;
191 size_t numExportSend = 0;
192 size_t numImportSend = 0;
198 numExportSend = (!exporter.
is_null() ? exporter->getNumExportIDs() : 0);
199 numImportSend = (!importer.
is_null() ? importer->getNumExportIDs() : 0);
200 numMsgs = neighMap.size();
201 map_type::const_iterator it = std::min_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
202 minMsg = (it != neighMap.end() ? it->second : 0);
203 it = std::max_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
204 maxMsg = (it != neighMap.end() ? it->second : 0);
207 ss << msgTag <<
" Communication info" << std::endl;
208 ss << msgTag <<
" # num export send : " << stringStats<global_size_t>(origComm, numActiveProcs, numExportSend) << std::endl;
209 ss << msgTag <<
" # num import send : " << stringStats<global_size_t>(origComm, numActiveProcs, numImportSend) << std::endl;
210 ss << msgTag <<
" # num msgs : " << stringStats<global_size_t>(origComm, numActiveProcs, numMsgs, rcpFromRef(absList)) << std::endl;
211 ss << msgTag <<
" # min msg size : " << stringStats<global_size_t>(origComm, numActiveProcs, minMsg) << std::endl;
212 ss << msgTag <<
" # max msg size : " << stringStats<global_size_t>(origComm, numActiveProcs, maxMsg) << std::endl;
218 int strLength = outstr.size();
219 MPI_Bcast(&strLength, 1, MPI_INT, root, rawComm);
220 if (origComm->getRank() != root)
221 outstr.resize(strLength);
222 MPI_Bcast(&outstr[0], strLength, MPI_CHAR, root, rawComm);
228 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
233 std::ostringstream ss;
237 bool activeProc =
true;
238 int numActiveProcs = origComm->getSize();
241 MPI_Comm rawComm = (*mpiComm->getRawMpiComm())();
247 absList.
set(
"print abs",
true);
249 typedef std::map<int,size_t> map_type;
252 if (exportPIDs.
size())
253 for (
int i = 0; i < exportPIDs.
size(); i++)
254 neighMap[exportPIDs[i]]++;
257 size_t numImportSend = 0;
263 numImportSend = importer->getNumExportIDs();
264 numMsgs = neighMap.size();
265 map_type::const_iterator it = std::min_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
266 minMsg = (it != neighMap.end() ? it->second : 0);
267 it = std::max_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
268 maxMsg = (it != neighMap.end() ? it->second : 0);
271 ss << msgTag <<
" Communication info" << std::endl;
272 ss << msgTag <<
" # num import send : " << stringStats<global_size_t>(origComm, numActiveProcs, numImportSend) << std::endl;
273 ss << msgTag <<
" # num msgs : " << stringStats<global_size_t>(origComm, numActiveProcs, numMsgs, rcpFromRef(absList)) << std::endl;
274 ss << msgTag <<
" # min msg size : " << stringStats<global_size_t>(origComm, numActiveProcs, minMsg) << std::endl;
275 ss << msgTag <<
" # max msg size : " << stringStats<global_size_t>(origComm, numActiveProcs, maxMsg) << std::endl;
281 int strLength = outstr.size();
282 MPI_Bcast(&strLength, 1, MPI_INT, root, rawComm);
283 if (origComm->getRank() != root)
284 outstr.resize(strLength);
285 MPI_Bcast(&outstr[0], strLength, MPI_CHAR, root, rawComm);
291 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
296 std::ostringstream out;
299 int myRank = comm->getRank();
301 out << msgTag <<
" " << myRank <<
":";
303 RCP<const Import> importer = (A.getCrsGraph() != Teuchos::null ? A.getCrsGraph()->getImporter() : Teuchos::null);
311 if (exportPIDs.
size()) {
313 int neigh = exportPIDs[0];
315 for (
int i = 1; i < exportPIDs.
size(); i++) {
316 if (exportPIDs[i] != exportPIDs[i-1]) {
317 out <<
" " << neigh <<
"(" << weight <<
")";
319 neigh = exportPIDs[i];
326 out <<
" " << neigh <<
"(" << weight <<
")" << std::endl;
332 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
339 bool hasCrsGraph =
true;
352 #endif // MUELU_PERFUTILS_DEF_HPP
static bool CheckMatrix(const Matrix &A)
std::string stringStats(const RCP< const Teuchos::Comm< int > > &comm, int numActiveProcs, const Type &v, RCP< ParameterList > paramList=Teuchos::null)
#define MueLu_sumAll(rcpComm, in, out)
#define MueLu_maxAll(rcpComm, in, out)
void calculateStats(Type &minVal, Type &maxVal, double &avgVal, double &devVal, const RCP< const Teuchos::Comm< int > > &comm, int numActiveProcs, const Type &v)
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define MueLu_minAll(rcpComm, in, out)
static std::string CommPattern(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
static std::string PrintImporterInfo(RCP< const Import > importer, const std::string &msgTag)
bool isParameter(const std::string &name) const
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
bool cmp_less(typename Map::value_type &v1, typename Map::value_type &v2)