Commit ccf520e5 authored by Hal Finkel's avatar Hal Finkel
Browse files

Initial Commit

parents
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = include src tests
AC_INIT([hpcrc64], [1.0], [hfinkel@anl.gov])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/CRC64.c])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
LT_INIT
AC_PROG_CC
AX_OPENMP
AC_PROG_CC_C99
AC_PROG_CXX
AC_SEARCH_LIBS(clock_gettime,rt)
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile include/Makefile src/Makefile tests/Makefile])
AC_OUTPUT
// Author: Hal Finkel
#ifndef CRC64_H
#define CRC64_H
#include <stdlib.h>
#include <stdint.h>
/*
* These functions compute the CRC-64 checksum on a block of data
* and provide a way to combine the checksums on two blocks of data.
* For more information, see:
* http://en.wikipedia.org/wiki/Computation_of_CRC
* http://checksumcrc.blogspot.com/2011/12/should-you-use-crc-or-checksum.html
* http://crcutil.googlecode.com/files/crc-doc.1.0.pdf
* http://www.ross.net/crc/download/crc_v3.txt
* This implementation uses the ECMA-182 polynomial with -1 initialization, and
* computes the bit-reversed CRC.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
* Calculate the CRC64 of the provided buffer using the slow reference
* implementation (in serial).
*/
uint64_t crc64_slow(const void *input, size_t nbytes);
/*
* Calculate the CRC64 of the provided buffer (in serial).
*/
uint64_t crc64(const void *input, size_t nbytes);
/*
* Calculate the CRC64 of the provided buffer, in parallel if possible.
*/
uint64_t crc64_omp(const void *input, size_t nbytes);
/*
* Calculate the 'check bytes' for the provided CRC64. If these bytes are
* appended to the original buffer, then the new total CRC64 should be -1.
*/
void crc64_invert(uint64_t cs, void *buffer);
/*
* Given the CRC64 of the first part of a buffer, and the CRC64 and length of
* the second part of a buffer, calculate the CRC64 of the complete buffer.
*/
uint64_t crc64_combine(uint64_t cs1, uint64_t cs2, size_t nbytes2);
#ifdef __cplusplus
}
#endif
#endif // CRC64_H
include_HEADERS = CRC64.h
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_openmp.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_OPENMP([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
#
# DESCRIPTION
#
# This macro tries to find out how to compile programs that use OpenMP a
# standard API and set of compiler directives for parallel programming
# (see http://www-unix.mcs/)
#
# On success, it sets the OPENMP_CFLAGS/OPENMP_CXXFLAGS/OPENMP_F77FLAGS
# output variable to the flag (e.g. -omp) used both to compile *and* link
# OpenMP programs in the current language.
#
# NOTE: You are assumed to not only compile your program with these flags,
# but also link it with them as well.
#
# If you want to compile everything with OpenMP, you should set:
#
# CFLAGS="$CFLAGS $OPENMP_CFLAGS"
# #OR# CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
# #OR# FFLAGS="$FFLAGS $OPENMP_FFLAGS"
#
# (depending on the selected language).
#
# The user can override the default choice by setting the corresponding
# environment variable (e.g. OPENMP_CFLAGS).
#
# ACTION-IF-FOUND is a list of shell commands to run if an OpenMP flag is
# found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it is
# not found. If ACTION-IF-FOUND is not specified, the default action will
# define HAVE_OPENMP.
#
# LICENSE
#
# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 9
AC_DEFUN([AX_OPENMP], [
AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX
AC_CACHE_CHECK([for OpenMP flag of _AC_LANG compiler], ax_cv_[]_AC_LANG_ABBREV[]_openmp, [save[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
ax_cv_[]_AC_LANG_ABBREV[]_openmp=unknown
# Flags to try: -fopenmp (gcc), -openmp (icc), -mp (SGI & PGI),
# -xopenmp (Sun), -omp (Tru64), -qsmp=omp (AIX), none
ax_openmp_flags="-fopenmp -openmp -mp -xopenmp -omp -qsmp=omp none"
if test "x$OPENMP_[]_AC_LANG_PREFIX[]FLAGS" != x; then
ax_openmp_flags="$OPENMP_[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flags"
fi
for ax_openmp_flag in $ax_openmp_flags; do
case $ax_openmp_flag in
none) []_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[] ;;
*) []_AC_LANG_PREFIX[]FLAGS="$save[]_AC_LANG_PREFIX[]FLAGS $ax_openmp_flag" ;;
esac
AC_TRY_LINK([#ifdef __cplusplus
extern "C"
#endif
void omp_set_num_threads(int);], [const int N = 100000;
int i, arr[N];
omp_set_num_threads(2);
#pragma omp parallel for
for (i = 0; i < N; i++) {
arr[i] = i;
}], [ax_cv_[]_AC_LANG_ABBREV[]_openmp=$ax_openmp_flag; break])
done
[]_AC_LANG_PREFIX[]FLAGS=$save[]_AC_LANG_PREFIX[]FLAGS
])
if test "x$ax_cv_[]_AC_LANG_ABBREV[]_openmp" = "xunknown"; then
m4_default([$2],:)
else
if test "x$ax_cv_[]_AC_LANG_ABBREV[]_openmp" != "xnone"; then
OPENMP_[]_AC_LANG_PREFIX[]FLAGS=$ax_cv_[]_AC_LANG_ABBREV[]_openmp
fi
m4_default([$1], [AC_DEFINE(HAVE_OPENMP,1,[Define if OpenMP is enabled])])
fi
])dnl AX_OPENMP
This diff is collapsed.
AM_CPPFLAGS = -I$(srcdir)/../include
lib_LTLIBRARIES = libcrc64.la
libcrc64_la_SOURCES = CRC64.c
libcrc64_la_LDFLAGS = -version-info 0:0:0
// Author: Hal Finkel
#define _XOPEN_SOURCE 600
#include <CRC64.h>
#include <ctime>
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int ntests = 10;
if (argc > 1) ntests = atoi(argv[1]);
int seed = 5;
if (argc > 2) seed = atoi(argv[2]);
int max_test_length = 2097152;
if (argc > 3) max_test_length = atoi(argv[3]);
cout << "Running " << ntests << " tests with seed " << seed << endl;
srand48(seed);
#ifdef __bgp__
#define THE_CLOCK CLOCK_REALTIME
#else
#define THE_CLOCK CLOCK_THREAD_CPUTIME_ID
#endif
double tot_time = 0, tot_bytes = 0;
int ntest = 0;
while (++ntest <= ntests) {
cout << ntest << " ";
size_t test_length = (size_t) (max_test_length*(drand48()+1));
cout << test_length << " ";
vector<unsigned char> buffer(test_length);
for (size_t i = 0; i < test_length; ++i) {
buffer[i] = (unsigned char) (255*drand48());
}
timespec b_start, b_end;
clock_gettime(THE_CLOCK, &b_start);
uint64_t cs = crc64_omp(&buffer[0], test_length);
clock_gettime(THE_CLOCK, &b_end);
double b_time = (b_end.tv_sec - b_start.tv_sec);
b_time += 1e-9*(b_end.tv_nsec - b_start.tv_nsec);
tot_time += b_time;
tot_bytes += test_length;
// Copy the buffer and append the check bytes.
size_t tlend = 8;
buffer.resize(test_length + tlend, 0);
crc64_invert(cs, &buffer[test_length]);
string pass("pass"), fail("fail");
uint64_t csc = crc64(&buffer[0], test_length+tlend);
cout << ((csc == (uint64_t) -1) ? pass : fail) << " ";
size_t div_pt = (size_t) (test_length*drand48());
uint64_t cs1 = crc64(&buffer[0], div_pt);
uint64_t cs2 = crc64(&buffer[div_pt], test_length - div_pt);
csc = crc64_combine(cs1, cs2, test_length - div_pt);
cout << ((csc == cs) ? pass : fail);
cout << endl;
}
cout << (tot_bytes/(1024*1024))/tot_time << " MB/s" << endl;
return 0;
}
AM_CPPFLAGS = -I$(srcdir)/../include
check_PROGRAMS = CRC64Test
CRC64Test_SOURCES = CRC64Test.cxx
CRC64Test_LDADD = ../src/libcrc64.la
TESTS = CRC64Test
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment