coz/benchmarks/linear_regression/stddefines.h
Charlie Curtsinger d1c592b097 Moving benchmarks to properly named dir
--HG--
rename : tests/Makefile => benchmarks/Makefile
rename : tests/experiment.py => benchmarks/experiment.py
rename : tests/histogram/Makefile => benchmarks/histogram/Makefile
rename : tests/histogram/histogram-pthread.c => benchmarks/histogram/histogram-pthread.c
rename : tests/histogram/stddefines.h => benchmarks/histogram/stddefines.h
rename : tests/kmeans/Makefile => benchmarks/kmeans/Makefile
rename : tests/kmeans/kmeans-pthread.c => benchmarks/kmeans/kmeans-pthread.c
rename : tests/kmeans/stddefines.h => benchmarks/kmeans/stddefines.h
rename : tests/linear_regression/Makefile => benchmarks/linear_regression/Makefile
rename : tests/linear_regression/linear_regression-pthread.c => benchmarks/linear_regression/linear_regression-pthread.c
rename : tests/linear_regression/stddefines.h => benchmarks/linear_regression/stddefines.h
rename : tests/matrix_multiply/Makefile => benchmarks/matrix_multiply/Makefile
rename : tests/matrix_multiply/map_reduce.h => benchmarks/matrix_multiply/map_reduce.h
rename : tests/matrix_multiply/matrix_multiply-pthread.c => benchmarks/matrix_multiply/matrix_multiply-pthread.c
rename : tests/matrix_multiply/stddefines.h => benchmarks/matrix_multiply/stddefines.h
rename : tests/pbzip2/AUTHORS => benchmarks/pbzip2/AUTHORS
rename : tests/pbzip2/BZ2StreamScanner.cpp => benchmarks/pbzip2/BZ2StreamScanner.cpp
rename : tests/pbzip2/BZ2StreamScanner.h => benchmarks/pbzip2/BZ2StreamScanner.h
rename : tests/pbzip2/COPYING => benchmarks/pbzip2/COPYING
rename : tests/pbzip2/ErrorContext.cpp => benchmarks/pbzip2/ErrorContext.cpp
rename : tests/pbzip2/ErrorContext.h => benchmarks/pbzip2/ErrorContext.h
rename : tests/pbzip2/Makefile => benchmarks/pbzip2/Makefile
rename : tests/pbzip2/README => benchmarks/pbzip2/README
rename : tests/pbzip2/pbzip2.cpp => benchmarks/pbzip2/pbzip2.cpp
rename : tests/pbzip2/pbzip2.h => benchmarks/pbzip2/pbzip2.h
rename : tests/pca/Makefile => benchmarks/pca/Makefile
rename : tests/pca/pca-pthread.c => benchmarks/pca/pca-pthread.c
rename : tests/pca/stddefines.h => benchmarks/pca/stddefines.h
rename : tests/producer_consumer/Makefile => benchmarks/producer_consumer/Makefile
rename : tests/producer_consumer/producer_consumer.cpp => benchmarks/producer_consumer/producer_consumer.cpp
rename : tests/string_match/Makefile => benchmarks/string_match/Makefile
rename : tests/string_match/map_reduce.h => benchmarks/string_match/map_reduce.h
rename : tests/string_match/stddefines.h => benchmarks/string_match/stddefines.h
rename : tests/string_match/string_match-pthread.c => benchmarks/string_match/string_match-pthread.c
rename : tests/unbalanced/Makefile => benchmarks/unbalanced/Makefile
rename : tests/unbalanced/unbalanced.cpp => benchmarks/unbalanced/unbalanced.cpp
rename : tests/word_count/Makefile => benchmarks/word_count/Makefile
rename : tests/word_count/sort-pthread.c => benchmarks/word_count/sort-pthread.c
rename : tests/word_count/sort-pthread.h => benchmarks/word_count/sort-pthread.h
rename : tests/word_count/stddefines.h => benchmarks/word_count/stddefines.h
rename : tests/word_count/word_count-pthread.c => benchmarks/word_count/word_count-pthread.c
rename : tests/work_queue/Makefile => benchmarks/work_queue/Makefile
rename : tests/work_queue/work_queue.cpp => benchmarks/work_queue/work_queue.cpp
2014-07-07 11:33:04 -04:00

115 lines
3.9 KiB
C

/* Copyright (c) 2007-2009, Stanford University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Stanford University nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``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 STANFORD UNIVERSITY 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 STDDEFINES_H_
#define STDDEFINES_H_
#include <assert.h>
#include <stdlib.h>
#include <sys/time.h>
#include <stdint.h>
#include <stdio.h>
//#define TIMING
/* Debug printf */
#define dprintf(...) fprintf(stdout, __VA_ARGS__)
/* Wrapper to check for errors */
#define CHECK_ERROR(a) \
if (a) \
{ \
perror("Error at line\n\t" #a "\nSystem Msg"); \
assert ((a) == 0); \
}
static inline void *MALLOC(size_t size)
{
void * temp = malloc(size);
assert(temp);
return temp;
}
static inline void *CALLOC(size_t num, size_t size)
{
void * temp = calloc(num, size);
assert(temp);
return temp;
}
static inline void *REALLOC(void *ptr, size_t size)
{
void * temp = realloc(ptr, size);
assert(temp);
return temp;
}
static inline char *GETENV(char *envstr)
{
char *env = getenv(envstr);
if (!env) return "0";
else return env;
}
#define GET_TIME(start, end, duration) \
duration.tv_sec = (end.tv_sec - start.tv_sec); \
if (end.tv_nsec >= start.tv_nsec) { \
duration.tv_nsec = (end.tv_nsec - start.tv_nsec); \
} \
else { \
duration.tv_nsec = (1000000000L - (start.tv_nsec - end.tv_nsec)); \
duration.tv_sec--; \
} \
if (duration.tv_nsec >= 1000000000L) { \
duration.tv_sec++; \
duration.tv_nsec -= 1000000000L; \
}
static inline unsigned int time_diff (
struct timeval *end, struct timeval *begin)
{
#ifdef TIMING
uint64_t result;
result = end->tv_sec - begin->tv_sec;
result *= 1000000; /* usec */
result += end->tv_usec - begin->tv_usec;
return result;
#else
return 0;
#endif
}
static inline void get_time (struct timeval *t)
{
#ifdef TIMING
gettimeofday (t, NULL);
#endif
}
#endif // STDDEFINES_H_