#include #include #include #include /* The same code is used for both C and Fortran entry points. */ #define WC_GUTS \ \ struct timeval s_val; \ \ gettimeofday(&s_val,0); \ return ((double) s_val.tv_sec + 0.000001*s_val.tv_usec); /* Returns the current value of the wall clock timer. * C entry point. */ double wc_second() { WC_GUTS; } /* Returns the current value of the wall clock timer. * Fortran entry point. */ double wc_second_() { WC_GUTS; } #define US_GUTS \ \ struct rusage ru; \ double tu, ts; \ \ getrusage(RUSAGE_SELF,&ru); \ \ tu = ru.ru_utime.tv_sec + 1.0e-6*ru.ru_utime.tv_usec; \ ts = ru.ru_stime.tv_sec + 1.0e-6*ru.ru_stime.tv_usec; \ \ return (tu + ts); \ /* Returns the current value of the user+system timer. C entry point. */ double us_second() { US_GUTS; } /* Returns the current value of the user+system timer. Fortran entry point. */ double us_second_() { US_GUTS; } #include #include #include #include #include #include #define TICKUNITS (1.0e-12) #define TRUE (1) #define FALSE (0) #define IO4_TIMER_IS_64BIT (TRUE) #if IO4_TIMER_IS_64BIT typedef unsigned long long iotimer_t; #else typedef unsigned int iotimer_t; #endif #define RT_GUTS \ \ static int first = TRUE; \ static volatile iotimer_t *iotimer_addr, counter_value0; \ static double tick; \ unsigned int cycleval; \ volatile iotimer_t counter_value; \ \ if (first) { \ \ __psunsigned_t phys_addr, raddr, poffmask; \ int fd; \ \ poffmask = getpagesize() - 1; \ phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval); \ raddr = phys_addr & ~poffmask; \ fd = open("/dev/mmem", O_RDONLY); \ iotimer_addr = (volatile iotimer_t *) mmap(NULL, poffmask, \ PROT_READ, \ MAP_PRIVATE, fd, \ (__psint_t) raddr); \ iotimer_addr = (iotimer_t *) ((__psunsigned_t) iotimer_addr + \ (phys_addr & poffmask)); \ tick = cycleval * TICKUNITS; \ counter_value0 = *iotimer_addr; \ first = FALSE; \ return (0.0); \ } \ \ counter_value = *iotimer_addr; \ \ return ((counter_value - counter_value0) * tick); /* Gets the time from the free running hardware counter. The time * is accurate until the counter wraps around, but no warning about * wrap around is provided. C entry point. */ double rt_second() { RT_GUTS; } /* Gets the time from the free running hardware counter. The time * is accurate until the counter wraps around, but no warning about * wrap around is provided. Fortran entry point. */ double rt_second_() { RT_GUTS; } /* Returns the current value of the real-time timer, wall clock timer, or * user+system timer depending on the valueof tmode: 0 means the real-time * timer, less than zero the wall-clock timer, and greater than zero * user+system time. C entry point. */ double second( int tmode) { if (tmode == 0) { RT_GUTS; } else if (tmode > 0) { US_GUTS; } else { WC_GUTS; } } /* Returns the current value of the real-time timer, wall clock timer, or * user+system timer depending on the valueof tmode: 0 means the real-time * timer, less than zero the wall-clock timer, and greater than zero * user+system time. C entry point. */ double second_( int *ptmode) { int tmode = *ptmode; if (tmode == 0) { RT_GUTS; } else if (tmode > 0) { US_GUTS; } else { WC_GUTS; } }