Hi Masaharu, Rene's suggestion works just fine. Thanks for everyone's help. Just for the sake of completeness, below is a self-contained piece of code that breaks (segmentation faults) in 3.02/07, but seems to work just fine in 3.01/06. { gROOT->Reset(); gSystem -> Load("libPhysics"); Int_t Njeta; Int_t Npart; Int_t Kfpar[40]; Double_t Pxpar[40]; Double_t Pypar[40]; Double_t Pzpar[40]; Njeta=3; Npart = 3; Kfpar[2] = 13; Pxpar[2]=13.0; Pypar[2]=23.0; Pzpar[2]=113.0; for (Int_t i=0; i<50000;i++) { for (Int_t ii=0 ; ii<Npart ; ii++) { if ( TMath::Abs(Kfpar[ii]) == 13 ) { TVector3 p_muon(Pxpar[ii],Pypar[ii],Pzpar[ii]); for ( Int_t iii=0 ; iii<Njeta ; iii++) { Double_t rap_muon; rap_muon=p_muon.Eta(); } } } } } On Wed, 23 Jan 2002, Masaharu Goto wrote: > Hello Matt, Rene and Kalen, > > Matt made a good point. Heap object does not disturb bytecode optimization. > It is a good tip to create heap object inside loop, rather than declare an > automatic object. > > BTW, Rene, > I do not recall the change you mention here. Do you remember when it was > or which Cint version that was on? > > Also, because I have only part of source code and may be data file is > needed, I can not run this program for debugging. > > Thank you > Masaharu Goto > > > > >Date: Wed, 23 Jan 2002 09:34:38 -0000 > >From: "Matthew Palmer" <mjp39@cam.ac.uk> > >To: "Kalen Martens" <fmartens@physics.utoronto.ca> > >Cc: <roottalk@pcroot.cern.ch>, <cint@pcroot.cern.ch> > >Subject: Re: [CINT] Re: [ROOT] ROOT 20 times slower > > > > > >If speed is an issue then you should avoid creating objects on the stack. > >CInt compiles functions that are called more than once into bytecode which > >is significantly faster, but it can't do that if stack objects are created. > >I came across this issue recently and found a very significant speed > >improvement (10-20 times) by changing all objects to heap objects. > >eg in Rene's code use TVector3 *p_muon = new TVector3(); etc > > > >Check out: http://root.cern.ch/root/Cint.phtml?bytecode > > > >Matt > > > >> Your problem seems to be a consequence of the attempts by Masa to follow > >> the C++ scoping rules. I suggest that you change your very innefficient > >code > >> with the TVector3 declaration inside the inner loop as shown below. > >> In the previous versions of CINT, Masa was "optimizing" the code by > >calling > >> the TVector3 constructor only once. In the new version, he follows the > >> C++ scoping rules where the TVector3 object will be created and deleted at > >each > >> instance of the loop ! > >> I am forwarding this mail to Masa for investigation. > >> Meanwhile, use this more efficient version of your code: > >> > >> TH1F *hmj = new TH1F("hmj", "muon-jet separation", 100, 0, 10); > >> Int_t nentries = h3333->GetEntries(); > >> TVector3 p_muon; > >> > >> for (Int_t i=0; i<nentries;i++) { > >> h3333->GetEntry(i); > >> for (Int_t ii=0 ; ii<Npart ; ii++) { > >> > >> if ( TMath::Abs(Kfpar[ii]) == 13 ) { > >> > >> p_muon.SetXYZ(Pxpar[ii], Pypar[ii], Pzpar[ii]); > >> > >> for ( Int_t iii=0 ; iii<Njeta ; iii++) { > >> > >> Double_t rap_muon; > >> > >> rap_muon=p_muon.Eta(); > >> hmj -> Fill(rap_muon); > >> > >> } > >> } > >> } > >> } > >> > >> > >> Rene Brun > >> > >>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:39 MET