FV3 Bundle
nsclock.c
Go to the documentation of this file.
1 /***********************************************************************
2  * GNU Lesser General Public License
3  *
4  * This file is part of the GFDL Flexible Modeling System (FMS).
5  *
6  * FMS is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or (at
9  * your option) any later version.
10  *
11  * FMS is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FMS. If not, see <http://www.gnu.org/licenses/>.
18  **********************************************************************/
19 #include <stdio.h>
20 #include <time.h>
21 #ifndef __aix
22 #ifdef __sgi
23 long delta_t=0; // clock resolution in nanoseconds
24 
25 long sgi_ticks_per_sec_() { // returns inverse clock resolution (1/sec)
26  struct timespec t;
27  clock_getres( CLOCK_SGI_CYCLE, &t );
28  delta_t = (long)t.tv_sec*1000000000 + (long)t.tv_nsec;
29  return 1000000000/delta_t;
30 }
31 
32 long sgi_tick_() { // returns current time in units of delta_t
33  struct timespec t;
34  if( delta_t==0 ) (void) sgi_ticks_per_sec_(); // initialize delta_t if needed
35  clock_gettime( CLOCK_SGI_CYCLE, &t );
36  return ( (long)t.tv_sec*1000000000+(long)t.tv_nsec )/delta_t;
37 }
38 
39 long sgi_max_tick_() { // clock rollover point is 2^max_tick
40 #include <sys/syssgi.h>
41  return syssgi(SGI_CYCLECNTR_SIZE);
42 }
43 #endif
44 
45 #ifdef test_nsclock
46 void main() {
47 #ifdef __sgi
48  printf( "ticks per second=%li\n", sgi_ticks_per_sec_() );
49  printf( "delta_t=%li\n", delta_t );
50  printf( "max tick=%li\n", sgi_max_tick_() );
51 #else
52  printf( "ticks per second=%i\n", CLOCKS_PER_SEC );
53 #endif
54 }
55 #endif
56 #endif
integer, parameter, public long
Definition: Type_Kinds.f90:76
real(r8), dimension(cast_m, cast_n) t
program main
Definition: xgrid.F90:5439