Home | History | Annotate | Line # | Download | only in posix
time.c revision 1.1.1.1.4.2
      1  1.1.1.1.4.2  yamt /* Copyright (C) 2005, 2009 Free Software Foundation, Inc.
      2  1.1.1.1.4.2  yamt    Contributed by Richard Henderson <rth (at) redhat.com>.
      3  1.1.1.1.4.2  yamt 
      4  1.1.1.1.4.2  yamt    This file is part of the GNU OpenMP Library (libgomp).
      5  1.1.1.1.4.2  yamt 
      6  1.1.1.1.4.2  yamt    Libgomp is free software; you can redistribute it and/or modify it
      7  1.1.1.1.4.2  yamt    under the terms of the GNU General Public License as published by
      8  1.1.1.1.4.2  yamt    the Free Software Foundation; either version 3, or (at your option)
      9  1.1.1.1.4.2  yamt    any later version.
     10  1.1.1.1.4.2  yamt 
     11  1.1.1.1.4.2  yamt    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
     12  1.1.1.1.4.2  yamt    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     13  1.1.1.1.4.2  yamt    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
     14  1.1.1.1.4.2  yamt    more details.
     15  1.1.1.1.4.2  yamt 
     16  1.1.1.1.4.2  yamt    Under Section 7 of GPL version 3, you are granted additional
     17  1.1.1.1.4.2  yamt    permissions described in the GCC Runtime Library Exception, version
     18  1.1.1.1.4.2  yamt    3.1, as published by the Free Software Foundation.
     19  1.1.1.1.4.2  yamt 
     20  1.1.1.1.4.2  yamt    You should have received a copy of the GNU General Public License and
     21  1.1.1.1.4.2  yamt    a copy of the GCC Runtime Library Exception along with this program;
     22  1.1.1.1.4.2  yamt    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23  1.1.1.1.4.2  yamt    <http://www.gnu.org/licenses/>.  */
     24  1.1.1.1.4.2  yamt 
     25  1.1.1.1.4.2  yamt /* This file contains system specific timer routines.  It is expected that
     26  1.1.1.1.4.2  yamt    a system may well want to write special versions of each of these.
     27  1.1.1.1.4.2  yamt 
     28  1.1.1.1.4.2  yamt    The following implementation uses the most simple POSIX routines.
     29  1.1.1.1.4.2  yamt    If present, POSIX 4 clocks should be used instead.  */
     30  1.1.1.1.4.2  yamt 
     31  1.1.1.1.4.2  yamt #include "libgomp.h"
     32  1.1.1.1.4.2  yamt #include <unistd.h>
     33  1.1.1.1.4.2  yamt #if TIME_WITH_SYS_TIME
     34  1.1.1.1.4.2  yamt # include <sys/time.h>
     35  1.1.1.1.4.2  yamt # include <time.h>
     36  1.1.1.1.4.2  yamt #else
     37  1.1.1.1.4.2  yamt # if HAVE_SYS_TIME_H
     38  1.1.1.1.4.2  yamt #  include <sys/time.h>
     39  1.1.1.1.4.2  yamt # else
     40  1.1.1.1.4.2  yamt #  include <time.h>
     41  1.1.1.1.4.2  yamt # endif
     42  1.1.1.1.4.2  yamt #endif
     43  1.1.1.1.4.2  yamt 
     44  1.1.1.1.4.2  yamt 
     45  1.1.1.1.4.2  yamt double
     46  1.1.1.1.4.2  yamt omp_get_wtime (void)
     47  1.1.1.1.4.2  yamt {
     48  1.1.1.1.4.2  yamt #ifdef HAVE_CLOCK_GETTIME
     49  1.1.1.1.4.2  yamt   struct timespec ts;
     50  1.1.1.1.4.2  yamt # ifdef CLOCK_MONOTONIC
     51  1.1.1.1.4.2  yamt   if (clock_gettime (CLOCK_MONOTONIC, &ts) < 0)
     52  1.1.1.1.4.2  yamt # endif
     53  1.1.1.1.4.2  yamt     clock_gettime (CLOCK_REALTIME, &ts);
     54  1.1.1.1.4.2  yamt   return ts.tv_sec + ts.tv_nsec / 1e9;
     55  1.1.1.1.4.2  yamt #else
     56  1.1.1.1.4.2  yamt   struct timeval tv;
     57  1.1.1.1.4.2  yamt   gettimeofday (&tv, NULL);
     58  1.1.1.1.4.2  yamt   return tv.tv_sec + tv.tv_usec / 1e6;
     59  1.1.1.1.4.2  yamt #endif
     60  1.1.1.1.4.2  yamt }
     61  1.1.1.1.4.2  yamt 
     62  1.1.1.1.4.2  yamt double
     63  1.1.1.1.4.2  yamt omp_get_wtick (void)
     64  1.1.1.1.4.2  yamt {
     65  1.1.1.1.4.2  yamt #ifdef HAVE_CLOCK_GETTIME
     66  1.1.1.1.4.2  yamt   struct timespec ts;
     67  1.1.1.1.4.2  yamt # ifdef CLOCK_MONOTONIC
     68  1.1.1.1.4.2  yamt   if (clock_getres (CLOCK_MONOTONIC, &ts) < 0)
     69  1.1.1.1.4.2  yamt # endif
     70  1.1.1.1.4.2  yamt     clock_getres (CLOCK_REALTIME, &ts);
     71  1.1.1.1.4.2  yamt   return ts.tv_sec + ts.tv_nsec / 1e9;
     72  1.1.1.1.4.2  yamt #else
     73  1.1.1.1.4.2  yamt   return 1.0 / sysconf(_SC_CLK_TCK);
     74  1.1.1.1.4.2  yamt #endif
     75  1.1.1.1.4.2  yamt }
     76  1.1.1.1.4.2  yamt 
     77  1.1.1.1.4.2  yamt ialias (omp_get_wtime)
     78  1.1.1.1.4.2  yamt ialias (omp_get_wtick)
     79