43 Int_t N_collectors = 2;
45 Int_t events_per_rank = 6;
47 Int_t sleep_sigma = 2;
56 std::string treename =
"test_tmpi";
57 std::string branchname =
"event";
60 std::stringstream smpifname;
61 smpifname <<
"/tmp/merged_output_" << getpid() <<
".root";
67 TMPIFile *newfile =
new TMPIFile(smpifname.str().c_str(),
"RECREATE", N_collectors);
73 if (newfile->GetMPIGlobalRank() == 0) {
74 Info(
"test_tmpi",
" running with parallel ranks: %d", newfile->GetMPIGlobalSize());
75 Info(
"test_tmpi",
" running with collecting ranks: %d", N_collectors);
76 Info(
"test_tmpi",
" running with working ranks: %d", (newfile->GetMPIGlobalSize() - N_collectors));
77 Info(
"test_tmpi",
" running with sync rate: %d", sync_rate);
78 Info(
"test_tmpi",
" running with events per rank: %d", events_per_rank);
79 Info(
"test_tmpi",
" running with sleep mean: %d", sleep_mean);
80 Info(
"test_tmpi",
" running with sleep sigma: %d", sleep_sigma);
85 if (newfile->IsCollector()) {
86 Info(
"Collector",
"[%d]\troot output filename = %s", newfile->GetMPIGlobalRank(), smpifname.str().c_str());
91 if (newfile->IsCollector()) {
94 newfile->RunCollector();
100 TTree *
tree =
new TTree(treename.c_str(),
"Event example with Jets");
103 tree->SetAutoFlush(sync_rate);
109 tree->Branch(branchname.c_str(),
"JetEvent", &event, 8000, 2);
112 auto sync_start = std::chrono::high_resolution_clock::now();
115 for (
int i = 0; i < events_per_rank; i++) {
117 auto start = std::chrono::high_resolution_clock::now();
119 event->Build(jetm, trackm, hitam, hitbm);
121 auto evt_built = std::chrono::high_resolution_clock::now();
122 double build_time = std::chrono::duration_cast<std::chrono::duration<double>>(evt_built -
start).count();
124 Info(
"Rank",
"[%d] [%d]\tevt = %d;\tbuild_time = %f", newfile->GetMPIColor(), newfile->GetMPILocalRank(), i,
128 auto adjusted_sleep = (
int)(sleep_mean - build_time);
132 std::this_thread::sleep_for(std::chrono::seconds(
int(
sleep)));
139 if ((i + 1) % sync_rate == 0) {
143 auto end = std::chrono::high_resolution_clock::now();
144 double sync_time = std::chrono::duration_cast<std::chrono::duration<double>>(
end - sync_start).count();
145 Info(
"Rank",
"[%d] [%d]\tevent collection time: %f", newfile->GetMPIColor(), newfile->GetMPILocalRank(),
147 sync_start = std::chrono::high_resolution_clock::now();
152 if (events_per_rank % sync_rate != 0) {
158 Info(
"Rank",
"[%d] [%d]\tclosing file", newfile->GetMPIColor(), newfile->GetMPILocalRank());
162 if (newfile->GetMPILocalRank() == 0) {
164 Info(
"Rank",
"[%d] [%d]\topening file: %s", newfile->GetMPIColor(), newfile->GetMPILocalRank(),
filename.Data());
172 Info(
"Rank",
"[%d] [%d]\tfile should have %d events and has %lld", newfile->GetMPIColor(),
173 newfile->GetMPILocalRank(), (newfile->GetMPILocalSize() - 1) * events_per_rank,
tree->GetEntries());
178void testTMPIFile(
Bool_t secRun)
180 auto start = std::chrono::high_resolution_clock::now();
184 auto end = std::chrono::high_resolution_clock::now();
185 double time = std::chrono::duration_cast<std::chrono::duration<double>>(
end -
start).count();
186 std::string msg =
"Total elapsed time: ";
187 msg += std::to_string(time);
188 Info(
"testTMPIFile",
"%s", msg.c_str());
189 Info(
"testTMPIFile",
"exiting");
197 MPI_Initialized(&flag);
199 MPI_Init(NULL, NULL);
204 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
205 MPI_Comm_size(MPI_COMM_WORLD, &
size);
211 gSystem->
Exec(
"cp " + tutdir +
"/tree/JetEvent* .");
212 gROOT->ProcessLine(
".L JetEvent.cxx+");
215 MPI_Barrier(MPI_COMM_WORLD);
217 gROOT->ProcessLine(
"#define TMPI_SECOND_RUN yes");
218 gROOT->ProcessLine(
"#include \"" __FILE__
"\"");
219 gROOT->ProcessLine(
"testTMPIFile(true)");
223 MPI_Finalized(&finalized);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
R__EXTERN C unsigned int sleep(unsigned int seconds)
R__EXTERN TRandom * gRandom
R__EXTERN TSystem * gSystem
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
virtual UInt_t GetSeed() const
Get the random generator seed.
virtual Int_t Exec(const char *shellcmd)
Execute a command.
A TTree represents a columnar dataset.
RVec< PromoteType< T > > abs(const RVec< T > &v)