Home | News | Documentation | Download

Memory leak in ROOT::Math::IntegratorMultiDim

Hi,

I am using ROOT::Math::IntegratorMultiDim for multi-dimensional integration, it is the GSLMCIntegrator. There is memory leak and it crashes after few run. My integration is like this:

fun1

double fun1(const double *k, const double *para)
{
        const double s = para[0];
        double z = k[0];

        double r = sqrt(s*s + z*z);
        double it =1/(1.0 + exp(((r - 7.0)/0.5)));

        return it;
}

fun2: integration over fun1

double fun2(const double *k, const double *para)
{
        double b = para[0];
        
        double s = k[0];
        double theta = k[1];

        double rp2 = s*s + (b/2)*(b/2) - s*b*cos(theta);
        double rt2 = s*s + (b/2)*(b/2) + s*b*cos(theta);

        double xl[1] = {-20.0};
        double xu[1] = {20.0};

        double par[1];
        ROOT::Math::IntegratorMultiDim *ig1 = new ROOT::Math::IntegratorMultiDim(ROOT::Math::IntegrationMultiDim::kVEGAS, 0, 0, 1000);
        ROOT::Math::WrappedParamFunction<> wf1(&fun1, 1, 1);

        ig1->SetFunction(wf1);
        par[0] = sqrt(rp2);

        wf1.SetParameters(par);
        double Ta = ig1->Integral(xl, xu);

        ROOT::Math::IntegratorMultiDim *ig2 = new ROOT::Math::IntegratorMultiDim(ROOT::Math::IntegrationMultiDim::kVEGAS, 0, 0, 1000);
        ROOT::Math::WrappedParamFunction<> wf2(&fun1, 1, 1);
        ig2->SetFunction(wf2);
        par[0] = sqrt(rt2);

        wf2.SetParameters(par);
        double Tb = ig2->Integral(xl, xu);

        delete ig1;
        delete ig2;
        ig1 = 0; ig2 = 0;
        wf1 = 0; wf2 = 0;
        double one = 197 * Ta * (1.0 - exp(-cross * Tb*197));
        return s * fun;
}

Final integration over fun2

double getResult(double b, int nIter = 600000)
{
        double xl[2] = {0.0, 0.0};
        double xu[2] = {20.0, 2.0*TMath::Pi()};

        par[0] = b;

        ROOT::Math::IntegratorMultiDim *ig = new ROOT::Math::IntegratorMultiDim(ROOT::Math::IntegrationMultiDim::kVEGAS, 0, 0, nIter);
        ROOT::Math::WrappedParamFunction<> wf(&fun2, 2, 1);
        ig->SetFunction(wf);

        wf.SetParameters(par);
        double val = ig->Integral(xl, xu);
        delete ig;
        ig = 0;
        wf = 0;

        return val;
}

However, It runs fine by just replacing the integrator with the plane GSL integrator.

Any idea where the memory is leaking?
Thanks.

I am having trouble to run root, 6.06.06. when I run try to write some program I get the following error.
Can any one help me to solve this problem. I looked over the posts but did not get the clear idea, about what is going on.
Thanks in advance.
IncrementalExecutor::executeFunction: symbol ‘_ZN5cling10printValueEPKi’ unresolved while linking [cling interface function]!
You are probably missing the definition of cling::printValue(int const*)
Maybe you need to load the corresponding shared library?
(int) Error in ValuePrinter: missing output string.

Which compiler version are you using for building your root?

I am using root 6.06. I was using 5.34 before and now I did dual boot on my computer and I am trying to reinstall root and all other data analysis tool. But I am having this problem.
Thanks again.

compiler version

What about using binary version of the ROOT for your gcc version?

I am using Ubuntu 16.04. and trying to install root 6.06 .06 on it. it shows my root build successfully but when I try to do some work even simple addition I got above error.
Thanks again.

Did you configure ROOT 6.06/06 using “proper” flags for Ubuntu 16.04 with gcc 5.x? cmake -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" -Dcxx14="ON" -Dall="ON" -Ddavix="OFF" -Dr="OFF" -Dpythia8="OFF" -Dgeocad="ON" -Dbuiltin_ftgl="OFF" -Dbuiltin_glew="OFF" -Dsoversion="ON" ...Another...Flags...You...May...Need... In particular, for the time being, -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" is mandatory for ROOT 6.06/06 with gcc 5.x.

