Imported healpix tree

This commit is contained in:
Guilhem Lavaux 2012-10-30 13:56:48 -04:00
parent 4182c30485
commit 4bfb62f177
136 changed files with 26534 additions and 0 deletions

83
external/healpix/c_utils/c_utils.c vendored Normal file
View file

@ -0,0 +1,83 @@
/*
* 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 Max-Planck-Society
* Author: Martin Reinecke
*/
#include <stdio.h>
#include <stdlib.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);
exit(1);
}
/* 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

125
external/healpix/c_utils/c_utils.h vendored Normal file
View file

@ -0,0 +1,125 @@
/*
* 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 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
#define UTIL_ASSERT(cond,msg) \
if(!(cond)) util_fail_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg)
#define UTIL_WARN(cond,msg) \
if(!(cond)) util_warn_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg)
#define UTIL_FAIL(msg) \
util_fail_(__FILE__,__LINE__,UTIL_FUNC_NAME__,msg)
#define ALLOC(ptr,type,num) \
do { (ptr)=(type *)util_malloc_((num)*sizeof(type)); } while (0)
#define RALLOC(type,num) \
((type *)util_malloc_((num)*sizeof(type)))
#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 REALLOC(ptr,type,num) \
do { \
ptr = (type *)realloc(ptr,(num)*sizeof(type)); \
UTIL_ASSERT(ptr,"realloc() failed"); \
} 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)
#define SET_ARRAY(ptr,i1,i2,val) \
do { \
ptrdiff_t cnt_; \
for (cnt_=(i1);cnt_<(i2);++cnt_) (ptr)[cnt_]=(val); \
} while(0)
#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

18
external/healpix/c_utils/planck.make vendored Normal file
View 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
OBJ:=$(OBJ:%=$(OD)/%)
$(OBJ): $(HDR_$(PKG)) | $(OD)_mkdir
$(LIB_$(PKG)): $(OBJ)
all_hdr+=$(HDR_$(PKG))
all_lib+=$(LIB_$(PKG))

137
external/healpix/c_utils/sse_utils.h vendored Normal file
View file

@ -0,0 +1,137 @@
/*
* 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 sse_utils.h
* SSE/SSE2/SSE3-related functionality
*
* Copyright (C) 2010 Max-Planck-Society
* \author Martin Reinecke
*/
#ifndef PLANCK_SSE_UTILS_H
#define PLANCK_SSE_UTILS_H
#ifndef PLANCK_DISABLE_SSE
#if (defined(__SSE__))
#include <xmmintrin.h>
#define PLANCK_HAVE_SSE
#ifdef __cplusplus
extern "C" {
#endif
typedef __m128 v4sf; /* vector of 4 floats (SSE1) */
typedef union {
float f[4];
v4sf v;
} V4SF;
static inline v4sf build_v4sf (float a, float b, float c, float d)
{ return _mm_set_ps(d,c,b,a); }
static inline void read_v4sf (v4sf v, float *a, float *b, float *c, float *d)
{
V4SF tmp;
tmp.v = v;
if (a) *a=tmp.f[0];
if (b) *b=tmp.f[1];
if (c) *c=tmp.f[2];
if (d) *d=tmp.f[3];
}
#ifdef __cplusplus
}
#endif
#endif
#if (defined(__SSE2__))
#include <emmintrin.h>
#define PLANCK_HAVE_SSE2
#ifdef __cplusplus
extern "C" {
#endif
typedef __m128d v2df; /* vector of 2 doubles (SSE2) */
typedef union {
double d[2];
v2df v;
} V2DF;
typedef struct {
v2df a,b;
} v2df2;
typedef struct {
V2DF a,b;
} V2DF2;
#define V2DF_SIGNMASK \
_mm_castsi128_pd(_mm_set_epi32(-0x80000000,0,-0x80000000,0))
static inline v2df build_v2df (double a, double b)
{ return _mm_set_pd(b,a); }
static inline void read_v2df (v2df v, double *a, double *b)
{ _mm_store_sd(a,v); _mm_storeh_pd(b,v); }
static inline int v2df_any_gt (v2df a, v2df b)
{
return (_mm_movemask_pd(_mm_cmpgt_pd(_mm_andnot_pd(V2DF_SIGNMASK,a),b))!=0);
}
static inline int v2df_all_ge (v2df a, v2df b)
{
return (_mm_movemask_pd(_mm_cmplt_pd(_mm_andnot_pd(V2DF_SIGNMASK,a),b))==0);
}
static inline V2DF to_V2DF (v2df x)
{ V2DF X; X.v=x; return X; }
static inline V2DF2 to_V2DF2 (v2df2 x)
{ V2DF2 X; X.a.v=x.a; X.b.v=x.b; return X; }
static inline v2df2 to_v2df2 (V2DF2 X)
{ v2df2 x; x.a=X.a.v; x.b=X.b.v; return x; }
static inline v2df2 zero_v2df2(void)
{ v2df2 x; x.a=x.b=_mm_setzero_pd(); return x; }
#ifdef __cplusplus
}
#endif
#endif
#if (defined(__SSE3__))
#include <pmmintrin.h>
#define PLANCK_HAVE_SSE3
#endif
#endif
#endif

78
external/healpix/c_utils/walltime_c.c vendored Normal file
View file

@ -0,0 +1,78 @@
/*
* 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 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
}
typedef struct
{
double ts,ta;
int on;
} wTimer;
#define NTIMERS 100
static wTimer wT[NTIMERS];
int wTimer_num(void)
{ return NTIMERS; }
void wTimer_reset(int n)
{ wT[n].ts=wT[n].ta=wT[n].on=0; }
void wTimer_start(int n)
{ wT[n].ts=wallTime(); wT[n].on=1; }
void wTimer_stop(int n)
{
if (wT[n].on)
{ wT[n].ta+=wallTime()-wT[n].ts; wT[n].on=0; }
}
double wTimer_acc(int n)
{ return wT[n].on ? wT[n].ta+wallTime()-wT[n].ts : wT[n].ta; }

59
external/healpix/c_utils/walltime_c.h vendored Normal file
View file

@ -0,0 +1,59 @@
/*
* 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
</li>
\note Only useful for measuring time differences. */
double wallTime(void);
int wTimer_num(void);
void wTimer_reset(int n);
void wTimer_start(int n);
void wTimer_stop(int n);
double wTimer_acc(int n);
#ifdef __cplusplus
}
#endif
#endif