-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
73 lines (52 loc) · 1.67 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>
#include "SparseMatrix.h"
#include "SupernodalCholesky.h"
#include <Eigen/Sparse>
#include <unsupported/Eigen/SparseExtra>
#include "Timer.hpp"
#include "Ordering.h"
#include <Eigen/OrderingMethods>
using namespace std;
// just loads a bunch of binary integers
vector<int>
loadIds(std::string fname)
{
ifstream file(fname, std::fstream::binary);
if(!file.good())
{
std::cout << "file not found" << std::endl;
return {};
}
std::vector<char> ids((std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>()));
int* idPtr = (int*)ids.data();
int nids = (int)ids.size() / sizeof(int);
return std::vector<int>(idPtr, idPtr + nids);
}
int main(int argc, const char * argv[])
{
Eigen::SparseMatrix<double> A;
Eigen::loadMarket(A, "../data/LTL.mtx");
assert(A.isCompressed());
auto roiIds = loadIds("../data/ids");
// factorize & update
CholUp::Timer t0("Factor");
CholUp::SupernodalCholesky<CholUp::SparseMatrix<double>> chol(A);
t0.printTime("full");
t0.reset();
auto cholPart0 = chol.dirichletPartialFactor(roiIds);
t0.printTime("partial");
// solve linear system involving cholPart0
// setup rhs
CholUp::Matrix<double> rhs(A.cols(), 1);
rhs.fill();
rhs(roiIds[0], 0) = 1;
auto rhs0 = rhs;
// solve. Permutation is automatically taken care of. Rhs defines values for boundary conditions, values in rhs[roiIds] are replaced by the solve.
cholPart0.solveL_RowMajor<1>(rhs.data);
cholPart0.solveLT_RowMajor<1>(rhs.data);
return 0;
}