cmake offers the option to generate a
compilation database in json format
using the option CMAKE_EXPORT_COMPILE_COMMANDS=YES
. The database holds
essentially the command, paths and compilers flags used to compile each file of
a project. The generated file (usually called compile_commands.json
) can be
used in conjunction with various code completion tools like
YouCompleteMe and Visual Studio’s
IntelliSense
in order to offer more complete information, completion and errors about the
code.
Hello!
The official cmake tutorial
There are many resources, posts and articles about using cmake and writing modern cmake code. Unfortunately for a new user it is sometimes difficult to locate the proper resource that contains no deprecated options or any other non-recommended practices. One of the quickest and simplest resource I became aware recently is the official tutorial that lives in the documentation of cmake.
Using ccache to speedup compilation of C/C++
ccache is a utility that caches intermediate files during compilation offering significant speedups. It is especially useful if you are switching between two branches of the same project see below.
To use it, prepend it before the compiler i.e. Use ccache gcc
instead of
gcc ...
. If you are using cmake with a version greater
that 3.4 you can use the option -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
for
older version you can modify the compiler settings or use the variable
RULE_LAUNCH_COMPILE
for more see
here.
Change pixels in 2D/3D images
Similar to an older post. One can modify 2D/3D images in order to change specific pixels /voxels. This became useful recently while trying to remove a tissue from a segmented image. For something more complicated you may want to use Slicer, but for simple cases like this a python script enough. Appended you can also find the corresponding C++ code. Keep in mind that python handles all supported PixelTypes automatically while for the C++ one needs to update the PixelType typedef and the dimension variable.
[Read More]Thousands separator in C++
As you print more and more numbers in the screen it may become cumbersome
to count digits just to see is if you are in the range of millions or 100’s of
millions. Visually grouping digits can simmplify things. There is
a pleathora of ways to do this in C++ but the one I find the best is the one provided
by the standand C++ library through the std::numpunct
object. Here is a small example that uses groups digits using commas.
#ifdef in Latex documents
Consider the case where you want to generate slightly different versions of a document out of single latex file. This could be needed when using different document templates or if you want to switch on/off commentary in your document. You may want different introduction or order of chapters based on each particular case. A way to do it is using conditionals that exists available in plain TeX. For example
\documentclass{article}
\newif\ifanswers
%\answerstrue
\begin{document}
question : what is the expected complexity of quicksort for an array of integers ?
\vspace{1cm}
\ifanswers
answer $o(n\log n)$ where $n$ is the numer of integers.
\fi
\vspace{1cm}
question : give the definition of an abelian group .
\vspace{1cm}
\ifanswers
answer : an abelian group is a set, $a$, together with an operation $\cdot$ that ...
\vspace{1cm}
\fi
\end{document}
Enabling conditionals can be achieved by commenting/uncommenting the 3rd line either by hand or using a makefile:
[Read More]Keep running until crash with gdb
Many times when trying to catch a bug , or to validate that your parallel code runs correctly you wish to run your code again and again and again until break on an assertion or even better until you persuade yourself that your code is good enough. Once more, stakoverflow has the answer for us:
set $n = 100
while $n-- > 0
printf "starting program\n"
run
if $_siginfo
printf "Received signal %d, stopping\n", $_siginfo.si_signo
loop_break
else
printf "program exited\n"
end
end
If you use it often save it in a file and launch it using
[Read More]How about stopping sending your public keys ?
Did you know that when connecting to a server wish ssh
it will first send all your public ssh keys and then
it will promt you for a password ? Sure it is just public keys, but still. See here for more https://github.com/FiloSottile/whosthere
Adding support for new mesh formats in ParaView
The architecture of ParaView allows extending its functionality by creating plugins which can be loaded as dynamic libraries without recompiling ParaView.
The main mesh filetypes we are handling in our lab are
.ugrid
generated by AFLR3 and used widely within FUN3D,
.meshb
from INRIA Gamma Team and .su2
from the SU2 solver. Unfortunately there is no support for these from
Paraview. Fortunately there is documentation for creating readers (plugin
guides).
Here is the boilerplate for writting a reader for an unstructred grid based on the Paraview wiki.
[Read More]Podcast series on history of AI
In this series created by the wondery network the host will transport you to the days or early AI, from the lonely ELIZA, to Apple’s Siri, and from Deep Blue to AlphaGo.
Episode 1 : Thinking Machines : Artificial Intelligence
Episode 2 : Thinking Machines : How Do You Make a Computer Blink
Episode 3 : Thinking Machines : Siri-ous Business
Episode 4 : Thinking Machines : I learn Therefore I am
Episode 5 : Thinking Machines : Passing For Human
[Read More]