ATLAS Offline Software
Loading...
Searching...
No Matches
ParallelCallTest.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include <vector>
5#include "tbb/parallel_reduce.h"
6#include "tbb/blocked_range.h"
8#include <unistd.h>
9#include <fcntl.h>
10#include <dlfcn.h>
11
12
13namespace {
14
15
16class RedirStderr
17{
18public:
19 RedirStderr();
20 ~RedirStderr();
21 RedirStderr (const RedirStderr&) = delete;
22 RedirStderr& operator= (const RedirStderr&) = delete;
23
24private:
25 int m_nullfd;
26 int m_stderr;
27};
28
29
30// Redirect stderr to /dev/null, remembering the original FD.
31RedirStderr::RedirStderr()
32{
33 if (dlsym (RTLD_DEFAULT, "__ubsan_handle_add_overflow") != NULL) {
34 m_nullfd = open ("/dev/null", O_WRONLY);
35 m_stderr = dup (2);
36 if (m_nullfd >= 0) {
37 dup2 (m_nullfd, 2);
38 }
39 }
40 else {
41 m_nullfd = m_stderr = -1;
42 }
43}
44
45
46// Restore stderr to its original FD.
47RedirStderr::~RedirStderr()
48{
49 if (m_stderr >= 0) {
50 dup2 (m_stderr, 2);
51 close (m_nullfd);
52 close (m_stderr);
53 }
54}
55
56
57} // anonymous namespace
58
59
60bool ParallelCallTest::run( size_t nrepeats ) {
61 firstCall();
62
63 return tbb::parallel_reduce( tbb::blocked_range<int>( 0, nrepeats, 1 ),
64 true, // initial value
65 [&]( tbb::blocked_range<int>, bool statusSoFar ) -> bool {
66 return callAndCompare() and statusSoFar;
67 },
68 []( bool allCallsStatus, bool thisCallStatus ) -> bool { // result accumulation
69 return allCallsStatus and thisCallStatus;
70 } );
71}
72
73
74bool ParallelCallTest::launchTests( size_t nrepeats, const std::vector<ParallelCallTest*>& tests ) {
75 // Suppress undefined behavior warning resulting from a tbb bug.
76 // /cvmfs/atlas-nightlies.cern.ch/repo/sw/master/sw/lcg/releases/LCG_88/tbb/44_20160413/x86_64-slc6-gcc62-dbg/include/tbb/parallel_reduce.h:177:32: runtime error: member call on address 0x2aab14047b40 which does not point to an object of type 'task'
77 //0x2aab14047b40: note: object has invalid vptr
78 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0
79 // cf. https://github.com/RcppCore/RcppParallel/issues/36
80 RedirStderr redir;
81
82 //std::vector<ParallelCallTest*> tests( testList.begin(), testList.end() );
83 return tbb::parallel_reduce( tbb::blocked_range< std::vector<ParallelCallTest*>::const_iterator >( tests.begin(), tests.end() ),
84 true, // initial value
85 [&]( tbb::blocked_range< std::vector<ParallelCallTest*>::const_iterator > groupOfTests, bool statusSoFar ) -> bool {
86 bool success = true;
87 for ( auto test : groupOfTests ) {
88 success = test->run( nrepeats ) and success;
89 }
90 return statusSoFar and success;
91 },
92 []( bool allCallsStatus, bool thisCallStatus ) -> bool { // result accumulation
93 return allCallsStatus and thisCallStatus;
94 } );
95}
96
bool run(size_t nrepeats)
runs the stress test by invoking it the firstCall and then repetitively the callAndCompare
virtual bool callAndCompare() const =0
a function that performs request, and compares the results obtained with the result of the first exec...
virtual void firstCall()=0
a method that will be called to obtain first results from the service It should set the reference qua...
static bool launchTests(size_t nrepeats, const std::vector< ParallelCallTest * > &tests)
Method to run launch number of tests in parallel (increasing the stress of the calle) It has a potent...
@ open
Definition BinningType.h:40