47 Int_t N_collectors = 2;
49 Int_t events_per_rank = 6;
51 Int_t sleep_sigma = 2;
60 std::string treename =
"test_tmpi";
61 std::string branchname =
"event";
64 std::stringstream smpifname;
65 smpifname <<
"/tmp/merged_output_" << getpid() <<
".root";
71 TMPIFile *newfile =
new TMPIFile(smpifname.str().c_str(),
"RECREATE", N_collectors);
77 if (newfile->GetMPIGlobalRank() == 0) {
78 Info(
"test_tmpi",
" running with parallel ranks: %d", newfile->GetMPIGlobalSize());
79 Info(
"test_tmpi",
" running with collecting ranks: %d", N_collectors);
80 Info(
"test_tmpi",
" running with working ranks: %d", (newfile->GetMPIGlobalSize() - N_collectors));
81 Info(
"test_tmpi",
" running with sync rate: %d", sync_rate);
82 Info(
"test_tmpi",
" running with events per rank: %d", events_per_rank);
83 Info(
"test_tmpi",
" running with sleep mean: %d", sleep_mean);
84 Info(
"test_tmpi",
" running with sleep sigma: %d", sleep_sigma);
89 if (newfile->IsCollector()) {
90 Info(
"Collector",
"[%d]\troot output filename = %s", newfile->GetMPIGlobalRank(), smpifname.str().c_str());
95 if (newfile->IsCollector()) {
98 newfile->RunCollector();
104 TTree *
tree =
new TTree(treename.c_str(),
"Event example with Jets");
107 tree->SetAutoFlush(sync_rate);
113 tree->Branch(branchname.c_str(),
"JetEvent", &event, 8000, 2);
116 auto sync_start = std::chrono::high_resolution_clock::now();
119 for (
int i = 0; i < events_per_rank; i++) {
121 auto start = std::chrono::high_resolution_clock::now();
123 event->Build(jetm, trackm, hitam, hitbm);
125 auto evt_built = std::chrono::high_resolution_clock::now();
126 double build_time = std::chrono::duration_cast<std::chrono::duration<double>>(evt_built - start).count();
128 Info(
"Rank",
"[%d] [%d]\tevt = %d;\tbuild_time = %f", newfile->GetMPIColor(), newfile->GetMPILocalRank(), i,
132 auto adjusted_sleep = (int)(sleep_mean - build_time);
136 std::this_thread::sleep_for(std::chrono::seconds(
int(
sleep)));
143 if ((i + 1) % sync_rate == 0) {
147 auto end = std::chrono::high_resolution_clock::now();
148 double sync_time = std::chrono::duration_cast<std::chrono::duration<double>>(end - sync_start).count();
149 Info(
"Rank",
"[%d] [%d]\tevent collection time: %f", newfile->GetMPIColor(), newfile->GetMPILocalRank(),
151 sync_start = std::chrono::high_resolution_clock::now();
156 if (events_per_rank % sync_rate != 0) {
162 Info(
"Rank",
"[%d] [%d]\tclosing file", newfile->GetMPIColor(), newfile->GetMPILocalRank());
166 if (newfile->GetMPILocalRank() == 0) {
167 TString filename = newfile->GetMPIFilename();
168 Info(
"Rank",
"[%d] [%d]\topening file: %s", newfile->GetMPIColor(), newfile->GetMPILocalRank(), filename.
Data());
176 Info(
"Rank",
"[%d] [%d]\tfile should have %d events and has %lld", newfile->GetMPIColor(),
177 newfile->GetMPILocalRank(), (newfile->GetMPILocalSize() - 1) * events_per_rank,
tree->GetEntries());
182void testTMPIFile(
Bool_t secRun)
184 auto start = std::chrono::high_resolution_clock::now();
188 auto end = std::chrono::high_resolution_clock::now();
189 double time = std::chrono::duration_cast<std::chrono::duration<double>>(end - start).count();
190 std::string msg =
"Total elapsed time: ";
191 msg += std::to_string(time);
192 Info(
"testTMPIFile",
"%s", msg.c_str());
193 Info(
"testTMPIFile",
"exiting");
201 MPI_Initialized(&flag);
203 MPI_Init(NULL, NULL);
208 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
209 MPI_Comm_size(MPI_COMM_WORLD, &size);
215 gSystem->
Exec(
"cp " + tutdir +
"/tree/JetEvent* .");
216 gROOT->ProcessLine(
".L JetEvent.cxx+");
219 MPI_Barrier(MPI_COMM_WORLD);
221 gROOT->ProcessLine(
"#define TMPI_SECOND_RUN yes");
222 gROOT->ProcessLine(
"#include \"" __FILE__
"\"");
223 gROOT->ProcessLine(
"testTMPIFile(true)");
227 MPI_Finalized(&finalized);
#define R__LOAD_LIBRARY(LIBRARY)
void Info(const char *location, const char *msgfmt,...)
R__EXTERN C unsigned int sleep(unsigned int seconds)
R__EXTERN TRandom * gRandom
R__EXTERN TSystem * gSystem
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
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
const char * Data() const
virtual Int_t Exec(const char *shellcmd)
Execute a command.
A TTree represents a columnar dataset.