Home | News | Documentation | Download

Fasing issue while using lambdas in TF1 (with use of source cpp files)

ROOT Version: 6.18 for centOs7
Platform: Not Provided
Compiler: g++

Dear ROOT community,
I am fasing some strange issue when applying lambda function in source file to TF1. Code snippet is as follows:

auto fit_lamb = [](Double_t* x, Double_t* par){return TMath::Sqrt((x)(*x)+par[0]par[0]);};
TF1
fit = new TF1(“fit”,fit_lamb,0,25,1);

This one works without problems under prompt, and any other way without lambdas in source file works just fine (seemingly at least). But, as long as I run snippet above with use of source file, I continue receiving segfault. Stack trace is as follows:

#0 0x00007fd91366845c in __libc_waitpid (pid=14175, stat_loc=stat_loc
entry=0x7fff0da2c120, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:31
#1 0x00007fd9135e5f52 in do_system (line=) at …/sysdeps/posix/system.c:148
#2 0x00007fd9181db9f4 in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libCore.so.6.18
#3 0x00007fd9181de12c in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libCore.so.6.18
#4
#5 0x00007fd91418bf2b in _M_is_leaked (this=) at /root/zuev/objdir/x86_64-pc-linux-gnu/libstdc+±v3/include/bits/basic_string.tcc:609
#6 _M_grab (__alloc2=…, __alloc1=…, this=) at /root/zuev/objdir/x86_64-pc-linux-gnu/libstdc+±v3/include/bits/basic_string.h:3286
#7 std::basic_string<char, std::char_traits, std::allocator >::basic_string (this=0x26356d8, __str=…) at /root/zuev/objdir/x86_64-pc-linux-gnu/libstdc+±v3/include/bits/basic_string.tcc:613
#8 0x00007fd9170396c8 in TF1::Copy(TObject&) const () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#9 0x00007fd91700ba94 in void HFit::StoreAndDrawFitFunction(TGraph*, TF1*, ROOT::Fit::DataRange const&, bool, bool, char const*) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#10 0x00007fd91700db2c in TFitResultPtr HFit::Fit(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#11 0x00007fd917006ffc in ROOT::Fit::FitObject(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#12 0x00007fd91709fd0f in TGraph::Fit(TF1*, char const*, char const*, double, double) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#13 0x00007fd9170a634e in TGraph::Fit(char const*, char const*, char const*, double, double) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#14 0x0000000000406224 in main ()

I attach full source file read_tree.cpp (1.7 KB)

I also tag @moneta since I am sure he can help me with the issue.

Thanks in advance.

Hi,
I would need a ROOT file to reproduce the problem.
It looks like there is an issue copying the lambda. In theory it should not be copied.
Trying with a simple script as this, it works fine

void test() {

   double x[] = {1,2,3,4,5};
   double y[] = {1,4,5,7,10};
   auto * gr = new TGraph(5,x,y);
   auto fit_lamb = [](Double_t* x, Double_t* par){return par[0] + x[0]*par[1];};
   TF1* fit = new TF1("fit",fit_lamb,0,6,2);
   fit->SetParameter(0,0);
   fit->SetParameter(1,2);
   gr->Draw("AC*");
   gr->Fit("fit");
}

Lorenzo

Dear Lorentzo,
Forgot to attach, here it is: momentum_dist.root (6.9 KB)

While running your example as main() I’ve got segfault again and it prints:

