Why the IMT spend more time than sequence mode?

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

Hi,

Welcome to the forum, and thanks for the interesting post.

Before diving into any investigation, could you make sure this is not a fluctuation? You can do that by running the sequential mode first and the parallelised after, by running the code several times to check the stability of the measurement…

Cheers,
Danilo

Hi,

Do you mean that put both codes into one file?
I ran the code about three times,and get the same results.
I guess the amount of data is small, thus parallel execution may not be as fast as sequential execution.

Best
Kun ZHU

That is of course one factor. It’s also true that setting up the thread pool also has some overhead. Without a profile, it’s hard to say for sure. However I still find the difference very small, especially since it’s in the subsecond range!

Thanks a lot,
D

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.