Skip to content

Commit e6bbdb7

Browse files
committed
[RDF] Use a RAII to enable IMT as suggested in review.
1 parent b559b8d commit e6bbdb7

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

tree/dataframe/test/dataframe_snapshot.cxx

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ TEST_F(RDFSnapshotMT, Reshuffled_friends)
12841284
TEST(RDFSnapshotMore, ManyTasksPerThread)
12851285
{
12861286
const auto nSlots = 4u;
1287-
ROOT::EnableImplicitMT(nSlots);
1287+
TIMTEnabler imt(nSlots);
12881288
// make sure the file is not here beforehand
12891289
gSystem->Unlink("snapshot_manytasks_out.root");
12901290

@@ -1314,8 +1314,6 @@ TEST(RDFSnapshotMore, ManyTasksPerThread)
13141314
for (auto i = 0u; i < nInputFiles; ++i)
13151315
gSystem->Unlink((inputFilePrefix + std::to_string(i) + ".root").c_str());
13161316
gSystem->Unlink(outputFile);
1317-
1318-
ROOT::DisableImplicitMT();
13191317
}
13201318

13211319
void checkSnapshotArrayFileMT(RResultPtr<RInterface<RLoopManager>> &df, unsigned int kNEvents)
@@ -1333,35 +1331,31 @@ void checkSnapshotArrayFileMT(RResultPtr<RInterface<RLoopManager>> &df, unsigned
13331331

13341332
TEST_F(RDFSnapshotArrays, MultiThread)
13351333
{
1336-
ROOT::EnableImplicitMT(4);
1334+
TIMTEnabler imt(4);
13371335

13381336
RDataFrame tdf("arrayTree", kFileNames);
13391337
auto dt = tdf.Snapshot("outTree", "test_snapshotRVecoutMT.root",
13401338
{"fixedSizeArr", "size", "varSizeArr", "varSizeBoolArr", "fixedSizeBoolArr"});
13411339

13421340
checkSnapshotArrayFileMT(dt, kNEvents);
1343-
1344-
ROOT::DisableImplicitMT();
13451341
}
13461342

13471343
TEST_F(RDFSnapshotArrays, MultiThreadJitted)
13481344
{
1349-
ROOT::EnableImplicitMT(4);
1345+
TIMTEnabler imt(4);
13501346

13511347
RDataFrame tdf("arrayTree", kFileNames);
13521348
auto dj = tdf.Snapshot("outTree", "test_snapshotRVecoutMTJitted.root",
13531349
{"fixedSizeArr", "size", "varSizeArr", "varSizeBoolArr", "fixedSizeBoolArr"});
13541350

13551351
checkSnapshotArrayFileMT(dj, kNEvents);
1356-
1357-
ROOT::DisableImplicitMT();
13581352
}
13591353

13601354
TEST_F(RDFSnapshotArrays, RedefineArrayMT)
13611355
{
13621356
static constexpr unsigned int newArraySize = 6u;
13631357
static_assert(kFixedSize != newArraySize);
1364-
ROOT::EnableImplicitMT(3);
1358+
TIMTEnabler(3);
13651359

13661360
// More input files than threads, so output branches need to be bound to new inputs
13671361
std::vector<std::string> fileNames(kFileNames);
@@ -1383,7 +1377,6 @@ TEST_F(RDFSnapshotArrays, RedefineArrayMT)
13831377
},
13841378
{"fixedSizeArr"});
13851379

1386-
ROOT::DisableImplicitMT();
13871380
gSystem->Unlink("test_snapshotRVecRedefineArray.root");
13881381
}
13891382

@@ -1418,7 +1411,7 @@ TEST(RDFSnapshotMore, ColsWithCustomTitlesMT)
14181411
WriteColsWithCustomTitles(tname, fname);
14191412

14201413
// read and write test tree with RDF (in parallel)
1421-
ROOT::EnableImplicitMT(4);
1414+
TIMTEnabler imt(4);
14221415
RDataFrame d(tname, fname);
14231416
const std::string prefix = "snapshotted_";
14241417
auto res_tdf = d.Snapshot(tname, prefix + fname, {"i", "float", "arrint", "vararrint"});
@@ -1430,7 +1423,7 @@ TEST(RDFSnapshotMore, ColsWithCustomTitlesMT)
14301423
// clean-up
14311424
gSystem->Unlink(fname);
14321425
gSystem->Unlink((prefix + fname).c_str());
1433-
ROOT::DisableImplicitMT();
1426+
14341427
}
14351428

14361429
TEST(RDFSnapshotMore, TreeWithFriendsMT)
@@ -1440,7 +1433,7 @@ TEST(RDFSnapshotMore, TreeWithFriendsMT)
14401433
RDataFrame(10).Define("x", []() { return 42; }).Snapshot("t", fname1, {"x"});
14411434
RDataFrame(10).Define("x", []() { return 0; }).Snapshot("t", fname2, {"x"});
14421435