#0 0x00007f1f98fb845c in waitpid () from /lib64/libc.so.6
#1 0x00007f1f98f35f52 in do_system () from /lib64/libc.so.6
#2 0x00007f1f9db2b9f4 in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libCore.so.6.18
#3 0x00007f1f9db2e12c in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libCore.so.6.18
#4
#5 0x00007f1f99062681 in __strlen_sse2_pminub () from /lib64/libc.so.6
#6 0x00007f1f99adc831 in length (__s=0x2 <Address 0x2 out of bounds>) at /root/zuev/objdir/x86_64-pc-linux-gnu/libstdc+±v3/include/bits/char_traits.h:335
#7 std::basic_string<char, std::char_traits, std::allocator >::basic_string (this=0x7ffc6b468e60, __s=0x2 <Address 0x2 out of bounds>, __a=…) at /root/zuev/objdir/x86_64-pc-linux-gnu/libstdc+±v3/include/bits/basic_string.tcc:664
#8 0x00007f1f9c9589f7 in ROOT::Math::WrappedMultiTF1Templ::ParameterName(unsigned int) const () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#9 0x00007f1f9a7be636 in void ROOT::Fit::FitConfig::CreateParamsSettings(ROOT::Math::IParametricFunctionMultiDimTempl const&) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libMathCore.so.6.18
#10 0x00007f1f9a7ba5d0 in ROOT::Fit::Fitter::SetFunction(ROOT::Math::IParametricFunctionMultiDimTempl const&, bool) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libMathCore.so.6.18
#11 0x00007f1f9c95d397 in TFitResultPtr HFit::Fit(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#12 0x00007f1f9c956ffc in ROOT::Fit::FitObject(TGraph*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#13 0x00007f1f9c9efd0f in TGraph::Fit(TF1*, char const*, char const*, double, double) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#14 0x00007f1f9c9f634e in TGraph::Fit(char const*, char const*, char const*, double, double) () from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib/libHist.so.6.18
#15 0x0000000000405b5f in main ()

Just to clarify: I do the compilation stuff via g++ command with flags, not via prompt. Loading same source in prompt and calling main() won’t trigger segfault

Hi,

Thanks for the file. I have tried also running your program as a standalone application (compiling and executing and not from the ROOT prompt) and I have not observed any segfault.
I have tested also 6.18.04 versionon Centos7 ( from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.20.04/x86_64-centos7-gcc48-opt/ )
and it works fine. Which version exactly are you using it ?

Lorenzo

Dear Lorenzo,
As follows:

/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt

Strange, I have tried now on lxplus7 also with /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt
by doing:

 . /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/bin/thisroot.sh
g++ `root-config --cflags --libs` read_tree.cpp
./a.out

and this works fine for me !

L.

Lorenzo,
I am not sure what to do then.
Does stacktrace notify about something?

I have also tried valfrind,

valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp ./a.out

and I don’t get any error. Are you sure you are using a consistent ROOT version 6.18 and not maybe some other version ?

Lorenzo

Lorenzo,
I am not sure 100% since I didn’t installed it myself, it was already installed on server. Next command

cd $ROOTSYS

moves me here

/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt

Also, name of module which I’ve loaded to my .bashrc was ROOT/v6.18.00 .

So I’m pretty sure it is.

And exactly what you are doing to have this problem? How do you compile your program ?
Which machine are you using ? lxplus7 ?

Lorenzo

Lorenzo,
I’ve created a bash script .runroot.txt (91 Bytes) that creates executable file, then compiles via g++ with flags, then runs executable and afterwards deletes it. I’ve made an alias command for this bash script so everything I do in order to reproduce segfault is

runroot temp.cpp

I’m not sure what “which machine are you using” means.

P

The question I have is if you are using a linux cluster such as lxplus7.cern.ch or your own PC.
For your script I would add this line:

 root-config --version

Lorenzo

Lorenzo,
I am using Hybrilit cluster http://hlit.jinr.ru/
What does this line do?

root-config --version

It prints the ROOT version. So we are sure on the ROOT version used in your script.
Actually do also:
root-config --version --libdir

Lorenzo,
output:
6.18/00 /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/lib
Nothing new seemingly : (

Hi,
I am sorry I cannot understand what is going on for you, maybe you can try using a newer version of ROOT, or a debug version and see with gdb what is causing the crash.

Lorenzo

1 Like

Lorenzo,
Thanks for trying.
I will create new topic if I find the answer.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.