Skip to content
Snippets Groups Projects
Commit dcfc7601 authored by Enrico Guiraud's avatar Enrico Guiraud Committed by Danilo Piparo
Browse files

[DF] Add test for Define+nested parallelism

parent cc0b8b19
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,10 @@ ROOT_ADD_GTEST(dataframe_leaves dataframe_leaves.cxx LIBRARIES ROOTDataFrame) ...@@ -18,6 +18,10 @@ ROOT_ADD_GTEST(dataframe_leaves dataframe_leaves.cxx LIBRARIES ROOTDataFrame)
ROOT_ADD_GTEST(dataframe_vecops dataframe_vecops.cxx LIBRARIES ROOTDataFrame) ROOT_ADD_GTEST(dataframe_vecops dataframe_vecops.cxx LIBRARIES ROOTDataFrame)
ROOT_ADD_GTEST(dataframe_resptr dataframe_resptr.cxx LIBRARIES ROOTDataFrame) ROOT_ADD_GTEST(dataframe_resptr dataframe_resptr.cxx LIBRARIES ROOTDataFrame)
if (imt)
ROOT_ADD_GTEST(dataframe_concurrency dataframe_concurrency.cxx LIBRARIES ROOTDataFrame)
endif()
ROOT_ADD_GTEST(datasource_more datasource_more.cxx LIBRARIES ROOTDataFrame) ROOT_ADD_GTEST(datasource_more datasource_more.cxx LIBRARIES ROOTDataFrame)
#ROOT_ADD_GTEST(datasource_root datasource_root.cxx LIBRARIES ROOTDataFrame) #ROOT_ADD_GTEST(datasource_root datasource_root.cxx LIBRARIES ROOTDataFrame)
ROOT_ADD_GTEST(datasource_trivial datasource_trivial.cxx LIBRARIES ROOTDataFrame) ROOT_ADD_GTEST(datasource_trivial datasource_trivial.cxx LIBRARIES ROOTDataFrame)
......
#include <ROOT/RDataFrame.hxx>
#include <ROOT/TThreadExecutor.hxx>
#include <atomic>
#include <chrono>
#include <thread>
#include "gtest/gtest.h"
#ifdef R__USE_IMT
TEST(RDFConcurrency, NestedParallelismBetweenDefineCalls)
{
ROOT::EnableImplicitMT();
// this Define will return unique values from 0 to nEntries - 1 (over all threads)
const auto nEntries = 100000u;
std::atomic_int i(0);
auto df = ROOT::RDataFrame(nEntries).Define("i", [&] { return i++; });
// this lambda will be used to introduce nested parallelism via a dummy Filter
auto manysleeps = [&] {
ROOT::TThreadExecutor().Foreach(
[] { std::this_thread::sleep_for(std::chrono::milliseconds(std::rand() / RAND_MAX * 200)); }, 8);
return true;
};
// first Take triggers the computation of i, then the Filter executes, then Take accesses the cached value of i
// hopefully it won't have changed in the meanwhile!
auto res1 = df.Take<int>("i");
auto res2 = df.Filter(manysleeps).Take<int>("i");
// check both Takes return vectors with all numbers from 0 to nEntries - 1
auto checkAllNumbersAreThere = [](std::vector<int> &vec) {
std::sort(vec.begin(), vec.end());
const int s = vec.size();
for (auto i = 0; i < s; ++i)
EXPECT_EQ(vec[i], i);
};
checkAllNumbersAreThere(*res1);
checkAllNumbersAreThere(*res2);
ROOT::DisableImplicitMT();
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment