14#include "HepMC3TestUtils.h"
17const int NinputCopies=4;
18const int NmaxThreads=3;
19void attribute_function1(
const GenEvent& e,
const int&
id)
22 printf(
"XS in event %i is %f, id=%i\n",e.
event_number(),xs->xsec(),
id);
27 if(inputA.failed())
return 1;
28 std::vector<GenEvent> evts;
29 while( !inputA.failed() )
32 inputA.read_event(evt);
33 if( inputA.failed() ) {
34 printf(
"End of file reached. Exit.\n");
40 std::vector<GenEvent> thr_evts[NinputCopies];
41 for (
int i=0; i<NinputCopies; i++)thr_evts[i]=evts;
43 for (
int i=0; i<NinputCopies; i++)
44 for (
size_t e=0; e<evts.size(); e++)
46 std::vector<std::thread> threads;
47 int j1=-((long)thr_evts[i].at(e).vertices().size());
48 int j2=thr_evts[i].at(e).particles().size();
49 int d=((long)(j2)-(long)(j1))/NmaxThreads;
52 for (
int j=j1; j<j2; j+=d)
58 for (
size_t j=0; j<ids.size(); j++)
59 threads.push_back(std::thread(attribute_function1,std::cref(thr_evts[i].at(e)),ids[j]));
60 for (
auto& th : threads) th.join();
63 for (
int k=0; k<NinputCopies; k++)
65 WriterAscii outputA(
"outputThreads1_"+std::to_string(k)+
".hepmc");
66 if(outputA.failed())
return 2;
67 for (
size_t i=0; i<thr_evts[k].size(); i++) outputA.write_event(thr_evts[k].at(i));
72 int result=COMPARE_ASCII_FILES(
"outputThreads1_"+std::to_string(k-1)+
".hepmc",
"outputThreads1_"+std::to_string(k)+
".hepmc");
73 if (result!=0)
return result;
Definition of class Attribute, class IntAttribute and class StringAttribute.
Definition of class GenEvent.
Definition of class GenParticle.
Definition of class GenVertex.
Definition of class ReaderAsciiHepMC2.
Definition of class ReaderAscii.
Definition of class WriterAsciiHepMC2.
Definition of class WriterAscii.
Stores additional information about cross-section.
Stores event-related information.
std::shared_ptr< T > attribute(const std::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.
GenEvent I/O serialization for structured text files.