Skip to content
Snippets Groups Projects
Commit 1bb34cdb authored by Tom Fischer's avatar Tom Fischer
Browse files

moved the following sources within the BaseLib folder into the namespace BaseLib:

- binarySearch
- class CPUTime
- class RunTime
- methods/functions from DateTools.{h,cpp}

changes in GeoLib and in SimpleTests folder results from changing the namespace
parent 1a30caa1
No related branches found
No related tags found
No related merge requests found
Showing
with 139 additions and 42 deletions
#include "CPUTimeTimer.h"
/*
* CPUTime.cpp
*
* Created on: May 10, 2012
* Author: TF
*/
void CPUTimeTimer::start()
#include "CPUTime.h"
namespace BaseLib {
void CPUTime::start()
{
_start = clock();
}
void CPUTimeTimer::stop()
void CPUTime::stop()
{
_stop = clock();
}
double CPUTimeTimer::elapsed()
double CPUTime::elapsed()
{
return (_stop-_start)/(double)(CLOCKS_PER_SEC);
}
} // end namespace BaseLib
#ifndef CPUTIMETIMER_H
#define CPUTIMETIMER_H
/*
* CPUTime.h
*
* Created on: May 10, 2012
* Author: TF
*/
#ifndef CPUTIME_H
#define CPUTIME_H
#include <ctime>
#include "TimeMeasurementBase.h"
class CPUTimeTimer
namespace BaseLib {
class CPUTime
{
public:
virtual void start();
virtual void stop();
virtual double elapsed();
~CPUTimeTimer() {};
virtual void start();
virtual void stop();
virtual double elapsed();
~CPUTime() {};
private:
clock_t _start;
clock_t _stop;
};
} // end namespace BaseLib
#endif
......@@ -10,6 +10,8 @@
#include <cmath>
#include <cstdlib>
namespace BaseLib {
double date2double(int y, int m, int d)
{
if ( (y<1000 || y>9999) || (m<1 || m>12) || (d<1 || d>31) )
......@@ -75,3 +77,5 @@ double xmlDate2double(const std::string &s)
}
return 0;
}
} // end namespace BaseLib
......@@ -9,6 +9,8 @@
#include "StringTools.h"
#include <string>
namespace BaseLib {
/**
* Converts three integers representing a date into a double.
* Note: It is not really checked if the date actually makes sense.
......@@ -39,4 +41,6 @@ double strDate2double(const std::string &s);
*/
double xmlDate2double(const std::string &s);
} // namespace BaseLib
#endif //DATETOOLS_H
#include "RunTimeTimer.h"
/*
* RunTime.cpp
*
* Created on: May 10, 2012
* Author: TF
*/
void RunTimeTimer::start()
#include "RunTime.h"
namespace BaseLib {
void RunTime::start()
{
#ifndef _WIN32
gettimeofday(&_start, 0);
......@@ -9,7 +18,7 @@ void RunTimeTimer::start()
#endif
}
void RunTimeTimer::stop()
void RunTime::stop()
{
#ifndef _WIN32
gettimeofday(&_stop, 0);
......@@ -18,7 +27,7 @@ void RunTimeTimer::stop()
#endif
}
double RunTimeTimer::elapsed()
double RunTime::elapsed()
{
#ifndef _WIN32
return (_stop.tv_sec + _stop.tv_usec/1000000.0 - (_start.tv_sec + _start.tv_usec/1000000.0));
......@@ -26,3 +35,5 @@ double RunTimeTimer::elapsed()
return (_stop - _start) / 1000;
#endif
}
} // end namespace BaseLib
#ifndef RUNTIMETIMER_H
#define RUNTIMETIMER_H
/*
* RunTime.h
*
* Created on: May 10, 2012
* Author: TF
*/
#ifndef RUNTIME_H
#define RUNTIME_H
#include "TimeMeasurementBase.h"
......@@ -11,13 +18,15 @@
#include "TimeMeasurementBase.h"
class RunTimeTimer : public TimeMeasurementBase
namespace BaseLib {
class RunTime : public TimeMeasurementBase
{
public:
virtual void start();
virtual void stop();
virtual double elapsed();
~RunTimeTimer() {};
~RunTime() {};
private:
#ifndef _WIN32
timeval _start;
......@@ -28,4 +37,6 @@ private:
#endif
};
} // end namespace BaseLib
#endif
......@@ -7,6 +7,8 @@
#include "binarySearch.h"
namespace BaseLib {
size_t searchElement (double const& val, size_t beg, size_t end, const std::vector<double>& array)
{
if (beg >= end) return std::numeric_limits<size_t>::max();
......@@ -20,3 +22,5 @@ size_t searchElement (double const& val, size_t beg, size_t end, const std::vect
}
return searchElement (val, m+1, end, array);
}
} // end namespace BaseLib
......@@ -13,6 +13,8 @@
#ifndef BINARYSEARCH_H_
#define BINARYSEARCH_H_
namespace BaseLib {
/**
* Binary search in a sorted vector of elements to get the
* id of an element according its key.
......@@ -40,4 +42,6 @@ size_t searchElement (const T& key, size_t beg, size_t end, const std::vector<T>
size_t searchElement (double const& val, size_t beg, size_t end, const std::vector<double>& array);
} // end namespace BaseLib
#endif /* BINARYSEARCH_H_ */
......@@ -308,7 +308,7 @@ StationBorehole* StationBorehole::createStation(const std::string &line)
borehole->_date = 0;
else
{
borehole->_date = strDate2double(fields.front());
borehole->_date = BaseLib::strDate2double(fields.front());
fields.pop_front();
}
}
......@@ -329,7 +329,7 @@ StationBorehole* StationBorehole::createStation(const std::string &name, double
(*station)[1] = y;
(*station)[2] = z;
station->_depth = depth;
if (date.compare("0000-00-00")) station->_date = xmlDate2double(date);
if (date.compare("0000-00-00")) station->_date = BaseLib::xmlDate2double(date);
return station;
}
......
......@@ -7,8 +7,8 @@
#include "LinAlg/Sparse/CRSMatrix.h"
#include "LinAlg/Sparse/CRSMatrixOpenMP.h"
#include "LinAlg/Sparse/CRSMatrixPThreads.h"
#include "RunTimeTimer.h"
#include "CPUTimeTimer.h"
#include "RunTime.h"
#include "CPUTime.h"
#include "logog.hpp"
#ifdef _OPENMP
......@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
unsigned *iA(NULL), *jA(NULL), n;
if (in) {
DBUG("reading matrix from %s ...", fname_mat.c_str());
RunTimeTimer timer;
BaseLib::RunTime timer;
timer.start();
CS_read(in, n, iA, jA, A);
timer.stop();
......@@ -69,8 +69,8 @@ int main(int argc, char *argv[])
x[k] = 1.0;
DBUG("matrix vector multiplication with Toms amuxCRS (%n threads) ...", n_threads);
RunTimeTimer run_timer;
CPUTimeTimer cpu_timer;
BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer;
run_timer.start();
cpu_timer.start();
for (size_t k(0); k<n_mults; k++) {
......
......@@ -8,9 +8,9 @@
#include <fstream>
#include <iostream>
// Base
#include "RunTimeTimer.h"
#include "CPUTimeTimer.h"
// BaseLib
#include "RunTime.h"
#include "CPUTime.h"
// MathLib
#include "LinAlg/Sparse/CRSMatrix.h"
......@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
if (verbose) {
std::cout << "reading matrix from " << fname_mat << " ... " << std::flush;
}
RunTimeTimer timer;
BaseLib::RunTime timer;
timer.start();
CS_read(in, n, iA, jA, A);
in.close();
......@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
rows_cols_to_erase[k] = (k+1)*2;
}
RunTimeTimer timer;
BaseLib::RunTime timer;
std::cout << "erasing " << n_rows_cols_to_erase << " rows and columns ... " << std::flush;
timer.start();
mat->eraseEntries(n_rows_cols_to_erase, rows_cols_to_erase);
......
......@@ -8,8 +8,8 @@
#include <cstdlib>
// BaseLib
#include "RunTimeTimer.h"
#include "CPUTimeTimer.h"
#include "RunTime.h"
#include "CPUTime.h"
// MathLib
#include "sparse.h"
......@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
if (verbose) {
std::cout << "reading matrix from " << fname_mat << " ... " << std::flush;
}
RunTimeTimer timer;
BaseLib::RunTime timer;
timer.start();
CS_read(in, n, iA, jA, A);
timer.stop();
......@@ -65,8 +65,8 @@ int main(int argc, char *argv[])
x[k] = 1.0;
// create time measurement objects
RunTimeTimer run_timer;
CPUTimeTimer cpu_timer;
BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer;
// calculate the nested dissection reordering
if (verbose) {
......
......@@ -8,8 +8,8 @@
#include <cstdlib>
// BaseLib
#include "RunTimeTimer.h"
#include "CPUTimeTimer.h"
#include "RunTime.h"
#include "CPUTime.h"
// MathLib
#include "sparse.h"
......@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
if (verbose) {
std::cout << "reading matrix from " << fname_mat << " ... " << std::flush;
}
RunTimeTimer timer;
BaseLib::RunTime timer;
timer.start();
CS_read(in, n, iA, jA, A);
timer.stop();
......@@ -67,8 +67,8 @@ int main(int argc, char *argv[])
x[k] = 1.0;
// create time measurement objects
RunTimeTimer run_timer;
CPUTimeTimer cpu_timer;
BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer;
// calculate the nested dissection reordering
if (verbose) {
......
......@@ -6,8 +6,8 @@
#include "LinAlg/Sparse/CRSMatrixDiagPrecond.h"
#include "sparse.h"
#include "vector_io.h"
#include "RunTimeTimer.h"
#include "CPUTimeTimer.h"
#include "RunTime.h"
#include "CPUTime.h"
#ifdef _OPENMP
#include <omp.h>
......@@ -59,8 +59,8 @@ int main(int argc, char *argv[])
double eps (1.0e-6);
unsigned steps (4000);
RunTimeTimer run_timer;
CPUTimeTimer cpu_timer;
BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer;
run_timer.start();
cpu_timer.start();
......
......@@ -6,8 +6,8 @@
#include "LinAlg/Sparse/CRSMatrixDiagPrecond.h"
#include "sparse.h"
#include "vector_io.h"
#include "RunTimeTimer.h"
#include "CPUTimeTimer.h"
#include "RunTime.h"
#include "CPUTime.h"
#ifdef _OPENMP
#include <omp.h>
......@@ -59,8 +59,8 @@ int main(int argc, char *argv[])
double eps (1.0e-6);
unsigned steps (4000);
RunTimeTimer run_timer;
CPUTimeTimer cpu_timer;
BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer;
run_timer.start();
cpu_timer.start();
......
......@@ -11,8 +11,8 @@
#include "LinAlg/Sparse/CRSMatrixDiagPrecond.h"
#include "sparse.h"
#include "vector_io.h"
#include "RunTimeTimer.h"
#include "CPUTimeTimer.h"
#include "RunTime.h"
#include "CPUTime.h"
int main(int argc, char *argv[])
{
......@@ -56,8 +56,8 @@ int main(int argc, char *argv[])
double eps(1.0e-6);
unsigned steps(4000);
RunTimeTimer run_timer;
CPUTimeTimer cpu_timer;
BaseLib::RunTime run_timer;
BaseLib::CPUTime cpu_timer;
run_timer.start();
cpu_timer.start();
......
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