ROOT Version:6.26.14
Platform:Ubuntu 22.04
Compiler: gcc 11.04
Problem
The time using ROOT::EnableImplicitMT()
is greater than that of sequence mode?
Code
MT Mode
#include <iostream>
#include <chrono>
void mt_first() {
int mumber_threads = 20;
ROOT::EnableImplicitMT(number_threads);
auto file = TFile::Open("./dstarmb.root");
TTree *tree = nullptr;
file->GetObject<TTree>("h42", tree);
const auto time_0{std::chrono::steady_clock::now()};
const auto entries = tree->GetEntries();
for(auto i : ROOT::TSeqUL(entries)) {
tree->GetEntry(i);
}
const auto time_1{std::chrono::steady_clock::now()};
const std::chrono::duration<double> elapsed_seconds{time_1 - time_0};
std::cout << "Time Spend: " << elapsed_seconds.count() << " s." << "\n";
}
Seq Mode
#include <iostream>
#include <chrono>
void seq_first() {
ROOT::DisableImplicitMT();
auto file = TFile::Open("./dstarmb.root");
TTree *tree = nullptr;
file->GetObject<TTree>("h42", tree);
const auto time_0{std::chrono::steady_clock::now()};
const auto entries = tree->GetEntries();
for(auto i = 0; i < entries; ++i) {
tree->GetEntry(i);
}
const auto time_1{std::chrono::steady_clock::now()};
const std::chrono::duration<double> elapsed_seconds{time_1 - time_0};
std::cout << "Time Spend: " << elapsed_seconds.count() << " s." << "\n";
}
Result
MT: 0.402365 s
Seq: 0.175275 s