Comment 7 for bug 1255632

Revision history for this message
Olivier Mattelaer (olivier-mattelaer) wrote : Re: [Bug 1255632] Problem with static variables in standalone_cpp

Hi,

Actually your solution 3) is what I was thinking for the solution 2)
But I'm a noob in C++, (The author of that part unfortunately left physics).
So I'll read a C++ manual before implementing the fix.
If you don't mind, I'll ask you to review my modification.

Cheers,

Olivier

On Dec 8, 2013, at 2:21 PM, Aurelijus Rinkevicius <email address hidden> wrote:

> Hi,
>
> You are right about the optimization, loosing it is also not a victory.
> However, I have an option 3):
>
> 3) Why not to make the variables private in the whole class and then
> simply reset them inside CPPProcess::initProc(). They don't have to be
> static.
>
> BTW, there is a problem with your 2) suggestion. The problem is that the
> static variables jump out of the object and will have a cross-talk in
> parallel calls, i.e., while declaring CPPProcess Model_1, Model_2; these
> two objects, Model_1 and Model_2 will see each other static variables as
> the statics are shared accross the same-type class and its derivatives
> (methods). Also, this is exactly where I have encountered the problem
> the first time and got surprised of this interference.
>
> Option 3) would provide two benefits: (1) calling initProc() would reset
> a model, (2) there would be no interference (memory sharing) between the
> same-type class objects. Hope it makes sense.
>
>
> Best regards,
> Aurelijus
>
> --
> You received this bug notification because you are a member of MadTeam,
> which is subscribed to MadGraph5.
> https://bugs.launchpad.net/bugs/1255632
>
> Title:
> Problem with static variables in standalone_cpp
>
> Status in The MadGraph Matrix Element Generator version 5:
> New
>
> Bug description:
> In some cases while using standalone_cpp classes multiple times, the
> static variables start to cause problems. In particular, the
> following:
>
> in void CPPProcess::sigmaKin() { ...
> static int ntry = 0, sum_hel = 0, ngood = 0;
> ...}
>
> the problem is that the second time the function is being called, the static members already exist in the memory and the 0s are not being assigned as the constructors are not called. The possible solution could be:
> static int ntry, sum_hel, ngood;
> ntry = 0, sum_hel = 0, ngood = 0;
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/madgraph5/+bug/1255632/+subscriptions