ATLAS Offline Software
Loading...
Searching...
No Matches
ParallelCallTest.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4#include <vector>
5// tbb/machine/gcc_generic.h has spurious trailing semicolons after
6// the clz() functiosn (as of TBB 2019 U1).
7#if defined(__GNUC__)
8# pragma GCC diagnostic push
9# pragma GCC diagnostic ignored "-Wpedantic"
10#endif
11#include "tbb/parallel_reduce.h"
12#include "tbb/blocked_range.h"
13#if defined(__GNUC__)
14# pragma GCC diagnostic pop
15#endif
17#include <unistd.h>
18#include <fcntl.h>
19#include <dlfcn.h>
20
21
22namespace {
23
24
25class RedirStderr
26{
27public:
28 RedirStderr();
29 ~RedirStderr();
30 RedirStderr (const RedirStderr&) = delete;
31 RedirStderr& operator= (const RedirStderr&) = delete;
32
33private:
34 int m_nullfd;
35 int m_stderr;
36};
37
38
39// Redirect stderr to /dev/null, remembering the original FD.
40RedirStderr::RedirStderr()
41{
42 if (dlsym (RTLD_DEFAULT, "__ubsan_handle_add_overflow") != NULL) {
43 m_nullfd = open ("/dev/null", O_WRONLY);
44 m_stderr = dup (2);
45 if (m_nullfd >= 0) {
46 dup2 (m_nullfd, 2);
47 }
48 }
49 else {
50 m_nullfd = m_stderr = -1;
51 }
52}
53
54
55// Restore stderr to its original FD.
56RedirStderr::~RedirStderr()
57{
58 if (m_stderr >= 0) {
59 dup2 (m_stderr, 2);
60 close (m_nullfd);
61 close (m_stderr);
62 }
63}
64
65
66} // anonymous namespace
67
68
69bool ParallelCallTest::run( size_t nrepeats ) {
70 firstCall();
71
72 return tbb::parallel_reduce( tbb::blocked_range<int>( 0, nrepeats, 1 ),
73 true, // initial value
74 [&]( tbb::blocked_range<int>, bool statusSoFar ) -> bool {
75 return callAndCompare() and statusSoFar;
76 },
77 []( bool allCallsStatus, bool thisCallStatus ) -> bool { // result accumulation
78 return allCallsStatus and thisCallStatus;
79 } );
80}
81
82
83bool ParallelCallTest::launchTests( size_t nrepeats, const std::vector<ParallelCallTest*>& tests ) {
84 // Suppress undefined behavior warning resulting from a tbb bug.
85 // /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'
86 //0x2aab14047b40: note: object has invalid vptr
87 // 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
88 // cf. https://github.com/RcppCore/RcppParallel/issues/36
89 RedirStderr redir;
90
91 //std::vector<ParallelCallTest*> tests( testList.begin(), testList.end() );
92 return tbb::parallel_reduce( tbb::blocked_range< std::vector<ParallelCallTest*>::const_iterator >( tests.begin(), tests.end() ),
93 true, // initial value
94 [&]( tbb::blocked_range< std::vector<ParallelCallTest*>::const_iterator > groupOfTests, bool statusSoFar ) -> bool {
95 bool success = true;
96 for ( auto test : groupOfTests ) {
97 success = test->run( nrepeats ) and success;
98 }
99 return statusSoFar and success;
100 },
101 []( bool allCallsStatus, bool thisCallStatus ) -> bool { // result accumulation
102 return allCallsStatus and thisCallStatus;
103 } );
104}
105
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