28 using namespace gtsam;
31 static std::mt19937
rng;
32 static std::uniform_real_distribution<>
uniform(0.0, 1.0);
34 int main(
int argc,
char *argv[]) {
40 size_t nBlocks = 4000;
44 double blockbuild, blocksolve, combbuild, combsolve;
46 cout <<
"\n1 variable of dimension " << vardim <<
", " <<
47 nBlocks <<
" blocks of dimension " << blockdim <<
"\n";
48 cout << nTrials <<
" trials\n";
55 cout <<
"Building blockwise Gaussian factor graphs... ";
58 vector<GaussianFactorGraph> blockGfgs;
59 blockGfgs.reserve(nTrials);
60 for(
size_t trial=0; trial<nTrials; ++trial) {
63 for(
size_t i=0;
i<nBlocks; ++
i) {
66 for(
size_t j=0;
j<blockdim; ++
j)
67 for(
size_t k=0; k<vardim; ++k)
70 for(
size_t j=0;
j<blockdim; ++
j)
72 blockGfgs[trial].push_back(std::make_shared<JacobianFactor>(
key,
A,
b, noise));
77 blockbuild = blockbuildNode->secs();
78 cout << blockbuild <<
" s" << endl;
81 cout <<
"Solving blockwise Gaussian factor graphs... ";
84 for(
size_t trial=0; trial<nTrials; ++trial) {
91 blocksolve = blocksolveNode->secs();
92 cout << blocksolve <<
" s" << endl;
101 cout <<
"Building combined-factor Gaussian factor graphs... ";
104 vector<GaussianFactorGraph> combGfgs;
105 for(
size_t trial=0; trial<nTrials; ++trial) {
109 Matrix Acomb(blockdim*nBlocks, vardim);
110 Vector bcomb(blockdim*nBlocks);
111 for(
size_t i=0;
i<nBlocks; ++
i) {
113 for(
size_t j=0;
j<blockdim; ++
j)
114 for(
size_t k=0; k<vardim; ++k)
117 for(
size_t j=0;
j<blockdim; ++
j)
120 combGfgs[trial].push_back(std::make_shared<JacobianFactor>(
key, Acomb, bcomb,
125 combbuild = combbuildNode->secs();
126 cout << combbuild <<
" s" << endl;
129 cout <<
"Solving combined-factor Gaussian factor graphs... ";
132 for(
size_t trial=0; trial<nTrials; ++trial) {
138 combsolve = combsolveNode->secs();
139 cout << combsolve <<
" s" << endl;
144 cout <<
"\nPer-factor-graph times for building and solving\n";
145 cout <<
"Blockwise: total " << (1000.0*(blockbuild+blocksolve)/
double(nTrials)) <<
146 " build " << (1000.0*blockbuild/
double(nTrials)) <<
147 " solve " << (1000.0*blocksolve/
double(nTrials)) <<
" ms/graph\n";
148 cout <<
"Combined: total " << (1000.0*(combbuild+combsolve)/
double(nTrials)) <<
149 " build " << (1000.0*combbuild/
double(nTrials)) <<
150 " solve " << (1000.0*combsolve/
double(nTrials)) <<
" ms/graph\n";
151 cout <<
"Fraction of time spent in overhead\n" <<
152 " total " << (((blockbuild+blocksolve)-(combbuild+combsolve)) / (blockbuild+blocksolve)) <<
"\n" <<
153 " build " << ((blockbuild-combbuild) / blockbuild) <<
"\n" <<
154 " solve " << ((blocksolve-combsolve) / blocksolve) <<
"\n";