Fixed error message. Imported libsharp
This commit is contained in:
parent
3aa898e636
commit
bddd26a5ca
65 changed files with 18489 additions and 1 deletions
81
external/sharp/c_utils/c_utils.c
vendored
Normal file
81
external/sharp/c_utils/c_utils.c
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of libc_utils.
|
||||
*
|
||||
* libc_utils 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* libc_utils 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 libc_utils; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* libc_utils is being developed at the Max-Planck-Institut fuer Astrophysik
|
||||
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
|
||||
* (DLR).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Convenience functions
|
||||
*
|
||||
* Copyright (C) 2008, 2009, 2010, 2011, 2012 Max-Planck-Society
|
||||
* Author: Martin Reinecke
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "c_utils.h"
|
||||
|
||||
void util_fail_ (const char *file, int line, const char *func, const char *msg)
|
||||
{
|
||||
fprintf(stderr,"%s, %i (%s):\n%s\n",file,line,func,msg);
|
||||
exit(1);
|
||||
}
|
||||
void util_warn_ (const char *file, int line, const char *func, const char *msg)
|
||||
{
|
||||
fprintf(stderr,"%s, %i (%s):\n%s\n",file,line,func,msg);
|
||||
}
|
||||
|
||||
/* This function tries to avoid allocations with a total size close to a high
|
||||
power of two (called the "critical stride" here), by adding a few more bytes
|
||||
if necssary. This lowers the probability that two arrays differ by a multiple
|
||||
of the critical stride in their starting address, which in turn lowers the
|
||||
risk of cache line contention. */
|
||||
static size_t manipsize(size_t sz)
|
||||
{
|
||||
const size_t critical_stride=4096, cacheline=64, overhead=32;
|
||||
if (sz < (critical_stride/2)) return sz;
|
||||
if (((sz+overhead)%critical_stride)>(2*cacheline)) return sz;
|
||||
return sz+2*cacheline;
|
||||
}
|
||||
|
||||
#ifdef __SSE__
|
||||
#include <xmmintrin.h>
|
||||
void *util_malloc_ (size_t sz)
|
||||
{
|
||||
void *res;
|
||||
if (sz==0) return NULL;
|
||||
res = _mm_malloc(manipsize(sz),16);
|
||||
UTIL_ASSERT(res,"_mm_malloc() failed");
|
||||
return res;
|
||||
}
|
||||
void util_free_ (void *ptr)
|
||||
{ if ((ptr)!=NULL) _mm_free(ptr); }
|
||||
#else
|
||||
void *util_malloc_ (size_t sz)
|
||||
{
|
||||
void *res;
|
||||
if (sz==0) return NULL;
|
||||
res = malloc(manipsize(sz));
|
||||
UTIL_ASSERT(res,"malloc() failed");
|
||||
return res;
|
||||
}
|
||||
void util_free_ (void *ptr)
|
||||
{ if ((ptr)!=NULL) free(ptr); }
|
||||
#endif
|
147
external/sharp/c_utils/c_utils.h
vendored
Normal file
147
external/sharp/c_utils/c_utils.h
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* This file is part of libc_utils.
|
||||
*
|
||||
* libc_utils 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* libc_utils 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 libc_utils; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* libc_utils is being developed at the Max-Planck-Institut fuer Astrophysik
|
||||
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
|
||||
* (DLR).
|
||||
*/
|
||||
|
||||
/*! \file c_utils.h
|
||||
* Convenience functions
|
||||
*
|
||||
* Copyright (C) 2008, 2009, 2010, 2011 Max-Planck-Society
|
||||
* \author Martin Reinecke
|
||||
* \note This file should only be included from .c files, NOT from .h files.
|
||||
*/
|
||||
|
||||
#ifndef PLANCK_C_UTILS_H
|
||||
#define PLANCK_C_UTILS_H
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void util_fail_ (const char *file, int line, const char *func, const char *msg);
|
||||
void util_warn_ (const char *file, int line, const char *func, const char *msg);
|
||||
void *util_malloc_ (size_t sz);
|
||||
void util_free_ (void *ptr);
|
||||
|
||||
#if defined (__GNUC__)
|
||||
#define UTIL_FUNC_NAME__ __func__
|
||||
#else
|
||||
#define UTIL_FUNC_NAME__ "unknown"
|
||||
#endif
|
||||
|
||||
/*! \def UTIL_ASSERT(cond,msg)
|
||||
If \a cond is false, print an error message containing function name,
|
||||
source file name and line number of the call, as well as \a msg;
|
||||
then exit the program with an error status. */
|
||||
#define UTIL_ASSERT(cond,msg) \
|
||||
if(!(cond)) util_fail_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg)
|
||||
/*! \def UTIL_WARN(cond,msg)
|
||||
If \a cond is false, print an warning containing function name,
|
||||
source file name and line number of the call, as well as \a msg. */
|
||||
#define UTIL_WARN(cond,msg) \
|
||||
if(!(cond)) util_warn_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg)
|
||||
/*! \def UTIL_FAIL(msg)
|
||||
Print an error message containing function name,
|
||||
source file name and line number of the call, as well as \a msg;
|
||||
then exit the program with an error status. */
|
||||
#define UTIL_FAIL(msg) \
|
||||
util_fail_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg)
|
||||
|
||||
/*! \def ALLOC(ptr,type,num)
|
||||
Allocate space for \a num objects of type \a type. Make sure that the
|
||||
allocation succeeded, else stop the program with an error. Return the
|
||||
resulting pointer in \a ptr. */
|
||||
#define ALLOC(ptr,type,num) \
|
||||
do { (ptr)=(type *)util_malloc_((num)*sizeof(type)); } while (0)
|
||||
/*! \def RALLOC(type,num)
|
||||
Allocate space for \a num objects of type \a type. Make sure that the
|
||||
allocation succeeded, else stop the program with an error. Cast the
|
||||
resulting pointer to \a (type*). */
|
||||
#define RALLOC(type,num) \
|
||||
((type *)util_malloc_((num)*sizeof(type)))
|
||||
/*! \def DEALLOC(ptr)
|
||||
Deallocate \a ptr. It must have been allocated using \a ALLOC or
|
||||
\a RALLOC. */
|
||||
#define DEALLOC(ptr) \
|
||||
do { util_free_(ptr); (ptr)=NULL; } while(0)
|
||||
#define RESIZE(ptr,type,num) \
|
||||
do { util_free_(ptr); ALLOC(ptr,type,num); } while(0)
|
||||
#define GROW(ptr,type,sz_old,sz_new) \
|
||||
do { \
|
||||
if ((sz_new)>(sz_old)) \
|
||||
{ RESIZE(ptr,type,2*(sz_new));sz_old=2*(sz_new); } \
|
||||
} while(0)
|
||||
/*! \def SET_ARRAY(ptr,i1,i2,val)
|
||||
Set the entries \a ptr[i1] ... \a ptr[i2-1] to \a val. */
|
||||
#define SET_ARRAY(ptr,i1,i2,val) \
|
||||
do { \
|
||||
ptrdiff_t cnt_; \
|
||||
for (cnt_=(i1);cnt_<(i2);++cnt_) (ptr)[cnt_]=(val); \
|
||||
} while(0)
|
||||
/*! \def COPY_ARRAY(src,dest,i1,i2)
|
||||
Copy the entries \a src[i1] ... \a src[i2-1] to
|
||||
\a dest[i1] ... \a dest[i2-1]. */
|
||||
#define COPY_ARRAY(src,dest,i1,i2) \
|
||||
do { \
|
||||
ptrdiff_t cnt_; \
|
||||
for (cnt_=(i1);cnt_<(i2);++cnt_) (dest)[cnt_]=(src)[cnt_]; \
|
||||
} while(0)
|
||||
|
||||
#define ALLOC2D(ptr,type,num1,num2) \
|
||||
do { \
|
||||
size_t cnt_, num1_=(num1), num2_=(num2); \
|
||||
ALLOC(ptr,type *,num1_); \
|
||||
ALLOC(ptr[0],type,num1_*num2_); \
|
||||
for (cnt_=1; cnt_<num1_; ++cnt_) \
|
||||
ptr[cnt_]=ptr[cnt_-1]+num2_; \
|
||||
} while(0)
|
||||
#define DEALLOC2D(ptr) \
|
||||
do { if(ptr) DEALLOC((ptr)[0]); DEALLOC(ptr); } while(0)
|
||||
|
||||
#define FAPPROX(a,b,eps) \
|
||||
(fabs((a)-(b))<((eps)*fabs(b)))
|
||||
#define ABSAPPROX(a,b,eps) \
|
||||
(fabs((a)-(b))<(eps))
|
||||
#define IMAX(a,b) \
|
||||
(((a)>(b)) ? (a) : (b))
|
||||
#define IMIN(a,b) \
|
||||
(((a)<(b)) ? (a) : (b))
|
||||
|
||||
#define SWAP(a,b,type) \
|
||||
do { type tmp_=(a); (a)=(b); (b)=tmp_; } while(0)
|
||||
|
||||
#define CHECK_STACK_ALIGN(align) \
|
||||
do { \
|
||||
double foo; \
|
||||
UTIL_WARN((((size_t)(&foo))&(align-1))==0, \
|
||||
"WARNING: stack not sufficiently aligned!"); \
|
||||
} while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
67
external/sharp/c_utils/memusage.c
vendored
Normal file
67
external/sharp/c_utils/memusage.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* This file is part of libc_utils.
|
||||
*
|
||||
* libc_utils 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* libc_utils 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 libc_utils; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* libc_utils is being developed at the Max-Planck-Institut fuer Astrophysik
|
||||
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
|
||||
* (DLR).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Functionality for measuring memory consumption
|
||||
*
|
||||
* Copyright (C) 2012 Max-Planck-Society
|
||||
* Author: Martin Reinecke
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "memusage.h"
|
||||
|
||||
double residentSetSize(void)
|
||||
{
|
||||
FILE *statm = fopen("/proc/self/statm","r");
|
||||
double res;
|
||||
if (!statm) return -1.0;
|
||||
fscanf(statm,"%*f %lf",&res);
|
||||
fclose(statm);
|
||||
return (res*4096);
|
||||
}
|
||||
|
||||
double VmHWM(void)
|
||||
{
|
||||
char word[1024];
|
||||
FILE *f = fopen("/proc/self/status", "r");
|
||||
double res;
|
||||
if (!f) return -1.0;
|
||||
while(1)
|
||||
{
|
||||
if (fscanf (f,"%1023s",word)<0)
|
||||
{ fclose(f); return -1.0; }
|
||||
if (!strncmp(word, "VmHWM:", 6))
|
||||
{
|
||||
fscanf(f,"%lf",&res);
|
||||
fscanf(f,"%2s",word);
|
||||
if (strncmp(word, "kB", 2))
|
||||
{ fclose(f); return -1.0; }
|
||||
res *=1024;
|
||||
fclose(f);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
51
external/sharp/c_utils/memusage.h
vendored
Normal file
51
external/sharp/c_utils/memusage.h
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of libc_utils.
|
||||
*
|
||||
* libc_utils 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* libc_utils 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 libc_utils; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* libc_utils is being developed at the Max-Planck-Institut fuer Astrophysik
|
||||
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
|
||||
* (DLR).
|
||||
*/
|
||||
|
||||
/*! \file memusage.h
|
||||
* Functionality for measuring memory consumption
|
||||
*
|
||||
* Copyright (C) 2012 Max-Planck-Society
|
||||
* \author Martin Reinecke
|
||||
*/
|
||||
|
||||
#ifndef PLANCK_MEMUSAGE_H
|
||||
#define PLANCK_MEMUSAGE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! Returns the current resident set size in bytes.
|
||||
\note Currently only supported on Linux. Returns -1 if unsupported. */
|
||||
double residentSetSize(void);
|
||||
|
||||
/*! Returns the high water mark of the resident set size in bytes.
|
||||
\note Currently only supported on Linux. Returns -1 if unsupported. */
|
||||
double VmHWM(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
18
external/sharp/c_utils/planck.make
vendored
Normal file
18
external/sharp/c_utils/planck.make
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
PKG:=c_utils
|
||||
|
||||
SD:=$(SRCROOT)/$(PKG)
|
||||
OD:=$(BLDROOT)/$(PKG)
|
||||
|
||||
FULL_INCLUDE+= -I$(SD)
|
||||
|
||||
HDR_$(PKG):=$(SD)/*.h
|
||||
LIB_$(PKG):=$(LIBDIR)/libc_utils.a
|
||||
|
||||
OBJ:=c_utils.o walltime_c.o memusage.o
|
||||
OBJ:=$(OBJ:%=$(OD)/%)
|
||||
|
||||
$(OBJ): $(HDR_$(PKG)) | $(OD)_mkdir
|
||||
$(LIB_$(PKG)): $(OBJ)
|
||||
|
||||
all_hdr+=$(HDR_$(PKG))
|
||||
all_lib+=$(LIB_$(PKG))
|
54
external/sharp/c_utils/walltime_c.c
vendored
Normal file
54
external/sharp/c_utils/walltime_c.c
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* This file is part of libc_utils.
|
||||
*
|
||||
* libc_utils 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* libc_utils 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 libc_utils; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* libc_utils is being developed at the Max-Planck-Institut fuer Astrophysik
|
||||
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
|
||||
* (DLR).
|
||||
*/
|
||||
|
||||
/*
|
||||
* Functionality for reading wall clock time
|
||||
*
|
||||
* Copyright (C) 2010, 2011 Max-Planck-Society
|
||||
* Author: Martin Reinecke
|
||||
*/
|
||||
|
||||
#if defined (_OPENMP)
|
||||
#include <omp.h>
|
||||
#elif defined (USE_MPI)
|
||||
#include "mpi.h"
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "walltime_c.h"
|
||||
|
||||
double wallTime(void)
|
||||
{
|
||||
#if defined (_OPENMP)
|
||||
return omp_get_wtime();
|
||||
#elif defined (USE_MPI)
|
||||
return MPI_Wtime();
|
||||
#else
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return t.tv_sec + 1e-6*t.tv_usec;
|
||||
#endif
|
||||
}
|
54
external/sharp/c_utils/walltime_c.h
vendored
Normal file
54
external/sharp/c_utils/walltime_c.h
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* This file is part of libc_utils.
|
||||
*
|
||||
* libc_utils 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* libc_utils 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 libc_utils; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* libc_utils is being developed at the Max-Planck-Institut fuer Astrophysik
|
||||
* and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
|
||||
* (DLR).
|
||||
*/
|
||||
|
||||
/*! \file walltime_c.h
|
||||
* Functionality for reading wall clock time
|
||||
*
|
||||
* Copyright (C) 2010 Max-Planck-Society
|
||||
* \author Martin Reinecke
|
||||
*/
|
||||
|
||||
#ifndef PLANCK_WALLTIME_C_H
|
||||
#define PLANCK_WALLTIME_C_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! Returns an approximation of the current wall time (in seconds).
|
||||
The first available of the following timers will be used:
|
||||
<ul>
|
||||
<li> \a omp_get_wtime(), if OpenMP is available
|
||||
<li> \a MPI_Wtime(), if MPI is available
|
||||
<li> \a gettimeofday() otherwise
|
||||
</ul>
|
||||
\note Only useful for measuring time differences.
|
||||
\note This function has an execution time between 10 and 100 nanoseconds. */
|
||||
double wallTime(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue