Global Constants in C++

Declaring the global constants can polute the names available and create conflicts as the project grow larger. One solution is to declare it using a namespace.


namespace GlobalConst{

const double PI=3.14;


and in your file, simply use


UPDATE: I have corrected the code, thanks


cannot reintegrate branch

I created a branch from another branch, and after I am ready to merge, I encounter this problem:

$ cd photon-branch; svn update

$ svn merge –reintegrate
svn: Cannot reintegrate from ‘’ yet:
Some revisions have been merged under it that have not been merged into the reintegration target; merge them first, then retry.

It turns out to be a problem in subversion 1.5. I found a blog that speaks about this problem. And then, in one of the forum, someone gave a clear explanation on how to do it. So basically what I need to do is to go back to my other branch, in this case “photon-recursive”, and delete the merge info of the files except the “.” merge info.

$ cd photon-recursive

$ svn propget svn:merge info –depth=infinity

you will many list, the term before “-” is the file. You will find one for “.” and maybe some other files. Mine is like this:

. – /branches/photon-branch:115-181
src/parallel – /branches/photon-branch/src/parallel:115-181
src/globalconst.h – /branches/photon-branch/src/globalconst.h:115-181
src/parallel/deviceinfo.h – /branches/photon-branch/src/parallel/deviceinfo.h:11
src/negf.cpp – /branches/photon-branch/src/negf.cpp:115-181
src/output – /branches/photon-branch/src/output:115-181
src/deviceinfo.h – /branches/photon-branch/src/deviceinfo.h:115-181
src/main.cpp – /branches/photon-branch/src/main.cpp:115-181
src/negf.h – /branches/photon-branch/src/negf.h:115-181
src/solvebias.cpp – /branches/photon-branch/src/solvebias.cpp:115-181
src/devrtd.cpp – /branches/photon-branch/src/devrtd.cpp:115-181
src/poisson.cpp – /branches/photon-branch/src/poisson.cpp:115-181
src/itppmath.h – /branches/photon-branch/src/itppmath.h:115-181
src/solvebias.h – /branches/photon-branch/src/solvebias.h:115-181
src/Makefile – /branches/photon-branch/src/Makefile:115-181
src/finvhalff77h.f – /branches/photon-branch/src/finvhalff77h.f:115-181
src/DevRTD.h – /branches/photon-branch/src/DevRTD.h:115-181
src/finvhalf.cpp – /branches/photon-branch/src/finvhalf.cpp:115-181
src/output.log – /branches/photon-branch/src/output.log:115-181
src/poisson.h – /branches/photon-branch/src/poisson.h:115-181

So now what I need to do is to delete the merge info from all other files except the “.” (root). To do this :

$ svn propdel svn:merge info ./src/globalconst.h

$ svn propdel svn:mergeinfo ./src/parallel/deviceinfo.h

Once it is done, it will only leave the merge info for “.”

$ svn propget svn:mergeinfo –depth=infinity
. – /branches/photon-branch:115-181

and we can commit

$ svn commit -m “Removed bogus merge info.”

After this, I went back to the main branch (in my case photon-branch) and do a merge –reintegrate. it turns out to solve the problem 🙂

Compiling IT++ with MKL library

I downloaded it++ 4.0.6 and tried to compile using MKL library. To do that, I need first to set the environment path

export LDFLAGS=-L/opt/intel/Compiler/11.0/081/mkl/lib/32/

export CPPFLAGS=-I/opt/intel/Compiler/11.0/081/mkl/include

and then I run the configure with this option

./configure –prefix=$HOME/local F77=gfortran –with-blas=”-lmkl_intel -lmkl_sequential -lmkl_core -lpthread” –with-lapack=”-lmkl_lapack”

With this settings configure can detect my MKL library

UPDATE: though it can detect MKL, but it gives a compilation error. I haven’t managed to solve it. so I currently by passing the mkl library and install ATLAS instead.

./configure –prefix=/scratch/ihpcoka/local CPPFLAGS=’-I$(HOME)/DATA/Download/boost_1_36_0 -I/scratch/ihpcoka/local/include’ F77=gfortran LDFLAGS=’-L/usr/lib64 -L/scratch/ihpcoka/local/lib’ –with-fftw=’-lfftw3′ –with-blas=’-lf77blas -latlas’ –with-lapack=’-llapack’

Using Eclipse with Subversion

For a detail instruction to install the plugin in Eclipse which enable Subversion, go to:

There are some differences with the version which I am using in Kubuntu. So I will list down again briefly.
1. Open Eclipse, click menu “Help->Software Updates->Find and Install”
2. click the option, “Search for new features to install”, and then “Next” button.
3. Click the button “New remote sites”, enter “Subclipse” in the name, and “” in the URL. Then click “Finish” button.
4. Then it will run some update and show the components to install. Check “Subclipse” or other name which you have put. If it gives some error due to dependencies, uncheck those components which causes this error. Then click “Next” button.
5. After this, accept the License agreement and Next.
6. It will show some other options, but you can click Next and leave to default, and finally Click Finish button.
7. Those steps will install Subclipse plugin. After installation it will ask to restart Eclipse.

Programming C/C++ using Eclipse with the use of CDT

I am developing C/C++ codes in Linux, and luckily Eclipse has a plugin called CDT to be used for C/C++ language. To install Eclipse and CDT plugin in Kubuntu/Ubuntu, just type:
sudo apt-get install eclipse eclipse-cdt

Guide to available mathematical libraries

I just found an interesting site to help you find the required mathematical libraries for computation.

Use fabs for getting the absolute from double

I am porting my Octave code to C++, somehow I always got zero for one expression that I calculate. After debugging, it turns out after I take abs(expression), the values always zero. Argh. I forgot, abs() in C++ is only for integer and long. I need to use fabs() for float or double. Now it works just fine.