44 Int_t N_collectors = 2;
46 Int_t events_per_rank = 6;
48 Int_t sleep_sigma = 2;
57 std::string treename =
"test_tmpi";
58 std::string branchname =
"event";
61 std::stringstream smpifname;
62 smpifname <<
"/tmp/merged_output_" << getpid() <<
".root";
68 TMPIFile *newfile =
new TMPIFile(smpifname.str().c_str(),
"RECREATE", N_collectors);
71 gRandom->SetSeed(
gRandom->GetSeed() + newfile->GetMPIGlobalRank());
74 if (newfile->GetMPIGlobalRank() == 0) {
75 Info(
"test_tmpi",
" running with parallel ranks: %d", newfile->GetMPIGlobalSize());
76 Info(
"test_tmpi",
" running with collecting ranks: %d", N_collectors);
77 Info(
"test_tmpi",
" running with working ranks: %d", (newfile->GetMPIGlobalSize() - N_collectors));
78 Info(
"test_tmpi",
" running with sync rate: %d", sync_rate);
79 Info(
"test_tmpi",
" running with events per rank: %d", events_per_rank);
80 Info(
"test_tmpi",
" running with sleep mean: %d", sleep_mean);
81 Info(
"test_tmpi",
" running with sleep sigma: %d", sleep_sigma);
82 Info(
"test_tmpi",
" running with seed: %d",
gRandom->GetSeed());
86 if (newfile->IsCollector()) {
87 Info(
"Collector",
"[%d]\troot output filename = %s", newfile->GetMPIGlobalRank(), smpifname.str().c_str());
92 if (newfile->IsCollector()) {
95 newfile->RunCollector();
101 TTree *tree =
new TTree(treename.c_str(),
"Event example with Jets");
110 tree->
Branch(branchname.c_str(),
"JetEvent", &event, 8000, 2);
113 auto sync_start = std::chrono::high_resolution_clock::now();
116 for (
int i = 0; i < events_per_rank; i++) {
118 auto start = std::chrono::high_resolution_clock::now();
120 event->Build(jetm, trackm, hitam, hitbm);
122 auto evt_built = std::chrono::high_resolution_clock::now();
123 double build_time = std::chrono::duration_cast<std::chrono::duration<double>>(evt_built -
start).count();
125 Info(
"Rank",
"[%d] [%d]\tevt = %d;\tbuild_time = %f", newfile->GetMPIColor(), newfile->GetMPILocalRank(), i,
129 auto adjusted_sleep = (
int)(sleep_mean - build_time);
133 std::this_thread::sleep_for(std::chrono::seconds(
int(
sleep)));
140 if ((i + 1) % sync_rate == 0) {
144 auto end = std::chrono::high_resolution_clock::now();
145 double sync_time = std::chrono::duration_cast<std::chrono::duration<double>>(end - sync_start).count();
146 Info(
"Rank",
"[%d] [%d]\tevent collection time: %f", newfile->GetMPIColor(), newfile->GetMPILocalRank(),
148 sync_start = std::chrono::high_resolution_clock::now();
153 if (events_per_rank % sync_rate != 0) {
159 Info(
"Rank",
"[%d] [%d]\tclosing file", newfile->GetMPIColor(), newfile->GetMPILocalRank());
163 if (newfile->GetMPILocalRank() == 0) {
164 TString filename = newfile->GetMPIFilename();
165 Info(
"Rank",
"[%d] [%d]\topening file: %s", newfile->GetMPIColor(), newfile->GetMPILocalRank(), filename.
Data());
169 TTree *tree = (
TTree *)file.Get(treename.c_str());
173 Info(
"Rank",
"[%d] [%d]\tfile should have %d events and has %lld", newfile->GetMPIColor(),
174 newfile->GetMPILocalRank(), (newfile->GetMPILocalSize() - 1) * events_per_rank, tree->
GetEntries());
179void testTMPIFile(
Bool_t secRun)
181 auto start = std::chrono::high_resolution_clock::now();
185 auto end = std::chrono::high_resolution_clock::now();
186 double time = std::chrono::duration_cast<std::chrono::duration<double>>(end -
start).count();
187 std::string msg =
"Total elapsed time: ";
188 msg += std::to_string(time);
189 Info(
"testTMPIFile",
"%s", msg.c_str());
190 Info(
"testTMPIFile",
"exiting");
198 MPI_Initialized(&flag);
200 MPI_Init(NULL, NULL);
205 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
206 MPI_Comm_size(MPI_COMM_WORLD, &
size);
212 gSystem->Exec(
"cp " + tutdir +
"/tree/JetEvent* .");
213 gROOT->ProcessLine(
".L JetEvent.cxx+");
216 MPI_Barrier(MPI_COMM_WORLD);
218 gROOT->ProcessLine(
"#define TMPI_SECOND_RUN yes");
219 gROOT->ProcessLine(
"#include \"" __FILE__
"\"");
220 gROOT->ProcessLine(
"testTMPIFile(true)");
224 MPI_Finalized(&finalized);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
unsigned int sleep(unsigned int seconds)
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
const char * Data() const
A TTree represents a columnar dataset.
virtual Int_t Fill()
Fill all branches.
void Print(Option_t *option="") const override
Print a summary of the tree contents.
virtual Long64_t GetEntries() const
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
virtual void SetAutoFlush(Long64_t autof=-30000000)
This function may be called at the start of a program to change the default value for fAutoFlush.
RVec< PromoteType< T > > abs(const RVec< T > &v)