ATLAS Offline Software
PerfMonTestMallocAlg.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // PerfMonTestMallocAlg.cxx
8 // Implementation file for class PerfMonTest::MallocAlg
9 // Author: S.Binet<binet@cern.ch>
11 
12 
13 // STL includes
14 #include <vector>
15 
16 // FrameWork includes
17 #include "Gaudi/Property.h"
18 
19 // CLHEP includes
20 #include "CLHEP/Units/SystemOfUnits.h"
21 #include "CLHEP/Random/RandGauss.h"
22 
23 // PerfMonTests includes
24 #include "PerfMonTestMallocAlg.h"
25 
26 using namespace PerfMonTest;
27 
29 // Public methods:
31 
32 // Constructors
34 MallocAlg::MallocAlg( const std::string& name,
35  ISvcLocator* pSvcLocator ) :
36  AthAlgorithm( name, pSvcLocator )
37 {
38  //
39  // Property declaration
40  //
41  //declareProperty( "Property", m_nProperty );
42 
43  declareProperty( "EvtNbr",
44  m_evtNbr = 10,
45  "event number at which to actually do stuff" );
46 
47  declareProperty( "UseStdVector",
48  m_useStdVector = false,
49  "switch between using a C-array and a std::vector");
50 }
51 
52 // Destructor
55 {
56  ATH_MSG_DEBUG ( "Calling destructor" ) ;
57 }
58 
59 // Athena Algorithm's Hooks
62 {
63  ATH_MSG_INFO ( "Initializing " << name() << "..." ) ;
64 
65  return StatusCode::SUCCESS;
66 }
67 
69 {
70  ATH_MSG_INFO ( "Finalizing " << name() << "..." ) ;
71 
72  return StatusCode::SUCCESS;
73 }
74 
76 {
77  ATH_MSG_DEBUG ( "Executing " << name() << "..." ) ;
78 
80 
81  //typedef int ElemType;
82  typedef float ElemType;
83 
84  if ( m_currentEvtNbr >= m_evtNbr ) {
85  const std::size_t nmax = 1024*1024;
86 
87  if (m_useStdVector) {
88  std::vector<ElemType> c1_array(nmax);
89  for ( std::size_t i = 0; i!=nmax; ++i ) {
90  c1_array[i] = i;
91  }
92 
93  if ( m_currentEvtNbr >= 2*m_evtNbr ) {
94  std::vector<ElemType> c2_array(nmax);
95  for ( std::size_t i = 0; i!=nmax; ++i ) {
96  c2_array[i] = -1*static_cast<int>(i);
97  }
98  }
99 
100  } else {
101  ElemType c1_array[nmax];
102  for ( std::size_t i = 0; i!=nmax; ++i ) {
103  c1_array[i] = i;
104  }
105  isUsed (&c1_array);
106 
107  if ( m_currentEvtNbr >= 2*m_evtNbr ) {
108  ElemType c2_array[nmax];
109  for ( std::size_t i = 0; i!=nmax; ++i ) {
110  c2_array[i] = -1*static_cast<int>(i);
111  }
112  // dummy stuff to silence gcc-warning.
113  if (c2_array[0] > c1_array[0]) {
114  c2_array[0] = c1_array[0];
115  }
116  }
117  }
118  }
119 
120  return StatusCode::SUCCESS;
121 }
PerfMonTest::MallocAlg::m_currentEvtNbr
unsigned int m_currentEvtNbr
current event number
Definition: PerfMonTestMallocAlg.h:71
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PerfMonTest::MallocAlg::initialize
virtual StatusCode initialize()
Definition: PerfMonTestMallocAlg.cxx:61
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PerfMonTestMallocAlg.h
PerfMonTest::MallocAlg::MallocAlg
MallocAlg()
Default constructor:
PerfMonTest::MallocAlg::execute
virtual StatusCode execute()
Definition: PerfMonTestMallocAlg.cxx:75
PerfMonTest::MallocAlg::m_evtNbr
unsigned int m_evtNbr
event number at which to actually do stuff
Definition: PerfMonTestMallocAlg.h:68
lumiFormat.i
int i
Definition: lumiFormat.py:85
PerfMonTest::MallocAlg::isUsed
virtual void isUsed(const void *)
Definition: PerfMonTestMallocAlg.h:62
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PerfMonTest::MallocAlg::~MallocAlg
virtual ~MallocAlg()
Destructor:
Definition: PerfMonTestMallocAlg.cxx:54
PerfMonTest
PerfMonTestPolyVectorAlg.h Example for the memory optimization tutorial.
Definition: Control/PerformanceMonitoring/PerfMonTests/src/Hit.h:7
PerfMonTest::MallocAlg::m_useStdVector
bool m_useStdVector
switch between using a C-array and a std::vector
Definition: PerfMonTestMallocAlg.h:74
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
PerfMonTest::MallocAlg::finalize
virtual StatusCode finalize()
Definition: PerfMonTestMallocAlg.cxx:68
nmax
const int nmax(200)