Skip to content

Commit d5e9790

Browse files
committed
refactor eigen
1 parent eb25f43 commit d5e9790

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

apps/MCF/mcf_chol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void mcf_cusolver_chol(rxmesh::RXMeshStatic& rx,
180180
B_mat.move(DEVICE, HOST);
181181
auto A_cpu = A_mat.to_eigen_copy();
182182
auto B_cpu = B_mat.to_eigen_copy();
183-
simplicial_llt(rx, A_cpu, B_cpu);
183+
run_eigen_all(rx, A_cpu, B_cpu);
184184

185185
// move the results to the host
186186
// if we use LU, the data will be on the host and we should not move the

apps/MCF/mcf_eigen.h

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,90 @@
1212

1313
#include <Eigen/src/SparseCholesky/SimplicialCholesky.h>
1414

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)
2221
{
2322
using namespace rxmesh;
2423

25-
Report report("MCF_Eigen");
24+
Report report("MCF_Eigen_" + name);
2625
report.command_line(Arg.argc, Arg.argv);
2726
report.device();
2827
report.system();
2928
report.model_data(Arg.obj_file_name, rx);
30-
report.add_member("method", std::string("SimplicialLLT"));
29+
report.add_member("method", name);
3130
report.add_member("application", std::string("MCF"));
3231

3332
float total_time = 0;
3433

35-
Eigen::SimplicialLLT<SpMat,
36-
Eigen::UpLoType::Lower,
37-
Eigen::AMDOrdering<typename SpMat::StorageIndex>>
38-
solver;
34+
SolverT solver;
3935

4036
CPUTimer timer;
4137
timer.start();
4238
solver.analyzePattern(A);
4339
timer.stop();
4440

4541
if (solver.info() != Eigen::Success) {
46-
std::cout << solver.info() << "\n";
47-
RXMESH_ERROR("Eigen::SimplicialLLT analyzePattern failed!");
42+
RXMESH_ERROR("{} analyzePattern failed!", name);
4843
}
4944

5045
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());
5348
report.add_member("analyze_pattern", timer.elapsed_millis());
5449

5550
timer.start();
5651
solver.factorize(A);
5752
timer.stop();
5853

5954
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());
6156
report.add_member("factorize", timer.elapsed_millis());
6257

6358
if (solver.info() != Eigen::Success) {
64-
std::cout << solver.info() << "\n";
65-
RXMESH_ERROR("Eigen::SimplicialLLT factorization failed!");
59+
RXMESH_ERROR("{} factorization failed!", name);
6660
}
6761

6862
timer.start();
6963
DMat X = solver.solve(B);
7064
timer.stop();
7165

7266
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());
7468
report.add_member("solve", timer.elapsed_millis());
7569

7670
if (solver.info() != Eigen::Success) {
77-
std::cout << solver.info() << "\n";
78-
RXMESH_ERROR("Eigen::SimplicialLLT solve failed!");
71+
RXMESH_ERROR("{} solve failed!", name);
7972
}
8073

81-
RXMESH_INFO("SimplicialLLT total_time {} (ms)", total_time);
74+
RXMESH_INFO("{} total_time {} (ms)", name, total_time);
8275
report.add_member("total_time", total_time);
8376

8477

8578
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);
87101
}

0 commit comments

Comments
 (0)