Multithreading with standalone_cpp output
Dear Madgraph team,
I'm trying to use the standalone c++ output in a multithreaded program, but I'm running into issues. I managed to condense the problem down to some code that's very similar to the check_sa.cc that comes with the c++ output (compiled with -std=c++11):
#include <iostream>
#include <iomanip>
#include <thread>
#include "CPPProcess.h"
#include "rambo.h"
struct MEC
{
MEC()
void run()
{
double energy = 1500;
double weight;
for (int i=0; i<3; i++)
{
// Get phase space point
vector<
// Set momenta for this event
process.
// Evaluate matrix element
process.
cout << process.
}
}
CPPProcess process;
};
int main()
{
thread t1(&MEC::run, MEC());
thread t2(&MEC::run, MEC());
t1.join();
t2.join();
}
The code is supposed to generate 3 sets of rambo momenta and calculate the matrix element. However, the output is
0.000000e+00
0.000000e+00
0.000000e+00
0.000000e+00
0.000000e+00
0.000000e+00
If I remove one of the threads, the output is something like
3.624505e-15
2.599132e-13
2.264434e-14
as I would expect. I'm hoping anyone knows what's going on here, since as far as I know, this is how you're supposed to multithread this kind of c++ code.
Thanks,
Rob Verheyen
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Rob Verheyen for more information if necessary.