56 double avgVal, devVal;
58 calculateStats<Type>(minVal, maxVal, avgVal, devVal, minProc, maxProc, comm, numActiveProcs, v);
60 const double zero = Teuchos::ScalarTraits<double>::zero();
61 const double one = Teuchos::ScalarTraits<double>::one();
62 std::ostringstream buf;
64 if ((avgVal != zero) && (paramList.is_null() || !paramList->isParameter(
"print abs") || paramList->get<
bool>(
"print abs") ==
false)) {
65 double relDev = (devVal / avgVal) * 100;
66 double relMin = (as<double>(Teuchos::ScalarTraits<Type>::real(minVal)) / avgVal - one) * 100;
67 double relMax = (as<double>(Teuchos::ScalarTraits<Type>::real(maxVal)) / avgVal - one) * 100;
68 buf <<
"avg = " << std::scientific << std::setw(10) << std::setprecision(2) << avgVal <<
", "
69 <<
"dev = " << std::fixed << std::setw(6) << std::setprecision(1) << relDev <<
"%, "
70 <<
"min = " << std::fixed << std::setw(7) << std::setprecision(1) << std::setw(7) << relMin <<
"%"
71 <<
" (" << std::scientific << std::setw(10) << std::setprecision(2) << minVal <<
" on " << std::fixed << std::setw(4) << minProc <<
"), "
72 <<
"max = " << std::fixed << std::setw(7) << std::setprecision(1) << relMax <<
"%"
73 <<
" (" << std::scientific << std::setw(10) << std::setprecision(2) << maxVal <<
" on " << std::fixed << std::setw(4) << maxProc <<
")";
75 double relDev = (avgVal != zero ? (devVal / avgVal) * 100 : zero);
76 buf <<
"avg = " << std::scientific << std::setw(10) << std::setprecision(2) << avgVal <<
", "
77 <<
"dev = " << std::fixed << std::setw(6) << std::setprecision(1) << relDev <<
"%, "
78 <<
"min = " << std::scientific << std::setw(10) << std::setprecision(2) << minVal
79 <<
" (on " << std::fixed << std::setw(4) << minProc <<
"), "
80 <<
"max = " << std::scientific << std::setw(10) << std::setprecision(2) << maxVal
81 <<
" (on " << std::fixed << std::setw(4) << maxProc <<
")";
96 typedef Xpetra::global_size_t global_size_t;
98 std::ostringstream ss;
100 ss << msgTag <<
" size = " << A.getGlobalNumRows() <<
" x " << A.getGlobalNumCols();
101 if (A.haveGlobalConstants())
102 ss <<
", nnz = " << A.getGlobalNumEntries();
105 if (params.is_null())
108 bool printLoadBalanceInfo =
false, printCommInfo =
false, printEntryStats =
false;
109 if (params->isParameter(
"printLoadBalancingInfo") && params->get<
bool>(
"printLoadBalancingInfo"))
110 printLoadBalanceInfo =
true;
111 if (params->isParameter(
"printCommInfo") && params->get<
bool>(
"printCommInfo"))
112 printCommInfo =
true;
113 if (params->isParameter(
"printEntryStats") && params->get<
bool>(
"printEntryStats"))
114 printEntryStats =
true;
116 if (!printLoadBalanceInfo && !printCommInfo && !printEntryStats)
119 RCP<const Import> importer = A.getCrsGraph()->getImporter();
120 RCP<const Export> exporter = A.getCrsGraph()->getExporter();
122 size_t numMyNnz = A.getLocalNumEntries(), numMyRows = A.getLocalNumRows();
125 RCP<const Teuchos::Comm<int> > origComm = A.getRowMap()->getComm();
126 bool activeProc =
true;
127 int numProc = origComm->getSize();
128 int numActiveProcs = 0;
130 RCP<const Teuchos::MpiComm<int> > mpiComm = rcp_dynamic_cast<const Teuchos::MpiComm<int> >(origComm);
131 MPI_Comm rawComm = (*mpiComm->getRawMpiComm())();
133 std::vector<size_t> numRowsPerProc(numProc);
134 Teuchos::gatherAll(*origComm, 1, &numMyRows, numProc, &numRowsPerProc[0]);
137 bool rootFlag =
true;
138 for (
int i = 0; i < numProc; i++) {
139 if (numRowsPerProc[i]) {
148 if (numMyRows == 0) {
153 if (numMyRows == 0) {
165 ParameterList absList;
166 absList.set(
"print abs",
true);
168 RCP<const Matrix> rcpA = rcpFromRef(A);
169 RCP<const CrsMatrixWrap> crsWrapA = rcp_dynamic_cast<const Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(rcpA);
170 RCP<const CrsMatrix> crsA;
171 if (!crsWrapA.is_null())
172 crsA = crsWrapA->getCrsMatrix();
173 if (printEntryStats && !crsA.is_null()) {
174 typedef Teuchos::ScalarTraits<Scalar> STS;
175 typedef typename STS::magnitudeType magnitudeType;
176 typedef Teuchos::ScalarTraits<magnitudeType> MTS;
177 ArrayRCP<const size_t> rowptr_RCP;
178 ArrayRCP<const LocalOrdinal> colind_RCP;
179 ArrayRCP<const Scalar> vals_RCP;
180 ArrayRCP<size_t> offsets_RCP;
181 ArrayView<const size_t> rowptr;
182 ArrayView<const Scalar> vals;
183 ArrayView<size_t> offsets;
185 crsA->getAllValues(rowptr_RCP, colind_RCP, vals_RCP);
186 crsA->getLocalDiagOffsets(offsets_RCP);
187 rowptr = rowptr_RCP();
189 offsets = offsets_RCP();
191 Scalar val, minVal, maxVal;
192 magnitudeType absVal, minAbsVal, maxAbsVal;
194 minVal = STS::rmax();
195 maxVal = STS::rmin();
196 minAbsVal = MTS::rmax();
197 maxAbsVal = MTS::zero();
199 for (
int i = 0; i < offsets.size(); i++) {
200 val = vals[rowptr[i] + offsets[i]];
201 if (STS::real(val) < STS::real(minVal))
203 if (STS::real(val) > STS::real(maxVal))
205 absVal = STS::magnitude(val);
206 minAbsVal = std::min(minAbsVal, absVal);
207 maxAbsVal = std::max(maxAbsVal, absVal);
210 ss << msgTag <<
" diag min : " << stringStats<Scalar>(origComm, numActiveProcs, minVal) << std::endl;
211 ss << msgTag <<
" diag max : " << stringStats<Scalar>(origComm, numActiveProcs, maxVal) << std::endl;
212 ss << msgTag <<
" abs(diag) min : " << stringStats<Scalar>(origComm, numActiveProcs, minAbsVal) << std::endl;
213 ss << msgTag <<
" abs(diag) max : " << stringStats<Scalar>(origComm, numActiveProcs, maxAbsVal) << std::endl;
217 minVal = STS::rmax();
218 maxVal = STS::rmin();
219 minAbsVal = MTS::rmax();
220 maxAbsVal = MTS::zero();
222 for (
int i = 0; i < vals.size(); i++) {
224 if (STS::real(val) < STS::real(minVal))
226 if (STS::real(val) > STS::real(maxVal))
228 absVal = STS::magnitude(val);
229 minAbsVal = std::min(minAbsVal, absVal);
230 maxAbsVal = std::max(maxAbsVal, absVal);
233 ss << msgTag <<
" entry min : " << stringStats<Scalar>(origComm, numActiveProcs, minVal) << std::endl;
234 ss << msgTag <<
" entry max : " << stringStats<Scalar>(origComm, numActiveProcs, maxVal) << std::endl;
235 ss << msgTag <<
" abs(entry) min : " << stringStats<Scalar>(origComm, numActiveProcs, minAbsVal) << std::endl;
236 ss << msgTag <<
" abs(entry) max : " << stringStats<Scalar>(origComm, numActiveProcs, maxAbsVal) << std::endl;
240 if (printLoadBalanceInfo) {
241 ss << msgTag <<
" Load balancing info" << std::endl;
242 ss << msgTag <<
" # active processes: " << numActiveProcs <<
"/" << numProc << std::endl;
243 ss << msgTag <<
" # rows per proc : " << stringStats<global_size_t>(origComm, numActiveProcs, numMyRows) << std::endl;
244 ss << msgTag <<
" # nnz per proc : " << stringStats<global_size_t>(origComm, numActiveProcs, numMyNnz) << std::endl;
247 if (printCommInfo && numActiveProcs != 1) {
248 typedef std::map<int, size_t> map_type;
250 if (!importer.is_null()) {
251 ArrayView<const int> exportPIDs = importer->getExportPIDs();
252 if (exportPIDs.size())
253 for (
int i = 0; i < exportPIDs.size(); i++)
254 neighMap[exportPIDs[i]]++;
258 size_t numExportSend = 0;
259 size_t numImportSend = 0;
265 numExportSend = (!exporter.is_null() ? exporter->getNumExportIDs() : 0);
266 numImportSend = (!importer.is_null() ? importer->getNumExportIDs() : 0);
267 numMsgs = neighMap.size();
268 map_type::const_iterator it = std::min_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
269 minMsg = (it != neighMap.end() ? it->second : 0);
270 it = std::max_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
271 maxMsg = (it != neighMap.end() ? it->second : 0);
274 ss << msgTag <<
" Communication info" << std::endl;
275 ss << msgTag <<
" # num export send : " << stringStats<global_size_t>(origComm, numActiveProcs, numExportSend) << std::endl;
276 ss << msgTag <<
" # num import send : " << stringStats<global_size_t>(origComm, numActiveProcs, numImportSend) << std::endl;
277 ss << msgTag <<
" # num msgs : " << stringStats<global_size_t>(origComm, numActiveProcs, numMsgs, rcpFromRef(absList)) << std::endl;
278 ss << msgTag <<
" # min msg size : " << stringStats<global_size_t>(origComm, numActiveProcs, minMsg) << std::endl;
279 ss << msgTag <<
" # max msg size : " << stringStats<global_size_t>(origComm, numActiveProcs, maxMsg) << std::endl;
285 int strLength = outstr.size();
286 MPI_Bcast(&strLength, 1, MPI_INT, root, rawComm);
287 if (origComm->getRank() != root)
288 outstr.resize(strLength);
289 MPI_Bcast(&outstr[0], strLength, MPI_CHAR, root, rawComm);
297 typedef Xpetra::global_size_t global_size_t;
299 std::ostringstream ss;
302 RCP<const Teuchos::Comm<int> > origComm = importer->getSourceMap()->getComm();
303 bool activeProc =
true;
304 int numActiveProcs = origComm->getSize();
306 RCP<const Teuchos::MpiComm<int> > mpiComm = rcp_dynamic_cast<const Teuchos::MpiComm<int> >(origComm);
307 MPI_Comm rawComm = (*mpiComm->getRawMpiComm())();
312 ParameterList absList;
313 absList.set(
"print abs",
true);
315 typedef std::map<int, size_t> map_type;
317 ArrayView<const int> exportPIDs = importer->getExportPIDs();
318 if (exportPIDs.size())
319 for (
int i = 0; i < exportPIDs.size(); i++)
320 neighMap[exportPIDs[i]]++;
323 size_t numImportSend = 0;
329 numImportSend = importer->getNumExportIDs();
330 numMsgs = neighMap.size();
331 map_type::const_iterator it = std::min_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
332 minMsg = (it != neighMap.end() ? it->second : 0);
333 it = std::max_element(neighMap.begin(), neighMap.end(), cmp_less<map_type>);
334 maxMsg = (it != neighMap.end() ? it->second : 0);
337 ss << msgTag <<
" Communication info" << std::endl;
338 ss << msgTag <<
" # num import send : " << stringStats<global_size_t>(origComm, numActiveProcs, numImportSend) << std::endl;
339 ss << msgTag <<
" # num msgs : " << stringStats<global_size_t>(origComm, numActiveProcs, numMsgs, rcpFromRef(absList)) << std::endl;
340 ss << msgTag <<
" # min msg size : " << stringStats<global_size_t>(origComm, numActiveProcs, minMsg) << std::endl;
341 ss << msgTag <<
" # max msg size : " << stringStats<global_size_t>(origComm, numActiveProcs, maxMsg) << std::endl;
346 int strLength = outstr.size();
347 MPI_Bcast(&strLength, 1, MPI_INT, root, rawComm);
348 if (origComm->getRank() != root)
349 outstr.resize(strLength);
350 MPI_Bcast(&outstr[0], strLength, MPI_CHAR, root, rawComm);