1443-
ROOT::EnableImplicitMT();
1436+
TIMTEnabler imt(0);
14441437

14451438
TFile file(fname1);
14461439
auto tree = file.Get<TTree>("t");
@@ -1454,7 +1447,6 @@ TEST(RDFSnapshotMore, TreeWithFriendsMT)
14541447
EXPECT_EQ(df_out->Max<int>("x").GetValue(), 42);
14551448
EXPECT_EQ(df_out->GetColumnNames(), std::vector<std::string>{"x"});
14561449

1457-
ROOT::DisableImplicitMT();
14581450
gSystem->Unlink(fname1);
14591451
gSystem->Unlink(fname2);
14601452
gSystem->Unlink(outfname);
@@ -1481,13 +1473,13 @@ TEST(RDFSnapshotMore, JittedSnapshotAndAliasedColumns)
14811473

14821474
TEST(RDFSnapshotMore, LazyNotTriggeredMT)
14831475
{
1484-
ROOT::EnableImplicitMT(4);
1476+
TIMTEnabler imt(4);
14851477
ROOT_EXPECT_WARNING(BookLazySnapshot(), "Snapshot",
14861478
"A lazy Snapshot action was booked but never triggered. The tree 't' in output file "
14871479
"'lazysnapshotnottriggered_shouldnotbecreated.root' was not created. "
14881480
"In case it was desired instead, remember to trigger the Snapshot operation, by "
14891481
"storing its result in a variable and for example calling the GetValue() method on it.");
1490-
ROOT::DisableImplicitMT();
1482+
14911483
}
14921484

14931485
TEST(RDFSnapshotMore, LazyTriggeredMT)
@@ -1504,7 +1496,7 @@ TEST(RDFSnapshotMore, EmptyBuffersMT)
15041496
const auto fname = "emptybuffersmt.root";
15051497
const auto treename = "t";
15061498
const unsigned int nslots = std::min(4U, std::thread::hardware_concurrency());
1507-
ROOT::EnableImplicitMT(nslots);
1499+
TIMTEnabler imt(nslots);
15081500
ROOT::RDataFrame d(10);
15091501
std::atomic_bool firstWorker{true};
15101502
auto dd = d.DefineSlot("x", [&](unsigned int) {
@@ -1527,15 +1519,13 @@ TEST(RDFSnapshotMore, EmptyBuffersMT)
15271519
EXPECT_EQ(t->GetListOfBranches()->GetEntries(), 1);
15281520
EXPECT_EQ(t->GetEntries(), Long64_t(passed));
15291521

1530-
ROOT::DisableImplicitMT();
15311522
gSystem->Unlink(fname);
15321523
}
15331524

15341525
TEST(RDFSnapshotMore, ReadWriteCarrayMT)
15351526
{
1536-
ROOT::EnableImplicitMT(4);
1527+
TIMTEnabler imt(4);
15371528
ReadWriteCarray("ReadWriteCarrayMT");
1538-
ROOT::DisableImplicitMT();
15391529
}
15401530

15411531
TEST(RDFSnapshotMore, TClonesArrayMT)
@@ -1605,12 +1595,10 @@ TEST(RDFSnapshotMore, SetMaxTreeSizeMT)
16051595
// Create an RDF from the previously snapshotted file, then Snapshot again
16061596
// with IMT enabled.
16071597
{
1608-
ROOT::EnableImplicitMT();
1598+
TIMTEnabler imt(0);
16091599

16101600
ROOT::RDataFrame df{"T", "rdfsnapshot_ttree_sequential_setmaxtreesize.root"};
16111601
df.Snapshot("T", "rdfsnapshot_imt_setmaxtreesize.root", {"x"});
1612-
1613-
ROOT::DisableImplicitMT();
16141602
}
16151603

16161604
// Check the file for data integrity.
@@ -1655,25 +1643,22 @@ TEST(RDFSnapshotMore, ZeroOutputEntriesMT)
16551643

16561644
TEST(RDFSnapshotMore, CustomBasketSizeMT)
16571645
{
1658-
ROOT::EnableImplicitMT();
1646+
TIMTEnabler imt(0);
16591647
TestCustomBasketSize();
1660-
ROOT::DisableImplicitMT();
16611648
}
16621649

16631650
// Test for default basket size
16641651
TEST(RDFSnapshotMore, DefaultBasketSizeMT)
16651652
{
1666-
ROOT::EnableImplicitMT();
1653+
TIMTEnabler imt(0);
16671654
TestDefaultBasketSize();
1668-
ROOT::DisableImplicitMT();
16691655
}
16701656

16711657
// Test for basket size preservation
16721658
TEST(RDFSnapshotMore, BasketSizePreservationMT)
16731659
{
1674-
ROOT::EnableImplicitMT();
1660+
TIMTEnabler imt(0);
16751661
TestBasketSizePreservation();
1676-
ROOT::DisableImplicitMT();
16771662
}
16781663

16791664
#endif // R__USE_IMT

0 commit comments

Comments
 (0)