本文整理汇总了C++中LocalVector::Zeros方法的典型用法代码示例。如果您正苦于以下问题:C++ LocalVector::Zeros方法的具体用法?C++ LocalVector::Zeros怎么用?C++ LocalVector::Zeros使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocalVector
的用法示例。
在下文中一共展示了LocalVector::Zeros方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CPUsolveCSRDouble
extern "C" __declspec(dllexport) void CPUsolveCSRDouble(int *row_offset, int *col, double *val,
const int nnz, const int N, double *_rhs, double *_x) {
std::string name = "s";
LocalVector<double> x;
LocalVector<double> rhs;
LocalMatrix<double> mat;
x.Allocate(name, N);
x.Zeros();
rhs.Allocate(name, N);
mat.AllocateCSR(name, nnz, N, N);
mat.CopyFromCSR(row_offset, col, val);
rhs.CopyFromData(_rhs);
CG<LocalMatrix<double>, LocalVector<double>, double> ls;
Jacobi<LocalMatrix<double>, LocalVector<double>, double> p;
ls.SetOperator(mat);
ls.SetPreconditioner(p);
ls.Build();
ls.Solve(rhs, &x);
x.CopyToData(_x);
mat.Clear();
x.Clear();
rhs.Clear();
ls.Clear();
}
示例2: solveCSRSingle
extern "C" __declspec(dllexport) void solveCSRSingle(int *row_offset, int *col, float *val,
const int nnz, const int N, float *_rhs, float *_x) {
std::string name = "s";
LocalVector<float> x;
LocalVector<float> rhs;
LocalMatrix<float> mat;
x.Allocate(name, N);
x.Zeros();
rhs.Allocate(name, N);
mat.AllocateCSR(name, nnz, N, N);
mat.CopyFromCSR(row_offset, col, val);
rhs.CopyFromData(_rhs);
// mat.Check();
/* rhs.SetDataPtr(&_rhs, name, N);
x.SetDataPtr(&_x, name, N);
mat.SetDataPtrCSR(&row_offset, &col, &val, name, nnz, N, N);
*/
mat.MoveToAccelerator();
x.MoveToAccelerator();
rhs.MoveToAccelerator();
CG<LocalMatrix<float>, LocalVector<float>, float> ls;
MultiColoredILU<LocalMatrix<float>, LocalVector<float>, float> p;
ls.SetOperator(mat);
ls.SetPreconditioner(p);
ls.Build();
ls.Solve(rhs, &x);
mat.MoveToHost();
x.MoveToHost();
rhs.MoveToHost();
/*
mat.LeaveDataPtrCSR(&row_offset, &col, &val);
rhs.LeaveDataPtr(&_rhs);
x.LeaveDataPtr(&_x);
*/
x.CopyToData(_x);
mat.Clear();
x.Clear();
rhs.Clear();
ls.Clear();
}
示例3: main
int main(int argc, char* argv[]) {
init_paralution();
info_paralution();
LocalVector<double> x;
LocalVector<double> rhs;
LocalStencil<double> stencil(Laplace2D);
stencil.SetGrid(100); // 100x100
x.Allocate("x", stencil.get_nrow());
rhs.Allocate("rhs", stencil.get_nrow());
// Linear Solver
CG<LocalStencil<double>, LocalVector<double>, double > ls;
rhs.Ones();
x.Zeros();
ls.SetOperator(stencil);
ls.Build();
stencil.info();
double tick, tack;
tick = paralution_time();
ls.Solve(rhs, &x);
tack = paralution_time();
std::cout << "Solver execution:" << (tack-tick)/1000000 << " sec" << std::endl;
ls.Clear();
stop_paralution();
return 0;
}
示例4: main
int main(int argc, char* argv[]) {
if (argc == 1) {
std::cerr << argv[0] << " <matrix> [Num threads]" << std::endl;
exit(1);
}
init_paralution();
if (argc > 2) {
set_omp_threads_paralution(atoi(argv[2]));
}
info_paralution();
LocalVector<double> x;
LocalVector<double> rhs;
LocalMatrix<double> mat;
mat.ReadFileMTX(std::string(argv[1]));
// Compute and apply (R)CMK ordering
LocalVector<int> cmk;
// mat.CMK(&cmk);
mat.RCMK(&cmk);
mat.Permute(cmk);
mat.MoveToAccelerator();
x.MoveToAccelerator();
rhs.MoveToAccelerator();
x.Allocate("x", mat.get_nrow());
rhs.Allocate("rhs", mat.get_nrow());
// Linear Solver
CG<LocalMatrix<double>, LocalVector<double>, double > ls;
// Preconditioner
ILU<LocalMatrix<double>, LocalVector<double>, double > p;
double tick, tack;
rhs.Ones();
x.Zeros();
ls.SetOperator(mat);
ls.SetPreconditioner(p);
ls.Build();
mat.info();
tick = paralution_time();
ls.Solve(rhs, &x);
tack = paralution_time();
std::cout << "Solver execution:" << (tack-tick)/1000000 << " sec" << std::endl;
// Revert CMK ordering on solution vector
x.PermuteBackward(cmk);
stop_paralution();
return 0;
}
示例5: main
//.........这里部分代码省略.........
}
// get lambda max (Rayleigh quotient)
mat.Apply(*b_k, b_k1);
plambda_max = b_k1->Dot(*b_k) ;
tack = paralution_time();
std::cout << "Power method (lambda max) execution:" << (tack-tick)/1000000 << " sec" << std::endl;
mat.AddScalarDiagonal(double(-1.0)*plambda_max);
b_k->Ones();
tick = paralution_time();
// compute lambda min
for (int i=0; i<=iter_max; ++i) {
mat.Apply(*b_k, b_k1);
// std::cout << b_k1->Dot(*b_k) + plambda_max << std::endl;
b_k1->Scale(double(1.0)/b_k1->Norm());
b_tmp = b_k1;
b_k1 = b_k;
b_k = b_tmp;
}
// get lambda min (Rayleigh quotient)
mat.Apply(*b_k, b_k1);
plambda_min = (b_k1->Dot(*b_k) + plambda_max);
// back to the original matrix
mat.AddScalarDiagonal(plambda_max);
tack = paralution_time();
std::cout << "Power method (lambda min) execution:" << (tack-tick)/1000000 << " sec" << std::endl;
std::cout << "Power method Lambda min = " << plambda_min
<< "; Lambda max = " << plambda_max
<< "; iter=2x" << iter_max << std::endl;
LocalVector<double> x;
LocalVector<double> rhs;
x.CloneBackend(mat);
rhs.CloneBackend(mat);
x.Allocate("x", mat.get_nrow());
rhs.Allocate("rhs", mat.get_nrow());
// Chebyshev iteration
Chebyshev<LocalMatrix<double>, LocalVector<double>, double > ls;
rhs.Ones();
x.Zeros();
ls.SetOperator(mat);
ls.Set(plambda_min, plambda_max);
ls.Build();
tick = paralution_time();
ls.Solve(rhs, &x);
tack = paralution_time();
std::cout << "Solver execution:" << (tack-tick)/1000000 << " sec" << std::endl;
// PCG + Chebyshev polynomial
CG<LocalMatrix<double>, LocalVector<double>, double > cg;
AIChebyshev<LocalMatrix<double>, LocalVector<double>, double > p;
// damping factor
plambda_min = plambda_max / 7;
p.Set(3, plambda_min, plambda_max);
rhs.Ones();
x.Zeros();
cg.SetOperator(mat);
cg.SetPreconditioner(p);
cg.Build();
tick = paralution_time();
cg.Solve(rhs, &x);
tack = paralution_time();
std::cout << "Solver execution:" << (tack-tick)/1000000 << " sec" << std::endl;
stop_paralution();
return 0;
}