From 73138fa3b148adad89f1b468a9f09d22e8da0a20 Mon Sep 17 00:00:00 2001 From: Chris Maffeo <cmaffeo2@illinois.edu> Date: Sat, 10 Dec 2016 16:47:46 +0000 Subject: [PATCH] Fixed minor issues with build system; replaced util.cpp with WKFUtils.cpp --- README | 3 + src/GPUManager.cpp | 14 +- src/GrandBrownTown.cu | 37 +++--- src/GrandBrownTown.h | 1 - src/Makefile | 4 +- src/WKFUtils.cpp | 212 +++++++++++++++++++++++++++++++ src/WKFUtils.h | 77 +++++++++++ src/util.cpp | 289 ------------------------------------------ src/util.h | 21 --- 9 files changed, 326 insertions(+), 332 deletions(-) create mode 100644 src/WKFUtils.cpp create mode 100644 src/WKFUtils.h delete mode 100644 src/util.cpp delete mode 100644 src/util.h diff --git a/README b/README index f002003..935089f 100644 --- a/README +++ b/README @@ -111,6 +111,9 @@ Terrance Howard particles further than the pairlist distance move to within the cutoff +* Failed assertions deliver messages that don't describe where the + failure occured + -- Bugs -- * An issue with memory management causes some invalid memory to be diff --git a/src/GPUManager.cpp b/src/GPUManager.cpp index b3f7d1d..4061674 100644 --- a/src/GPUManager.cpp +++ b/src/GPUManager.cpp @@ -1,5 +1,13 @@ #include "GPUManager.h" +#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } +inline void gpuAssert(cudaError_t code, const char* file, int line, bool abort=true) { + if (code != cudaSuccess) { + fprintf(stderr,"CUDA Error: %s %s:%d\n", cudaGetErrorString(code), __FILE__, line); + if (abort) exit(code); + } +} + int GPUManager::nGPUs = 0; bool GPUManager::is_safe = true; std::vector<int> GPUManager::gpus, GPUManager::timeouts, GPUManager::notimeouts; @@ -20,10 +28,14 @@ void GPUManager::init() { is_safe = false; gpus = timeouts; } + if (gpus.size() == 0) { + fprintf(stderr, "Error: Did not find a GPU\n"); + exit(1); + } } void GPUManager::load_info() { - cudaGetDeviceCount(&nGPUs); + gpuErrchk(cudaGetDeviceCount(&nGPUs)); printf("Found %d GPU(s)\n", nGPUs); for (int dev = 0; dev < nGPUs; dev++) { diff --git a/src/GrandBrownTown.cu b/src/GrandBrownTown.cu index bc77640..fc766ed 100644 --- a/src/GrandBrownTown.cu +++ b/src/GrandBrownTown.cu @@ -1,6 +1,7 @@ #include "GrandBrownTown.h" #include "GrandBrownTown.cuh" /* #include "ComputeGridGrid.cuh" */ +#include "WKFUtils.h" #define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { @@ -339,11 +340,11 @@ void GrandBrownTown::run() { remember(0.0f); // Initialize timers (util.*) - rt_timerhandle cputimer; - cputimer = rt_timer_create(); - rt_timerhandle timer0, timerS; - timer0 = rt_timer_create(); - timerS = rt_timer_create(); + wkf_timerhandle cputimer; + cputimer = wkf_timer_create(); + wkf_timerhandle timer0, timerS; + timer0 = wkf_timer_create(); + timerS = wkf_timer_create(); copyToCUDA(); internal -> copyToCUDA(forceInternal, pos); @@ -376,8 +377,8 @@ void GrandBrownTown::run() { } // endif (imd_on) // Start timers - rt_timer_start(timer0); - rt_timer_start(timerS); + wkf_timer_start(timer0); + wkf_timer_start(timerS); // We haven't done any steps yet. // Do decomposition if we have to @@ -400,7 +401,7 @@ void GrandBrownTown::run() { float energy = 0.0f; // Set the timer - rt_timer_start(cputimer); + wkf_timer_start(cputimer); // 'interparticleForce' - determines whether particles interact with each other if (interparticleForce) { @@ -461,10 +462,10 @@ void GrandBrownTown::run() { } /* Time force computations. - rt_timer_stop(cputimer); - float dt1 = rt_timer_time(cputimer); + wkf_timer_stop(cputimer); + float dt1 = wkf_timer_time(cputimer); printf("Force Computation Time: %f ms\n", dt1 * 1000); - rt_timer_start(cputimer); + wkf_timer_start(cputimer); // */ // Make sure the force computation has completed without errors before continuing. @@ -500,8 +501,8 @@ void GrandBrownTown::run() { //gpuErrchk(cudaPeekAtLastError()); // Does not work on old GPUs (like mine). TODO: write a better wrapper around Peek /* Time position computations. - rt_timer_stop(cputimer); - float dt2 = rt_timer_time(cputimer); + wkf_timer_stop(cputimer); + float dt2 = wkf_timer_time(cputimer); printf("Position Update Time: %f ms\n", dt2 * 1000); */ @@ -589,7 +590,7 @@ void GrandBrownTown::run() { if (get_energy) { // Stop the timer. // cudaSetDevice(0); - rt_timer_stop(timerS); + wkf_timer_stop(timerS); // Copy back forces to display (internal only) gpuErrchk(cudaMemcpy(&force0, internal -> getForceInternal_d(), sizeof(Vector3), cudaMemcpyDeviceToHost)); @@ -599,7 +600,7 @@ void GrandBrownTown::run() { // Simulation progress and statistics. float percent = (100.0f * s) / steps; - float msPerStep = rt_timer_time(timerS) * 1000.0f / outputEnergyPeriod; + float msPerStep = wkf_timer_time(timerS) * 1000.0f / outputEnergyPeriod; float nsPerDay = numReplicas * timestep / msPerStep * 864E5f; // Nice thousand separator @@ -621,7 +622,7 @@ void GrandBrownTown::run() { writeRestart(repID); // restart the timer - rt_timer_start(timerS); + wkf_timer_start(timerS); } // s % outputEnergyPeriod { @@ -657,10 +658,10 @@ void GrandBrownTown::run() { } // Stop the main timer. - rt_timer_stop(timer0); + wkf_timer_stop(timer0); // Compute performance data. - const float elapsed = rt_timer_time(timer0); // seconds + const float elapsed = wkf_timer_time(timer0); // seconds int tot_hrs = (int) std::fmod(elapsed / 3600.0f, 60.0f); int tot_min = (int) std::fmod(elapsed / 60.0f, 60.0f); float tot_sec = std::fmod(elapsed, 60.0f); diff --git a/src/GrandBrownTown.h b/src/GrandBrownTown.h index 9810664..95857aa 100644 --- a/src/GrandBrownTown.h +++ b/src/GrandBrownTown.h @@ -40,7 +40,6 @@ /* #include "RigidBodyType.h" */ /* #include "RigidBodyGrid.h" */ #include "RigidBodyController.h" -#include "util.h" // IMD #include "vmdsock.h" diff --git a/src/Makefile b/src/Makefile index b58905b..5523dd2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,7 +10,7 @@ else endif CC_FLAGS += -I$(CUDA_PATH)/include -CC_FLAGS += -Wall -Wno-write-strings -std=c++0x -pedantic # TODO: test on Mac OSX +CC_FLAGS += -Wall -Wno-write-strings -std=c++0x -pedantic # TODO: test on Mac OSX and other architectures NV_FLAGS += -lineinfo ifneq ($(DARWIN),) @@ -24,7 +24,7 @@ endif $(info $(NVCC)) ## Find valid compute capabilities for this machine -SMS ?= 20 30 35 37 50 52 60 +SMS ?= 30 35 37 50 52 60 $(info Testing CUDA toolkit with compute capabilities SMS='$(SMS)') SMS := $(shell for sm in $(SMS); do $(NVCC) cuda-test.c -arch=sm_$$sm -o /dev/null &> /dev/null && echo $$sm; done) diff --git a/src/WKFUtils.cpp b/src/WKFUtils.cpp new file mode 100644 index 0000000..e10dd85 --- /dev/null +++ b/src/WKFUtils.cpp @@ -0,0 +1,212 @@ +/*************************************************************************** + *cr + *cr (C) Copyright 1995-2009 John E. Stone + *cr + ***************************************************************************/ +/*************************************************************************** + * RCS INFORMATION: + * + * $RCSfile: WKFUtils.C,v $ + * $Author: johns $ $Locker: $ $State: Exp $ + * $Revision: 1.1 $ $Date: 2009/10/26 14:59:44 $ + * + ***************************************************************************/ +/* + * Copyright (c) 1994-2009 John E. Stone + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "WKFUtils.h" + +#include <string.h> +#include <ctype.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> + +#if defined(_MSC_VER) +#include <windows.h> +#include <conio.h> +#else +#include <unistd.h> +#include <sys/time.h> +#include <errno.h> + +#if defined(ARCH_AIX4) +#include <strings.h> +#endif + +#if defined(__irix) +#include <bstring.h> +#endif + +#if defined(__hpux) +#include <time.h> +#endif // HPUX +#endif // _MSC_VER + + +#ifdef __cplusplus +extern "C" { +#endif + + +#if defined(_MSC_VER) +typedef struct { + DWORD starttime; + DWORD endtime; +} wkf_timer; + +void wkf_timer_start(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + t->starttime = GetTickCount(); +} + +void wkf_timer_stop(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + t->endtime = GetTickCount(); +} + +double wkf_timer_time(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + double ttime; + + ttime = ((double) (t->endtime - t->starttime)) / 1000.0; + + return ttime; +} + +double wkf_timer_start_time(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + double ttime; + ttime = ((double) (t->starttime)) / 1000.0; + return ttime; +} + +double wkf_timer_stop_time(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + double ttime; + ttime = ((double) (t->endtime)) / 1000.0; + return ttime; +} + +#else + +// Unix with gettimeofday() +typedef struct { + struct timeval starttime, endtime; + struct timezone tz; +} wkf_timer; + +void wkf_timer_start(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + gettimeofday(&t->starttime, &t->tz); +} + +void wkf_timer_stop(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + gettimeofday(&t->endtime, &t->tz); +} + +double wkf_timer_time(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + double ttime; + ttime = ((double) (t->endtime.tv_sec - t->starttime.tv_sec)) + + ((double) (t->endtime.tv_usec - t->starttime.tv_usec)) / 1000000.0; + return ttime; +} + +double wkf_timer_start_time(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + double ttime; + ttime = ((double) t->starttime.tv_sec) + + ((double) t->starttime.tv_usec) / 1000000.0; + return ttime; +} + +double wkf_timer_stop_time(wkf_timerhandle v) { + wkf_timer * t = (wkf_timer *) v; + double ttime; + ttime = ((double) t->endtime.tv_sec) + + ((double) t->endtime.tv_usec) / 1000000.0; + return ttime; +} + +#endif + +// system independent routines to create and destroy timers +wkf_timerhandle wkf_timer_create(void) { + wkf_timer * t; + t = (wkf_timer *) malloc(sizeof(wkf_timer)); + memset(t, 0, sizeof(wkf_timer)); + return t; +} + +void wkf_timer_destroy(wkf_timerhandle v) { + free(v); +} + +double wkf_timer_timenow(wkf_timerhandle v) { + wkf_timer_stop(v); + return wkf_timer_time(v); +} + +/// initialize status message timer +wkfmsgtimer * wkf_msg_timer_create(double updatetime) { + wkfmsgtimer *mt; + mt = (wkfmsgtimer *) malloc(sizeof(wkfmsgtimer)); + if (mt != NULL) { + mt->timer = wkf_timer_create(); + mt->updatetime = updatetime; + wkf_timer_start(mt->timer); + } + return mt; +} + +/// return true if it's time to print a status update message +int wkf_msg_timer_timeout(wkfmsgtimer *mt) { + double elapsed = wkf_timer_timenow(mt->timer); + if (elapsed > mt->updatetime) { + // reset the clock and return true that our timer expired + wkf_timer_start(mt->timer); + return 1; + } else if (elapsed < 0) { + // time went backwards, best reset our clock! + wkf_timer_start(mt->timer); + } + return 0; +} + +/// destroy message timer +void wkf_msg_timer_destroy(wkfmsgtimer * mt) { + wkf_timer_destroy(mt->timer); + free(mt); +} + +#ifdef __cplusplus +} +#endif + diff --git a/src/WKFUtils.h b/src/WKFUtils.h new file mode 100644 index 0000000..d05a1be --- /dev/null +++ b/src/WKFUtils.h @@ -0,0 +1,77 @@ +/*************************************************************************** + *cr + *cr (C) Copyright 1995-2009 John E. Stone + *cr + ***************************************************************************/ +/*************************************************************************** + * RCS INFORMATION: + * + * $RCSfile: WKFUtils.h,v $ + * $Author: johns $ $Locker: $ $State: Exp $ + * $Revision: 1.1 $ $Date: 2009/10/26 14:59:45 $ + * + ***************************************************************************/ +/* + * Copyright (c) 1994-2009 John E. Stone + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef WKF_UTILS_INC +#define WKF_UTILS_INC 1 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void * wkf_timerhandle; ///< a timer handle +wkf_timerhandle wkf_timer_create(void); ///< create a timer (clears timer) +void wkf_timer_destroy(wkf_timerhandle); ///< create a timer (clears timer) +void wkf_timer_start(wkf_timerhandle); ///< start a timer (clears timer) +void wkf_timer_stop(wkf_timerhandle); ///< stop a timer +double wkf_timer_time(wkf_timerhandle); ///< report elapsed time in seconds +double wkf_timer_timenow(wkf_timerhandle); ///< report elapsed time in seconds +double wkf_timer_start_time(wkf_timerhandle); ///< report wall starting time +double wkf_timer_stop_time(wkf_timerhandle); ///< report wall stopping time + +typedef struct { + wkf_timerhandle timer; + double updatetime; +} wkfmsgtimer; + +/// initialize periodic status message timer +extern wkfmsgtimer * wkf_msg_timer_create(double updatetime); + +/// return true if it's time to print a status update message +extern int wkf_msg_timer_timeout(wkfmsgtimer *time); + +/// destroy message timer +void wkf_msg_timer_destroy(wkfmsgtimer * mt); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/util.cpp b/src/util.cpp deleted file mode 100644 index c994b85..0000000 --- a/src/util.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/* - * util.c - Contains all of the timing functions for various platforms. - * - * $Id: util.c,v 1.1.1.1 2013/05/30 22:18:41 awknaust1 Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include "util.h" - -#if defined(__PARAGON__) || defined(__IPSC__) -#if defined(__IPSC__) -#include <cube.h> -#endif /* iPSC/860 specific */ - -#if defined(__PARAGON__) -#include <nx.h> -#endif /* Paragon XP/S specific */ - -#include <estat.h> -#endif /* iPSC/860 and Paragon specific items */ - -/* most platforms will use the regular time function gettimeofday() */ -#if !defined(__IPSC__) && !defined(__PARAGON__) && !defined(NEXT) -#define STDTIME -#endif - -#if defined(NEXT) -#include <time.h> -#undef STDTIME -#define OLDUNIXTIME -#endif - -#if defined(_MSC_VER) || defined(WIN32) -#include <windows.h> -#undef STDTIME -#define WIN32GETTICKCOUNT -#endif - -#if defined(__linux) || defined(Bsd) || defined(AIX) || defined(SunOS) || defined(HPUX) || defined(_CRAYT3E) || defined(_CRAY) || defined(_CRAYC) || defined(__osf__) || defined(__BEOS__) || defined(__APPLE__) || defined(__irix) -#include <sys/time.h> -#endif - -#if defined(MCOS) || defined(VXWORKS) -#define POSIXTIME -#endif - - -#if defined(WIN32GETTICKCOUNT) -typedef struct { - DWORD starttime; - DWORD endtime; -} rt_timer; - -void rt_timer_start(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - t->starttime = GetTickCount(); -} - -void rt_timer_stop(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - t->endtime = GetTickCount(); -} - -double rt_timer_time(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - double ttime; - - ttime = (double) (t->endtime - t->starttime) / 1000.0f; - - return (double) ttime; -} -#endif - - -#if defined(POSIXTIME) -#undef STDTIME -#include <time.h> - -typedef struct { - struct timespec starttime; - struct timespec endtime; -} rt_timer; - -void rt_timer_start(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - clock_gettime(CLOCK_REALTIME, &t->starttime); -} - -void rt_timer_stop(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - clock_gettime(CLOCK_REALTIME, &t->endtime); -} - -double rt_timer_time(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - double ttime, start, end; - - start = (t->starttime.tv_sec + 1.0 * t->starttime.tv_nsec / 1000000000.0); - end = (t->endtime.tv_sec + 1.0 * t->endtime.tv_nsec / 1000000000.0); - ttime = end - start; - - return (double) ttime; -} -#endif - - - -/* if we're running on a Paragon or iPSC/860, use mclock() hi res timers */ -#if defined(__IPSC__) || defined(__PARAGON__) - -typedef struct { - long starttime; - long stoptime; -} rt_timer; - -void rt_timer_start(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - t->starttime=mclock(); -} - -void rt_timer_stop(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - t->stoptime=mclock(); -} - -double rt_timer_time(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - double a; - a = t->stoptime - t->starttime; - a = ( a / 1000.0 ); - return (double) a; -} -#endif - - - -/* if we're on a Unix with gettimeofday() we'll use newer timers */ -#ifdef STDTIME -typedef struct { - struct timeval starttime, endtime; -#ifndef VMS - struct timezone tz; -#endif -} rt_timer; - -void rt_timer_start(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; -#ifdef VMS - gettimeofday(&t->starttime, NULL); -#else - gettimeofday(&t->starttime, &t->tz); -#endif -} - -void rt_timer_stop(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; -#ifdef VMS - gettimeofday(&t->endtime, NULL); -#else - gettimeofday(&t->endtime, &t->tz); -#endif -} - -double rt_timer_time(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - double ttime, start, end; - - start = (t->starttime.tv_sec + 1.0 * t->starttime.tv_usec / 1000000.0); - end = (t->endtime.tv_sec + 1.0 * t->endtime.tv_usec / 1000000.0); - ttime = end - start; - - return (double) ttime; -} -#endif - - - -/* use the old fashioned Unix time functions */ -#ifdef OLDUNIXTIME -typedef struct { - time_t starttime; - time_t stoptime; -} rt_timer; - -void rt_timer_start(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - time(&t->starttime); -} - -void rt_timer_stop(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - time(&t->stoptime); -} - -double rt_timer_time(rt_timerhandle v) { - rt_timer * t = (rt_timer *) v; - double a; - a = difftime(t->stoptime, t->starttime); - return (double) a; -} -#endif - - -/* - * system independent routines to create and destroy timers - */ -rt_timerhandle rt_timer_create(void) { - rt_timer * t; - t = (rt_timer *) malloc(sizeof(rt_timer)); - memset(t, 0, sizeof(rt_timer)); - return t; -} - -void rt_timer_destroy(rt_timerhandle v) { - free(v); -} - -double rt_timer_timenow(rt_timerhandle v) { - rt_timer_stop(v); - return rt_timer_time(v); -} - - - -/* - * Code for machines with deficient libc's etc. - */ - -#if defined(__IPSC__) && !defined(__PARAGON__) - -/* the iPSC/860 libc is *missing* strstr(), so here it is.. */ -char * strstr(const char *s, const char *find) { - register char c, sc; - register size_t len; - - if ((c = *find++) != 0) { - len = strlen(find); - do { - do { - if ((sc = *s++) == 0) - return (NULL); - } while (sc != c); - } while (strncmp(s, find, len) != 0); - s--; - } - return ((char *)s); -} -#endif - -/* the Mercury libc is *missing* isascii(), so here it is.. */ -#if defined(MCOS) - int isascii(int c) { - return (!((c) & ~0177)); - } -#endif - -/* - * Thread Safe Random Number Generators - * (no internal static data storage) - * - * Note: According to numerical recipes, one should not use - * random numbers in any way similar to rand() % number, - * as the greatest degree of randomness tends to be found - * in the upper bits of the random number, rather than the - * lower bits. - */ - -/* - * Simple 32-bit random number generator suggested in - * numerical recipes in C book. - * - * This random number generator has been fixed to work on - * machines that have "int" types which are larger than 32 bits. - * - * The rt_rand() API is similar to the reentrant "rand_r" version - * found in some libc implementations. - */ -unsigned int rt_rand(unsigned int * idum) { - *idum = ((1664525 * (*idum)) + 1013904223) & ((unsigned int) 0xffffffff); - return *idum; -} - - diff --git a/src/util.h b/src/util.h deleted file mode 100644 index d3ef258..0000000 --- a/src/util.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * util.h - This file contains defines for the timer functions... - * - * $Id: util.h,v 1.1.1.1 2013/05/30 22:18:41 awknaust1 Exp $ - */ - -#if !defined(RT_UTIL_H) -#define RT_UTIL_H 1 - -typedef void * rt_timerhandle; /* a timer handle */ -rt_timerhandle rt_timer_create(void); /* create a timer (clears timer) */ -void rt_timer_destroy(rt_timerhandle); /* create a timer (clears timer) */ -void rt_timer_start(rt_timerhandle); /* start a timer (clears timer) */ -void rt_timer_stop(rt_timerhandle); /* stop a timer */ -double rt_timer_time(rt_timerhandle); /* report elapsed time in seconds */ -double rt_timer_timenow(rt_timerhandle); /* report elapsed time in seconds */ - -#define RT_RAND_MAX 4294967296.0 /* Maximum random value from rt_rand */ -unsigned int rt_rand(unsigned int *); /* thread-safe 32-bit random numbers */ - -#endif -- GitLab