조금 더 빠른 졸업을 위해
#include <TThreadExecutor.h>
#include <iostream>
const UInt_t poolSize = 4U;
Int_t mtbb201_parallelHistoFill()
{
ROOT::EnableThreadSafety();
TH1::AddDirectory(false);
ROOT::TThreadExecutor pool(poolSize);
auto fillRandomHisto = [](int seed = 0) {
TRandom3 rndm(seed);
auto h = new TH1F("myHist", "Filled in parallel", 128, -8, 8);
for (auto i : ROOT::TSeqI(1000000)) {
h->Fill(rndm.Gaus(0, 1));
}
return h;
};
auto seeds = ROOT::TSeqI(23);
ROOT::ExecutorUtils::ReduceObjects<TH1F *> redfunc;
auto sumRandomHisto = pool.MapReduce(fillRandomHisto, seeds, redfunc);
auto c = new TCanvas();
sumRandomHisto->Draw();
return 0;
}#include <iostream>
using namespace std;
// The number of workers
const UInt_t nWorkers = 10U;
Int_t main() {
auto workItem = [](UInt_t workerID) {
for (int i = workerID; i < 1111; i += nWorkers) {
cout<<"worker["<<workerID<<"] : "<< i<<endl;
}
}
// Create the pool of workers
ROOT::TProcessExecutor workers(nWorkers);
// Fill the pool with work
workers.Map(workItem, ROOT::TSeqI(nWorkers));
FILE *fk = fopen("KILLME","r");
if(fk){
printf("KILLME file exist Bye \n");
gSystem->Exec("rm -f KILLME");
}
return 0;
}#include <iostream>
using namespace std;
Int_t main() {
// Total amount of numbers
const UInt_t nNumbers = 20000000U;
// The number of workers
const UInt_t nWorkers = 4U;
// We define our work item
auto workItem = [](UInt_t workerID) {
// One generator, file and ntuple per worker
TRandom3 workerRndm(workerID); // Change the seed
TFile f(Form("myFile_%u.root", workerID), "RECREATE");
TH1F h(Form("myHisto_%u", workerID), "The Histogram", 64, -4, 4);
for (UInt_t i = 0; i < nNumbers; ++i) {
h.Fill(workerRndm.Gaus());
}
h.Write();
return 0;
};
// Create the pool of workers
ROOT::TProcessExecutor workers(nWorkers);
// Fill the pool with work
workers.Map(workItem, ROOT::TSeqI(nWorkers));
}