46 #ifndef MUELU_PERFUTILS_DEF_HPP 47 #define MUELU_PERFUTILS_DEF_HPP 53 #include <Teuchos_CommHelpers.hpp> 68 int numProcs = comm->getSize();
77 avgVal = as<double>(sumVal) / numProcs;
78 devVal = (numProcs != 1 ? sqrt((sum2Val - sumVal*avgVal)/(numProcs-1)) : 0);
84 double avgVal, devVal;
85 calculateStats<Type>(minVal, maxVal, avgVal, devVal, comm, v);
88 if (avgVal && (paramList.is_null() || !paramList->isParameter(
"print abs") || paramList->get<
bool>(
"print abs") ==
false))
89 sprintf(buf,
"avg = %.2e, dev = %5.1f%%, min = %+6.1f%%, max = %+6.1f%%", avgVal,
90 (devVal/avgVal)*100, (minVal/avgVal-1)*100, (maxVal/avgVal-1)*100);
92 sprintf(buf,
"avg = %8.2f, dev = %6.2f, min = %6.1f , max = %6.1f", avgVal,
93 devVal, as<double>(minVal), as<double>(maxVal));
98 bool cmp_less(
typename Map::value_type& v1,
typename Map::value_type& v2) {
99 return v1.second < v2.second;
102 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
106 std::ostringstream ss;
108 ss << msgTag <<
" size = " << A.getGlobalNumRows() <<
" x " << A.getGlobalNumCols()
109 <<
", nnz = " << A.getGlobalNumEntries() << std::endl;
111 if (params.is_null())
114 bool printLoadBalanceInfo =
false, printCommInfo =
false;
115 if (params->isParameter(
"printLoadBalancingInfo") && params->get<
bool>(
"printLoadBalancingInfo"))
116 printLoadBalanceInfo =
true;
117 if (params->isParameter(
"printCommInfo") && params->get<
bool>(
"printCommInfo"))
118 printCommInfo =
true;
120 if (!printLoadBalanceInfo && !printCommInfo)
123 RCP<const Import> importer = A.getCrsGraph()->getImporter();
124 RCP<const Export> exporter = A.getCrsGraph()->getExporter();
126 size_t numMyNnz = A.getNodeNumEntries(), numMyRows = A.getNodeNumRows();
129 RCP<const Teuchos::Comm<int> > origComm = A.getRowMap()->getComm();
131 RCP<const Teuchos::MpiComm<int> > mpiComm = rcp_dynamic_cast<
const Teuchos::MpiComm<int> >(origComm);
132 int numProc = origComm->getSize();
133 MPI_Comm rawComm = (*mpiComm->getRawMpiComm())();
135 std::vector<size_t> numRowsPerProc(numProc);
136 Teuchos::gatherAll(*origComm, 1, &numMyRows, numProc, &numRowsPerProc[0]);
139 for (
int i = 0; i < numProc; i++)
140 if (numRowsPerProc[i]) {
145 RCP<const Teuchos::Comm<int> > comm = origComm->split((numMyRows > 0) ? 0 : MPI_UNDEFINED, 0);
147 RCP<const Teuchos::Comm<int> > comm = origComm->split((numMyRows > 0) ? 0 : -1, 0);
151 if (!comm.is_null()) {
152 ParameterList absList;
153 absList.set(
"print abs",
true);
155 if (printLoadBalanceInfo) {
156 ss << msgTag <<
" Load balancing info" << std::endl;
157 ss << msgTag <<
" # active processes: " << comm->getSize() <<
"/" << origComm->getSize() << std::endl;
158 ss << msgTag <<
" # rows per proc : " << stringStats<global_size_t>(comm, numMyRows) << std::endl;
159 ss << msgTag <<
" # nnz per proc : " << stringStats<global_size_t>(comm, numMyNnz) << std::endl;
162 if (printCommInfo && comm->getSize() != 1) {
163 typedef std::map<int,size_t> map_type;
165 if (!importer.is_null()) {
166 ArrayView<const int> exportPIDs = importer->getExportPIDs();
167 if (exportPIDs.size())
168 for (
int i = 0; i < exportPIDs.size(); i++)
169 neighMap[exportPIDs[i]]++;
173 size_t numExportSend = (!exporter.is_null() ? exporter->getNumExportIDs() : 0);
174 size_t numImportSend = (!importer.is_null() ? importer->getNumExportIDs() : 0);
175 size_t numMsgs = neighMap.size();
177 map_type::const_iterator it = std::min_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
178 size_t minMsg = (it != neighMap.end() ? it->second : 0);
179 it = std::max_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
180 size_t maxMsg = (it != neighMap.end() ? it->second : 0);
182 ss << msgTag <<
" Communication info" << std::endl;
183 ss << msgTag <<
" # num export send : " << stringStats<global_size_t>(comm, numExportSend) << std::endl;
184 ss << msgTag <<
" # num import send : " << stringStats<global_size_t>(comm, numImportSend) << std::endl;
185 ss << msgTag <<
" # num msgs : " << stringStats<global_size_t>(comm, numMsgs, rcpFromRef(absList)) << std::endl;
186 ss << msgTag <<
" # min msg size : " << stringStats<global_size_t>(comm, minMsg) << std::endl;
187 ss << msgTag <<
" # max msg size : " << stringStats<global_size_t>(comm, maxMsg) << std::endl;
194 int strLength = outstr.size();
195 MPI_Bcast(&strLength, 1, MPI_INT, root, rawComm);
196 if (origComm->getRank() != root)
197 outstr.resize(strLength);
198 MPI_Bcast(&outstr[0], strLength, MPI_CHAR, root, rawComm);
204 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
206 std::ostringstream out;
208 RCP<const Teuchos::Comm<int> > comm = A.getRowMap()->getComm();
209 int myRank = comm->getRank();
211 out << msgTag <<
" " << myRank <<
":";
213 RCP<const Import> importer = (A.getCrsGraph() != Teuchos::null ? A.getCrsGraph()->getImporter() : Teuchos::null);
214 if (importer.is_null()) {
219 ArrayView<const int> exportPIDs = importer->getExportPIDs();
221 if (exportPIDs.size()) {
223 int neigh = exportPIDs[0];
225 for (
int i = 1; i < exportPIDs.size(); i++) {
226 if (exportPIDs[i] != exportPIDs[i-1]) {
227 out <<
" " << neigh <<
"(" << weight <<
")";
229 neigh = exportPIDs[i];
236 out <<
" " << neigh <<
"(" << weight <<
")" << std::endl;
244 #endif // MUELU_PERFUTILS_DEF_HPP #define MueLu_sumAll(rcpComm, in, out)
#define MueLu_maxAll(rcpComm, in, out)
Namespace for MueLu classes and methods.
#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 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)
void calculateStats(Type &minVal, Type &maxVal, double &avgVal, double &devVal, const RCP< const Teuchos::Comm< int > > &comm, const Type &v)
std::string stringStats(const RCP< const Teuchos::Comm< int > > &comm, const Type &v, RCP< ParameterList > paramList=Teuchos::null)