| [2aa6644] | 1 | /*BHEADER**********************************************************************
|
|---|
| 2 | * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
|
|---|
| 3 | * Produced at the Lawrence Livermore National Laboratory.
|
|---|
| 4 | * This file is part of HYPRE. See file COPYRIGHT for details.
|
|---|
| 5 | *
|
|---|
| 6 | * HYPRE is free software; you can redistribute it and/or modify it under the
|
|---|
| 7 | * terms of the GNU Lesser General Public License (as published by the Free
|
|---|
| 8 | * Software Foundation) version 2.1 dated February 1999.
|
|---|
| 9 | *
|
|---|
| 10 | * $Revision: 2.4 $
|
|---|
| 11 | ***********************************************************************EHEADER*/
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | /*
|
|---|
| 15 | * File: timer.c
|
|---|
| 16 | * Copyright: (c) 1997 The Regents of the University of California
|
|---|
| 17 | * Author: Scott Kohn (skohn@llnl.gov)
|
|---|
| 18 | * Description: somewhat portable timing routines for C++, C, and Fortran
|
|---|
| 19 | *
|
|---|
| 20 | * If TIMER_USE_MPI is defined, then the MPI timers are used to get
|
|---|
| 21 | * wallclock seconds, since we assume that the MPI timers have better
|
|---|
| 22 | * resolution than the system timers.
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 | #include <time.h>
|
|---|
| 26 | #include <unistd.h>
|
|---|
| 27 | #ifndef WIN32
|
|---|
| 28 | #include <sys/times.h>
|
|---|
| 29 | #endif
|
|---|
| 30 | #ifdef TIMER_USE_MPI
|
|---|
| 31 | #include "mpi.h"
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | double time_getWallclockSeconds(void)
|
|---|
| 35 | {
|
|---|
| 36 | #ifdef TIMER_USE_MPI
|
|---|
| 37 | return(MPI_Wtime());
|
|---|
| 38 | #else
|
|---|
| 39 | #ifdef WIN32
|
|---|
| 40 | clock_t cl=clock();
|
|---|
| 41 | return(((double) cl)/((double) CLOCKS_PER_SEC));
|
|---|
| 42 | #else
|
|---|
| 43 | struct tms usage;
|
|---|
| 44 | long wallclock = times(&usage);
|
|---|
| 45 | return(((double) wallclock)/((double) sysconf(_SC_CLK_TCK)));
|
|---|
| 46 | #endif
|
|---|
| 47 | #endif
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | double time_getCPUSeconds(void)
|
|---|
| 51 | {
|
|---|
| 52 | #ifndef TIMER_NO_SYS
|
|---|
| 53 | clock_t cpuclock = clock();
|
|---|
| 54 | return(((double) (cpuclock))/((double) CLOCKS_PER_SEC));
|
|---|
| 55 | #else
|
|---|
| 56 | return(0.0);
|
|---|
| 57 | #endif
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | double time_get_wallclock_seconds_(void)
|
|---|
| 61 | {
|
|---|
| 62 | return(time_getWallclockSeconds());
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | double time_get_cpu_seconds_(void)
|
|---|
| 66 | {
|
|---|
| 67 | return(time_getCPUSeconds());
|
|---|
| 68 | }
|
|---|