Yes I did all the necessary installation, I follow youtube.com/watch?v=LfSFGkkBT-k this video and it happens exactly up to the build and it says successfully build, and when I type root it shows the root display and goes to root also. Then If I try to do even 2+2 that shows the error.
I saw similar problems on some other pages but not the exact solution for root 6.06.
Thanks again.
I will try the idea you gave me .

This video shows how someone builds ROOT 5(.34).
However, ROOT 6 is a completely different story (especially with newer gcc 5.x).

Thanks Pepe.
I spend too much time on installing this 6.06 version, but I am unable to do it. Would you mind to suggest me the best way or any links to get done this.
I need it ASAP.
Thank you again.

Try (ROOT 6.06/06 with gcc 5.x): [code]# install it into …
ROOT_INSTALL_DIR="${HOME}/ROOT/v6-06-06"
rm -rf ${ROOT_INSTALL_DIR}
mkdir -p ${ROOT_INSTALL_DIR}

download, unpack and build it in /tmp

cd /tmp
rm -rf root-build root-6.06.06 root_v6.06.06.source.tar.gz*
wget https://root.cern.ch/download/root_v6.06.06.source.tar.gz
tar -zxf root_v6.06.06.source.tar.gz
mkdir root-build
cd root-build
unset ROOTSYS
cmake -DCMAKE_INSTALL_PREFIX="${ROOT_INSTALL_DIR}" -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" -Dcxx14=“ON” -Dall=“ON” -Ddavix=“OFF” -Dr=“OFF” -Dpythia8=“OFF” -Dgeocad=“ON” -Dbuiltin_ftgl=“OFF” -Dbuiltin_glew=“OFF” -Dsoversion=“ON” …/root-6.06.06
make
cmake --build . --target install

final cleanup

cd …/
rm -rf root-build root-6.06.06 root_v6.06.06.source.tar.gz*[/code]
For ROOT 6.06/06 with gcc 4.[89].x see: viewtopic.php?f=3&t=22202&p=97236#p97236

Last, but not least … you will NOT be able to install ROOT 6, if your gcc compiler comes from the RedHat “Software Collections” / “Developer Toolset” (e.g. on Scientific Linux / CentOS 5, 6 and 7 platforms).

BTW. Before you begin, make sure that nothing in your setup points to any existing ROOT installation. In particular, on Ubuntu execute “sudo apt-get purge root-system* root-plugin* libroot*” and then check that the “/usr/lib/i386-linux-gnu/root5.34” and the “/usr/lib/x86_64-linux-gnu/root5.34” subdirectories disappeared completely.

Thanks Pepe,
I did all the process up to cd…/ and then type the command the next one you wrote. When I type root after i run the command it says no such a file or directory. here I have attached the output I got .

– Installing: /home/hemanta/ROOT/v6-06-06/include/RooStats/ToyMCStudy.h
hemanta@hemanta:/tmp/root-build$ cd …/
hemanta@hemanta:/tmp$ rm -rf root-build root-6.06.06 root_v6.06.06.source.tar.gz*
hemanta@hemanta:/tmp$ root
bash: /usr/bin/root: No such file or directory


Thank you again.

Open a teminal window and execute (assuming that you use “bash”):source ${HOME}/ROOT/v6-06-06/bin/thisroot.sh root

Great,
Thanks Pepe.
Finally it works.
I really appreciate your help.

HI,

Homanta, I suggest to not reply to things comply not relevant to a post. Open a new issue in case you have something.

Coming back to the original post. "Memory leak in ROOT::Math::IntegrationMultiDim: posted by monoj.
The code does not run directly, some variable are undefined. I have tried to define putting some dummy values and it runs fine for me.
Please post in case you still have this problem, a full running macro.

Lorenzo

Hi,

Could you point me out which variables are undefined? I got the memory leak when I loop over this integral.

All functions are in my original post. Main function is:

for(int i=0; i<16; i++) {
	double res = getResult(i);
}

At this point it consumes large memory and finally crashes. However, it runs fine if the loop is over few points (say 2) instead of 16.
Thanks.

Hi,

Just try to compile your code. For example cross and fun are not defined.
I am happy to look at this problem, but please post a full running program or macro

Thank you

Lorenzo