本文整理汇总了C++中LocalVector::MoveToAccelerator方法的典型用法代码示例。如果您正苦于以下问题:C++ LocalVector::MoveToAccelerator方法的具体用法?C++ LocalVector::MoveToAccelerator怎么用?C++ LocalVector::MoveToAccelerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocalVector
的用法示例。
在下文中一共展示了LocalVector::MoveToAccelerator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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]));
mat.info();
x.Allocate("x", mat.get_nrow());
rhs.Allocate("rhs", mat.get_nrow());
x.info();
rhs.info();
rhs.Ones();
mat.Apply(rhs, &x);
std::cout << "dot=" << x.Dot(rhs) << std::endl;
mat.ConvertToELL();
mat.info();
mat.MoveToAccelerator();
x.MoveToAccelerator();
rhs.MoveToAccelerator();
mat.info();
rhs.Ones();
mat.Apply(rhs, &x);
std::cout << "dot=" << x.Dot(rhs) << std::endl;
stop_paralution();
return 0;
}
示例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: solveCSRDouble
extern "C" __declspec(dllexport) void solveCSRDouble(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);
mat.MoveToAccelerator();
x.MoveToAccelerator();
rhs.MoveToAccelerator();
CG<LocalMatrix<double>, LocalVector<double>, double> ls;
MultiColoredILU<LocalMatrix<double>, LocalVector<double>, double> p;
ls.SetOperator(mat);
ls.SetPreconditioner(p);
ls.Build();
ls.Solve(rhs, &x);
mat.MoveToHost();
x.MoveToHost();
rhs.MoveToHost();
x.CopyToData(_x);
mat.Clear();
x.Clear();
rhs.Clear();
ls.Clear();
}
示例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
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();
// int ii;
LocalVector<double> x;
LocalVector<double> rhs;
LocalMatrix<double> mat;
struct timeval ti1,ti2;//timer
mat.ReadFileMTX(std::string(argv[1]));
mat.info();
x.Allocate("x", mat.get_nrow());
rhs.Allocate("rhs", mat.get_nrow());
x.info();
rhs.info();
rhs.Ones();
gettimeofday(&ti1,NULL); /* read starttime in t1 */
mat.Apply(rhs, &x);
gettimeofday(&ti2,NULL); /* read endtime in t2 */
fflush(stderr);
fprintf(stderr, "\nTime cost host spmv code microseconds: %ld microseconds\n",
((ti2.tv_sec - ti1.tv_sec)*1000000L
+ti2.tv_usec) - ti1.tv_usec
);
std::cout << "\ndot=" << x.Dot(rhs) << std::endl;
mat.ConvertToBCSR();
mat.info();
mat.MoveToAccelerator();
x.MoveToAccelerator();
rhs.MoveToAccelerator();
mat.info();
rhs.Ones();
// exit(1);
gettimeofday(&ti1,NULL); /* read starttime in t1 */
mat.Apply(rhs, &x);
gettimeofday(&ti2,NULL); /* read endtime in t2 */
fflush(stderr);
fprintf(stderr, "\nTime cost for accelerator spmv microseconds: %ld microseconds\n",
((ti2.tv_sec - ti1.tv_sec)*1000000L
+ti2.tv_usec) - ti1.tv_usec
);
std::cout << "\ndot=" << x.Dot(rhs) << std::endl;
stop_paralution();
return 0;
}
示例6: main
int main(int argc, char* argv[]) {
if (argc == 1) {
std::cerr << argv[0] << " <matrix> <initial_guess> <rhs> [Num threads]" << std::endl;
exit(1);
}
init_paralution();
// if (argc > 4) {
// set_omp_threads_paralution(atoi(argv[]));
// }
set_omp_threads_paralution(8);
info_paralution();
struct timeval now;
double tick, tack, b,s, sol_norm, diff_norm, ones_norm;
double *phi_ptr=NULL;
int *bubmap_ptr=NULL, phisize, maxbmap, setlssd, lvst_offst;
int xdim, ydim, zdim, defvex_perdirec;
#ifdef BUBFLO
xdim=atoi(argv[5]);
setlssd=atoi(argv[6]);
defvex_perdirec=atoi(argv[7]);
lvst_offst=atoi(argv[8]);
phisize=(xdim+2*lvst_offst)*(ydim+2*lvst_offst)*(zdim+2*lvst_offst);
#endif
LocalVector<double> x;
LocalVector<double> rhs;
LocalMatrix<double> mat;
LocalVector<double> Dinvhalf_min;
LocalVector<double> Dinvhalf_plus;
#ifdef GUUS
LocalMatrix<double> Zin;
LocalVector<double> refsol;
LocalVector<double> refones;
#endif
mat.ReadFileMTX(std::string(argv[1]));
mat.info();
#ifdef GUUS
Zin.ReadFileMTX(std::string(argv[2]));
Zin.info();
refsol.Allocate("refsol", mat.get_nrow());
refones.Allocate("refones", mat.get_nrow());
//refsol.Ones();
refsol.ReadFileASCII(std::string(argv[4]));
refones.Ones();
#endif
x.Allocate("x", mat.get_nrow());
rhs.Allocate("rhs", mat.get_nrow());
// Linear Solver
DPCG<LocalMatrix<double>, LocalVector<double>, double > ls;
MultiElimination<LocalMatrix<double>, LocalVector<double>, double > p;
Jacobi<LocalMatrix<double>, LocalVector<double>, double > j_p;
MultiColoredILU<LocalMatrix<double>, LocalVector<double>, double > mcilu_p;
ILU<LocalMatrix<double>, LocalVector<double>, double > ilu_p;
MultiColoredSGS<LocalMatrix<double>, LocalVector<double>, double > mcsgs_p;
FSAI<LocalMatrix <double>, LocalVector<double>, double > fsai_p ;
SPAI<LocalMatrix <double>, LocalVector <double>, double > spai_p ;
#ifdef GPURUN
mat.MoveToAccelerator();
x.MoveToAccelerator();
rhs.MoveToAccelerator();
#endif
#ifdef SCALIN
mat.ExtractInverseDiagonal_sqrt(&Dinvhalf_min, -1);
mat.ExtractInverseDiagonal_sqrt(&Dinvhalf_plus, 1);
mat.DiagonalMatrixMult(Dinvhalf_min);
mat.DiagonalMatrixMult_fromL(Dinvhalf_min);
//x.PointWiseMult(Dinvhalf_plus);
rhs.PointWiseMult(Dinvhalf_min);
#endif
/////////////////////////////////////////////////////////////////
std::cout << "-----------------------------------------------" << std::endl;
std::cout << "DPCG solver MCSGS" << std::endl;
#ifdef GUUS
rhs.ReadFileASCII(std::string(argv[3]));
x.SetRandom(0.0,1.0,1000);
ls.SetZ(Zin);
#endif
#ifdef BUBFLO
x.ReadFileASCII(std::string(argv[2]));
rhs.ReadFileASCII(std::string(argv[3]));
#endif
gettimeofday(&now, NULL);
tick = now.tv_sec*1000000.0+(now.tv_usec);
#ifdef BUBFLO
//.........这里部分代码省略.........
示例7: main
int main(int argc, char* argv[]) {
if (argc == 1) {
std::cerr << argv[0] << " <matrix> <initial_guess> <rhs> [Num threads]" << std::endl;
exit(1);
}
init_paralution();
// if (argc > 4) {
// set_omp_threads_paralution(atoi(argv[5]));
// }
set_omp_threads_paralution(8);
info_paralution();
struct timeval now;
double tick, tack, b=0.0f,s=0.0f, lprep=0.0f, sol_norm, diff_norm, ones_norm;
double *phi_ptr=NULL;
int *bubmap_ptr=NULL, phisize, maxbmap, setlssd, lvst_offst;
int xdim, ydim, zdim, defvex_perdirec, defvex_perdirec_y, defvex_perdirec_z;
DPCG<LocalMatrix<double>, LocalVector<double>, double > ls;
#ifdef BUBFLO
xdim=atoi(argv[5]);
setlssd=atoi(argv[6]);
defvex_perdirec=atoi(argv[7]);
lvst_offst=atoi(argv[8]);
phisize=(xdim+2*lvst_offst)*(ydim+2*lvst_offst)*(zdim+2*lvst_offst);
#endif
LocalVector<double> x;
LocalVector<double>refsol;
LocalVector<double>refones;
LocalVector<double>chk_r;
LocalVector<double> rhs;
LocalMatrix<double> mat;
LocalVector<double> Dinvhalf_min;
LocalVector<double> Dinvhalf_plus;
#ifdef GUUS
LocalMatrix<double> Zin;
#endif
mat.ReadFileMTX(std::string(argv[1]));
mat.info();
#ifdef GUUS
Zin.ReadFileMTX(std::string(argv[2]));
Zin.info();
#endif
x.Allocate("x", mat.get_nrow());
refsol.Allocate("refsol", mat.get_nrow());
refones.Allocate("refones", mat.get_nrow());
rhs.Allocate("rhs", mat.get_nrow());
chk_r.Allocate("chk_r", mat.get_nrow());
#ifdef BUBFLO
x.ReadFileASCII(std::string(argv[2]));
#endif
rhs.ReadFileASCII(std::string(argv[3]));
#ifdef GUUS
x.SetRandom(0.0,1.0,1000);
refsol.ReadFileASCII(std::string(argv[4]));
refones.Ones();
#endif
//refsol.Ones();
//
// // Uncomment for GPU
#ifdef GPURUN
mat.MoveToAccelerator();
x.MoveToAccelerator();
rhs.MoveToAccelerator();
chk_r.MoveToAccelerator();
Dinvhalf_min.MoveToAccelerator();
Dinvhalf_plus.MoveToAccelerator();
#endif
gettimeofday(&now, NULL);
tick = now.tv_sec*1000000.0+(now.tv_usec);
#ifdef BUBFLO
if(setlssd){
LocalVector<double> phi;
LocalVector<int> bubmap;
phi.Allocate("PHI", phisize);
bubmap.Allocate("bubmap",mat.get_nrow());
phi.ReadFileASCII(std::string(argv[4]));
bubmap.LeaveDataPtr(&bubmap_ptr);
phi.LeaveDataPtr(&phi_ptr);
bubmap_create(phi_ptr, bubmap_ptr, xdim, xdim, xdim, mat.get_nrow(), &maxbmap, lvst_offst);
phi.Clear();
}
ls.Setxdim(xdim);
ls.SetNVectors_eachdirec(defvex_perdirec+1, defvex_perdirec+2, defvex_perdirec+3);
ls.Set_alldims(xdim, xdim, xdim);
ls.Setlvst_offst(lvst_offst);
ls.SetNVectors(defvex_perdirec);
ls.SetZlssd(setlssd);
//.........这里部分代码省略.........