Looking for information

Hello there,

I have been using some macros written in C to use Root tools. So far I had not had any problem, however, now there is an issue I am trying to figure out by myself.

The point is that after some time of (apparently) hard work, the final result is not what I am asking Root to produce (a figure in a eps file). I am afraid the problem is related to great consumption of my PC resources. I am not sure if this is true, but it did not happen to me before, even with the same macros, that when I run Root with my macro, my PC gets almost died!

So, before going into any detail about my macros, I was wondering if there is an easy way (say a command) to asking Root to provide information about the PC resources it is using while running through a macro.

I hope you could help me, even if I did not explain my problem better… :confused:

Cheer,

Mario AAO.

You can run ROOT with valgrind to see if there is any memory leaks.

Can you send images showing what you should get and what you get when it is going wrong, so we can compare ?

Is your macro small enough so you can post it here ?

Hi,
Thank you for your reply.

I’m sorry, but I could not figure out how to use valgrind, therefore, so far I have not solved my problem.

The macro is actually rather long, but still I would really like to you to help me. So, is there an easy way to me to send you a couple of files?

Thanks a lot.

Cheers,

Mario AAO.

You can attach the files here.

OK. Then I attach here the files.

There are four files:
– forum.C : is the short version I created for this forum.
– functions_new.C: contains the functions used in the main macro.
– constants.txt : just a file containing numerical constants used in the macros.
– test_23Apr12.ps : the figure I want to generate with the main macro and the functions used in it.

Actually, the macro I attach here, should only generate the blue line (Magnus O(2)).

I hope the files are self-explanatory with some comments include on them.

Thank you very much!
test_23Apr12.ps (43.7 KB)
forum.C (2.95 KB)
functions_new.C (34.1 KB)
constants.txt (1.18 KB)

I started you macro … it is more or less blocking my machine right now…
It prints the message "The oscillation … " many time …
And the graphics window is still empty … how long should I wait ?

ok … I get the plot … all looks normal … I will check your code to see if I see something wrong

Oh, Sorry. While checking, I asked it to print some information ("The oscillation … ").

So you got the same problem. My PC gets stuck, and it takes very long. So long I have not actually waited until the end, so I have not got the plot. Ah, actually, what usually happens is that it stops suddenly and it does not generate the plot.

Thanks!

I am running it under valgrind right now … my IMac is almost dead … I let it go to see if valgrind find something …

Hello.

  1. Forget about valgrind. Your mistakes are so basic and simple, that you DO NOT NEED THIS MONSTER to find them.

  2. Is it your code? If yes, I would recommend you to read something about memory management in C++. If not, still, it’s not a bad idea to read about memory management in C++:)

  3. In short, you are creating a huge number of TF1 objects using new expression and never delete ANY OF THEM. I do not know how many times all these nested functions are executed (I’m too lazy to statically analyze your code :slight_smile:) - but it’s clear, that all these terrible functions are executed many times when you try to draw, producing memory leaks in every function. So either you use stack objects (read about them), or call delete for TF1 objects you dynamically allocate, or … do something else :slight_smile:))

  4. I’m attaching “fixed” macro, it’s still not too good, since I’m too lazy to re-write ~1 kloc of code :slight_smile: But at least it works (or “works”).

P.S.
Well, with your original macro program eats 4.5 Gb of ram on my laptop (since I have 8, ROOT still works ok and is able to finish this execution). I can not imagine, how this will work with vallgrind. With fixed functions_new.C it’s much more better :slight_smile:

P.P.S.

And by the way, every time canvas has to repaint (say, you resize it), you repeat all these calculations. :slight_smile:
functions_new.C (34.8 KB)

Hello,

First of all, thank you very much for your help.
I feel pretty embarrassed :blush:, even if I am not an expert neither on Root nor on C/C++. I’ve been doing some coding since some time now, and there are many things I have never cared enough, and clearly this issue about memory management is one of them.

This, actually, is a code I modified based on a someone else’s code, and I think none of us noticed this basic and simple point (problem). However, I wonder why this was not happening before… Or maybe it did, but it was not such a big thing, because my PC did not get stuck… Anyway…

So, thank you again. Right now I will have a look on the modifications you made and I will try to follow all your recommendation from now on. For sure, I’m learning a lot from this mistakes :confused: .

Cheers.

Hello again,

Just for completeness, I was wondering if you, couet, would have something else to say. Any comment/suggestion would be highly appreciated :wink: .

Thanks!

Hi. I’ve made two kinds of modifications:

  1. If you have TF1 *f = new TF1(…, at some point you have to add delete f; to free memory. Another way to fix it is to use stack object:

TF1 f("asdasd", ptr_to_fun, -2., 2.); f.SetParameter(... f.Eval(xxx);

In this case, you have an object with automatic storage duration and do not care about deleting it - everything is done by language. (Sure, for me it was easier to add ‘delete func’ instead of replacing every ‘func->’ with ‘func.’ :wink: )
Of course, advice about memory management is not an absolute - you should care about object’s lifetime, for example, if you need to have something, what is created in a function and live longer than function is executed, you’ll have to use new and delete this object somewhere outside a function. Also, ROOT has its own ‘object ownership’ policy, which you’d better read about (or you’ll have other weird problems with empty canvases instead of plots etc. :slight_smile: ).

  1. In several functions you had

[code]if (condition) {
TF1 *hhh = …
}

hhh->Eval(…[/code]

This is also wrong, the scope for ‘hhh’ identifier is limited by conditional statement, you can not use it outside ‘if’ block (it worked with CINT, but this is ill-formed C++ code).

I’ll answer :slight_smile: If you still want to use valgrind and see its output, just reduce the size of your problem - call SetNpx with small number of points before you draw.