blob: ce4dab0aac3212b88804d334ba358f85d0368fb7 [file] [log] [blame]
Keir Mierle8ebb0732012-04-30 23:09:08 -07001%!TEX root = ceres.tex
2\chapter{Building Ceres}
3\label{chapter:build}
4Ceres source code and documentation is hosted at
Sameer Agarwalba3ccfb2012-05-22 06:58:47 -07005\url{http://code.google.com/p/ceres-solver/}.
Keir Mierle8ebb0732012-04-30 23:09:08 -07006
7\section{Dependencies}
8Ceres relies on a number of open source libraries, some of which are optional. However, we recommend that you start out by building Ceres with all its dependencies. For details on customizing the build process, please see Section~\ref{sec:custom}.
9
10\begin{enumerate}
11\item{\cmake~\footnote{\url{http://www.cmake.org/}}} is the cross-platform build system used by Ceres.
12\item{\eigen~\footnote{\url{http://eigen.tuxfamily.org}}} is used for doing all the low level matrix and
Sameer Agarwalba3ccfb2012-05-22 06:58:47 -070013 linear algebra operations.
Sameer Agarwal0d2d3412012-05-06 21:16:03 -070014
Keir Mierle8ebb0732012-04-30 23:09:08 -070015\item{\glog~\footnote{\url{http://code.google.com/p/google-glog}}} is used for error checking and logging.
Sameer Agarwal0d2d3412012-05-06 21:16:03 -070016
17 Note: Ceres requires \texttt{glog}\ version 0.3.1 or later. Version 0.3 (which ships with Fedora 16) has a namespace bug which prevents Ceres from building.
18
Keir Mierle8ebb0732012-04-30 23:09:08 -070019\item{\gflags~\footnote{\url{http://code.google.com/p/gflags}}} is used by the code in
Sameer Agarwal921e8ab2012-05-13 11:39:47 -070020 \texttt{examples}. It is also used by some of the tests. Strictly speaking it is not required to build the core library, we do not recommend building Ceres without it.
Sameer Agarwalba3ccfb2012-05-22 06:58:47 -070021\item{\suitesparse~\footnote{\url{http://www.cise.ufl.edu/research/sparse/SuiteSparse/}}} is used for sparse matrix analysis,
Keir Mierle8ebb0732012-04-30 23:09:08 -070022 ordering and factorization. In particular Ceres uses the
23 \amd, \colamd\ and \cholmod\ libraries. This is an optional
24 dependency.
25\item{\blas\ and \lapack} are needed by
26 \suitesparse. We
27 recommend either
28 \texttt{GotoBlas2}~\footnote{\url{http://www.tacc.utexas.edu/tacc-projects/gotoblas2}}
29 or
30 \texttt{ATLAS}~\footnote{\url{http://math-atlas.sourceforge.net/}},
31 both of which ship with \blas\ and \lapack\ routines.
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -070032\item{\texttt{protobuf}~\footnote{\url{http://code.google.com/p/protobuf/}}} is an optional dependency that is used for serializing and deserializing linear least squares problems to disk. This is useful for debugging and testing. Without it, some of the tests will be disabled.
Keir Mierle8ebb0732012-04-30 23:09:08 -070033\end{enumerate}
34
35Currently we support building on Linux and MacOS X. Support for other
36platforms is forthcoming.
37
38\section{Building on Linux}
39We will use Ubuntu as our example platform.
40
41\begin{enumerate}
42\item{\cmake}
43\begin{minted}{bash}
44sudo apt-get install cmake
45\end{minted}
46
Sameer Agarwalba3ccfb2012-05-22 06:58:47 -070047\item{\gflags} can either be installed from source via the \texttt{autoconf} invocation
Keir Mierle8ebb0732012-04-30 23:09:08 -070048\begin{minted}{bash}
49tar -xvzf gflags-2.0.tar.gz
50cd gflags-2.0
51./configure --prefix=/usr/local
52make
53sudo make install.
54\end{minted}
55or via the \texttt{deb} or \texttt{rpm} packages available on the \gflags\ website.
56
57\item{\glog} must be configured to use the previously installed
58\gflags, rather than the stripped down version that is bundled with \glog. Assuming you have it installed in \texttt{/usr/local} the following \texttt{autoconf} invocation installs it.
59\begin{minted}{bash}
60tar -xvzf glog-0.3.2.tar.gz
61cd glog-0.3.2
62./configure --with-gflags=/usr/local/
63make
64sudo make install
65\end{minted}
66
67\item{\eigen}
68\begin{minted}{bash}
69sudo apt-get install libeigen3-dev
70\end{minted}
71
72\item{\suitesparse}
73\begin{minted}{bash}
74sudo apt-get install libsuitesparse-dev
75\end{minted}
76This should automatically bring in the necessary \blas\ and \lapack\ dependencies.
77
78\item{\texttt{protobuf}}
79\begin{minted}{bash}
80sudo apt-get install libprotobuf-dev
81\end{minted}
82\end{enumerate}
83
84
85We are now ready to build and test Ceres. Note that \texttt{cmake} requires the exact path to the \texttt{libglog.a} and \texttt{libgflag.a}
86
87\begin{minted}{bash}
88tar zxf ceres-solver-1.0.tar.gz
89mkdir ceres-bin
90cd ceres-bin
Sameer Agarwalba3ccfb2012-05-22 06:58:47 -070091cmake ../ceres-solver-1.0
Keir Mierle8ebb0732012-04-30 23:09:08 -070092make -j3
93make test
94\end{minted}
95
96You can also try running the command line bundling application with one of the
97included problems, which comes from the University of Washington's BAL dataset~\cite{Agarwal10bal}:
98\begin{minted}{bash}
99examples/simple_bundle_adjuster \
100 ../ceres-solver-1.0/data/problem-16-22106-pre.txt \
101\end{minted}
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700102This runs Ceres for a maximum of 10 iterations using the \denseschur\ linear solver. The output should look something like this.
Keir Mierle8ebb0732012-04-30 23:09:08 -0700103\clearpage
104\begin{minted}{bash}
1050: f: 1.598216e+06 d: 0.00e+00 g: 5.67e+18 h: 0.00e+00 rho: 0.00e+00 mu: 1.00e-04 li: 0
1061: f: 1.116401e+05 d: 1.49e+06 g: 1.42e+18 h: 5.48e+02 rho: 9.50e-01 mu: 3.33e-05 li: 1
1072: f: 4.923547e+04 d: 6.24e+04 g: 8.57e+17 h: 3.21e+02 rho: 6.79e-01 mu: 3.18e-05 li: 1
1083: f: 1.884538e+04 d: 3.04e+04 g: 1.45e+17 h: 1.25e+02 rho: 9.81e-01 mu: 1.06e-05 li: 1
1094: f: 1.807384e+04 d: 7.72e+02 g: 3.88e+16 h: 6.23e+01 rho: 9.57e-01 mu: 3.53e-06 li: 1
1105: f: 1.803397e+04 d: 3.99e+01 g: 1.35e+15 h: 1.16e+01 rho: 9.99e-01 mu: 1.18e-06 li: 1
1116: f: 1.803390e+04 d: 6.16e-02 g: 6.69e+12 h: 7.31e-01 rho: 1.00e+00 mu: 3.93e-07 li: 1
112
113Ceres Solver Report
114-------------------
115 Original Reduced
116Parameter blocks 22122 22122
117Parameters 66462 66462
118Residual blocks 83718 83718
119Residual 167436 167436
120
121 Given Used
122Linear solver DENSE_SCHUR DENSE_SCHUR
123Preconditioner N/A N/A
124Ordering SCHUR SCHUR
125num_eliminate_blocks N/A 22106
126Threads: 1 1
127Linear Solver Threads: 1 1
128
129Cost:
130Initial 1.598216e+06
131Final 1.803390e+04
132Change 1.580182e+06
133
134Number of iterations:
135Successful 6
136Unsuccessful 0
137Total 6
138
139Time (in seconds):
140Preprocessor 0.000000e+00
141Minimizer 2.000000e+00
142Total 2.000000e+00
143Termination: FUNCTION_TOLERANCE
144\end{minted}
145
146\section{Building on OS X}
147On OS X, we recommend using the \texttt{homebrew}~\footnote{\url{http://mxcl.github.com/homebrew/}} package manager.
148
149\begin{enumerate}
150\item{\cmake}
151\begin{minted}{bash}
152brew install cmake
153\end{minted}
Sameer Agarwal017c9532012-05-02 08:21:59 -0700154\item{\texttt{glog}\ and \texttt{gflags}}
Keir Mierle8ebb0732012-04-30 23:09:08 -0700155
Sameer Agarwal017c9532012-05-02 08:21:59 -0700156Installing \texttt{\glog} takes also brings in \texttt{gflags} as a dependency.
Keir Mierle8ebb0732012-04-30 23:09:08 -0700157\begin{minted}{bash}
Sameer Agarwal017c9532012-05-02 08:21:59 -0700158brew install glog
Keir Mierle8ebb0732012-04-30 23:09:08 -0700159\end{minted}
160\item{\eigen}
161\begin{minted}{bash}
162brew install eigen
163\end{minted}
164\item{\suitesparse}
165\begin{minted}{bash}
166brew install suite-sparse
167\end{minted}
168\item{\texttt{protobuf}}
169\begin{minted}{bash}
170brew install protobuf
171\end{minted}
172\end{enumerate}
173
174We are now ready to build and test Ceres.
175\begin{minted}{bash}
176tar zxf ceres-solver-1.0.tar.gz
177mkdir ceres-bin
178cd ceres-bin
Sameer Agarwalba3ccfb2012-05-22 06:58:47 -0700179cmake ../ceres-solver-1.0
Keir Mierle8ebb0732012-04-30 23:09:08 -0700180make -j3
181make test
182\end{minted}
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700183Like the Linux build, you should now be able to run \texttt{examples/simple\_bundle\_adjuster}.
Keir Mierle8ebb0732012-04-30 23:09:08 -0700184\section{Customizing the Build Process}
185\label{sec:custom}
186It is possible to reduce the libraries needed to build Ceres and
187customize the build process by passing appropriate flags to \texttt{cmake}. But unless you really know what you are
188doing, we recommend against disabling any of the following flags.
189
190\begin{enumerate}
191\item{\texttt{protobuf}}
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700192
193
Keir Mierle8ebb0732012-04-30 23:09:08 -0700194Protocol Buffers is a big dependency and if you do not care for the tests that depend on it and the logging support it enables, you can turn it off by using
195\begin{minted}{bash}
196-DPROTOBUF=OFF.
197\end{minted}
198
199\item{\suitesparse}
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700200
Sameer Agarwalba3ccfb2012-05-22 06:58:47 -0700201By default, Ceres will only link to SuiteSparse if all its dependencies are present.
Sameer Agarwal921e8ab2012-05-13 11:39:47 -0700202To build Ceres without \suitesparse\ use
Keir Mierle8ebb0732012-04-30 23:09:08 -0700203\begin{minted}{bash}
204-DSUITESPARSE=OFF.
205\end{minted}
Sameer Agarwal921e8ab2012-05-13 11:39:47 -0700206 This will also disable dependency checking for \lapack\ and \blas. This saves on binary size, but the resulting version of Ceres is not suited
207to large scale problems due to the lack of a sparse Cholesky solver. This will reduce Ceres' dependencies down to
208\eigen, \gflags\ and \glog.
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700209
Keir Mierle8ebb0732012-04-30 23:09:08 -0700210\item{\gflags}
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700211
Keir Mierle8ebb0732012-04-30 23:09:08 -0700212To build Ceres without \gflags, use
213\begin{minted}{bash}
214-DGFLAGS=OFF.
215\end{minted}
216Disabling this flag will prevent some of the example code from building.
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700217
Keir Mierle8ebb0732012-04-30 23:09:08 -0700218\item{Template Specializations}
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700219
220
Keir Mierle8ebb0732012-04-30 23:09:08 -0700221If you are concerned about binary size/compilation time over some
222small (10-20\%) performance gains in the \sparseschur\ solver, you can disable some of the template
223specializations by using
224\begin{minted}{bash}
225-DSCHUR_SPECIALIZATIONS=OFF.
226\end{minted}
227
228\item{\texttt{OpenMP}}
Sameer Agarwal17fbc8e2012-05-01 00:21:19 -0700229
230
Keir Mierle8ebb0732012-04-30 23:09:08 -0700231On certain platforms like Android, multithreading with OpenMP is not supported. OpenMP support can be disabled by using
232\begin{minted}{bash}
233-DOPENMP=OFF.
234\end{minted}
Sameer Agarwalba3ccfb2012-05-22 06:58:47 -0700235\end{enumerate}