10 #include "HepMC3TestUtils.h"
12 using namespace HepMC3;
13 const int NinputCopies=4;
14 const int NmaxThreads=3;
15 void attribute_function1(
const GenEvent& e,
const int&
id)
18 printf(
"XS in event %i is %f, id=%i\n",e.
event_number(),xs->xsec(),id);
23 if(inputA.failed())
return 1;
24 std::vector<GenEvent> evts;
25 while( !inputA.failed() )
28 inputA.read_event(evt);
29 if( inputA.failed() ) {
30 printf(
"End of file reached. Exit.\n");
36 std::vector<GenEvent> thr_evts[NinputCopies];
37 for (
int i=0; i<NinputCopies; i++)thr_evts[i]=evts;
39 for (
int i=0; i<NinputCopies; i++)
40 for (
size_t e=0; e<evts.size(); e++)
42 std::vector<std::thread> threads;
43 int j1=-thr_evts[i].at(e).vertices().size();
44 int j2=thr_evts[i].at(e).particles().size();
45 int d=(j2-j1)/NmaxThreads;
48 for (
int j=j1; j<j2; j+=d)
54 for (
size_t j=0; j<ids.size(); j++)
55 threads.push_back(std::thread(attribute_function1,std::cref(thr_evts[i].at(e)),ids[j]));
56 for (
auto& th : threads) th.join();
59 for (
int k=0; k<NinputCopies; k++)
61 WriterAscii outputA(
"outputThreads1_"+std::to_string(k)+
".hepmc");
62 if(outputA.failed())
return 2;
63 for (
size_t i=0; i<thr_evts[k].size(); i++) outputA.write_event(thr_evts[k].at(i));
68 int result=COMPARE_ASCII_FILES(
"outputThreads1_"+std::to_string(k-1)+
".hepmc",
"outputThreads1_"+std::to_string(k)+
".hepmc");
69 if (result!=0)
return result;
Definition of class GenParticle.
Definition of class GenVertex.
Definition of class WriterAscii.
shared_ptr< T > attribute(const string &name, const int &id=0) const
Get attribute of type T.
int event_number() const
Get event number.
Parser for HepMC2 I/O files.
Definition of class ReaderAsciiHepMC2.
Stores event-related information.
Definition of class ReaderAscii.
Definition of class WriterAsciiHepMC2.
int main(int argc, char **argv)
Definition of class GenEvent.
Definition of class Attribute, class IntAttribute and class StringAttribute.
GenEvent I/O serialization for structured text files.
Stores additional information about cross-section.