Skip to content

Commit eadf870

Browse files
author
Roberto Di Remigio
committed
Both logger and timer can be disabled. Useful when linking to host programs
1 parent 1791f9a commit eadf870

File tree

9 files changed

+68
-43
lines changed

9 files changed

+68
-43
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ option(ENABLE_EIGEN_MKL "Enable Eigen3 automatic fallback to some of Inte
2323
option(ENABLE_64BIT_INTEGERS "Enable 64-bit integers" OFF)
2424
option(ENABLE_CXX11_SUPPORT "Enable C++11 compiler support" ON)
2525
# Developers only options
26-
option(ENABLE_LOGGER "Enables logger: needs C++11 support" ON)
26+
option(ENABLE_LOGGER "Enable logger: needs C++11 support" ON)
27+
option(ENABLE_TIMER "Enable timer" ON)
2728
#
2829
# CMake modules
2930
#

cmake/ConfigBoost.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Just change the Boost version number here
22
# The version of the Boost archive we ship
3-
set(BOOSTVER 1.54.0)
3+
set(BOOSTVER 1.54.0)
44
# The minimum required version of Boost
5-
set(BOOSTVERMIN 1.54.0)
5+
set(BOOSTVERMIN 1.54.0)
66
if (NOT DEFINED BUILD_CUSTOM_BOOST)
77
set(BUILD_CUSTOM_BOOST FALSE)
88
endif()
@@ -34,10 +34,10 @@ if(NOT Boost_FOUND)
3434
set(Boost_LIBRARIES "")
3535
# Read documentation in FindBoost.cmake for the difference between the singular and plural forms
3636
set(Boost_INCLUDE_DIR ${CUSTOM_BOOST_LOCATION}/include)
37-
set(Boost_INCLUDE_DIRS ${CUSTOM_BOOST_LOCATION}/include)
37+
set(Boost_INCLUDE_DIRS ${CUSTOM_BOOST_LOCATION}/include)
3838
set(Boost_LIBRARY_DIR ${CUSTOM_BOOST_LOCATION}/lib)
3939
set(Boost_LIBRARY_DIRS ${CUSTOM_BOOST_LOCATION}/lib)
40-
# We will link statically, so just set the Boost_<C>_LIBRARY for the static library
40+
# We will link statically, so just set the Boost_<C>_LIBRARY for the static library
4141
foreach(_component ${needed_components})
4242
string(TOUPPER ${_component} _COMP)
4343
set(Boost_${_COMP}_FOUND TRUE)

src/cavity/GePolCavity.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
/*
33
* PCMSolver, an API for the Polarizable Continuum Model
44
* Copyright (C) 2013 Roberto Di Remigio, Luca Frediani and contributors
5-
*
5+
*
66
* This file is part of PCMSolver.
7-
*
8-
* PCMSolver is free software: you can redistribute it and/or modify
7+
*
8+
* PCMSolver is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
1010
* the Free Software Foundation, either version 3 of the License, or
1111
* (at your option) any later version.
12-
*
12+
*
1313
* PCMSolver is distributed in the hope that it will be useful,
1414
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
* GNU Lesser General Public License for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20-
*
20+
*
2121
* For information on the complete list of contributors to the
2222
* PCMSolver API, see: <http://pcmsolver.github.io/pcmsolver-doc>
2323
*/
@@ -37,6 +37,7 @@
3737

3838
#include "Sphere.hpp"
3939
#include "Symmetry.hpp"
40+
#include "TimerInterface.hpp"
4041

4142
extern "C" void generatecavity_cpp(int * maxts, int * maxsph, int * maxvert,
4243
double * xtscor, double * ytscor, double * ztscor, double * ar,
@@ -97,7 +98,7 @@ void GePolCavity::build(int maxts, int maxsph, int maxvert)
9798
double * ze = zv.data();
9899

99100
double * rin = radii_scratch.data();
100-
double * mass = new double[molecule_.nAtoms()];
101+
double * mass = new double[molecule_.nAtoms()];
101102
for (int i = 0; i < molecule_.nAtoms(); ++i) {
102103
mass[i] = molecule_.masses(i);
103104
}
@@ -110,14 +111,14 @@ void GePolCavity::build(int maxts, int maxsph, int maxvert)
110111
int gen3 = molecule_.pointGroup().generators(2);
111112

112113
// Go PEDRA, Go!
113-
timerON("GePolCavity::generatecavity_cpp");
114+
TIMER_ON("GePolCavity::generatecavity_cpp");
114115
generatecavity_cpp(&maxts, &maxsph, &maxvert,
115116
xtscor, ytscor, ztscor, ar, xsphcor, ysphcor, zsphcor, rsph,
116117
&nts, &ntsirr, &nSpheres_, &addedSpheres,
117118
xe, ye, ze, rin, mass,
118119
&averageArea, &probeRadius, &minimalRadius,
119120
&nr_gen, &gen1, &gen2, &gen3);
120-
timerOFF("GePolCavity::generatecavity_cpp");
121+
TIMER_OFF("GePolCavity::generatecavity_cpp");
121122

122123
// The "intensive" part of updating the spheres related class data members will be of course
123124
// executed iff addedSpheres != 0

src/cavity/GePolCavity.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
/*
33
* PCMSolver, an API for the Polarizable Continuum Model
44
* Copyright (C) 2013 Roberto Di Remigio, Luca Frediani and contributors
5-
*
5+
*
66
* This file is part of PCMSolver.
7-
*
8-
* PCMSolver is free software: you can redistribute it and/or modify
7+
*
8+
* PCMSolver is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
1010
* the Free Software Foundation, either version 3 of the License, or
1111
* (at your option) any later version.
12-
*
12+
*
1313
* PCMSolver is distributed in the hope that it will be useful,
1414
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
* GNU Lesser General Public License for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20-
*
20+
*
2121
* For information on the complete list of contributors to the
2222
* PCMSolver API, see: <http://pcmsolver.github.io/pcmsolver-doc>
2323
*/
@@ -37,7 +37,7 @@
3737
#include "Cavity.hpp"
3838
#include "CavityData.hpp"
3939
#include "CavityFactory.hpp"
40-
#include "Timer.hpp"
40+
#include "TimerInterface.hpp"
4141

4242
/*! \file GePolCavity.hpp
4343
* \class GePolCavity
@@ -54,20 +54,20 @@ class GePolCavity : public Cavity
5454
public:
5555
GePolCavity() {}
5656
GePolCavity(const Molecule & molec, double a, double pr, double minR) :
57-
Cavity(molec), averageArea(a), probeRadius(pr), minimalRadius(minR)
58-
{
57+
Cavity(molec), averageArea(a), probeRadius(pr), minimalRadius(minR)
58+
{
5959
std::string checkpointName = "GePolCavity::build";
60-
timerON(checkpointName);
61-
build(10000, 200, 25000);
62-
timerOFF(checkpointName);
60+
TIMER_ON(checkpointName);
61+
build(10000, 200, 25000);
62+
TIMER_OFF(checkpointName);
6363
}
6464
GePolCavity(const std::vector<Sphere> & sph, double a, double pr, double minR) :
6565
Cavity(sph), averageArea(a), probeRadius(pr), minimalRadius(minR)
66-
{
66+
{
6767
std::string checkpointName = "GePolCavity::build";
68-
timerON(checkpointName);
69-
build(10000, 200, 25000);
70-
timerOFF(checkpointName);
68+
TIMER_ON(checkpointName);
69+
build(10000, 200, 25000);
70+
TIMER_OFF(checkpointName);
7171
}
7272
virtual ~GePolCavity() {}
7373
friend std::ostream & operator<<(std::ostream & os, GePolCavity & cavity) {

src/interface/Interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ extern "C" void tear_down_pcm()
109109
extern "C" void write_timings()
110110
{
111111
// Print out timings to pcmsolver.timer.dat
112-
timerDONE("pcmsolver.timer.dat");
112+
TIMER_DONE("pcmsolver.timer.dat");
113113
}
114114

115115
extern "C" void compute_asc(char * potString, char * chgString, int * irrep)

src/utils/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ list(SORT headers_list)
88
set(to_includer "${headers_list}")
99
# Write headers to Includer.hpp
1010
file(APPEND "${PROJECT_BINARY_DIR}/include/Includer.hpp" "// Helper classes\n")
11-
list(REMOVE_ITEM to_includer "BuildInfo.hpp" "cnpy.hpp" "Logger.hpp" "LoggerImpl.hpp" "LoggerInterface.hpp" "TestingMolecules.hpp")
11+
list(REMOVE_ITEM to_includer "BuildInfo.hpp" "cnpy.hpp" "Logger.hpp" "LoggerImpl.hpp" "LoggerInterface.hpp" "TestingMolecules.hpp" "Timer.hpp")
1212
write_to_Includer("${to_includer}")
1313

1414
set(sources_list "")

src/utils/LoggerInterface.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef LOGGERINTERFACE_HPP
22
#define LOGGERINTERFACE_HPP
33

4-
#ifdef HAS_CXX11
4+
#ifdef ENABLE_LOGGER
55

66
#include "Logger.hpp"
77
#include "Timer.hpp"
@@ -11,15 +11,15 @@ static logging::logger<logging::FileLogPolicy> loggerInstance("pcmsolver.executi
1111
#define LOG loggerInstance.print<logging::printLevel::coarse>
1212
#define LOG_FINE loggerInstance.print<logging::printLevel::fine>
1313
#define LOG_ALL loggerInstance.print<logging::printLevel::everything>
14-
#define LOG_TIME loggerInstance.print<logging::printLevel::timings>(Timer::TheTimer());
14+
#define LOG_TIME loggerInstance.print<logging::printLevel::timings>(timer::Timer::TheTimer());
1515

16-
#else // HAS_CXX11
16+
#else // ENABLE_LOGGER
1717

1818
#define LOG(...)
1919
#define LOG_FINE(...)
2020
#define LOG_ALL(...)
2121
#define LOG_TIME
2222

23-
#endif // HAS_CXX11
23+
#endif // ENABLE_LOGGER
2424

2525
#endif // LOGGERINTERFACE_HPP

src/utils/Timer.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <boost/foreach.hpp>
3737
#include <boost/timer/timer.hpp>
3838

39+
namespace timer {
3940
typedef std::map<std::string, boost::timer::cpu_timer> timersMap;
4041
typedef std::pair<std::string, boost::timer::cpu_timer> timersPair;
4142

@@ -48,13 +49,6 @@ typedef std::pair<std::string, boost::timer::cpu_times> timingsPair;
4849
* \author Roberto Di Remigio
4950
* \date 2014
5051
*
51-
* To time a code snippet:
52-
* \code{.cpp}
53-
* timerON("code-snippet");
54-
* // code-snippet
55-
* timerOFF("code-snippet");
56-
* \endcode
57-
* The timings are printed out by a call to the timerDONE function.
5852
*/
5953

6054
class Timer
@@ -163,5 +157,6 @@ inline void timerDONE(const std::string & fname)
163157
timing_report << Timer::TheTimer() << std::endl;
164158
timing_report.close();
165159
}
160+
} // namespace timer
166161

167162
#endif // TIMER_HPP

src/utils/TimerInterface.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef TIMERINTERFACE_HPP
2+
#define TIMERINTERFACE_HPP
3+
4+
/* To time a code snippet:
5+
* \code{.cpp}
6+
* TIMER_ON("code-snippet");
7+
* // code-snippet
8+
* TIMER_OFF("code-snippet");
9+
* \endcode
10+
* The timings are printed out by a call to the TIMER_DONE function.
11+
*/
12+
#ifdef ENABLE_TIMER
13+
14+
#include "Timer.hpp"
15+
16+
#define TIMER_ON timer::timerON
17+
#define TIMER_OFF timer::timerOFF
18+
#define TIMER_DONE timer::timerDONE
19+
20+
#else // ENABLE_TIMER
21+
22+
#define TIMER_ON(...)
23+
#define TIMER_OFF(...)
24+
#define TIMER_DONE(...)
25+
26+
#endif // ENABLE_TIMER
27+
28+
#endif // TIMERINTERFACE_HPP

0 commit comments

Comments
 (0)