本文整理汇总了C++中Solver::Residual方法的典型用法代码示例。如果您正苦于以下问题:C++ Solver::Residual方法的具体用法?C++ Solver::Residual怎么用?C++ Solver::Residual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver::Residual方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
b.Load(vectorBFileName, ENUMUNDEF, ENUMUNDEF, orderingFileName); // Load RHS vector with ordering
} else {
b.Load(vectorBFileName); //if interval parameters not set, matrix will be divided automatically
}
//b.Save(vectorBFileName + "_saved_test.rhs");
} else { // Set local RHS to 1 if it was not specified
INMOST_DATA_ENUM_TYPE mbeg, mend, k;
mat.GetInterval(mbeg, mend);
b.SetInterval(mbeg, mend);
for (k = mbeg; k < mend; ++k) b[k] = 1.0;
}
BARRIER
if (processRank == 0) {
std::cout << "load vector: " << Timer() - tempTimer << std::endl;
}
solvingTimer = Timer();
int iters;
bool success;
double resid, realresid = 0;
std::string reason;
BARRIER
tempTimer = Timer();
solver.SetMatrix(mat);
//s.SetMatrix(mat); // Compute the preconditioner for the original matrix
BARRIER
if (processRank == 0) std::cout << "preconditioner time: " << Timer() - tempTimer << std::endl;
tempTimer = Timer();
success = solver.Solve(b, x); // Solve the linear system with the previously computted preconditioner
BARRIER
solvingTimer = Timer() - solvingTimer;
if (processRank == 0) std::cout << "iterations time: " << Timer() - tempTimer << std::endl;
iters = solver.Iterations(); // Get the number of iterations performed
resid = solver.Residual(); // Get the final residual achieved
reason = solver.ReturnReason(); // Get the convergence reason
if (saveVector) {
x.Save("output.sol"); // Save the solution if required
}
// Compute the true residual
double aresid = 0, bresid = 0;
Sparse::Vector test;
tempTimer = Timer();
Solver::OrderInfo info;
info.PrepareMatrix(mat, 0);
info.PrepareVector(x);
info.Update(x);
mat.MatVec(1.0, x, 0.0, test); // Multiply the original matrix by a vector
{
INMOST_DATA_ENUM_TYPE mbeg, mend, k;
info.GetLocalRegion(info.GetRank(), mbeg, mend);
for (k = mbeg; k < mend; ++k) {
aresid += (test[k] - b[k]) * (test[k] - b[k]);
bresid += b[k] * b[k];
}
}
double temp[2] = {aresid, bresid}, recv[2] = {aresid, bresid};
#if defined(USE_MPI)
MPI_Reduce(temp, recv, 2, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
#endif
realresid = sqrt(recv[0] / (recv[1] + 1.0e-100));
info.RestoreVector(x);
if (processRank == 0) {
std::cout << "||Ax-b||=" << sqrt(recv[0]) << " ||b||=" << sqrt(recv[1]) << " ||Ax-b||/||b||=" <<