[dune-pdelab] [dune-pdelab-commit] dune-pdelab r2050 - in trunk: . dune/pdelab/common lib m4

Christian Engwer christian.engwer at uni-muenster.de
Wed May 23 14:06:39 CEST 2012


Hi Jö,

isn't this so fundamental functionality, that it should go into
dune-common?

Cheers
Christian

On Wed, May 23, 2012 at 01:51:42PM +0200, joe at conan.iwr.uni-heidelberg.de wrote:
> Author: joe
> Date: Wed May 23 13:51:42 2012
> New Revision: 2050
> URL: http://svn.dune-project.org/websvn/listing.php?repname=dune-pdelab&path=/&rev=2050&sc=1
> 
> Log:
> [clock] Functions to get wall time and process time and a class to store times
> with nanosecond resolution, as provided by modern systems.
> 
> Note: nanosecond resolution doesn't imply nanosecond accuracy...
> 
> Added:
>    trunk/dune/pdelab/common/clock.cc
>    trunk/dune/pdelab/common/clock.hh
>    trunk/lib/
>    trunk/lib/Makefile.am
> Modified:
>    trunk/Makefile.am
>    trunk/configure.ac
>    trunk/dune/pdelab/common/Makefile.am
>    trunk/m4/dune-pdelab.m4
> 
> Modified: trunk/Makefile.am
> ==============================================================================
> --- trunk/Makefile.am	Wed May 23 13:41:37 2012	(r2049)
> +++ trunk/Makefile.am	Wed May 23 13:51:42 2012	(r2050)
> @@ -7,7 +7,15 @@
>  # we need automake 1.5
>  AUTOMAKE_OPTIONS = foreign 1.5
>  
> -SUBDIRS = doc dune m4
> +# All subdirectories that must (or can) be handled before the library is built
> +SUBDIRS =					\
> +	doc					\
> +	dune					\
> +	m4
> +# The library subdirectory itself
> +SUBDIRS += lib
> +# All subdirectories that must (or can) be handled after the library is built
> +# none yet...
>  
>  # pass most important options when "make distcheck" is used
>  DISTCHECK_CONFIGURE_FLAGS = --with-dune=$(DUNEROOT) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" CC="$(CC)"
> 
> Modified: trunk/configure.ac
> ==============================================================================
> --- trunk/configure.ac	Wed May 23 13:41:37 2012	(r2049)
> +++ trunk/configure.ac	Wed May 23 13:51:42 2012	(r2050)
> @@ -55,6 +55,7 @@
>    dune/pdelab/newton/Makefile
>    dune/pdelab/stationary/Makefile
>    dune/pdelab/test/Makefile
> +  lib/Makefile
>    m4/Makefile
>    Makefile
>  ])
> 
> Modified: trunk/dune/pdelab/common/Makefile.am
> ==============================================================================
> --- trunk/dune/pdelab/common/Makefile.am	Wed May 23 13:41:37 2012	(r2049)
> +++ trunk/dune/pdelab/common/Makefile.am	Wed May 23 13:51:42 2012	(r2050)
> @@ -1,8 +1,9 @@
> -commondir = $(includedir)/dune/pdelab/common
>  SUBDIRS =                                       \
>  	typetree
>  
> +commondir = $(includedir)/dune/pdelab/common
>  common_HEADERS =				\
> +	clock.hh				\
>  	countingptr.hh				\
>  	cpstoragepolicy.hh			\
>  	crossproduct.hh				\
> @@ -17,4 +18,10 @@
>          typetraits.hh                           \
>  	vtkexport.hh
>  
> +noinst_LTLIBRARIES = libpdelabcommon.la
> +libpdelabcommon_la_SOURCES =			\
> +	clock.cc
> +libpdelabcommon_la_LIBADD =			\
> +	-lrt
> +
>  include $(top_srcdir)/am/global-rules
> 
> Added: trunk/dune/pdelab/common/clock.cc
> ==============================================================================
> --- /dev/null	00:00:00 1970	(empty, because file is newly added)
> +++ trunk/dune/pdelab/common/clock.cc	Wed May 23 13:51:42 2012	(r2050)
> @@ -0,0 +1,69 @@
> +// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
> +// vi: set et ts=8 sw=2 sts=2:
> +
> +//make sure clock_gettime is available
> +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE < 199309L
> +#undef _POSIX_C_SOURCE
> +#endif
> +#ifndef _POSIX_C_SOURCE
> +#define _POSIX_C_SOURCE 199309L
> +#endif
> +
> +#if HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <cerrno>
> +#include <iomanip>
> +#include <ostream>
> +#include <sstream>
> +#include <string>
> +
> +#include <sys/resource.h>
> +#include <sys/time.h>
> +#include <time.h>
> +
> +#include <dune/common/exceptions.hh>
> +
> +#include "clock.hh"
> +
> +namespace Dune {
> +  namespace PDELab {
> +
> +    std::ostream &operator<<(std::ostream &s, const TimeSpec &t) {
> +      std::ostringstream tmp;
> +      tmp << t.tv_sec << '.' << std::setfill('0') << std::setw(9) << t.tv_nsec;
> +      std::string tmpstr = tmp.str();
> +      if(s.precision() < 9)
> +        tmpstr.resize(tmpstr.size() - ( 9 - s.precision() ));
> +      if(s.precision() == 0)
> +        tmpstr.resize(tmpstr.size() - 1);
> +      s << tmpstr;
> +      return s;
> +    }
> +
> +    TimeSpec getWallTime() {
> +      timespec result;
> +      if(clock_gettime(CLOCK_REALTIME, &result) < 0)
> +        DUNE_THROW(ClockError, "clock_gettime(CLOCK_REALTIME, ...) failed: "
> +                   "errno = " << errno);
> +      TimeSpec tmp = { result.tv_sec, result.tv_nsec };
> +      return tmp;
> +    }
> +
> +    TimeSpec getProcessTime() {
> +      // Use clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...) even though that may
> +      // be problematic in the context of process migration between cores.  In
> +      // practice, it appears to still be far better then the next best
> +      // alternative, getrusage(), which will only update the clock every
> +      // jiffy.
> +      timespec result;
> +      if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &result) < 0)
> +        DUNE_THROW(ClockError, "clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...) "
> +                   "failed: errno = " << errno);
> +      TimeSpec tmp = { result.tv_sec, result.tv_nsec };
> +      return tmp;
> +    }
> +
> +  } // namespace PDELab
> +} // namespace Dune
> 
> Added: trunk/dune/pdelab/common/clock.hh
> ==============================================================================
> --- /dev/null	00:00:00 1970	(empty, because file is newly added)
> +++ trunk/dune/pdelab/common/clock.hh	Wed May 23 13:51:42 2012	(r2050)
> @@ -0,0 +1,72 @@
> +// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
> +// vi: set et ts=8 sw=2 sts=2:
> +
> +#ifndef DUNE_PDELAB_COMMON_CLOCK_HH
> +#define DUNE_PDELAB_COMMON_CLOCK_HH
> +
> +#include <ostream>
> +
> +#include <sys/types.h>
> +
> +#include <dune/common/exceptions.hh>
> +
> +namespace Dune {
> +  namespace PDELab {
> +
> +    //! struct to store temporal values
> +    struct TimeSpec {
> +      //! seconds part
> +      time_t tv_sec;
> +      //! nanoseconds part
> +      /**
> +       * \note 0 <= tv_nsec < 1e9 should always hold.
> +       */
> +      long tv_nsec;
> +
> +      inline TimeSpec &operator+=(const TimeSpec &o) {
> +        tv_sec += o.tv_sec;
> +        tv_nsec += o.tv_nsec;
> +        if(tv_nsec >= 1000000000L) {
> +          ++tv_sec;
> +          tv_nsec -= 1000000000L;
> +        }
> +        return *this;
> +      }
> +      inline TimeSpec operator+(const TimeSpec &o) const {
> +        TimeSpec tmp(*this);
> +        tmp += o;
> +        return tmp;
> +      }
> +      inline TimeSpec &operator-=(const TimeSpec &o) {
> +        tv_sec -= o.tv_sec;
> +        tv_nsec -= o.tv_nsec;
> +        if(tv_nsec < 0L) {
> +          --tv_sec;
> +          tv_nsec += 1000000000L;
> +        }
> +        return *this;
> +      }
> +      inline TimeSpec operator-(const TimeSpec &o) const {
> +        TimeSpec tmp(*this);
> +        tmp -= o;
> +        return tmp;
> +      }
> +
> +    };
> +
> +    //! insert a timespec into an output stream
> +    std::ostream &operator<<(std::ostream &s, const TimeSpec &t);
> +
> +    //! exception thrown by clock functions
> +    struct ClockError : Exception {};
> +
> +    //! get the wall time in seconds since the epoch
> +    TimeSpec getWallTime();
> +    //! get the cpu time in seconds used by the current process
> +    TimeSpec getProcessTime();
> +
> +  } // namespace PDELab
> +} //namespace Dune
> +
> +#endif // DUNE_PDELAB_COMMON_CLOCK_HH
> +
> 
> Added: trunk/lib/Makefile.am
> ==============================================================================
> --- /dev/null	00:00:00 1970	(empty, because file is newly added)
> +++ trunk/lib/Makefile.am	Wed May 23 13:51:42 2012	(r2050)
> @@ -0,0 +1,12 @@
> +#the dune-pdelab library
> +lib_LTLIBRARIES = libdunepdelab.la
> +
> +# this is just a renaming of libpdelabcommon to prevent name clashes
> +libdunepdelab_la_SOURCES =
> +# This forces automake to use the C++ linker
> +# (see the automake manual, section "Libtool Convenience Libraries")
> +nodist_EXTRA_libdunepdelab_la_SOURCES = dummy.cc
> +sourcescheck_DUMMY = dummy.cc
> +libdunepdelab_la_LIBADD = ../dune/pdelab/common/libpdelabcommon.la
> +
> +include $(top_srcdir)/am/global-rules
> 
> Modified: trunk/m4/dune-pdelab.m4
> ==============================================================================
> --- trunk/m4/dune-pdelab.m4	Wed May 23 13:41:37 2012	(r2049)
> +++ trunk/m4/dune-pdelab.m4	Wed May 23 13:51:42 2012	(r2050)
> @@ -11,5 +11,7 @@
>  # Additional checks needed to find the module
>  AC_DEFUN([DUNE_PDELAB_CHECK_MODULE],[
>    AC_MSG_NOTICE([Searching for dune-pdelab...])
> -  DUNE_CHECK_MODULES([dune-pdelab], [pdelab/common/function.hh])
> +  DUNE_CHECK_MODULES([dune-pdelab], [pdelab/common/clock.hh],[dnl
> +    return Dune::PDELab::getWallTime().tv_sec;
> +  ])
>  ])
> 
> _______________________________________________
> dune-pdelab-commit mailing list
> dune-pdelab-commit at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-pdelab-commit
> 




More information about the dune-pdelab mailing list