|
12 | 12 |
|
13 | 13 | #include <Eigen/src/SparseCholesky/SimplicialCholesky.h> |
14 | 14 |
|
15 | | -/** |
16 | | - * @brief using Eigen to solve the same system |
17 | | - */ |
18 | | -template <typename SpMat, typename DMat> |
19 | | -void simplicial_llt(const rxmesh::RXMeshStatic& rx, |
20 | | - const SpMat& A, |
21 | | - const DMat& B) |
| 15 | + |
| 16 | +template <typename SolverT, typename SpMat, typename DMat> |
| 17 | +void run_eigen(const rxmesh::RXMeshStatic& rx, |
| 18 | + const std::string name, |
| 19 | + const SpMat& A, |
| 20 | + const DMat& B) |
22 | 21 | { |
23 | 22 | using namespace rxmesh; |
24 | 23 |
|
25 | | - Report report("MCF_Eigen"); |
| 24 | + Report report("MCF_Eigen_" + name); |
26 | 25 | report.command_line(Arg.argc, Arg.argv); |
27 | 26 | report.device(); |
28 | 27 | report.system(); |
29 | 28 | report.model_data(Arg.obj_file_name, rx); |
30 | | - report.add_member("method", std::string("SimplicialLLT")); |
| 29 | + report.add_member("method", name); |
31 | 30 | report.add_member("application", std::string("MCF")); |
32 | 31 |
|
33 | 32 | float total_time = 0; |
34 | 33 |
|
35 | | - Eigen::SimplicialLLT<SpMat, |
36 | | - Eigen::UpLoType::Lower, |
37 | | - Eigen::AMDOrdering<typename SpMat::StorageIndex>> |
38 | | - solver; |
| 34 | + SolverT solver; |
39 | 35 |
|
40 | 36 | CPUTimer timer; |
41 | 37 | timer.start(); |
42 | 38 | solver.analyzePattern(A); |
43 | 39 | timer.stop(); |
44 | 40 |
|
45 | 41 | if (solver.info() != Eigen::Success) { |
46 | | - std::cout << solver.info() << "\n"; |
47 | | - RXMESH_ERROR("Eigen::SimplicialLLT analyzePattern failed!"); |
| 42 | + RXMESH_ERROR("{} analyzePattern failed!", name); |
48 | 43 | } |
49 | 44 |
|
50 | 45 | total_time += timer.elapsed_millis(); |
51 | | - RXMESH_INFO("SimplicialLLT analyze_pattern took {} (ms)", |
52 | | - timer.elapsed_millis()); |
| 46 | + RXMESH_INFO( |
| 47 | + "{} analyze_pattern took {} (ms)", name, timer.elapsed_millis()); |
53 | 48 | report.add_member("analyze_pattern", timer.elapsed_millis()); |
54 | 49 |
|
55 | 50 | timer.start(); |
56 | 51 | solver.factorize(A); |
57 | 52 | timer.stop(); |
58 | 53 |
|
59 | 54 | total_time += timer.elapsed_millis(); |
60 | | - RXMESH_INFO("SimplicialLLT factorize took {} (ms)", timer.elapsed_millis()); |
| 55 | + RXMESH_INFO("{} factorize took {} (ms)", name, timer.elapsed_millis()); |
61 | 56 | report.add_member("factorize", timer.elapsed_millis()); |
62 | 57 |
|
63 | 58 | if (solver.info() != Eigen::Success) { |
64 | | - std::cout << solver.info() << "\n"; |
65 | | - RXMESH_ERROR("Eigen::SimplicialLLT factorization failed!"); |
| 59 | + RXMESH_ERROR("{} factorization failed!", name); |
66 | 60 | } |
67 | 61 |
|
68 | 62 | timer.start(); |
69 | 63 | DMat X = solver.solve(B); |
70 | 64 | timer.stop(); |
71 | 65 |
|
72 | 66 | total_time += timer.elapsed_millis(); |
73 | | - RXMESH_INFO("SimplicialLLT solve took {} (ms)", timer.elapsed_millis()); |
| 67 | + RXMESH_INFO("{} solve took {} (ms)", name, timer.elapsed_millis()); |
74 | 68 | report.add_member("solve", timer.elapsed_millis()); |
75 | 69 |
|
76 | 70 | if (solver.info() != Eigen::Success) { |
77 | | - std::cout << solver.info() << "\n"; |
78 | | - RXMESH_ERROR("Eigen::SimplicialLLT solve failed!"); |
| 71 | + RXMESH_ERROR("{} solve failed!", name); |
79 | 72 | } |
80 | 73 |
|
81 | | - RXMESH_INFO("SimplicialLLT total_time {} (ms)", total_time); |
| 74 | + RXMESH_INFO("{} total_time {} (ms)", name, total_time); |
82 | 75 | report.add_member("total_time", total_time); |
83 | 76 |
|
84 | 77 |
|
85 | 78 | report.write(Arg.output_folder + "/rxmesh", |
86 | | - "MCF_EIGEN_LDLT_" + extract_file_name(Arg.obj_file_name)); |
| 79 | + "MCF_" + name + "_" + extract_file_name(Arg.obj_file_name)); |
| 80 | +} |
| 81 | + |
| 82 | + |
| 83 | +template <typename SpMat, typename DMat> |
| 84 | +void run_eigen_all(const rxmesh::RXMeshStatic& rx, |
| 85 | + const SpMat& A, |
| 86 | + const DMat& B) |
| 87 | +{ |
| 88 | + using LLT = |
| 89 | + Eigen::SimplicialLLT<SpMat, |
| 90 | + Eigen::UpLoType::Lower, |
| 91 | + Eigen::AMDOrdering<typename SpMat::StorageIndex>>; |
| 92 | + |
| 93 | + run_eigen<LLT>(rx, "SimplicialLLT", A, B); |
| 94 | + |
| 95 | + using LDLT = |
| 96 | + Eigen::SimplicialLDLT<SpMat, |
| 97 | + Eigen::UpLoType::Lower, |
| 98 | + Eigen::AMDOrdering<typename SpMat::StorageIndex>>; |
| 99 | + |
| 100 | + run_eigen<LDLT>(rx, "SimplicialLDLT", A, B); |
87 | 101 | } |
0 commit comments