diff --git a/c_tools/mock/loaders/multidark_loader.cpp b/c_tools/mock/loaders/multidark_loader.cpp index 01a37dd..fbe26ba 100644 --- a/c_tools/mock/loaders/multidark_loader.cpp +++ b/c_tools/mock/loaders/multidark_loader.cpp @@ -27,12 +27,14 @@ #include #include #include "simulation_loader.hpp" -#include using boost::format; using namespace std; using namespace CosmoTool; +static const double one_kpc = 3.08567802e16; /* km */ +static const double one_Gyr = 3.1558149984e16; /* sec */ + class MultiDarkLoader: public SimulationLoader { protected: diff --git a/c_tools/mock/loaders/sdf_loader.cpp b/c_tools/mock/loaders/sdf_loader.cpp index f72aae6..dd8a8d9 100644 --- a/c_tools/mock/loaders/sdf_loader.cpp +++ b/c_tools/mock/loaders/sdf_loader.cpp @@ -26,16 +26,44 @@ #include #include "sdfloader_internal.hpp" #include "simulation_loader.hpp" -#include -#include -#include -#include +#include + +#undef SDFgetfloatOrDie +#undef SDFgetdoubleOrDie +#undef SDFgetintOrDie using boost::format; using namespace std; using namespace CosmoTool; +static const double one_kpc = 3.08567802e16; /* km */ +static const double one_Gyr = 3.1558149984e16; /* sec */ + +static void SDFgetfloatOrDie(SDF *sdfp, const char *name, float *v) +{ + if( SDFgetfloat(sdfp, name, v) ) { + cerr << format("SDFgetfloat(%s) failed") % name << endl; + abort(); + } +} + +static void SDFgetdoubleOrDie(SDF *sdfp, const char *name, double *v) +{ + if( SDFgetdouble(sdfp, name, v) ) { + cerr << format("SDFgetdouble(%s) failed") % name << endl; + abort(); + } +} + +static void SDFgetintOrDie(SDF *sdfp, const char *name, int *v) +{ + if( SDFgetint(sdfp, name, v) ) { + cerr << format("SDFgetint(%s) failed") % name << endl; + abort(); + } +} + class SDFLoader: public SimulationLoader { private: @@ -277,5 +305,4 @@ SimulationLoader *sdfLoader(const std::string& snapshot, int flags, void sdfLoaderInit(int& argc, char **& argv) { - MPMY_Init(&argc, &argv); } diff --git a/external/external_build.cmake b/external/external_build.cmake index 2885053..f43be0d 100644 --- a/external/external_build.cmake +++ b/external/external_build.cmake @@ -327,15 +327,20 @@ IF(SDF_SUPPORT) SET(LIBSDF_PATH ${CMAKE_SOURCE_DIR}/external/libsdf) ExternalProject_Add(libSDF + URL ${CMAKE_SOURCE_DIR}/external/mswarren-libsdf-b4b9f9464b5b.tar.gz PREFIX ${BUILD_PREFIX}/libSDF-prefix - SOURCE_DIR ${LIBSDF_PATH} CONFIGURE_COMMAND echo No configure - BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} ARCH=${LIBSDF_ARCH} - INSTALL_COMMAND ${CMAKE_COMMAND} -DDEST_DIR=${CMAKE_BINARY_DIR}/ext_build/sdf -DLIBSDF_ARCH=${LIBSDF_ARCH} -DLIBSDF_PATH=${LIBSDF_PATH} -P ${CMAKE_SOURCE_DIR}/external/install_sdf.cmake + BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -f Make.simple + INSTALL_COMMAND ${CMAKE_COMMAND} -DDEST_DIR=${CMAKE_BINARY_DIR}/ext_build/sdf -DLIBSDF_ARCH=${LIBSDF_ARCH} -DLIBSDF_PATH=${BUILD_PREFIX}/libSDF-prefix/src/libSDF -P ${CMAKE_SOURCE_DIR}/external/install_sdf.cmake BUILD_IN_SOURCE 1 + PATCH_COMMAND ${CMAKE_COMMAND} + -DBUILD_PREFIX=${BUILD_PREFIX}/libSDF-prefix + -DPATCH_FILE=${CMAKE_SOURCE_DIR}/external/patch_sdf + -DSOURCE_PREFIX=${BUILD_PREFIX}/libSDF-prefix/src/libSDF + -P ${CMAKE_SOURCE_DIR}/external/check_and_apply_patch.cmake ) - SET(LIBSDF_INCLUDE_PATH ${LIBSDF_PATH}/include) - SET(LIBSDF_LIBRARY ${LIBSDF_PATH}/Objfiles/${LIBSDF_ARCH}/libsw.a) + SET(LIBSDF_INCLUDE_PATH ${BUILD_PREFIX}/libSDF-prefix/src) + SET(LIBSDF_LIBRARY ${BUILD_PREFIX}/libSDF-prefix/src/libSDF/libSDF.a) find_library(RT_LIBRARY rt) IF (RT_LIBRARY) diff --git a/external/install_sdf.cmake b/external/install_sdf.cmake index 81cb790..065430d 100644 --- a/external/install_sdf.cmake +++ b/external/install_sdf.cmake @@ -1,4 +1,3 @@ file(MAKE_DIRECTORY ${DEST_DIR}) file(MAKE_DIRECTORY ${DEST_DIR}/bin) -file(INSTALL ${LIBSDF_PATH}/apps/SDFcvt/SDFcvt.${LIBSDF_ARCH} DESTINATION ${DEST_DIR}/bin PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_EXECUTE GROUP_READ) -file(RENAME ${DEST_DIR}/bin/SDFcvt.${LIBSDF_ARCH} ${DEST_DIR}/bin/SDFcvt) +file(INSTALL ${LIBSDF_PATH}/SDFcvt DESTINATION ${DEST_DIR}/bin PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_EXECUTE GROUP_READ) diff --git a/external/libsdf/GNUmakefile b/external/libsdf/GNUmakefile deleted file mode 100644 index 45309fd..0000000 --- a/external/libsdf/GNUmakefile +++ /dev/null @@ -1,34 +0,0 @@ -tarname:=tree19 -ARCH=x86_64 - -# Make.$(ARCH) sets many of the variables that are then used in -# Make.generic. Leaving it out can cause problems, for example, -# Make.$(ARCH) wants to redefine 'TAR'. On the other hand, leaving -# it in can cause problems (apparently) with older versions of GNUmake -# because, e.g., assignements like LOADLIBES:=-foo $(LOADLIBES) get -# 'executed' multiple times. Once in this Makefile, and once in the -# daughter makefiles. - -###include Make-common/Make.$(ARCH) - -# we should also go into SDFcvt, SDF2fld, commtst, lsv, lsvtst, (anything -# else?) and build them. Possibly under a different target? - -all: All - -# Make.generic has targets for clean, all, etc., so we need to -# spell them a little differently in this file... -include Make-common/Make.generic - -subdirs:= libSDF libmpmy libsw apps/SDFcvt - -All: - for dir in $(subdirs); do (cd $$dir; $(MAKE) ARCH=$(ARCH) all); done - -Depends : - for dir in $(subdirs); do (cd $$dir; $(MAKE) ARCH=$(ARCH) depends); done - -Clean : - for dir in $(subdirs); do (cd $$dir; $(MAKE) ARCH=$(ARCH) clean); done - -# $(treedir) diff --git a/external/libsdf/Make-common/Make.default b/external/libsdf/Make-common/Make.default deleted file mode 100644 index d2460ef..0000000 --- a/external/libsdf/Make-common/Make.default +++ /dev/null @@ -1,87 +0,0 @@ -# You can override the specification of any of these variables with -# make command line arguments. Those that should not be completely -# replaced require the "override" modifier. - -# You can further modify these values in the Make.$(ARCH) files - -ifndef defaultPAROS -defaultPAROS:=seq -endif - -ifndef defaultCC -defaultCC:=cc -endif - -ifndef defaultFC -defaultFC:=g77 -endif - -ifndef OPTIMIZE -OPTIMIZE:=-O2 -CC_SPECIFIC:=$(CC_SPECIFIC) -g -Wall -endif - -ifndef FOPTIMIZE -OPTIMIZE=-O -endif - -PAROS:=$(defaultPAROS) -CC:=$(defaultCC) -FC:=$(defaultFC) - -ifneq ($(PAROS),$(defaultPAROS)) -PAROSsuf:=-$(PAROS) -endif - -# Put a non-default CC into ARCH -ifneq ($(defaultCC),$(CC)) -override ARCH:=$(ARCH)-$(CC) -endif - -ifeq ($(FC),g77) -OPTIMIZE:=-O2 -FC_SPECIFIC:=$(FC_SPECIFIC) -g -ffast-math -endif - -# Some compilers turn off optimization with -g, so we don't specify -# -g by default on those machines. -ifdef DEBUG -override ARCH:=$(ARCH)-g -OPTIMIZE:= -endif - -# i.e., specify PROFILE=-p or PROFILE=-pg -ifdef PROFILE -override ARCH:=$(ARCH)-p -endif - -ifeq ($(PAROS),pvm) -PAROSCFLAGS:=-I$(PVM_ROOT)/include -LOADLIBES:=$(LOADLIBES) $(PVM_ROOT)/lib/$(PVM_ARCH)/libpvm3.a -endif - -ifeq ($(EXTRALIB),efence) -PRELIBS:=$(treedir)/Objfiles/$(ARCH)/libefence.a -programname:=$(programname)-efence -endif - -ifndef ARFLAGS -ARFLAGS:=r -endif - -ifndef RANLIB -RANLIB:=@echo no ranlib -endif - -ifdef fsrc -LD:=$(FC) -else -LD:=$(CC) -endif -objsuf:=.o -libext:=.a - -CFLAGS:=$(DEBUG) $(OPTIMIZE) $(PROFILE) $(CC_SPECIFIC) $(ARCH_SPECIFIC) -FFLAGS:=$(DEBUG) $(FOPTIMIZE) $(PROFILE) $(FC_SPECIFIC) $(ARCH_SPECIFIC) -LDFLAGS:=$(DEBUG) $(PROFILE) $(LDFLAGS) - diff --git a/external/libsdf/Make-common/Make.generic b/external/libsdf/Make-common/Make.generic deleted file mode 100644 index c23a12c..0000000 --- a/external/libsdf/Make-common/Make.generic +++ /dev/null @@ -1,217 +0,0 @@ -## This is a 'generic' makefile with all the stuff that we seem to -## repeat over and over in all our application (and library!) Makefiles. - -incdir=$(treedir)/include/libsdf -objdir=Objfiles/$(ARCH) -libdir=$(treedir)/Objfiles/$(ARCH) -override CFLAGS:=-I$(incdir) $(CFLAGS) $(EXTRACFLAGS) -override LDFLAGS:=$(LDFLAGS) $(EXTRALDFLAGS) -ifndef tarname -tarname:=$(programname) -endif -tarpath:=$(TARPREFIX)$(tarname) -excludepath:=$(TARPREFIX)exclude - -# Allow the local directory to do arch-specific stuff... -localmake:=$(wildcard Make.$(ARCH)) -ifneq ($(localmake),) -include $(localmake) -endif - -ifeq ($(PAROS),$(defaultPAROS)) -# we don't need mpmy if we are using the default PAROS! -LIBDEPENDS=$(libdir)/libsw.a -else -LIBDEPENDS=$(libdir)/mpmy_$(PAROS)$(objsuf) \ - $(libdir)/libsw.a -endif - -# If we're going to the trouble to list out the full directory names -# in LIBDEPENDS, there's not much point in making the linker figure them -# out (possibly erroneously) again with -L... -l... -LOADLIBES_:=$(PRELIBS) $(LIBDEPENDS) -L$(libdir) -lm $(POSTLIBS) $(LOADLIBES) - -ifdef programname -bin:=$(programname).$(ARCH)$(PAROSsuf) -# Substitue for the string PAROS in the 'src' variable -# It would be really nice if we could then check to make sure the -# file exists, and if not, substitue with, e.g., "generic". But -# I can't figure out how to do that. -_src:=$(subst PAROS,$(PAROS),$(src)) -obj=$(patsubst %.c,$(objdir)/%$(objsuf),$(src)) \ - $(patsubst %.cu,$(objdir)/%$(objsuf),$(cusrc)) \ - $(patsubst %.f,$(objdir)/%$(objsuf),$(fsrc)) -ifndef special_rule_for_all -all: $(bin) -endif - -$(bin) : $(objdir) $(obj) $(LIBDEPENDS) - $(LD) $(LDFLAGS) -o $@ $(obj) $(LOADLIBES_) - $(finishlink) - -release : $(bin) - rsync -abq $(bin) ../release -else -bin:= -endif - -ifdef libname -lib:=$(libdir)/$(libname)$(libext) -libobj=$(patsubst %.c,$(lib)($(objdir)/%$(objsuf)),$(src)) -ifeq ($(libname),libsw) -libobj:=$(libobj) $(patsubst %.c,$(lib)($(objdir)/%$(objsuf)),$(swsrc)) \ - $(patsubst %.s,$(lib)($(objdir)/%$(objsuf)),$(asmsrc)) \ - $(patsubst %.S,$(lib)($(objdir)/%$(objsuf)),$(cppasmsrc)) -endif -ifndef special_rule_for_all -all: $(lib) -endif - - -$(lib) : $(objdir) $(libdir) $(libobj) - $(RANLIB) $@ - -endif - -$(objdir)/%$(objsuf) : %.c - $(CC) $(CFLAGS) -c $< - -@mv $*$(objsuf) $@ - -$(objdir)/%$(objsuf) : %.cu - $(CUDACC) $(CUDACFLAGS) -c $< - -@mv $*$(objsuf) $@ - -$(objdir)/%$(objsuf) : %.f - $(FC) $(FFLAGS) -c $< - -@mv $*$(objsuf) $@ - -$(objdir)/%$(objsuf) : $(asmdir)/%.s - (cd $(asmdir); $(AS) $(ASFLAGS) -o $*$(objsuf) $*.s) - -@mv $(asmdir)/$*$(objsuf) $@ - -$(objdir)/%$(objsuf) : $(asmdir)/%.S - (cd $(asmdir); $(CC) $(ASFLAGS) -c -o $*$(objsuf) $*.S) - -@mv $(asmdir)/$*$(objsuf) $@ - -# Gnu tar doesn't seem to do -X exclude properly?? It's probably -# because it uses names without a leading './'. I could add a sed to -# double each line in exclude??? -ifndef TAR -TAR=/bin/tar -endif - -ifndef FIND -FIND=/usr/bin/find -endif - -MAKEDEPEND=makedepend - -ifndef RANLIB -RANLIB=/usr/bin/ranlib -endif - -$(objdir) : - if [ ! -d Objfiles ]; then mkdir Objfiles; fi - if [ ! -d $(objdir) ]; then mkdir $(objdir); fi - -$(libdir) : - if [ ! -d $(treedir)/Objfiles ]; then mkdir $(treedir)/Objfiles; fi - if [ ! -d $(libdir) ]; then mkdir $(libdir); fi - -# Use appexcludes to exclude any particular application-specific directories. -# e.g., -# appexcludes="-name data -prune -o -name secret_dir -prune" -ifdef appexcludes -extraexcludes=\( $(appexcludes) \) -o -endif - -ifndef treedir_sed -treedir_sed:=$(treedir) -endif - -# Exclude emacs backups (*~), and auto-saves (#*#) -# Exclude anything in one of the object dirs, or misc.*, -# anything named 'core' or *.tar.* or anything that's executable and -# bigger than 10k or anything at all that's bigger than 100k. -# In addition, just in case they don't exist yet, we have to explicitly -# exclude the $(tarname).tar.Z and .gz targets. -# Finally exclude the "proprietary" ibm assembly language -$(excludepath) : FORCE - ($(FIND) . $(extraexcludes) -name Objfiles -prune -o -name '*.o' -o -name '#*#' -o -name '*~' -o -name '*-' -o -name '*.bak' -o -name '*.bak2' -o -name Obsolete -o -name NOT_PORTED -o -name '*.orig' -o -name core -o -name 'lsv.core.*' -o -name 'misc.*' -o -name '*.tar.*' -o -name '*gz' -o \( -perm +0111 -and -size +10k \) -o -size +100k -o -name '*readrtc.s*' ; \ - echo ./$(tarname).tar.Z ; \ - echo ./$(tarname).tgz ; \ - echo ./$(tarname)-dist.tgz ; \ - ) | sed "s/^\.\//`basename $$PWD`\//" > $@ - -tar : $(tarpath).tgz - -dist : $(tarpath)-dist.tgz - -$(tarpath).tar.Z: $(excludepath) - (dir=`basename $$PWD`; cd `dirname $$PWD`; $(TAR) cvfX - $$dir/$(excludepath) $$dir)| compress > $(tarpath).tar.Z - -$(tarpath).tgz: $(excludepath) - (dir=`basename $$PWD`; cd `dirname $$PWD`; $(TAR) cvfX - $$dir/$(excludepath) $$dir)| gzip > $(tarpath).tgz - -$(tarpath)-dist.tgz: $(excludepath) - (dir=`basename $$PWD`; cd `dirname $$PWD`; $(TAR) cvfX - $$dir/$(excludepath) $$dir/COPY* $$dir/Make-common $$dir/INSTRUCTIONS $$dir/GNUmakefile $$dir/include $$dir/relerr $$dir/Change* $$dir/lib* $$dir/bin $$dir/lsv $$dir/shmz $$dir/snsph $$dir/nln)| gzip > $(tarpath)-dist.tgz - -# Make a floppy by writing a meta-tar file containing $(tarname).tgz -floppy: $(tarname).tgz - $(TAR) cvf /dev/fd0 $(tarname).tgz - -# clean...how much should we attempt to clean up?? Should there be -# additional clean-ables set in the application-makefile? - -# clean-clutter will remove the ~ files, the #*#, etc. -clean-clutter: FORCE - rm -f *~ #*# *.bak *.bakk - -# clean will remove the binary and object files associated with the -# current ARCH-PAROS pair -clean: FORCE clean-clutter - rm $(bin) $(objdir)/* - -# clean-all will attempt to remove all object files in Objfiles/ and -# all executables in . associated with them. USE WITH CARE!! -clean-all: FORCE clean-clutter - for dir in `ls Objfiles`; do \ - set arch=`basename $$dir`; \ - rm -rf Objfiles/$$dir; \ - rm -f $(programname).$$dir* ; \ - done - -# Run makedepend, and then massage the Makfile to the symbolic names -# for the files in $(treedir). WARNING! If $(treedir) contains -# sed meta-characters you lose in a big way! We fix this by letting you -# override it with $(treedir_sed), e.g., if treedir=.., you should -# probably set treedir_sed=\.\. . This should be automatic :-(. -# This command kills the entire line with the /usr/ dependency. -# -e '/ \/usr/d' Makefile.bak2 > foo -# The sed below leaves lines with no dependency. Is that a problem? -MAKEFILENAME=GNUmakefile -#depends: -# $(MAKEDEPEND) -f$(MAKEFILENAME) '-o$$(objsuf)' '-p$$(objdir)/' -- $(CFLAGS) -- $(src) -# cp $(MAKEFILENAME) $(MAKEFILENAME).bak2 -# sed \ -# -e '/DO NOT DELETE/,$$s!$(treedir_sed)!$$(treedir)!g'\ -# -e '/DO NOT DELETE/,$$s@ /usr/[^ ]*@@g'\ -# $(MAKEFILENAME).bak2 > $(MAKEFILENAME) - -# The last rule replaces -p$$(objdir)/ which doesn't work in openwin -# and presumably in X11R4 or earlier -depends: - $(MAKEDEPEND) -f$(MAKEFILENAME) '-o$$(objsuf)' -- $(CFLAGS) -- $(src) - cp $(MAKEFILENAME) $(MAKEFILENAME).bak2 - sed \ - -e '/DO NOT DELETE/,$$s!$(treedir_sed)!$$(treedir)!g'\ - -e '/DO NOT DELETE/,$$s@ /usr/[^ ]*@@g'\ - -e '/DO NOT DELETE/,$$s@ float.h@@g'\ - -e '/DO NOT DELETE/,$$s@ stdarg.h@@g'\ - -e '/DO NOT DELETE/,$$s@^\([A-Za-z]\)@$$(objdir)/\1@g'\ - $(MAKEFILENAME).bak2 > $(MAKEFILENAME) - -depends-nosed: - $(MAKEDEPEND) -f$(MAKEFILENAME) '-o$$(objsuf)' '-p$$(objdir)/' -- $(CFLAGS) -- $(src) - -FORCE: diff --git a/external/libsdf/Make-common/Make.x86_64 b/external/libsdf/Make-common/Make.x86_64 deleted file mode 100644 index be62088..0000000 --- a/external/libsdf/Make-common/Make.x86_64 +++ /dev/null @@ -1,25 +0,0 @@ -defaultCC:=gcc - -CC_SPECIFIC:=-g -Wall -ARCH_SPECIFIC:=-D__iX86__=x86_64 -DLONG_NK1_KEY -DSTK_FORCE_ALIGNMENT=4 -D_FILE_OFFSET_BITS=64 -DUSE_SYSTEM_MALLOC -DUSE_MPIIO -DUSE_HWCLOCK -DPROCS_PER_NODE=8 -OPTIMIZE=-O2 -AGGRESSIVE_OPT=-Ofast -LDFLAGS=-g -LEX:=flex -YACC:=bison -y - -include $(treedir)/Make-common/Make.default - -swsrc:=lsv.c swampi.c -asmdir:=asm-sse -asmsrc= -cppasmsrc= - -LOADLIBES=-lrt - -MPI_ROOT=/softs/openmpi/1.6.4-ifort-13.0-torque-CentOS5 -ifeq ($(PAROS),mpi) -LOADLIBES:=-L$(MPI_ROOT)/lib -L$(MPI_ROOT)/lib64 -lmpi -PAROSCFLAGS:=-I$(MPI_ROOT)/include -endif - diff --git a/external/libsdf/_NOTES_ b/external/libsdf/_NOTES_ deleted file mode 100644 index f7fd449..0000000 --- a/external/libsdf/_NOTES_ +++ /dev/null @@ -1 +0,0 @@ -This is Tree19, a snapshot of some of Michael S. Warren's code to handle SDF data format and parallel IO. diff --git a/external/libsdf/apps/SDFcvt/GNUmakefile b/external/libsdf/apps/SDFcvt/GNUmakefile deleted file mode 100644 index 234ff45..0000000 --- a/external/libsdf/apps/SDFcvt/GNUmakefile +++ /dev/null @@ -1,15 +0,0 @@ -TREEHOME=../.. -##### Application-specific stuff goes here - -treedir=$(TREEHOME) -programname=SDFcvt -src=SDFcvt.c - -#### end of application-specific stuff -include $(treedir)/Make-common/Make.$(ARCH) - -include $(treedir)/Make-common/Make.generic - -# DO NOT DELETE THIS LINE -- make depend depends on it. - - diff --git a/external/libsdf/apps/SDFcvt/SDFcvt.c b/external/libsdf/apps/SDFcvt/SDFcvt.c deleted file mode 100644 index f236cc1..0000000 --- a/external/libsdf/apps/SDFcvt/SDFcvt.c +++ /dev/null @@ -1,461 +0,0 @@ -/* Convert SDF to ascii - Usage: - SDFcvt [-s skip][-n nrecout][-h hdrfile] [-bfv] sdffile name ... - - Not too fancy, but it should handle most SDF files, including - non-unit arrcnt. By using -s and -n is is possible to skip - to a place in the file and examine pieces of files - that would otherwise be too big to handle. We do NOT read the - whole file into memory. We process output lines one at a time, - reading one value of each of the names into memory at a time. - Thrashing is possible. We do nothing to prevent it. - - With -v it prints a potentially useful pair of header lines - starting with '#'. - - CHANGELOG: - 6/28/94: Added the FORMAT_NATIVE option, and made it the default. - This will write SDF_INTS as ints, SDF_SHORTS as shorts, etc. It's - useful for post-processing by programs that can handle mixed types, - e.g., perl, but not AVS. - - 10/18/93: Added the -S (Swapping) flag to write binary data swapped. - Use limits.h/INT_MAX instead of SunOS values.h/MAXINT. - - 8/1/93: add the AT_A_TIME construction. We no longer process lines - one at a time. Instead, we read up to AT_A_TIME to beat the - excessive overhead in each SDFrdvecs call. One of these days - I'll add a hash table to SDF's symbol-lookup functions. Until - then, reading one element at a time will be extremely slow. - - 8/20/93: added the option to produce output in binary. This is MUCH - faster. With a little luck, perl (and presumably other programs) - can read it MUCH faster too (perl uses read and unpack). - -*/ -#define AT_A_TIME 512 /* read this many values at a time */ -#include -#include -#include -#include -#include "SDF.h" -#include "protos.h" -#include "byteswap.h" -#include "error.h" -#include "Malloc.h" - -#ifndef __SUN5__ -extern int getopt(int, char**, const char *); -extern char *optarg; -extern int optind, opterr; -#endif - -#define FORMAT_FLOAT 1 -#define FORMAT_DOUBLE 2 -#define FORMAT_INT 3 -#define FORMAT_NATIVE 4 - -int binary = 0; -int format = FORMAT_NATIVE; -int swap_out = 0; - -int fwrite_maybe_swap(void *p, size_t sz, size_t n, FILE *fp){ - if( swap_out ) - Byteswap(sz, n, p, p); - return fwrite(p, sz, n, fp); -} - -void output_char(short c){ - float f; - double d; - int i; - - if( binary ){ - switch(format){ - case FORMAT_DOUBLE: - d = c; - fwrite_maybe_swap(&d, sizeof(d), 1, stdout); - break; - case FORMAT_FLOAT: - f = c; - fwrite_maybe_swap(&f, sizeof(f), 1, stdout); - break; - case FORMAT_INT: - i = c; - fwrite_maybe_swap(&i, sizeof(i), 1, stdout); - break; - case FORMAT_NATIVE: - fwrite_maybe_swap(&c, sizeof(c), 1, stdout); - break; - } - }else{ - printf("%d", c); - } -} - -void output_short(short s){ - float f; - double d; - int i; - - if( binary ){ - switch(format){ - case FORMAT_DOUBLE: - d = s; - fwrite_maybe_swap(&d, sizeof(d), 1, stdout); - break; - case FORMAT_FLOAT: - f = s; - fwrite_maybe_swap(&f, sizeof(f), 1, stdout); - break; - case FORMAT_INT: - i = s; - fwrite_maybe_swap(&i, sizeof(i), 1, stdout); - break; - case FORMAT_NATIVE: - fwrite_maybe_swap(&s, sizeof(s), 1, stdout); - break; - } - }else{ - printf("%d", s); - } -} - -void output_int(int i){ - float f; - double d; - - if( binary ){ - switch(format){ - case FORMAT_DOUBLE: - d = i; - fwrite_maybe_swap(&d, sizeof(d), 1, stdout); - break; - case FORMAT_FLOAT: - f = i; - fwrite_maybe_swap(&f, sizeof(f), 1, stdout); - break; - case FORMAT_NATIVE: - case FORMAT_INT: - fwrite_maybe_swap(&i, sizeof(i), 1, stdout); - break; - } - }else{ - printf("%d", i); - } -} - -void output_long(long l){ - float f; - double d; - - if( binary ){ - switch(format){ - case FORMAT_DOUBLE: - d = l; - fwrite_maybe_swap(&d, sizeof(d), 1, stdout); - break; - case FORMAT_FLOAT: - f = l; - fwrite_maybe_swap(&f, sizeof(f), 1, stdout); - break; - case FORMAT_NATIVE: - case FORMAT_INT: - fwrite_maybe_swap(&l, sizeof(l), 1, stdout); - break; - } - }else{ - printf("%ld", l); - } -} - -void output_int64(int64_t i64){ - float f; - double d; - - if( binary ){ - switch(format){ - case FORMAT_DOUBLE: - d = i64; - fwrite_maybe_swap(&d, sizeof(d), 1, stdout); - break; - case FORMAT_FLOAT: - f = i64; - fwrite_maybe_swap(&f, sizeof(f), 1, stdout); - break; - case FORMAT_NATIVE: - case FORMAT_INT: - fwrite_maybe_swap(&i64, sizeof(i64), 1, stdout); - break; - } - }else{ -#if __WORDSIZE==64 - printf("%ld", i64); -#else - printf("%lld", i64); -#endif - } -} - - - -void output_float(float f){ - double d; - int i; - - if( binary ){ - switch(format){ - case FORMAT_DOUBLE: - d = f; - fwrite_maybe_swap(&d, sizeof(d), 1, stdout); - break; - case FORMAT_FLOAT: - case FORMAT_NATIVE: - fwrite_maybe_swap(&f, sizeof(f), 1, stdout); - break; - case FORMAT_INT: - i = f; - fwrite_maybe_swap(&i, sizeof(i), 1, stdout); - break; - } - }else{ - switch(format){ - case FORMAT_DOUBLE: - printf("%.15e", f); - break; - case FORMAT_FLOAT: - case FORMAT_NATIVE: - printf("%.6e", f); - break; - case FORMAT_INT: - printf("%.0f", f); - break; - } - } -} - -void output_double(double d){ - float f; - int i; - - if( binary ){ - switch(format){ - case FORMAT_NATIVE: - case FORMAT_DOUBLE: - fwrite_maybe_swap(&d, sizeof(d), 1, stdout); - break; - case FORMAT_FLOAT: - f = d; - fwrite_maybe_swap(&f, sizeof(f), 1, stdout); - break; - case FORMAT_INT: - i = d; - fwrite_maybe_swap(&i, sizeof(i), 1, stdout); - break; - } - }else{ - switch(format){ - case FORMAT_DOUBLE: - case FORMAT_NATIVE: - printf("%.15e", d); - break; - case FORMAT_FLOAT: - printf("%.6e", d); - break; - case FORMAT_INT: - printf("%.0f", d); - break; - } - } -} - -void output_string(const char *s){ - fwrite(s, strlen(s), 1, stdout); -} - -void output_separator(void){ - if( !binary ) - putchar(' '); -} - -void output_record_terminator(void){ - if( !binary ) - putchar('\n'); -} - -int main(int argc, char **argv){ - int c; - char *fname, *hdr; - SDF *sdfp; - int64_t n, start; - int nnames, nn, i, j, k, kk; - int at_a_time; - int64_t nrecs, minnrecs, maxnrecs; - char *newname; - char **names; - void **addrs; - int *nread; - int *acnt; - int *strides; - enum SDF_type_enum *types, t; - int verbose; - - hdr = NULL; - start = 0; - n = 0; - verbose = 0; - at_a_time = 0; - while((c=getopt(argc, argv, "a:h:s:n:vbfdiS")) != -1) - switch(c){ - case 'h': - hdr = optarg; - break; - case 's': - start = atoll(optarg); - break; - case 'n': - n = atoll(optarg); - break; - case 'a': - at_a_time = atoi(optarg); - break; - case 'v': - verbose = 1; - break; - case 'b': - binary = 1; - break; - case 'f': - format = FORMAT_FLOAT; - break; - case 'S': - swap_out = 1; - break; - case 'd': - format = FORMAT_DOUBLE; - break; - case 'i': - format = FORMAT_INT; - break; - case '?': - fprintf(stderr, "Usage: %s [-s start][-n number][-a at-a-time][-v][-h hdrfile][-b][-f][-d][-i][-S] sdffile name ...\n", argv[0]); - } - - fname = argv[optind]; - optind++; - sdfp = SDFopen(hdr, fname); - if( sdfp == NULL ){ - Error("Could not SDFopen(%s, %s): %s\n", - hdr?hdr:"", - fname?fname:"", - SDFerrstring); - } - if( at_a_time == 0 ) - at_a_time = AT_A_TIME; - - nnames = argc - optind; - names = Malloc(nnames*sizeof(char*)); - addrs = Malloc(nnames*sizeof(void*)); - nread = Malloc(nnames*sizeof(int)); - types = Malloc(nnames*sizeof(enum SDF_type_enum)); - strides = Malloc(nnames*sizeof(int)); - acnt = Malloc(nnames*sizeof(int)); - - nn = 0; - minnrecs = INT64_MAX; - maxnrecs = 0; - for(; optind < argc; optind++){ - newname = argv[optind]; - if( !SDFhasname(newname, sdfp) ){ - Error("%s not in %s\n", newname, fname); - } - t = SDFtype(newname, sdfp); - acnt[nn] = SDFarrcnt(newname, sdfp); - addrs[nn] = Malloc(SDFtype_sizes[t] * acnt[nn] * at_a_time); - strides[nn] = SDFtype_sizes[t]*acnt[nn]; - names[nn] = newname; - types[nn] = t; - nrecs = SDFnrecs(newname, sdfp); - if( nrecs < minnrecs ) - minnrecs = nrecs; - if( nrecs > maxnrecs ) - maxnrecs = nrecs; - nread[nn] = at_a_time; - nn++; - } - if( n==0 ){ - n = maxnrecs - start; - } - if( start+n > minnrecs ){ - Error("Not enough records to start at %ld\n", start); - } - - if( start ){ - for(j=0; j0 ){ - if( n < at_a_time ){ - at_a_time = n; - for(j=0; j -#include "error.h" - -#ifdef __cplusplus -extern "C"{ -#endif -/* Set the default behavior of the Malloc family when encountering */ -/* errors, e.g., NULL returns, etc. */ -Error_t MallocHandler(Error_t); - -void xFree (void *ptr, const char *file, int lineno); -void *xMalloc (size_t, const char *file, int lineno); -void *xRealloc (void *ptr, size_t, const char *file, int lineno); -void *xCalloc (size_t, size_t, const char *file, int lineno); -/* No extra parens needed ?? */ -void Free_f (void *ptr); -void *Malloc_f (size_t); -void *Realloc_f (void *ptr, size_t); -void *Calloc_f (size_t, size_t); -#ifdef __cplusplus -} -#endif -/* Some pre-processors are so stupid that they will convert - foo(Realloc); -into - foo(xRealloc(,,__FILE__, __LINE__)); -Thus, we can't use Realloc as function name. -*/ -#define Free(p) xFree(p, __FILE__, __LINE__) -#define Malloc(n) xMalloc(n, __FILE__, __LINE__) -#define Calloc(n,s) xCalloc(n, s, __FILE__, __LINE__) -#define Realloc(p, n) xRealloc(p, n, __FILE__, __LINE__) - -#endif /* _MAllocDOTh */ diff --git a/external/libsdf/include/libsdf/Msgs.h b/external/libsdf/include/libsdf/Msgs.h deleted file mode 100644 index 493e8ce..0000000 --- a/external/libsdf/include/libsdf/Msgs.h +++ /dev/null @@ -1,88 +0,0 @@ -/* Declarations for the functions defined in Msgs.c */ -#ifndef MsgsDOTh -#define MsgsDOTh -#include - -#include "gccextensions.h" - -/* These two typedefs simplify the task of casting function ptrs */ -/* to the appropriate type when calling Msg_addfile */ -typedef int (*Msgvfprintf_t)(void *, const char *, va_list); -typedef int (*Msgfflush_t)(void *); - -#ifdef __cplusplus -extern "C" { -#endif -/* The fflush_like function pointer MUST BE ASYNCHRONOUSLY CALLABLE */ -/* If you don't have one, don't worry. Pass NULL instead. */ -int Msg_addfile(void *fp, /* add fp to the list of msg files */ - int (*vfprintf_like)(void *, const char *, va_list), - int (*fflush_like)(void *)); -int Msg_delfile(void *fp); /* fp should no longer receive msgs */ -int Msg_on(const char *); /* turn on a specific type of msgs */ -int Msg_off(const char *); /* turn off a specific type of msgs */ -/* Normally, you should use the Msg_test macro instead. */ -int _Msg_test(const char *); /* is a specific type on or off? */ -int Msg_set_enable(int); /* enable (1) or disable (0) all message */ - /* return the previous state. */ -void Msg_turnon(const char *msg_turn_on); /* an interface to Msg_on */ - /* that calls Msg_on for every file */ - /* in a comma-whitespace delimited list */ - /* of names. If a name is specified as */ - /* NAME:lo-hi or NAME:procnum, then */ - /* messages are on only in the corresponding */ - /* processors. If the string is "nomsgs", */ - /* then msgs are totally disabled. */ -void MsgdirInit(const char *path); /* tries to do a mkdir and open */ - /* msg files for each process */ -int Msg_do(const char *fmt, ...) /* Unconditionally say something. */ - __attribute__ ((format (printf, 1, 2))) ; /* it's printf-like! */ -int Msg_doalist(const char *fmt, va_list) -/* this is broken in gcc2.4.0 through 2.4.4 */ -#ifndef BROKEN_GCC_FORMAT_ATTRIBUTE - __attribute__ ((format (printf, 1, 0))) -#endif - ; - -int Msg_flush(void); /* flush all the buffers now. */ -int Msg_flushalways(int newval);/* flush buffers after every Msg_do. - return the previous value.*/ -#ifdef __cplusplus -} -#endif - -/* Don't use these! _Msg_enabled */ -extern int _Msg_enabled; - -/* Msg is called with an extra set of parentheses, to hide */ -/* the variadic arguments, e.g. - Msg("foo", ("Hello world this is a \"foo\" message\n")); -or - Msg(__FILE__, ("Hello from file: %s, line: %d\n", __FILE__, __LINE__)); - -The macro 'Msgf' is a shorthand for the Msg(__FILE__, ...) construction. -The macro 'Msglno' is a shorthand for: - Msg(name, "%s(%d):" , __FILE__, __LINE__, ); -The macro 'Msgfunc' is a shorthand for Msg(__FUNCTION__, ...). - Thus, you can turn on messaging at the function level. -*/ - -#define Msglno(name, args) Msg(name, ("%s(%d): ", __FILE__, __LINE__)),Msg(name, args) -#define Msgf(args) Msg(__FILE__, args) -#define Msglnof(args) Msglno(__FILE__, args) -#ifdef __FUNCTION__ -#define Msgfunc(args) Msg(__FUNCTION__, args) -#else -#define Msgfunc(args) -#endif - -#ifndef NO_MSGS -#define Msg_test(name) (_Msg_enabled && _Msg_test(name)) -#define Msg(name, args) ((void)((Msg_test(name))? Msg_do args : 0 )) -#else -#define Msg_test(name) (0) -#define Msg(name, args) ((void)0) -#endif - - -#endif /* MsgsDOTh */ diff --git a/external/libsdf/include/libsdf/SDF.h b/external/libsdf/include/libsdf/SDF.h deleted file mode 100644 index 01b1eed..0000000 --- a/external/libsdf/include/libsdf/SDF.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - SDF Library for reading Self-Describing Files - Copyright (C) 1991,1992 John K. Salmon - - Terms and conditions are specified in the file "copyright.h", - and more precisely in the file COPYING.LIB which you should have - received with this library. -*/ -#ifndef sdfDOTh -#define sdfDOTh -#include -#include -#define SDF_SEEK_SET 0 -#define SDF_SEEK_CUR 1 -#define SDF_SEEK_END 2 - -#define SDF_SYNC 0 -#define SDF_ASYNC 1 - -#define SDF_SINGL 0 -#define SDF_MULTI 1 - -#ifndef INT64_MAX -#if __WORDSIZE==64 -#define INT64_MAX LONG_MAX -#else -/* #define INT64_MAX LLONG_MAX Why doesn't this work? */ -#define INT64_MAX 9223372036854775807LL -#endif -#endif - -#ifndef sdfprivateDOTh -/* It isn't really this, but I don't want to tell you what it is. */ -/* If you believe it's this, then your compiler can check prototypes */ -/* for you. */ -typedef char *SDF[32]; - -/* Identical to declaration in SDF-private.h */ -enum SDF_type_enum{SDF_NOTYPE, - SDF_CHAR, - SDF_SHORT, - SDF_INT, - SDF_LONG, - SDF_INT64, - SDF_FLOAT, - SDF_DOUBLE, - SDF_STRING}; -#endif - -/* Provided for backwards compatibility. Not recommended! */ -#ifdef SDF_OLD_ENUM_NAMES -#define CHAR SDF_CHAR -#define SHORT SDF_SHORT -#define INT SDF_INT -#define FLOAT SDF_FLOAT -#define DOUBLE SDF_DOUBLE -#define STRING SDF_STRING -#endif - -#ifdef __cplusplus -extern "C" { -#endif -/* Two arrays indexed by a type_enum */ -extern char *SDFtype_names[]; -extern int SDFtype_sizes[]; - -extern char SDFerrstring[]; - -int SDFissdf(const char *filename); /* Not guaranteed correct! */ -SDF *SDFopen(const char *hdrfname, const char *datafname); -int SDFseekable(SDF *hdr); /* are non-sequential reads allowed? */ -int SDFclose(SDF *hdr); -int SDFnvecs(SDF *hdr); -int SDFhasname(const char *name, SDF *hdr); -char **SDFvecnames(SDF *hdr); -int64_t SDFnrecs(const char *name, SDF *hdr); -int SDFarrcnt(const char *name, SDF *hdr); -enum SDF_type_enum SDFtype(const char *name, SDF *hdr); -int SDFseek(const char *name, int64_t offset, int whence, SDF *hdr); -int SDFtell(const char *name, SDF *hdr); -unsigned int SDFcpubyteorder(void); -unsigned int SDFbyteorder(SDF *hdr); -int SDFswap(SDF *hdr); -int SDFnoswap(SDF *hdr); -int SDFisswapping(SDF *hdr); -int SDFsetmaxbufsz(int new_size); -int SDFrdvecs(SDF *hdr, ... - /* char *name, int n, void *address, int stride, - ... , - NULL */ ); -int SDFrdvecsv(SDF *hdr, va_list ap); -/* Where is the const supposed to go? */ -int SDFrdvecsarr(SDF *hdr, int nreq, - char **names, int *ns, void **addresses, int *strides); - -int SDFseekrdvecs(SDF *hdr, ... - /* char *name, int start, int n, void *addr, int stride, - ... , - NULL */ ); -int SDFseekrdvecsv(SDF *hdr, va_list ap); -int SDFseekrdvecsarr(SDF *hdr, int nreq, - char **names, int64_t *starts, int *ns, void **addresses, int *strides); -void SDFsetiomode(int mode); - -/* These two subvert the SDF "abstraction" and tell you about */ -/* the actual layout of the file. Are you absolutely sure you need */ -/* to call these? */ -int64_t SDFfileoffset(const char *name, SDF *hdr); -int64_t SDFfilestride(const char *name, SDF *hdr); - -/* These four are harder to write than one might guess. */ -/* They're in the library to avoid duplicating code. */ -int SDFgetint(SDF *sdfp, char *name, int *value); -int SDFgetint64(SDF *sdfp, char *name, int64_t *value); -int SDFgetfloat(SDF *sdfp, char *name, float *value); -int SDFgetdouble(SDF *sdfp, char *name, double *value); -int SDFgetstring(SDF *sdfp, const char *name, char *string, int size); -#ifdef __cplusplus -} -#endif - -/* four macros that call SDFget and bail out if the value isn't there */ -#define SDFgetintOrDie(sdfp, name, value) \ - do{ if( SDFgetint(sdfp, name, value) ) \ - Error("SDFgetint(\"%s\") failed\n", name); } while(0) - -#define SDFgetint64OrDie(sdfp, name, value) \ - do{ if( SDFgetint64(sdfp, name, value) ) \ - Error("SDFgetint64(\"%s\") failed\n", name); } while(0) - -#define SDFgetfloatOrDie(sdfp, name, value) \ - do{ if( SDFgetfloat(sdfp, name, value) ) \ - Error("SDFgetfloat(\"%s\") failed\n", name); } while(0) - -#define SDFgetdoubleOrDie(sdfp, name, value) \ - do{ if( SDFgetdouble(sdfp, name, value) ) \ - Error("SDFgetdouble(\"%s\") failed\n", name); } while(0) - -#define SDFgetstringOrDie(sdfp, name, string, size) \ - do{ if( SDFgetstring(sdfp, name, string, size) ) \ - Error("SDFgetstring(\"%s\") failed", name); } while(0) - -/* And four more that use a default if the value isn't there */ -#define SDFgetintOrDefault(sdfp, name, value, def) \ - do{ if( SDFgetint(sdfp, name, value) ){ \ - *value = def;}} while(0) - -#define SDFgetint64OrDefault(sdfp, name, value, def) \ - do{ if( SDFgetint64(sdfp, name, value) ){ \ - *value = def;}} while(0) - -#define SDFgetfloatOrDefault(sdfp, name, value, def) \ - do{ if( SDFgetfloat(sdfp, name, value) ){ \ - *value = def;} } while(0) - - -#define SDFgetdoubleOrDefault(sdfp, name, value, def) \ - do{ if( SDFgetdouble(sdfp, name, value) ){ \ - *value = def;} } while(0) - -#define SDFgetstringOrDefault(sdfp, name, value, size, def) \ - do{ if( SDFgetstring(sdfp, name, value, size) ){ \ - strncpy(value, def, size);} } while(0) - -#endif /* sdfDOTh */ diff --git a/external/libsdf/include/libsdf/SDFread.h b/external/libsdf/include/libsdf/SDFread.h deleted file mode 100644 index ac76884..0000000 --- a/external/libsdf/include/libsdf/SDFread.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _RdDataDOTh -#define _RdDataDOTh - -#include "timers.h" -#include "SDF.h" -/* Can read distributed datafiles if csdfp contains something like: -struct {char datafiles[64];}[4] = {"foo1", "foo2", "foo3", "foo4"}; -*/ -#ifdef __cplusplus -extern "C" { -#endif -extern Timer_t SDFreadTm; - -/* By default, SDFread will look for a "char datafile[]" in csdfp and - read data from there. The name of the variable to look for is - stored in this variable. I.e., it defaults to "datafile". Set it - to NULL to turn this feature off altogether. */ -extern char *SDFread_datafile; - -/* Do the same thing with "hdrfile" */ -extern char *SDFread_hdrfile; - -/* Also by default, SDFread will look for a variable "int npart" in csdfp - and attempt to read that many "particles" from datafile. This variable - storest the name of that variable. Default: "npart"; */ -extern char *SDFread_npart; - -SDF *SDFread(SDF *csdfp, void **btabp, int *gnobjp, int *nobjp, int stride, - /* char *name, offset_t offset, int *confirm */...); -SDF *SDFread64(SDF *csdfp, void **btabp, int64_t *gnobjp, int *nobjp, int stride, - /* char *name, offset_t offset, int *confirm */...); -SDF *SDFreadf(char *hdr, char *name, void **btabp, int *gnobjp, int *nobjp, - int stride, /* char *name, offset_t offset, int *confirm */...); -SDF *SDFreadf64(char *hdr, char *name, void **btabp, int64_t *gnobjp, int *nobjp, - int stride, /* char *name, offset_t offset, int *confirm */...); -#ifdef __cplusplus -} -#endif -#endif diff --git a/external/libsdf/include/libsdf/SDFwrite.h b/external/libsdf/include/libsdf/SDFwrite.h deleted file mode 100644 index 4963ffa..0000000 --- a/external/libsdf/include/libsdf/SDFwrite.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _SDFWriteDOTh -#define _SDFWRiteDOTh - -#ifdef __cplusplus -extern "C" { -#endif -void SDFwrite(const char *filename, int gnobj, int nobj, const void *btab, - int bsize, const char *bodydesc, - /* const char *name, SDF_type_enum type, val */ ...); -void SDFwrite64(const char *filename, int64_t gnobj, int64_t nobj, const void *btab, - int bsize, const char *bodydesc, - /* const char *name, SDF_type_enum type, val */ ...); -void SDFappend64(const char *filename, int64_t gnobj, int64_t nobj, const void *btab, - int bsize, const char *bodydesc, - /* const char *name, SDF_type_enum type, val */ ...); - -/* A trivial special case, just don't write any body data */ -void SDFwritehdr(const char *filename, const char *bodydesc, - /* const char *name, SDF_type_enum type, val */ ...); - -void SDFunsetwroteheader(void); -void SDFsetwroteheader(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/external/libsdf/include/libsdf/abm.h b/external/libsdf/include/libsdf/abm.h deleted file mode 100644 index 1e54286..0000000 --- a/external/libsdf/include/libsdf/abm.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef ABM_dot_H -#define ABM_dot_H - -#include "chn.h" -#include "dll.h" -#include "mpmy.h" -#include "timers.h" - -/* Notice that memcpy is a perfectly good ABMpktz_t. Overzealous - compilers will complain because arg2 isn't const and arg3 is an int - rather than a size_t. AAAARRRRGGGGHHHH.... */ -typedef void (ABMpktz_t)(void *to, void *arg, int sz); -typedef void (ABMhndlr_t)(int src, int len, void *ptr); - -typedef struct { - int nfuncs; - ABMhndlr_t **hndlarray; - Dll undeliveredLL; /* An LL of all messages that have been ISent, but - not Test'ed affirmative. */ - int done; /* I hate these! */ - int doc; - int allbitsdone; - int alldone; - Dll *Enqueued; /* array of DLL's, one for each dest */ - int *destarr; /* which of Enqueued are non-empty? */ - int ndests; /* how many of Enqueued are non-empty? */ - int *cntarr; /* how much data for each dest? */ - Chn undelChn; /* chain for undelivereLL */ - Chn QelmtChn; /* chain for all of the Enqueued Dll's */ - MPMY_Comm_request Recv_Hndl; - int tag; - int pktsize; - char *recvbuf1; - char *recvbuf2; - char *recvbufA; - char *recvbufB; -} ABM ; - -#ifdef __cplusplus -extern "C"{ -#endif -/* Set the whole thing up. State goes into abm */ -void ABMSetup(ABM *abm, int pktsize, int tag, int nfuncs, ABMhndlr_t *hndlarray[]); - -/* Post a message of given size. When it's time to deliver it, - the packetizing func will be called-back with the given arg. - When it arrives, the 'handler' hndlarray[type] on the dest node - will be called to process it. */ -void ABMPost(ABM *abm, int dest, int sz, int type, ABMpktz_t *func, void *arg); - -/* Poll for incoming messages. Handlers get called under here. */ -int ABMPoll(ABM *abm); - -/* Poll for incoming messages. But wait until something arrives. */ -int ABMPollWait(ABM *abm); - -/* Flush any Posted messages to dest. Packetizers get called under here. (but - this may be called by ABMPost if we run out of space) */ -void ABMFlush(ABM *abm); - -/* Assert that we won't be sending out any more 'requests' AND that they, - along with any 'cascades' that they may have generated have been received. - This is automatic with a request/reply type protocol, but requires some - kind of ack if messages do not generate a reply to the originator. - See pqsort.c for one way to do the acks. */ -void ABMIamDone(ABM *abm); - -/* Return true if everybody has called ABMIamDone */ -int ABMAllDone(ABM *abm); - -/* Free all memory. Etc. */ -void ABMShutdown(ABM *abm); - -/* Maintain a bunch of 'informative' Counter_t's. They record the number - of bytes sent in messages of logarithmically binned lenths between - lo and hi. */ -void ABMHistEnable(int log2lo, int log2hi); - -#define ABMHISTFIRST 3 /* don't bother with the hist below 8 bytes */ -#define ABMHISTLEN 16 -extern Counter_t ABMIsendCnt; /* How many 'buffers' did we actualy Isend. */ -extern Counter_t ABMPostCnt; /* How many 'messages' did we Post. */ -extern Counter_t ABMByteCnt; /* How many bytes were Isent. */ -extern Counter_t ABMHistCnt[ABMHISTLEN]; - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/external/libsdf/include/libsdf/byteswap.h b/external/libsdf/include/libsdf/byteswap.h deleted file mode 100644 index 3723d8f..0000000 --- a/external/libsdf/include/libsdf/byteswap.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _ByteSwapDOTh -#define _ByteSwapDOTh - -/* A general, in-place, byte-swapper. */ -/* It swaps a total of unit_len*n_units bytes, unit_len bytes at a time. */ -/* Thus, you can use it for arrays of doubles with unit_len=8, or */ -/* arrays of chars with unit_len=1 (which is equivalent to memcpy). */ -/* It checks for stupid arguments. It works fine when */ -/* from and to are identical. It breaks if from and to are */ -/* almost the same. */ -#ifdef __cplusplus -extern "C" { -#endif -int Byteswap(int unit_len, int n_units, void *from, void *to); -#ifdef __cplusplus -} -#endif - -/* It would probalby be worthwhile to inline these! */ - -#endif diff --git a/external/libsdf/include/libsdf/chn.h b/external/libsdf/include/libsdf/chn.h deleted file mode 100644 index 2760f5c..0000000 --- a/external/libsdf/include/libsdf/chn.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef chnDOTh -#define chnDOTh -#include - -/* - CHN.C: Routines for allocating and freeing memory - in fixed length blocks. CHN is mnemonic for either 'chain' or 'chunk'. - The idea is that malloc is called infrequently to get large chunks - which are broken down into smaller pieces which are chained together - to make a freelist. ChnAlloc and ChnFree are very fast O(1), and - use memory efficiently even for small objects. In contrast, - malloc and free are often slow and typically waste several bytes per - allocated object. The down side is that fragmentation problems can be - magnified. Once a large chunk is allocated it never gets freed, even - if all the objects in it have been freed. - Entry points: - void ChnInit(Chn *id, int sz, int nalloc, - void *(realloc_like)(void *, size_t)); - void *ChnAlloc(Chn *id); - void ChnFree(Chn *id, Void *p); - void ChnFreeAll(Chn *id); - void ChnTerminate(Chn *id); - int ChnCheck(Chn *id); - int ChnFreeCnt(Chn *id); - int ChnAllocCnt(Chn *id); - It wouldn't be hard to write "ChnCrunch" which would look for chunks - that have been completely freed, and return them to the system. This - has limited utility, but it might be handy when running near the edge - of memory. - - For diagnostic purposes, use ChnFreeCnt to get the length of the current - freelist. Note that more space will be dynamically allocated, so this - is NOT an upper limit. ChnAllocCnt is the count of how many chunks - are currently allocated. - */ - -typedef struct { - int sz; - int nalloc; - void *free_list; - void *first_chunk; - int free_cnt; - int nmalloced; /* diagnostic purposes only */ - int tbl_sz; - void *(*realloc_like)(void *, size_t); -} Chn; - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ -extern int ChnMoreMem(Chn *id); -extern void ChnInit(Chn *new, int sz, int nalloc, - void *(*realloc_like)(void *, size_t)); -extern void ChnTerminate(Chn *id); -extern void ChnFreeAll(Chn *id); -extern int ChnCheck(Chn *id); -#if !(__STDC_VERSION__ >= 199901L) -extern void *ChnAlloc(Chn *id); -extern void ChnFree(Chn *id, void *p); -extern int ChnFreeCnt(Chn *id); -extern int ChnAllocCnt(Chn *id); -extern size_t ChnUnitSz(Chn *id); -#endif -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#if (defined(__GNUC__) || defined(__ICC__)) || defined(CHNdotC) - -#undef INLINE -#if (__STDC_VERSION__ >= 199901L) && !defined (CHNdotC) -#define INLINE inline -#else -#if (defined (__GNUC__) || defined(__ICC__)) && !defined (CHNdotC) -#define INLINE extern __inline__ -#else -#define INLINE -#endif -#endif - -#if defined(ChnNext) || defined(ChnMagic) || defined(ChnMAGIC) - # error define conflict in __FILE__ -#endif -#define ChnNext(x) (*(void**)(x)) -#define ChnMagic(x) (*(int *)((void**)x+1)) -#define ChnMAGIC 0x82345078 - -#ifndef assert -#include "Assert.h" -#endif - -INLINE void *ChnAlloc(Chn *id) -{ - void *c; - - if (id->free_cnt <= 0) { - if(ChnMoreMem(id)) - return 0; - } - c = id->free_list; - - assert(c); - assert(ChnMagic(c) == ChnMAGIC); - - id->free_cnt--; - id->free_list = ChnNext(c); - return (c); -} - -INLINE void ChnFree(Chn *id, void *p) -{ - /* This assertion can give a false-error reading if the "user" */ - /* has stored the exact value ChnMAGIC in the right location. */ - /* assert(ChnMagic(p) != ChnMAGIC); */ - ChnNext(p) = id->free_list; - ChnMagic(p) = ChnMAGIC; - id->free_list = p; - id->free_cnt++; -} - -INLINE int ChnFreeCnt(Chn *id){ - return id->free_cnt; -} - -INLINE int ChnAllocCnt(Chn *id){ - return id->nmalloced - id->free_cnt; -} - -INLINE size_t ChnUnitSz(Chn *id){ - return id->sz; -} - -#ifndef CHNdotC -#undef ChnNext -#undef ChnMagic -#undef ChnMAGIC -#endif -#undef INLINE - -#endif /* __GNUC__ || CHNdotC */ -#endif diff --git a/external/libsdf/include/libsdf/cosmo.h b/external/libsdf/include/libsdf/cosmo.h deleted file mode 100644 index df107e4..0000000 --- a/external/libsdf/include/libsdf/cosmo.h +++ /dev/null @@ -1,113 +0,0 @@ -/* Hide the cosmological parameters in here. - Keep them self-consistent... */ - -struct cosmo_s { - double t; - double a; - double H0; - double Omega0; - double Omega_m; - double Omega_r; - double Omega_de; - double w0; - double wa; - double Lambda; - double Gnewt; - double Zel_f;/* the 'f' factor for linearly growing modes */ -}; - -/* new struct for CLASS interface */ -/* some names have changed definition (Omega_m/Omega_r not constants now) */ -typedef struct cosmology { - double z; - double t; - double tau; - double a; - double H; - double Omega_m; - double Omega_r; - double conf_distance; - double kick; /* union with tau? */ - double drift; - double growthfac; - double velfac; - double velfac2; - /* constants */ - double h_100; - double H0; - double Omega0; /* m+r+lambda+fld */ - double Omega0_m; /* cdm+b+ur+some ncdm */ - double Omega0_r; /* g+ur+rest of ncdm */ - double Omega0_lambda; - double Omega0_cdm; - double Omega0_ncdm_tot; - double Omega0_b; - double Omega0_g; - double Omega0_ur; - double Omega0_fld; - double w0_fld; - double wa_fld; - double Gnewt; - double age; - void *reserved; - void (*background_at_z)(struct cosmology *c, double z); - void (*background_at_t)(struct cosmology *c, double t); - void (*background_at_tau)(struct cosmology *c, double tau); - double (*t_at_z)(struct cosmology *c, double z); - double (*z_at_t)(struct cosmology *c, double t); - double (*a_at_t)(struct cosmology *c, double t); - double (*t_at_a)(struct cosmology *c, double a); - double (*H_at_z)(struct cosmology *c, double z); - double (*H_at_t)(struct cosmology *c, double t); - double (*conformal_distance_at_z)(struct cosmology *c, double z); - double (*conformal_distance_at_t)(struct cosmology *c, double t); - double (*angular_diameter_distance_at_z)(struct cosmology *c, double z); - double (*angular_diameter_distance_at_t)(struct cosmology *c, double t); - double (*luminosity_distance_at_z)(struct cosmology *c, double z); - double (*luminosity_distance_at_t)(struct cosmology *c, double t); - double (*growthfac_at_z)(struct cosmology *c, double z); - double (*growthfac_at_t)(struct cosmology *c, double t); - double (*velfac_at_z)(struct cosmology *c, double z); - double (*velfac_at_t)(struct cosmology *c, double t); - double (*kick_t0_t1)(struct cosmology *c, double t0, double t1); - double (*drift_t0_t1)(struct cosmology *c, double t0, double t1); - void (*free)(struct cosmology *c); -} cosmology; - -void class_init(cosmology *c, char *class_ini, char *class_pre, double zmax); -void class_params(cosmology *c, char *class_ini); -void tbl_init(cosmology *c, char *tbl); - -double Anow(struct cosmo_s *c, double time); -double Znow(struct cosmo_s *c, double time); -double Hnow(struct cosmo_s *c, double time); -double growthfac_from_Z(struct cosmo_s *c, double z); -double velfac_from_Z(struct cosmo_s *c, double z); -double velfac_approx_from_Z(struct cosmo_s *c, double z); -double t_from_Z(struct cosmo_s *c, double z); -double comoving_distance_from_Z(struct cosmo_s *c, double z); -double dp_from_Z(struct cosmo_s *c, double z); -double hubble_from_Z(struct cosmo_s *c, double z); -double kick_delta(struct cosmo_s *c, double t0, double t1); -double drift_delta(struct cosmo_s *c, double t0, double t1); -void CosmoPush(struct cosmo_s *c, double time); - -#define one_kpc 3.08567802e16 /* km */ -#define one_Gyr 3.1558149984e16 /* sec */ -#define cm_kpc 3.08567802e21 -#define sec_Gyr 3.1558149984e16 -#define g_Msol 1.98892e33 -#define g_Msol10 1.98892e43 /* 10^10 Msol */ -/* http://physics.nist.gov/cgi-bin/cuu/Value?bg|search_for=G */ -/* #define G_cgs (6.67384e-8) cm3 g-1 s-2 */ -#define G_cgs (6.67259e-8) -#define speed_of_light (299792.458) /* km/sec */ -/* Gaussian Gravitational Constant */ -#define k_cgs 0.01720209895 -#define GM_cgs 1.32712442099e26 -/* GM_cgs*sec_Gyr*sec_Gyr/cm_kpc*cm_kpc*cm_kpc */ -#define GNEWT 44986.564 - - - - diff --git a/external/libsdf/include/libsdf/dll.h b/external/libsdf/include/libsdf/dll.h deleted file mode 100644 index 5d510d0..0000000 --- a/external/libsdf/include/libsdf/dll.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef _DLLdotH_ -#define _DLLdotH_ - -#include "chn.h" - -#ifdef __cplusplus -extern "C"{ -#endif - -typedef struct Dll_elmt_s{ - struct Dll_elmt_s *up, *down; - void *stuff[1]; /* Will be alloc'ed to something else! */ - /* DON'T PUT ANYTHING HERE!!! It will be silently mangleded */ -} Dll_elmt; - -typedef struct { - Dll_elmt Sup, Inf; - Chn *chn; - int length; /* why not? */ -} Dll ; - -/* Create a Chain suitable for passing to DllCreate */ -void DllCreateChn(Chn *chn, int sz, int n); -/* Create a new Dll */ -void DllCreate(Dll *dll, Chn *chn); -/* Terminate a Dll */ -void DllTerminate(Dll *dll); -/* Return a new element just above 'DOWN' */ -Dll_elmt *DllInsertAbove(Dll *dll, Dll_elmt *down); -/* Return a new element just below 'UP' */ -Dll_elmt *DllInsertBelow(Dll *dll, Dll_elmt *up); -/* Delete OLD. Return nothing. */ -void DllDelete(Dll *dll, Dll_elmt *old); -/* Delete OLD. Return the entry that used to be above it. */ -Dll_elmt *DllDeleteUp(Dll *dll, Dll_elmt *old); -/* Delete OLD. Return the entry that used to be below it. */ -Dll_elmt *DllDeleteDown(Dll *dll, Dll_elmt *old); -/* Extract the 'mover' and place it immediately above 'down'. - Like DllDelete, followed by DllInsertAbove, but preserve the - data in the object. */ -void DllMoveAbove(Dll *dll, Dll_elmt *mover, Dll_elmt *down); -/* Extract the 'mover' and place it immediately below 'up'. - Like DllDelete, followed by DllInsertBelow, but preserve the - data in the object. */ -void DllMoveBelow(Dll *dll, Dll_elmt *mover, Dll_elmt *up); - -/* These would require __inline__ to be done properly. */ -/* Insert a new element at the bottom, equivalent to: - DllInsertAbove(dll, DllInf(dll)); */ -Dll_elmt *DllInsertAtBottom(Dll *dll); -/* Insert a new element at the top, equivalent to: - DllInsertBelow(dll, DllSup(dll)); */ -Dll_elmt *DllInsertAtTop(Dll *dll); -/* Move to bottom */ -void DllMoveToBottom(Dll *dll, Dll_elmt *mover); -/* Move to top */ -void DllMoveToTop(Dll *dll, Dll_elmt *mover); - -/* Should we bother with __inline__. These are simple enough that #define - is sufficient. */ - -/* How many elements? */ -int DllLength(Dll *dll); -#define DllLength(dll) ((dll)->length) -/* One past the topmost 'user' element */ -Dll_elmt *DllSup(Dll *dll); -#define DllSup(dll) (&((dll)->Sup)) -/* One below the lowest 'user' element */ -Dll_elmt *DllInf(Dll *dll); -#define DllInf(dll) (&((dll)->Inf)) -/* The highest 'user' element */ -Dll_elmt *DllTop(Dll *dll); -#define DllTop(dll) ((dll)->Sup.down) -/* The lowest 'user' element */ -Dll_elmt *DllBottom(Dll *dll); -#define DllBottom(dll) ((dll)->Inf.up) -/* The 'user' data */ -void *DllData(Dll_elmt *elmt); -#define DllData(elmt) ((void *)((elmt)->stuff)) -/* The next elements, both up and down */ -Dll_elmt *DllUp(Dll_elmt *elmt); -#define DllUp(elmt) ((elmt)->up) -Dll_elmt *DllDown(Dll_elmt *elmt); -#define DllDown(elmt) ((elmt)->down) - -#ifdef __cplusplus -} -#endif - -#endif /* _DLLdotH_ */ diff --git a/external/libsdf/include/libsdf/error.h b/external/libsdf/include/libsdf/error.h deleted file mode 100644 index 749e4a3..0000000 --- a/external/libsdf/include/libsdf/error.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _ErrorDOTh -#define _ErrorDOTh - -#include -#include "gccextensions.h" - -/* Define an Error_t to describe error-like functions. */ -typedef void (*Error_t)(const char *, ...); - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -void SWError(const char *, ...) -/* noreturn only works in 2.5 or higher */ -#if (__GNUC_MINOR__>=5 && __GNUC__==2)||__GNUC__>2 - __attribute__ ((format (printf, 1, 2),noreturn)); -#else - __attribute__ ((format (printf, 1, 2))); -#endif - -void vError(const char *, va_list) -/* noreturn only works in 2.5 or higher */ -#if (__GNUC_MINOR__>=5 && __GNUC__==2)||__GNUC__>2 - __attribute__ ((format (printf, 1, 0),noreturn)); -#else - ; -#endif - -void SinglError(const char *, ...) -/* noreturn only works in 2.5 or higher */ -#if (__GNUC_MINOR__>=5 && __GNUC__==2)||__GNUC__>2 - __attribute__ ((format (printf, 1, 2),noreturn)); -#else - __attribute__ ((format (printf, 1, 2))); -#endif -void Warning(const char *, ...) - __attribute__ ((format (printf, 1, 2))); -void SinglWarning(const char *, ...) - __attribute__ ((format (printf, 1, 2))); -void SeriousWarning(const char *, ...) - __attribute__ ((format (printf, 1, 2))); -void Shout(const char *mesg, ...) - __attribute__ ((format (printf, 1, 2))); -void SinglShout(const char *mesg, ...) - __attribute__ ((format (printf, 1, 2))); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#if __GNUC__>1 /* Actually, only 2.4 or higher? */ -/* We have varargs macros! */ -#define Error(format, args...) \ - (SWError)("%s (%d) in %s :\n" format, __FILE__, __LINE__, __FUNCTION__, ##args) -#define SinglError(format, args...) \ - (SinglError)("%s (%d) in %s :\n" format, __FILE__, __LINE__, __FUNCTION__, ##args) -#define Warning(format, args...) \ - (Warning)("%s (%d) in %s :\n" format, __FILE__, __LINE__, __FUNCTION__, ##args) -#define SinglWarning(format, args...) \ - (SinglWarning)("%s (%d) in %s :\n" format, __FILE__, __LINE__, __FUNCTION__, ##args) -#define SeriousWarning(format, args...) \ - (SeriousWarning)("%s (%d) in %s :\n" format, __FILE__, __LINE__, __FUNCTION__, ##args) - -#else /* No wacky GNUC varargs stuff...*/ -/* This prevents namespace collisions when linking SDF into perl5! (really!) */ -#define Error SWError - -#endif - -#endif /* _ErrorDOTh */ diff --git a/external/libsdf/include/libsdf/files.h b/external/libsdf/include/libsdf/files.h deleted file mode 100644 index 0b3b78b..0000000 --- a/external/libsdf/include/libsdf/files.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _FILESdotH -#define _FILESdotH - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -int fexists(const char *name); -int fexists_and_unlink(const char *name); -/* These are advisory routines. They don't actually do anything */ -/* They just check for files named "_ForceOutput_" and "_ForceStop_" */ -int ForceCheckpoint(void); -int ForceOutput(void); -int ForceStop(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif - diff --git a/external/libsdf/include/libsdf/gc.h b/external/libsdf/include/libsdf/gc.h deleted file mode 100644 index d3fd667..0000000 --- a/external/libsdf/include/libsdf/gc.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _GCdotH -#define _GCdotH - -#include - -/* little functions for doing gray-code stuff. */ - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ - -/* Return the parity of num, i.e., parity(0x22)=0 */ -unsigned int parity(unsigned int num); - -/* Return the index of the highest bit in num, i.e., - hibit(3) = 1, hibit(1)=0, hibit(513)=9, hibit(0)=-1 */ -int hibit(unsigned int num); - -/* Return the index of the lowest bit in num, i.e., - lobit(3) = 0, lobit(2)=1, lobit(512)=9, lobit(513)=0, lobit(0)=BITSPERWORD - */ -int lobit(unsigned int num); - -/* Return the integer log2 of the argument. Round down. Return -1 for 0. */ -/* Same as hibit! */ -int ilog2(unsigned int num); - -/* Return the word-wise xor checksum of n bytes in buf. */ -unsigned int cksum(const void *buf, unsigned int n); - -/* Return the number of set bits in num. Is this sometimes called - "popcount"? */ -unsigned int countbits(unsigned int num); - -/* Return the 'up' graycode neighbor of proc (out of nproc) */ -int Gcup(unsigned int proc, unsigned int nproc); - -/* Return the 'down' graycode neighbor of proc (out of nproc) */ -int Gcdown(unsigned int proc, unsigned int nproc); - -/* This isn't really gray-code related, but where else can it go? */ -/* It does the simple-minded "decomposition" of gnobj objects over nproc */ -/* processors. It returns how many to keep and which one to start with. */ -void NobjInitial(int gnobj, int nproc, int procnum, int *nobj, int *start); -void NobjInitial64(int64_t gnobj, int nproc, int procnum, int *nobj, int64_t *start); - -/* These two came from alt.sources */ -/* Return the 'index' of the given gray code (assuming 32-bit longs!) */ -unsigned long gray2bin(unsigned long b); - -/* Return the graycode of a given index */ -unsigned long bin2gray(unsigned long g); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/external/libsdf/include/libsdf/gccextensions.h b/external/libsdf/include/libsdf/gccextensions.h deleted file mode 100644 index b43a8ea..0000000 --- a/external/libsdf/include/libsdf/gccextensions.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _GccExtensionsDOTh -#define _GccExtensionsDOTh - -/* this is broken in gcc2.4.0 through 2.4.4 */ -#if __GNUC__<2 || (__GNUC__== 2 && __GNUC_MINOR__<=4) -#define BROKEN_GCC_FORMAT_ATTRIBUTE -#endif - -/* This isn't an entirely perfect way to deal with functions that - don't return because sometimes we want more than one __attribute__. - See, for example, the code in error.h and mpmy_abnormal.h */ -#if (__GNUC_MINOR__>=5 && __GNUC__==2)||__GNUC__>2 -#define __NORETURN__ __attribute__ ((noreturn)) -#else -#define __NORETURN__ -#endif - -#undef __attribute__ -#if !defined(__GNUC__) || defined(printf) || defined(scanf) -#define __attribute__(x) -#endif /* __GNUC__ */ - -/* NoInline can be used to prevent inlining of function calls at the */ -/* calling location. I.e., NoInline(func)(arg) instead of func(arg) */ -/* We leave everything alone if we're not optimizing because there */ -/* are no inlines in that case anyway. */ -#if defined(__GNUC__) && defined(__OPTIMIZE__) -#define NoInline(f) ({typeof(f) *fp = &f; *fp;}) -#else -#define NoInline(f) f -#endif - -#endif - diff --git a/external/libsdf/include/libsdf/heap.h b/external/libsdf/include/libsdf/heap.h deleted file mode 100644 index 9c36356..0000000 --- a/external/libsdf/include/libsdf/heap.h +++ /dev/null @@ -1,152 +0,0 @@ -/* Super-fast priority queue. ? Completely inlined by gcc. */ -/* Assume that each pointer points at */ -/* a key, AND whatever else the caller is interested in keeping. */ -#ifndef HEAPdotH -#define HEAPdotH - - -typedef struct{ - const float **arr; - unsigned int sz; - unsigned int cnt; -} Heap; - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -extern void HeapInit(Heap *hp, unsigned int initial_nelem); -extern void HeapTerminate(Heap *hp); -extern void HeapPush(Heap *hp, const float *ptr); -extern void HeapPop(Heap *hp, const float **keyp); -extern const float *HeapPeek(const Heap *hp); -extern const float **HeapBase(const Heap *hp); -extern const float **HeapEnd(const Heap *hp); -extern unsigned int HeapCnt(const Heap *hp); -extern int HeapIsBad(const Heap *hp); -extern const float HeapMinf; -extern const float HeapInf; -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* This is an attempt to get the inline functions into the .h file */ -/* without having to maintain two source files. */ -#if (defined(__GNUC__) || defined(__ICC__)) || defined(HEAPdotC) - -#ifndef assert -#include "Assert.h" -#endif -#include -#include -#include "Malloc.h" - -#undef INLINE -#if (defined (__GNUC__) || defined(__ICC__)) && !defined (HEAPdotC) -#define INLINE extern __inline__ -#else -#define INLINE -#endif - -#ifndef NULL -#define NULL (void *)0 -#endif -#ifndef EXIT_SUCCESS -#define EXIT_SUCCESS 0 -#endif - -#if defined(HeapKey) || defined(HeapParent) || defined(HeapLeft) - # error Problems with conflicting definitions in heap.h -#endif -#define HeapKey(i) (*arr[i]) -#define HeapParent(i) (i>>1) -#define HeapLeft(i) (i<<1) -/* Use left+1 for right */ - -INLINE void HeapPush(Heap *hp, const float *ptr){ - const float **arr = hp->arr; - const float *tmp; - unsigned int i = hp->cnt++; - unsigned int pi; - - if( i == hp->sz ){ - unsigned int newsz = (hp->sz)<<1; - arr = hp->arr = Realloc(hp->arr, (newsz+1)*sizeof(*(hp->arr))); - assert(hp->arr); - hp->sz = newsz; - } - - arr[i] = ptr; - pi = HeapParent(i); - while( HeapKey(pi) <= HeapKey(i) ){ - tmp = arr[pi]; - arr[pi] = arr[i]; - arr[i] = tmp; - i = pi; - pi = HeapParent(i); - } -} - -INLINE void HeapPop(Heap *hp, const float **keyp){ - const float **arr = hp->arr; - const float *save; - unsigned int i, li, ri, ix, n; - float kl, kr, ksave, kx; - - *keyp = arr[1]; - n = --hp->cnt; - assert( n>0 ); - i = 1; - li = 2; - ri = 3; - save = arr[n]; - ksave = *save; - arr[n] = &HeapMinf; - while( li < n ){ - kl = HeapKey(li); - kr = HeapKey(ri); - if( kl >= kr ){ - ix = li; - kx = kl; - }else{ - ix = ri; - kx = kr; - } - if( ksave >= kx ){ - break; - } - - /* Move ix up the heap */ - arr[i] = arr[ix]; - i = ix; - li = HeapLeft(ix); - ri = li+1; - } - arr[i] = save; -} - -INLINE const float *HeapPeek(const Heap *hp){ - return hp->arr[1]; -} - -INLINE const float **HeapBase(const Heap *hp){ - return &hp->arr[1]; -} - -INLINE const float **HeapEnd(const Heap *hp){ - return &hp->arr[hp->cnt]; -} - -INLINE unsigned int HeapCnt(const Heap *hp){ - return hp->cnt-1; -} - -/* Undefine our private macros */ -#ifndef HEAPdotC -#undef HeapKey -#undef HeapParent -#undef HeapLeft -#endif /* HEAPdotC */ -#undef INLINE - -#endif /* __GNUC__ || HEAPdotC */ -#endif /* already included */ diff --git a/external/libsdf/include/libsdf/hwclock.h b/external/libsdf/include/libsdf/hwclock.h deleted file mode 100644 index 408a38a..0000000 --- a/external/libsdf/include/libsdf/hwclock.h +++ /dev/null @@ -1,3 +0,0 @@ -double hwclock(void); -double hwtick(void); -void zero_hwclock(void); diff --git a/external/libsdf/include/libsdf/key.h b/external/libsdf/include/libsdf/key.h deleted file mode 100644 index 856e532..0000000 --- a/external/libsdf/include/libsdf/key.h +++ /dev/null @@ -1,524 +0,0 @@ -#ifndef _KeyDOTh -#define _KeyDOTh - -#include - -/* Should we use long long keys??? - Compiling tree.c (which does a fair amount of key arith), with - LONG_LONG_KEYS turned on results - in 25% shorter sparc code (12k vs. 9k), and 15% shorter i860 code - (14k vs 12k). - - HOWEVER: in both cases, the LONG_LONG_KEYS code does NOT inline - the leftshift and rightshift operators. They are implemented as - calls to ___lshrdi3 and ___lshldi3 in libgcc.a - - The bottom line: TBD. I-cache vs. call overhead, vs. do the __lsh calls - prevent gcc from doing any optimizations across the call? I'd guess - that the LONG_LONG_KEYS are faster. -*/ -#if defined(KEY96BITS) -#define NK 3 -#define _KTYPE unsigned int -#define KEYBITS 94 -#else -#if defined(LONG_NK1_KEY) -#define NK 1 -#define _KTYPE unsigned long int -#else -#if defined(LONG_LONG_KEYS) -#define NK 2 -#define _KTYPE unsigned long long int -#define KEYBITS 94 -#else -#define NK 2 -#define _KTYPE unsigned long int -#define KEYBITS 94 -#endif - -#endif /* LONG_LONG */ -#endif /* ONE_LONG */ - -/* Test for #if FORCE_KEY_ALIGNMENT, not for #ifdef, which gives - the Make.$(ARCH) the opportunity to do -DFORCE_KEY_ALIGNMENT=0 -*/ -#if !defined(FORCE_KEY_ALIGNMENT) && NK==1 -#define FORCE_KEY_ALIGNMENT 1 -#endif - -/* We have to typedef Key_t as a struct, or else we can't return it from */ -/* a function */ -typedef struct { - _KTYPE k[NK]; -} Key_t; - -/* Be careful! KEYBITS is not necessarily where the "body" bit is located */ -#ifndef KEYBITS -#define KEYBITS (CHAR_BIT*sizeof(Key_t)) -#endif - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -extern char *PrintKey(Key_t key); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#if (defined(__GNUC__) || defined(__ICC__)) || defined(KEYdotC) - -#if (__STDC_VERSION__ >= 199901L) && !defined (KEYdotC) -#define INLINE inline -#else -#if (defined (__GNUC__) || defined(__ICC__)) && !defined (KEYdotC) -#define INLINE extern __inline__ -#else -#define INLINE -#endif -#endif - -#if NK==1 - -INLINE int -KeyGT(Key_t key1, Key_t key2) -{ - return (key1.k[0] > key2.k[0]); -} - -INLINE int -KeyLT(Key_t key1, Key_t key2) -{ - return (key1.k[0] < key2.k[0]); -} - -INLINE int -KeyGE(Key_t key1, Key_t key2) -{ - return (key1.k[0] >= key2.k[0]); -} - -INLINE int -KeyLE(Key_t key1, Key_t key2) -{ - return (key1.k[0] <= key2.k[0]); -} - -INLINE int -KeyEQ(Key_t key1, Key_t key2) -{ - return (key1.k[0] == key2.k[0]); -} - -INLINE int -KeyNEQ(Key_t key1, Key_t key2) -{ - return (key1.k[0] != key2.k[0]); -} - -INLINE Key_t -KeyXOR(Key_t key1, Key_t key2) -{ - Key_t ret; - ret.k[0] = key1.k[0] ^ key2.k[0]; - return(ret); -} - -INLINE Key_t -KeyAnd(Key_t key1, Key_t key2) -{ - Key_t ret; - ret.k[0] = key1.k[0] & key2.k[0]; - return(ret); -} - -INLINE Key_t -KeyOr(Key_t key1, Key_t key2) -{ - Key_t ret; - ret.k[0] = key1.k[0] | key2.k[0]; - return(ret); -} - -INLINE int -KeyCmp(Key_t key1, Key_t key2) -{ - if(key1.k[0] > key2.k[0] ) - return 1; - else if( key1.k[0] < key2.k[0] ) - return -1; - else - return 0; -} - -INLINE Key_t -KeyNot(Key_t key1) -{ - key1.k[0] = ~key1.k[0]; - return key1; -} - -INLINE Key_t -KeyRshift(Key_t u, int b) -{ - Key_t ret; - if (b >= CHAR_BIT*sizeof(u.k[0])) ret.k[0] = 0; - else ret.k[0] = u.k[0] >> b; - return(ret); -} - -INLINE Key_t -KeyLshift(Key_t u, int b) -{ - Key_t ret; - ret.k[0] = u.k[0] << b; - return(ret); -} - -/* cast int to Key_t */ -INLINE Key_t -KeyInt(int i) -{ - Key_t ret; - ret.k[0] = i; - return(ret); -} - -INLINE Key_t -KeyOrInt(Key_t u, unsigned int i) -{ - Key_t ret; - ret.k[0] = u.k[0] | i; - return(ret); -} - -/* bitwise and key with int */ -/* This is a common operation, and is more efficient than converting the */ -/* int to a key. It returns an int! */ - -INLINE unsigned int -KeyAndInt(Key_t u, unsigned int i) -{ - return(u.k[0] & i); -} - -/* bitwise and key with ~int */ -/* This is also common operation, and is more efficient than converting the */ -/* int to a key. It returns an Key_t (leaving the top bits alone)! */ - -INLINE Key_t -KeyAndNotInt(Key_t u, unsigned int i) -{ - u.k[0] &= ~((_KTYPE)i); - return u; -} - -INLINE Key_t -KeyAdd(Key_t key1, Key_t key2) -{ - Key_t ret; - - ret.k[0] = key1.k[0] + key2.k[0]; - return(ret); -} - -INLINE Key_t -KeySub(Key_t key1, Key_t key2) -{ - Key_t ret; - - ret.k[0] = key1.k[0] - key2.k[0]; - return(ret); -} - -INLINE Key_t -KeyAddInt(Key_t key1, int i) -{ - Key_t ret; - - ret.k[0] = key1.k[0] + i; - return(ret); -} - -#else -#if NK==2 - -INLINE int -KeyGT(Key_t key1, Key_t key2) -{ - if( key1.k[1] > key2.k[1] ) - return 1; - else if( key1.k[1] < key2.k[1] ) - return 0; - else - return (key1.k[0] > key2.k[0]); -} - -INLINE int -KeyLT(Key_t key1, Key_t key2) -{ - if( key1.k[1] < key2.k[1] ) - return 1; - else if( key1.k[1] > key2.k[1] ) - return 0; - else - return (key1.k[0] < key2.k[0]); -} - -INLINE int -KeyGE(Key_t key1, Key_t key2) -{ - if( key1.k[1] > key2.k[1] ) - return 1; - else if( key1.k[1] < key2.k[1] ) - return 0; - else - return (key1.k[0] >= key2.k[0]); -} - -INLINE int -KeyLE(Key_t key1, Key_t key2) -{ - if( key1.k[1] < key2.k[1] ) - return 1; - else if( key1.k[1] > key2.k[1] ) - return 0; - else - return (key1.k[0] <= key2.k[0]); -} - -INLINE int -KeyEQ(Key_t key1, Key_t key2) -{ - return (key1.k[0] == key2.k[0] && key1.k[1] == key2.k[1]); -} - -INLINE int -KeyNEQ(Key_t key1, Key_t key2) -{ - return (key1.k[0] != key2.k[0] || key1.k[1] != key2.k[1]); -} - -INLINE Key_t -KeyXOR(Key_t key1, Key_t key2) -{ - Key_t ret; - ret.k[0] = key1.k[0] ^ key2.k[0]; - ret.k[1] = key1.k[1] ^ key2.k[1]; - return(ret); -} - -INLINE Key_t -KeyAnd(Key_t key1, Key_t key2) -{ - Key_t ret; - ret.k[0] = key1.k[0] & key2.k[0]; - ret.k[1] = key1.k[1] & key2.k[1]; - return(ret); -} - -INLINE Key_t -KeyOr(Key_t key1, Key_t key2) -{ - Key_t ret; - ret.k[0] = key1.k[0] | key2.k[0]; - ret.k[1] = key1.k[1] | key2.k[1]; - return(ret); -} - -INLINE int -KeyCmp(Key_t key1, Key_t key2) -{ - if(key1.k[1] > key2.k[1] ) - return 1; - else if( key1.k[1] < key2.k[1] ) - return -1; - - if(key1.k[0] > key2.k[0] ) - return 1; - else if( key1.k[0] < key2.k[0] ) - return -1; - return 0; -} - -INLINE Key_t -KeyNot(Key_t key1) -{ - key1.k[0] = ~key1.k[0]; - key1.k[1] = ~key1.k[1]; - return key1; -} - -INLINE Key_t -KeyRshift(Key_t u, int b) -{ - Key_t ret; - long bm = CHAR_BIT*sizeof(u.k[0])-b; - - if (b == 0) { - ret = u; - } else if (bm > 0) { - ret.k[0] = (u.k[0] >> b) | (u.k[1] << bm); - ret.k[1] = u.k[1] >> b; - } else { - ret.k[0] = u.k[1] >> -bm; - ret.k[1] = 0; - } - return(ret); -} - -INLINE Key_t -KeyLshift(Key_t u, int b) -{ - Key_t ret; - long bm = CHAR_BIT*sizeof(u.k[0])-b; - - if (b == 0) { - ret = u; - } else if (bm > 0) { - ret.k[1] = (u.k[1] << b) | (u.k[0] >> bm); - ret.k[0] = u.k[0] << b; - } else { - ret.k[1] = u.k[0] << -bm; - ret.k[0] = 0; - } - return(ret); -} - -/* cast int to Key_t */ -INLINE Key_t -KeyInt(int i) -{ - Key_t ret; - ret.k[1] = 0; - ret.k[0] = i; - return(ret); -} - -INLINE Key_t -KeyOrInt(Key_t u, unsigned int i) -{ - Key_t ret; - ret.k[0] = u.k[0] | i; - ret.k[1] = u.k[1]; - return(ret); -} - -/* bitwise and key with int */ -/* This is a common operation, and is more efficient than converting the */ -/* int to a key. It returns an int! */ - -INLINE unsigned int -KeyAndInt(Key_t u, unsigned int i) -{ - return(u.k[0] & i); -} - -/* bitwise and key with ~int */ -/* This is also common operation, and is more efficient than converting the */ -/* int to a key. It returns an Key_t (leaving the top bits alone)! */ - -INLINE Key_t -KeyAndNotInt(Key_t u, unsigned int i) -{ - u.k[0] &= ~((_KTYPE)i); - return u; -} - -INLINE Key_t -KeyAdd(Key_t key1, Key_t key2) -{ - Key_t ret; - - ret.k[0] = key1.k[0] + key2.k[0]; - ret.k[1] = key1.k[1] + key2.k[1]; - /* We assume keys are unsigned quantities */ - if (ret.k[0] < key1.k[0] || ret.k[0] < key2.k[0]) /* carry */ - ret.k[1]++; - return(ret); -} - -INLINE Key_t -KeySub(Key_t key1, Key_t key2) -{ - Key_t ret; - - ret.k[0] = key1.k[0] - key2.k[0]; - ret.k[1] = key1.k[1] - key2.k[1]; - /* We assume keys are unsigned quantities */ - if (ret.k[0] > key1.k[0] || ret.k[0] > key2.k[0]) /* borrow */ - ret.k[1]--; - return(ret); -} - -INLINE Key_t -KeyAddInt(Key_t key1, int i) -{ - Key_t ret; - - ret.k[0] = key1.k[0] + i; - ret.k[1] = key1.k[1]; - if (i >= 0 && ret.k[0] < key1.k[0]) /* carry */ - ret.k[1]++; - else if (i < 0 && ret.k[0] > key1.k[0]) /* borrow */ - ret.k[1]--; - return(ret); -} - -#else - # error NK must be 1 or 2 -#endif /* NK==2 */ -#endif /* NK==1 */ - -INLINE int -TreeLevel(Key_t key, int ndim) -{ - int level; - int chubits = (KEYBITS-1)/ndim; - Key_t testkey; - - /* First check whether it's a 'body' (at the deepest level.) */ - /* This will save considerable time... */ - testkey = KeyLshift(KeyInt(1), chubits*ndim); - if( KeyEQ( testkey, KeyAnd(testkey, key) ) ) - return chubits; - - /* Now start looking from low levels */ - testkey = KeyInt(1); - for (level = 0; level= pos[i]. The equality - can be a headache for float-to-int conversions! Consider using - InflateBbox and or CubeBbox! */ -void TightBbox(float *pstart, int nobj, int pstride, int ndim, tbbox *bb); - -/* Make the bbox a cube by expanding the smaller dimensions. */ -void CubeBbox(tbbox *bb); - -/* Increase the linear dimension by 'factor' on all sides */ -void InflateBbox(tbbox *bb, float factor); - -/* Return 1 if bb1 completely contains bb2 */ -int ContainsBbox(tbbox *bb1, tbbox *bb2); - -/* Construct bbu, the 'union' of bb1 and bb2 */ -void UnionBbox(tbbox *bb1, tbbox *bb2, tbbox *bbu); - -/* Generate keys for an array of positions (imagine sizeof(body) as the - stride argument!) */ -void GenerateKeys(float *pstart, int nobj, int pstride, tbbox *bb, Key_t *kstart, int kstride, int ordering); -/* This will be set when GenerateKeys detects that a key is out of - bounds. GenerateKeys will not crash and burn, but prudent callers - will check KeyOutOfBounds after calling it. It is cumulative. */ -extern int KeyOutOfBounds; - -/* Replacement for CellCorner: you supply the bbox that describes the - Universe, and we return a bbox that describes the cell */ -void CellBBFromKey(Key_t key, tbbox *bb, tbbox *cellbb, int ordering); - -/* Some primitive building blocks. They can be combined with - KeyFromInts and IntsFromKey to do the full conversion... */ -void IntsFromFloats(const float *x, unsigned int *ix, tbbox *bb, int nbits); -void FloatsFromInts(const int *ix, float *x, tbbox *bb, int nbits); - -/* These two names conflict with physics_generic.c. Good. It will - keep me from using physics_generic.c accidentally. */ -Key_t KeyFromInts(unsigned int *xp, int ndim, int nbits); -int IntsFromKey(Key_t key, unsigned int *ip, int ndim); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif diff --git a/external/libsdf/include/libsdf/lsv.h b/external/libsdf/include/libsdf/lsv.h deleted file mode 100644 index 5383e2d..0000000 --- a/external/libsdf/include/libsdf/lsv.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _LsvDOTh -#define _LsvDOTh - -#define LSV_ANY (-2) - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -extern int LSV_procnum; -extern int LSV_nproc; - -extern char Smy_name[]; /* my hostname or inet address */ - -void Ssend(const void *outb, int outcnt, int dest, int type); -int Srecv_block(void *inb, int size, int type, int *from); -int Srecv(void *inb, int size, int type, int *from); -void Sclose(void); -void Sdiag(int (*)(const char *, ...)); - -void Sinit_host1(int *portp, char **namep); -void Sinit_host(int nproc); -void Sinit_elt(void); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _LsvDOTh */ diff --git a/external/libsdf/include/libsdf/memfile.h b/external/libsdf/include/libsdf/memfile.h deleted file mode 100644 index 8259ec9..0000000 --- a/external/libsdf/include/libsdf/memfile.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _MemfilEdotH -#define _MemfilEdotH - -#ifdef __cplusplus -extern "C"{ -#endif -void memfile_init(int sz) ; -void memfile_delete(void) ; -void memfile_vfprintf(void *junk, const char *fmt, va_list args) ; -void PrintMemfile(void); -#ifdef __cplusplus -} -#endif - -#endif diff --git a/external/libsdf/include/libsdf/mpmy.h b/external/libsdf/include/libsdf/mpmy.h deleted file mode 100644 index 32d016f..0000000 --- a/external/libsdf/include/libsdf/mpmy.h +++ /dev/null @@ -1,164 +0,0 @@ -#ifndef _MpMYdotH -#define _MpMYdotH - -#include "timers.h" - -typedef void *MPMY_Comm_request; -typedef struct { - int tag; - int src; - int count; -}MPMY_Status; - -#define MPMY_SUCCESS (0) -#define MPMY_FAILED (1) -/* This corresponds to the ANY-source in udp.c. */ -/* What about other PAROS??? */ -#define MPMY_SOURCE_ANY -2 -#define MPMY_TAG_ANY -1 - -/* Data types and operations supported in MPMY_Combine */ - -typedef enum { - MPMY_SUM, MPMY_PROD, MPMY_MAX, MPMY_MIN, MPMY_BAND, MPMY_BOR, MPMY_BXOR -} MPMY_Op; - -typedef void (*MPMY_user_comb_func)(const void *from1, const void *from2, - void *to); - -typedef enum { - MPMY_FLOAT, MPMY_DOUBLE, MPMY_INT, MPMY_CHAR, MPMY_SHORT, MPMY_LONG, - MPMY_UNSIGNED_INT, MPMY_UNSIGNED_CHAR, MPMY_UNSIGNED_SHORT, - MPMY_UNSIGNED_LONG, MPMY_OFFT, MPMY_INT64, MPMY_USER_DATA -} MPMY_Datatype; - -extern unsigned int MPMY_Datasize[]; - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -/* Reduction prototypes */ -int MPMY_Combine(const void *sendbuf, void *recvbuf, const int count, - const MPMY_Datatype datatype, const MPMY_Op op); -int MPMY_ICombine_Init(MPMY_Comm_request *reqp); -int MPMY_ICombine_Wait(MPMY_Comm_request req); -int MPMY_ICombine(const void *sendbuf, void *recvbuf, int count, - MPMY_Datatype datatype, MPMY_Op op, - MPMY_Comm_request req); -/* A separate entry point for the user-specified-function version */ -int MPMY_ICombine_func(const void *sendbuf, void *recvbuf, int size, - MPMY_user_comb_func func, - MPMY_Comm_request req); -int MPMY_AllGather(const void *sndbuf, int count, MPMY_Datatype type, - void *rcvbuf); -int MPMY_Gather(const void *sendbuf, int count, MPMY_Datatype type, - void *recvbuf, int recvproc); -int MPMY_NGather(const void *sendbuf, int count, MPMY_Datatype type, - void **recvhndl, int recvproc); -int MPMY_Bcast(void *buf, int count, MPMY_Datatype type, int sendproc); -int MPMY_BcastTag(void *buf, int count, MPMY_Datatype type, int sendproc, int Tag0); -int MPMY_Alltoall(void *sendbuf, int sendcount, MPMY_Datatype sendtype, - void *recvbuf, int recvcount, MPMY_Datatype recvtype); -int MPMY_Alltoallv(void *sendbuf, int *sendcounts, int *sendoffsets, MPMY_Datatype sendtype, - void *recvbuf, int *recvcounts, int *recvoffsets, MPMY_Datatype recvtype); -int Native_MPMY_Allgather(void *sendbuf, int sendcount, MPMY_Datatype type, void *recvbuf); -int Native_MPMY_Allgatherv(void *sendbuf, int sendcount, MPMY_Datatype type, void *recvbuf, - int *rcounts, int *roffsets); -int Native_MPMY_Alltoall(void *sendbuf, int sendcount, MPMY_Datatype sendtype, - void *recvbuf, int recvcount, MPMY_Datatype recvtype); -int Native_MPMY_Alltoallv(void *sendbuf, int *sendcounts, int *sendoffsets, MPMY_Datatype sendtype, - void *recvbuf, int *recvcounts, int *recvoffsets, MPMY_Datatype recvtype); - -/* - A NULL stat argument is allowed, indicating that you aren't interested in - the status. -*/ -int MPMY_Init(int *argcp, char ***argvp); -int MPMY_Isend(const void *buf, int cnt, int dest, int tag, MPMY_Comm_request *req); -int MPMY_Irsend(const void *buf, int cnt, int dest, int tag, MPMY_Comm_request *req); -int MPMY_Irecv(void *buf, int cnt, int src, int tag, MPMY_Comm_request *req); -int MPMY_Test(MPMY_Comm_request request, int *flag, MPMY_Status *stat); -int MPMY_Wait(MPMY_Comm_request request, MPMY_Status *stat); -/* I don't know how to write the general WaitN, but we seem to use Wait2 - often enough that it's worth providing in the library. Note that this - waits for BOTH. Not EITHER. */ -int MPMY_Wait2(MPMY_Comm_request req1, MPMY_Status *stat1, - MPMY_Comm_request req2, MPMY_Status *stat2); -/* send with wait */ -void MPMY_send(const void *buf, int cnt, int dest, int tag); -/* Blocking recv of exactly cnt bytes */ -void MPMY_recvn(void *buf, int cnt, int src, int tag); -int MPMY_Finalize(void); - -/* These are occasionally useful and seem to be highly system-dependent */ -int MPMY_Sync(void); -int MPMY_Flick(void); - -/* Desperate times require desperate measures... (c.f. malloc_print) - Consider using Msg_do or Shout as the argument. Note that, despite - the name, they aren't strictly printf-identical because they don't - return an int. C'est la vie. */ -void MPMY_Diagnostic(int (*printflike)(const char *, ...)); - -/* And a version suitable for passing to OnAbnormal */ -void PrintMPMYDiags(void); - -/* These don't really have analogues in mpi. MPI does have Sendrecv - and Sendrecv_replace, but those are both more general (allowing - different sources and destinations, allowing tags, allowing *_ANY) - and less general ('replace' instead of 'overlap'). - -*/ -int MPMY_Shift(int proc, void *recvbuf, int recvcnt, - const void *sendbuf, int sendcnt, MPMY_Status *stat); - -int MPMY_Shift_overlap(int proc, void *recvbuf, int recvcnt, - const void *sendbuf, int sendcnt, MPMY_Status *stat); - - -/* In MPI, they actually give you the name of the field element. For backward - compatibility, I'll also give them as macros */ -#define MPMY_SOURCE src -#define MPMY_TAG tag -#define MPMY_Source(stat) ((stat)->src) -#define MPMY_Tag(stat) ((stat)->tag) -/* In MPI, this is still a function because it has to deal with typing. - We don't worry about typing... */ -#define MPMY_COUNT count -#define MPMY_Count(stat) ((stat)->count) - -int MPMY_Nproc(void); -int MPMY_Procnum(void); -/* Returns a pointer to a static char string describing the phys node. */ -const char *MPMY_Physnode(void); -/* We call these an awful lot. Let's just set them up in init and - save a function-call */ -extern int _MPMY_nproc_; -extern int _MPMY_procnum_; -extern int _MPMY_procs_per_node_; -#define MPMY_Nproc() (_MPMY_nproc_) -#define MPMY_Procnum() (_MPMY_procnum_) -#define MPMY_ProcsPerNode() (_MPMY_procs_per_node_) - -/* How can a "subsystem" like SDF know if MPMY has been initialized? */ -extern int MPMY_Initialized(void); -extern int _MPMY_initialized_; /* internal use only! */ - -/* Counters for the number of Isends, Irecvs and (successful Tests + Waits) */ -extern Counter_t MPMYSendCnt; -extern Counter_t MPMYRecvCnt; -extern Counter_t MPMYDoneCnt; - -void MPMY_CheckpointSetup(int job_seconds, int interval_seconds, int step_seconds); -int MPMY_CheckpointDue(int next_output_seconds); -void MPMY_CheckpointFinished(void); -int MPMY_JobDone(void); -int MPMY_JobRemaining(void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* INTERNAL USE ONLY!! */ - -#endif diff --git a/external/libsdf/include/libsdf/mpmy_abnormal.h b/external/libsdf/include/libsdf/mpmy_abnormal.h deleted file mode 100644 index 5b2c819..0000000 --- a/external/libsdf/include/libsdf/mpmy_abnormal.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef _MPMYAbnormalDOTh_ -#define _MPMYAbnormalDOTh_ -#include "gccextensions.h" - -/* Abhndlrs are void functions of void. Use them as arguments to - MPMY_OnAbnormal. */ -typedef void (*Abhndlr)(void); - -#ifdef __cplusplus -extern "C"{ -#endif - -/* MPMY_Abort will execute MPMY_RaiseAbnormal(SIGABRT) and then call - MPMY_SystemAbort. Don't be surprised if the OnAbnormal functions - themselves call MPMY_SystemAbort first, though. */ -void MPMY_Abort(void) __NORETURN__; - -extern int MPMY_Abnormal_signum; -extern int MPMY_stop_abnormal_processing; -void MPMY_RaiseAbnormal(int sig); /* fake a signal of type 'sig' */ - -/* Push a handler to the stack that will be executed on abnormal termination. - Some useful arguments to consider are: - malloc_print(); - PrintMemfile(); - Msg_flush(); - MPMY_abchdir(); (with MPMY_abchdir_arg set beforehand) - MPMY_SystemAbort(); - MPMY_SystemExit(); (with MPMY_exit_arg set beforehand) - - They are called in the reverse chronological order from the order that - they were requested by MPMY_OnAbnormal, so later functions - might 'override' earlier ones. This isn't perfect, but it's better than - the monolithic handler we had before. The handler can - find out which signal is being handled by looking at - int MPMY_current_signal ; - - As a final twist, it is possible to bail out of the stack and just - return from the handler immediately by setting: - int MPMY_stop_abnormal_processing; - to non-zero. -*/ -void MPMY_OnAbnormal(Abhndlr hndlr); - -/* Really, truly, abort(). Now! */ -void MPMY_SystemAbort(void) __NORETURN__; - -/* Really, truly, exit(MPMY_exit_arg). Now! */ -extern int MPMY_exit_arg; -void MPMY_SystemExit(void) __NORETURN__; /* An Abhndlr */ - -/* Do a mkdir/chdir to the directory named by MPMY_abchdir_arg. - This can be extremely useful before dumping core... */ -extern char MPMY_Abchdir_arg[]; -void MPMY_Abchdir(void); /* An Abhndlr */ - -/* Announce (Shout) that we are handling a signal. Try not to repeat - yourself if it's been said already... */ -void MPMY_Abannounce(void); - -/* Arrange to crash and burn if n seconds elapse before Reset is called */ -void MPMY_TimeoutSet(int n); -void MPMY_TimeoutReset(int n); -void MPMY_TimeoutCancel(void); - -/* Not for public use. */ -void _MPMY_setup_absigs(void); -#ifdef __cplusplus -} -#endif -#endif /* _MPMYAbnormalDOTh_ */ diff --git a/external/libsdf/include/libsdf/mpmy_io.h b/external/libsdf/include/libsdf/mpmy_io.h deleted file mode 100644 index 2839b98..0000000 --- a/external/libsdf/include/libsdf/mpmy_io.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef MPMY_IOdotH -#define MPMY_IOdotH - -#include -#include - -typedef void MPMYFile; - -/* mode flags for open */ -/* The first three correspond to the analogous modes O_??? that seem - to be fairly common on different unices (linux, sunos, solaris). I - guess that's a good thing. But who decided that OR'ing zero - (O_RDONLY) with other values should be used as a flag???? The latter - ones show no commonality between other flavors of unix anyway, so - there's nothing to remain analogous to... */ -#define MPMY_RDONLY 00000000 -#define MPMY_WRONLY 00000001 -#define MPMY_RDWR 00000002 -#define MPMY_APPEND 00000004 -#define MPMY_CREAT 00000010 -#define MPMY_TRUNC 00000020 -/* io modes */ -#define MPMY_SINGL 00010000 /* like cubix single mode */ -#define MPMY_MULTI 00020000 /* like cubix multi mode */ -/* These four are used by the 'mpmy_pario' implementation, but that is - no longer linked with any of our default systems... */ -#define MPMY_UNIX 00040000 /* one file, UNIX multi-process semantics */ -#define MPMY_IOZERO 00100000 /* if(procnum==0){...} */ -#define MPMY_INDEPENDENT 00200000 /* many files. Complete independence */ -#define MPMY_NFILE 00400000 /* many files. Really. */ - -/* modes for seek */ -#define MPMY_SEEK_SET 0 -#define MPMY_SEEK_CUR 1 -#define MPMY_SEEK_END 2 - - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -MPMYFile *MPMY_Fopen(const char *path, int flags); -int MPMY_SetIOMode(MPMYFile *fp, int iomode); -int MPMY_Fclose(MPMYFile *fp); -int MPMY_Mkdir(const char *path, int mode); -size_t MPMY_Fread(void *ptr, size_t size, size_t nitems, MPMYFile *fp); -size_t MPMY_Fwrite(const void *ptr, size_t size, size_t nitems, MPMYFile *fp); -off_t MPMY_Fseek(MPMYFile *fp, off_t offset, int whence); -off_t MPMY_Ftell(MPMYFile *fp); -off_t MPMY_Flen(MPMYFile *fp); -int MPMY_Getc(MPMYFile *fp); -int MPMY_Ungetc(char c, MPMYFile *fp); -size_t MPMY_Fseekrd(MPMYFile *fp, off_t offset, int whence, void *buf, size_t reclen, - size_t nrecs); -int MPMY_Fprintf(MPMYFile *fp, const char *fmt, ...); -int MPMY_Vfprintf(MPMYFile *fp, const char *fmt, va_list args); -int MPMY_Fflush(MPMYFile *fp); -int MPMY_Nfileio(int val); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* MPMY_IOdotH */ diff --git a/external/libsdf/include/libsdf/mpmy_time.h b/external/libsdf/include/libsdf/mpmy_time.h deleted file mode 100644 index f333063..0000000 --- a/external/libsdf/include/libsdf/mpmy_time.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef MPMY_timeDOTh -#define MPMY_timeDOTh - -/* some simple system-dependent routines to facilitate timing */ - -#define MPMY_CPU_TIME 1 -#define MPMY_WC_TIME 2 - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -void *MPMY_CreateTimer(int type); -int MPMY_StartTimer(void *); - int MPMY_CopyTimer(void *, void *); -int MPMY_StopTimer(void *); -int MPMY_ClearTimer(void *); -double MPMY_ReadTimer(void *); -int MPMY_DestroyTimer(void *); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/external/libsdf/include/libsdf/peano.h b/external/libsdf/include/libsdf/peano.h deleted file mode 100644 index 854b0a5..0000000 --- a/external/libsdf/include/libsdf/peano.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __PeanoDOt_H_ -#define __PeanoDOt_H_ -#include "key.h" - -Key_t PHKeyFromInts(unsigned int ikey[], int ndim, int depth); -unsigned int IntsFromPHKey(Key_t key, unsigned int ikey[], int ndim); - -#endif diff --git a/external/libsdf/include/libsdf/protos.h b/external/libsdf/include/libsdf/protos.h deleted file mode 100644 index 9e08a57..0000000 --- a/external/libsdf/include/libsdf/protos.h +++ /dev/null @@ -1,128 +0,0 @@ -/* This is where we keep the code to shut up warnings about implicit */ -/* declarations. */ - -/* - * Copyright 1991 Michael S. Warren and John K. Salmon. All Rights Reserved. - */ -#ifndef _ProtosDOTh -#define _ProtosDOTh - -/* gcc's fixprotos changed in 2.5 so that it is no longer necessary - to have protos for all these. If __GNUC__ and __GNUC_MINOR are undefined, - ANSI says the pre-processor should treat them as 0, so the test should - pass and we should see the prototypes - fingers crossed. -*/ -/* AIEEEE!!! The above comment only applied to the short-lived - aberation 2.5.4. It is broken again in 2.5.5. Unfortunately, - there is no __GNUC__SUBMINOR__ so I can't switch on it. The - following conditional worked for 2.5.4... -#if defined(sun) && !defined(__SUN5__) && __GNUC__<=2 && __GNUC_MINOR__<=4 -*/ - -/*------------------------------------------------------*/ -/* ----------------BEGIN--SUNOS------------------------ */ -/*------------------------------------------------------*/ -#if defined(sun) -#include -/* Sunos4.1.3 sometimes seems to come with prototypes...And they're wrong! */ -/* Setting ARCH=sun4proto will activate this */ -#ifndef _SUNOS4_PROTOTYPES_ -extern int bcopy(const void *from, void *to, size_t); -#if !defined(__SUN5__) && !defined (_SUNACC) -/* Sun's stdio doesn't have protos for fflush, printf, what else?? */ -/* I can't predict whether FILE is meaningful, so I use void* */ -/* Furthermore, I can't give a prototype for sprintf because gcc complains */ -/* about a conflict between old-style decl and one with an ellipsis */ -#include "gccextensions.h" -#include - -/* Sigh... In 2.5.6 and 2.5.7 (at least). fixincludes gives full - prototypes for all the non-integer-return functions in std*.h. */ -#if 0 -extern char *sprintf(); -#endif - -extern int printf( const char *, ... ) - __attribute__ ((format (printf, 1, 2))); -extern int fprintf(void *, const char *, ...) - __attribute__((format (printf, 2, 3))); -extern int vfprintf(void *, const char *, va_list) - __attribute__((format (printf, 2, 0))); -extern int vsprintf(char *, const char *, va_list) - __attribute__((format (printf, 2, 0))); -extern int scanf(const char *, ...) - __attribute__((format (scanf, 1, 2))); -extern int sscanf(const char *, const char *, ...) - __attribute__((format (scanf, 2, 3))); -extern int fflush(void *); -extern int fwrite(const void *, size_t, size_t, void/*FILE*/ *); -extern int fseek(void/*FILE*/ *, long, int); -extern int fread(void *, size_t, size_t, void/*FILE*/ *); -extern int fclose(void *); -extern int raise(int); -extern int _filbuf(void *); -extern int _flsbuf(int, void *); -#ifndef ungetc -extern int ungetc(int, void*); -#endif -extern int setvbuf(void *, void *, int, size_t); -/* We carefully include stdlib.h when we use these, */ -/* but Sun has elected to leave them out of stdlib.h...go figure */ -extern void *memmove(void *, const void *, size_t); -extern void *memccpy (void *, const void *, int, size_t ); -extern void *memchr (const void *, int, size_t ); -extern void *memcpy (void *, const void *, size_t ); -extern void *memset (void *, int, size_t ); -#endif /* __SUN5__ */ -#endif /* _SUNOS4_PROTOTYPES_ */ -#endif /* sun */ -/*------------------------------------------------------*/ -/* ------------------END--SUNOS------------------------ */ -/*------------------------------------------------------*/ - -/*------------------------------------------------------*/ -/* ------------------BEGIN--INTEL---------------------- */ -/*------------------------------------------------------*/ -#if defined(__INTEL_SSD__) -#include -extern int bcopy(const void *from, void *to, size_t); - -/* This should be in nx.h or cube.h or mesh.h */ -extern void flick(void); - -#if defined(__DELTA__) || defined(__GAMMA__) -/* This should be in fcntl.h */ -int open(const char *, int flags, ...); -int creat(const char *, int/* mode_t */); - -/* These should be in unistd.h */ -int close(int); -int unlink(const char *); -int read(int, void *buf, unsigned int); -int write(int, const void *, unsigned int); -/*off_t*/long lseek(int, long/*off_t*/, int); - -/* Should be in sys/stat.h */ -int mkdir(const char *, int); -#ifdef S_IRGRP -/* this means we already included */ -int fstat(int, struct stat *); -#endif -#endif /* __DELTA__ || __GAMMA__ */ - -#endif /* !__INTEL_SSD__ */ -/*------------------------------------------------------*/ -/* ------------------END--INTEL------------------------ */ -/*------------------------------------------------------*/ - -/*------------------------------------------------------*/ -/* ------------------BEGIN--SOLARIS/STARDENT----------- */ -/*------------------------------------------------------*/ -#if defined(__STARDENT__) || defined(__SUN5__) -int finite(double); -#endif -/*------------------------------------------------------*/ -/* --------------------END--SOLARIS/STARDENT----------- */ -/*------------------------------------------------------*/ - -#endif /* _PrototDOTh */ diff --git a/external/libsdf/include/libsdf/qromo.h b/external/libsdf/include/libsdf/qromo.h deleted file mode 100644 index c3577fc..0000000 --- a/external/libsdf/include/libsdf/qromo.h +++ /dev/null @@ -1,8 +0,0 @@ -float qromo(float (*func)(float), float a, float b, - float (*choose)(float (*)(float), float, float, int)); -float midpnt(float (*func)(float), float a, float b, int n); - -double qromod(double (*func)(double), double a, double b, - double (*choose)(double (*)(double), double, double, int)); -double midpntd(double (*func)(double), double a, double b, int n); - diff --git a/external/libsdf/include/libsdf/randoms.h b/external/libsdf/include/libsdf/randoms.h deleted file mode 100644 index 663eebf..0000000 --- a/external/libsdf/include/libsdf/randoms.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef Randoms2DOTh -#define Randoms2DOTh - -#define NTAB 32 - -typedef struct{ - long idum, idum2; - long iy, iv[NTAB]; - int did_init; - int next_norml_ok; - float next_norml; -} ran_state; - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -void ran_init(int seed, ran_state *st); -float uniform_rand(ran_state *s); -float normal_rand(ran_state *s); -float sphere_rand(ran_state *st, int ndim, float *x); -float cube_rand(ran_state *st, int ndim, float *x); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/external/libsdf/include/libsdf/ring.h b/external/libsdf/include/libsdf/ring.h deleted file mode 100644 index e05717c..0000000 --- a/external/libsdf/include/libsdf/ring.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _RingDOTh -#define _RingDOTh - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -void Ring(void *bptr, int bsize, int bnobj, - void *optr, int osize, int onobj, int oused, - void initf(void *, void *), void interactf(void *, void *, int, int)); - -void Ring2(void *bptr, int bsize, int bnobj, - void *optr, int osize, int onobj, int tsize, - void initf(void *, void *), void interactf(void *, void *, int, int), void finishf(void *, void *)); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _RingDOTh */ diff --git a/external/libsdf/include/libsdf/singlio.h b/external/libsdf/include/libsdf/singlio.h deleted file mode 100644 index b63ff0c..0000000 --- a/external/libsdf/include/libsdf/singlio.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _SinglIODOTh -#define _SinglIODOTh - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -int singlPrintf(const char *, ...); -void singlFflush(void); -int singlAutoflush(int); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/external/libsdf/include/libsdf/stk.h b/external/libsdf/include/libsdf/stk.h deleted file mode 100644 index 82512f8..0000000 --- a/external/libsdf/include/libsdf/stk.h +++ /dev/null @@ -1,192 +0,0 @@ -#ifndef STKdotH -#define STKdotH - -#include -#include -#include "Malloc.h" - -/* A quick and dirty stack implementation. Less functionality than */ -/* the RMS obstack. Is it faster? */ - -/* We could lift the code from obstack to determine proper alignment, - but I think it's easier to just -Define it in Make.$ARCH */ - -/* Use char * so we can do arithmetic without annoying casts. */ -typedef struct stk{ - char *bottom; - char *ptr; - char *top; - int growby; - void *(*realloc_like)(void *, size_t); - unsigned int align_mask; -} Stk; - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -/* StkInitWithData starts with the given DATA ptr */ -void StkInitWithData(struct stk *s, size_t initial_sz, - void *(*realloc_like)(void *, size_t), void *data, - unsigned int alignment); - -/* StkCopy makes a completely new stack, initialized with the data in FROM */ - -void StkCopy(struct stk *to, const struct stk *from); -/* StkInit initializes a stack. */ -void StkInit(struct stk *s, size_t initial_sz, - void *(*realloc_like)(void *, size_t), unsigned int alignment); - -/* StkGrow adds at least nbytes to the available space in the stack. */ -/* FOR INTERNAL USE ONLY */ -void StkGrow(Stk *s, int nbytes); - -/* StkTerminate frees the space and forget about it forever */ -void StkTerminate(struct stk *s); - -#if !(__STDC_VERSION__ >= 199901L) -/* StkInitEz chooses reasonable defaults. */ -extern void StkInitEz(struct stk *s); - -/* StkPush returns a pointer to room for nbytes at the top of the */ -/* stack. It's up to you to put something there. */ -extern void *StkPush(struct stk *s, int nbytes); -/* The 'Align' version makes sure that the stack remains aligned. - Use if WITH AND ONLY WITH StkPopAlign */ -extern void *StkPushAlign(struct stk *s, int nbytes); - -/* StkPushData does a push and a memcpy */ -extern void *StkPushData(struct stk *s, void *p, int nbytes); - -/* StkPop returns a pointer to the beginning of the nbytes at the */ -/* top of the stack. The data under those bytes is guaranteed to */ -/* remain intact ONLY UNTIL THE NEXT StkPush, i.e., the data has been */ -/* popped. */ -extern void *StkPop(struct stk *s, int nbytes); -/* The 'Align' version makes sure that the stack remains aligned. Use - it IF AND ONLY IF with StkPushAlign was used. NOTE: you must use - the StkPushAlign on the push BEFORE the one that requires alignment! */ -extern void *StkPopAlign(struct stk *s, int nbytes); - -/* StkPeek returns the same thing as StkPop, but it doesn't "pop" anything. */ -/* The top of the stack is found by StkPeek(s, 0); */ -extern void *StkPeek(const struct stk *s, int nbytes); - -/* StkBase returns the current base of the stack. Beware, it can move */ -/* around! It is only guaranteed to stay in place until the next StkPush */ -extern void *StkBase(const struct stk *s); - -/* StkSz is the size of the stack. */ -extern size_t StkSz(const struct stk *s); - -/* StkTop is easily constructed from the others, but we provide it anyway. */ -/* It returns a pointer just past the end of the current stack. */ -extern void *StkTop(const struct stk *s); - -/* StkClear is equivalent to StkPop(s, StkSz(s)), but it returns void */ -extern void StkClear(struct stk *s); - -/* StkCrunch realloc's the stack so it doesn't use any more space */ -/* than necessary. Use it if you know you've reached the high-water-mark */ -extern void *StkCrunch(struct stk *s); - -/* Discover the alignment of a given stack. I.e., how would it */ -extern int StkAlign(const struct stk *s, unsigned int nbytes); - -#endif - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -/* Here's a convenient define for popping a known type. */ -#define StkPopType(s, t) (*(t *)StkPop(s, sizeof(t))) - -#define StkPushType(s, val, t) (*(t *)StkPush(s, sizeof(t)) = val) - -/* StkAlign(n) tells you how many bytes will really be pushed if you */ -/* do a StkPush(n) */ -#ifdef STK_FORCE_ALIGNMENT -#define _STK_DEFAULT_ALIGNMENT STK_FORCE_ALIGNMENT -#else -#define _STK_DEFAULT_ALIGNMENT 1 -#endif - -/* Here are all the inlined definitions. Non-inlined functions */ -/* can go in stk.c */ - -#if (defined(__GNUC__) || defined(__ICC__)) || defined(STKdotC) - -#undef INLINE -#if (__STDC_VERSION__ >= 199901L) && !defined (STKdotC) -#define INLINE inline -#else -#if (defined (__GNUC__) || defined(__ICC__)) && !defined (STKdotC) -#define INLINE extern __inline__ -#else -#define INLINE -#endif -#endif - -INLINE int StkAlign(const struct stk *s, unsigned int nbytes){ - return (nbytes + s->align_mask ) & ~s->align_mask; -} - -INLINE void StkInitEz(struct stk *s){ - StkInit(s, 1024, Realloc_f, _STK_DEFAULT_ALIGNMENT); -} - -INLINE void *StkPush(struct stk *s, int nbytes){ - char *ret; - nbytes = StkAlign(s, nbytes); - - if( s->ptr + nbytes > s->top ){ - StkGrow(s, nbytes); - } - ret = s->ptr; - s->ptr += nbytes; - return ret; -} - -INLINE void *StkPushData(struct stk *s, void *p, int nbytes){ - return memcpy(StkPush(s, nbytes), p, nbytes); -} - -INLINE void *StkPop(struct stk *s, int nbytes){ - nbytes = StkAlign(s, nbytes); -#ifdef NO_CHECK - return s->ptr -= nbytes; -#else - s->ptr -= nbytes; - if( s->ptr < s->bottom ){ - s->ptr += nbytes; /* undo the damage */ - return NULL; - }else - return s->ptr; -#endif -} - -INLINE void *StkPeek(const struct stk *s, int nbytes){ - return s->ptr - nbytes; -} - -INLINE void StkClear(struct stk *s){ - s->ptr = s->bottom; -} - -INLINE void *StkBase(const struct stk *s){ - return s->bottom; -} - -INLINE size_t StkSz(const struct stk *s){ - return s->ptr - s->bottom; -} - -INLINE void *StkTop(const struct stk *s){ - /* NOTE that StkTop is NOT s->top !! */ - return s->ptr; -} - -#undef INLINE -#endif /* GNUC || STKdotC */ - -#endif /* STKdotH */ diff --git a/external/libsdf/include/libsdf/swampi.h b/external/libsdf/include/libsdf/swampi.h deleted file mode 100644 index 7a11b93..0000000 --- a/external/libsdf/include/libsdf/swampi.h +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef _MpiDOTh -#define _MpiDOTh - -#define MPI_Init SWAMPI_Init -#define MPI_Finalize SWAMPI_Finalize -#define MPI_Abort SWAMPI_Abort -#define MPI_Comm_rank SWAMPI_Comm_rank -#define MPI_Comm_size SWAMPI_Comm_size -#define MPI_Comm_free SWAMPI_Comm_free -#define MPI_Get_count SWAMPI_Get_count -#define MPI_Isend SWAMPI_Isend -#define MPI_Irecv SWAMPI_Irecv -#define MPI_Issend SWAMPI_Isend /* can Isend handle Issends? */ -#define MPI_Test SWAMPI_Test -#define MPI_Wait SWAMPI_Wait -#define MPI_Waitall SWAMPI_Waitall -#define MPI_Send SWAMPI_Send -#define MPI_Recv SWAMPI_Recv -#define MPI_Sendrecv SWAMPI_Sendrecv -#define MPI_Bcast SWAMPI_Bcast -#define MPI_Reduce SWAMPI_Reduce -#define MPI_Allreduce SWAMPI_Allreduce -#define MPI_Barrier SWAMPI_Barrier -#define MPI_Alltoallv SWAMPI_Alltoallv -#define MPI_Alltoall SWAMPI_Alltoall -#define MPI_Comm_dup SWAMPI_Comm_dup -#define MPI_Comm_split SWAMPI_Comm_split -#define MPI_Type_contiguous SWAMPI_Type_contiguous -#define MPI_Type_commit SWAMPI_Type_commit -#define MPI_Wtime SWAMPI_Wtime -#define MPI_Wtick SWAMPI_Wtick - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ - -typedef struct { - int MPI_SOURCE; - int MPI_TAG; - int MPI_ERROR; - int count; -} MPI_Status; - -/* MAXLOC and MINLOC structures */ -typedef struct { float x; int i;} MPI_float_int; -typedef struct { double x; int i;} MPI_double_int; -typedef struct { long x; int i;} MPI_long_int; -typedef struct { int x; int i;} MPI_2int; -typedef struct { short x; int i;} MPI_short_int; -typedef struct { long double x; int i;} MPI_long_double_int; - -/* Fortran types */ -typedef struct { float real; float imag; } MPI_complex; -typedef struct { double real; double imag; } MPI_double_complex; - -/* must match MPI_Datasize array in swampi.c */ -typedef enum { - MPI_FLOAT, MPI_DOUBLE, MPI_LONG_DOUBLE, - MPI_BYTE, MPI_CHAR, MPI_SHORT, MPI_INT, - MPI_LONG, MPI_LONG_LONG, - MPI_UNSIGNED, MPI_UNSIGNED_INT, MPI_UNSIGNED_CHAR, - MPI_UNSIGNED_SHORT, MPI_UNSIGNED_LONG, MPI_UNSIGNED_LONG_LONG, - MPI_FLOAT_INT, MPI_DOUBLE_INT, MPI_LONG_INT, - MPI_2INT, MPI_SHORT_INT, MPI_LONG_DOUBLE_INT, - MPI_COMPLEX, MPI_DOUBLE_COMPLEX, /* for Fortran */ - MPI_USER_DATA, _MPI_NUMDATATYPES -} MPI_Datatype; - -typedef enum { - MPI_SUM, MPI_PROD, MPI_MAX, MPI_MIN, MPI_BAND, MPI_BOR, - MPI_BXOR, MPI_LAND, MPI_LOR, MPI_LXOR, MPI_MAXLOC, MPI_MINLOC, - _MPI_NUMOPS -} MPI_Op; - - -typedef void (*MPI_user_comb_func)(void *from1, void *from2, void *to); -typedef int MPI_Comm; -typedef void * MPI_Request; - -enum MPI_comm { MPI_COMM_WORLD, MPI_COMM_PRIVATE, MPI_COMM_NULL }; -enum MPI_src { MPI_ANY_SOURCE = -1 }; -enum MPI_tag { MPI_ANY_TAG = -1 }; -enum MPI_ret { MPI_ERR_OTHER = -1, MPI_SUCCESS = 0 }; - -#define MPI_UNDEFINED (-32766) -#define MPI_REQUEST_NULL ((MPI_Request) 0) - -int MPI_Init(int *argcp, char ***argvp); -int MPI_Finalize(void); -int MPI_Abort(MPI_Comm comm, int errorcode); -int MPI_Comm_rank(MPI_Comm comm, int *rank); -int MPI_Comm_size(MPI_Comm comm, int *size); -int MPI_Get_count(MPI_Status *status, MPI_Datatype type, int *cnt); -int MPI_Isend(void *buf, int cnt, MPI_Datatype type, int dest, int tag, - MPI_Comm comm, MPI_Request *req); -int MPI_Irecv(void *buf, int cnt, MPI_Datatype type, int src, int tag, - MPI_Comm comm, MPI_Request *req); -int MPI_Test(MPI_Request *cptr, int *flag, MPI_Status *stat); -int MPI_Wait(MPI_Request *cptr, MPI_Status *status); -int MPI_Waitall(int count, MPI_Request *reqv, MPI_Status *statusv); -int MPI_Send(void *buf, int cnt, MPI_Datatype type, int dest, int tag, - MPI_Comm comm); -int MPI_Recv(void *buf, int cnt, MPI_Datatype type, int src, int tag, - MPI_Comm comm, MPI_Status *status); -int MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, - int dest, int sendtag, void *recvbuf, int recvcount, - MPI_Datatype recvtype, int source, int recvtag, - MPI_Comm comm, MPI_Status *status); -int MPI_Bcast(void *buf, int cnt, MPI_Datatype type, int src, MPI_Comm comm); -int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, - MPI_Op op, int root, MPI_Comm comm); -int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, - MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); -int MPI_Barrier(MPI_Comm comm); -int MPI_Alltoallv(void *sbuf, int *sendcnts, int *sdispls, MPI_Datatype stype, - void *rbuf, int *recvcnts, int *rdispls, MPI_Datatype rtype, - MPI_Comm comm); -int MPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype, - void *recvbuf, int recvcount, MPI_Datatype recvtype, - MPI_Comm comm); -int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm); -int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm); -int MPI_Comm_free(MPI_Comm *comm); -int MPI_Type_contiguous(int len, MPI_Datatype type, MPI_Datatype *ptr); -int MPI_Type_commit(MPI_Datatype *ptr); - -double MPI_Wtime(void); -double MPI_Wtick(void); - -/* These convert the enums to a text description */ -char *mpi_op_name[_MPI_NUMOPS], *mpi_datatype_name[_MPI_NUMDATATYPES]; - -/* These are private for mpi_reduce.c and mpi_bcast.c */ -extern int _MPI_Procnum, _MPI_Nproc; -extern unsigned int *_MPI_Datasize; - -/* These are for mpirun.c */ -void _MPI_init_host1(int *portp, char **namep, int nproc); -void _MPI_init_host(int nproc); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _MpiDOTh */ diff --git a/external/libsdf/include/libsdf/timers.h b/external/libsdf/include/libsdf/timers.h deleted file mode 100644 index a983e29..0000000 --- a/external/libsdf/include/libsdf/timers.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 1991, 1992, 1993 Michael S. Warren and John K. Salmon. - * All Rights Reserved. - */ - -#ifndef _TimersDOTh -#define _TimersDOTh -#include - -/* This used to look more like a Counter_t, but it was just too much */ -/* trouble to deal with the archtecture specific differences, so we */ -/* hide all the ugliness behind another layer of indirection. In */ -/* fact, it would make more sense if, e.g., EnableTimer returned a void* */ -/* but that would require too much changing of "application" code. */ -typedef struct { - int enabled; - void *mpmy_tm; - char *name; - double min, max, mean; -} Timer_t; - -typedef struct { - int enabled; - int64_t counter; - int64_t max, min; - double mean, sum; - char *name; -} Counter_t; - -#ifdef __cplusplus -extern "C"{ -#endif /* __cplusplus */ -void StartTimer(Timer_t *t); -void StopTimer(Timer_t *t); -void SumTimers(void); -void CopyTimer(Timer_t *src, Timer_t *dest); -void EnableWCTimer(Timer_t *t, char *name); -void EnableCPUTimer(Timer_t *t, char *name); -void DisableTimer(Timer_t *t); -void ClearTimer(Timer_t *t); -void ClearEnabledTimers(void); -void OutputTimers(int (*Printf_Like)(const char *, ...)); -void OutputTimer(Timer_t *t, int (*Printf_Like)(const char *, ...)); -void OutputIndividualTimers(int (*Printf_Like)(const char *, ...)); -double ReadTimer(Timer_t *t); - -void SumCounters(void); -void EnableCounter(Counter_t *t, char *name); -void DisableCounter(Counter_t *t); -void ClearCounter(Counter_t *c); -void ClearEnabledCounters(void); -void OutputCounters(int (*Printf_Like)(const char *, ...)); -void OutputIndividualCounters(int (*Printf_Like)(const char *, ...)); -void OutputOneCounter(Counter_t *c, int (*Printf_Like)(const char *, ...)); -int64_t ReadCounter(Counter_t *c); -int64_t ReadCounter64(Counter_t *c); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#define EnableTimer(t, name) EnableWCTimer(t, name) - -#ifdef NOTIMERS -#define StartTimer(x) /**/ -#define StopTimer(x) /**/ -#define StartWCTimer(x) /**/ -#define StopWCTimer(x) /**/ -#endif - -#ifndef NOCOUNTERS -#define IncrCounter(c) ((c)->counter++) -#define AddCounter(c, add) ((c)->counter += (add)) -#else -#define IncrCounter(c) -#define AddCounter(c, add) -#endif - -#endif /* _TimersDOTh */ diff --git a/external/libsdf/include/libsdf/verify.h b/external/libsdf/include/libsdf/verify.h deleted file mode 100644 index 64cb75e..0000000 --- a/external/libsdf/include/libsdf/verify.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Defines Verify and VerifyX, which verify the truth of the given - expression. Unlike assert, they guarantee that the expression be evaluated - exactly once. Thus, you might say: - - Verify(fp=fopen(name, "w")) - Verify((nwrit=fwrite(p, sz,ni, fp)) >= 0); - VerifyX((nwrit=fwrite(p, sz, ni, fp)) >= 0, Shout("errno=%d, nwrit=%d\n", - errno, nwrit)); - Verify0(stat(path, , &buf)); - Notice that VerifyX allows you to add "Xtra" information in the event of - a failure. -*/ -#undef Verify -#undef VerifyX -/* Is there ever really a good reason to shut this off?? */ -/* You can with -DNVERIFY. */ -# ifndef NVERIFY -#include "error.h" - -#ifndef NO_STRINGIFICATION -/* One can write a really slick version that uses GNU varargs macros, but */ -/* unfortunately, it would break every other pre-processor. It isn't even */ -/* possible to #ifdef __GNUC__ it because the pre-processor complains */ -/* about an incorrect arg count. It might be possible to write it as a */ -/* varargs function, but what's the point? */ -#define VerifyX( expr, xtra) \ - (expr) ? (void)0 : (xtra, Error("%s failed\n" , #expr)) -#define VerifySX( expr, xtra) \ - (expr) ? (void)0 : (xtra, SinglError("%s failed\n" , #expr)) -#else -/* Not only do we not have Stringification, but we assume that we have */ -/* the brain-damaged macro substitution into string constants. */ -#define VerifyX( expr, xtra) \ - (expr) ? (void)0 : (xtra, Error("%s failed\n" , "expr")) -#define VerifySX( expr, xtra) \ - (expr) ? (void)0 : (xtra, SinglError("%s failed\n" , "expr")) -#endif /* NO_STRINGIFICATION */ -# else -# define VerifyX( expr, xtra) ((expr),(void)0) -# endif -#define Verify( expr ) VerifyX(expr, (void)0) -#define VerifyS( expr ) VerifySX(expr, (void)0) -#define Verify0( expr ) Verify(!(expr)) -#define VerifyS0( expr ) VerifyS(!(expr)) diff --git a/external/libsdf/include/libsdf/vop.h b/external/libsdf/include/libsdf/vop.h deleted file mode 100644 index 5ec749a..0000000 --- a/external/libsdf/include/libsdf/vop.h +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright 1991 Michael S. Warren and John K. Salmon. All Rights Reserved. - */ - -#ifndef NDIM - # error NDIM must be defined before reading this file. -#endif - -#if (NDIM!=3) && (NDIM!=2) - #error NDIM must be either 2 or 3 -#endif - -#ifdef __STDC__ -#define GLUE(a,b) a##b -#else -#define GLUE(a,b) a/**/b -#endif - -/* UGLY, but you can use these for parentheses inside the VV macros! */ -#define LPAREN ( -#define RPAREN ) -#define COMMA , -#define Dot(a, b) (VVinfix(a, *b, +)) - -#if (NDIM==3) - -#define Sinfix(s, op) s op s op s -#define Vinfix(a, op) a[0] op a[1] op a[2] -#define VVinfix(a, b, op) a[0] b[0] op a[1] b[1] op a[2] b[2] -/* Usage: printf(Sinfix("%g", " "), Vinfix(pos, COMMA)) */ - -#define VS(a, b) do { \ - a[0] b; \ - a[1] b; \ - a[2] b; \ - } while(0) - -#define VV(a, b) do { \ - a[0] b[0]; \ - a[1] b[1]; \ - a[2] b[2]; \ - } while(0) - -#define VVS(a, b, s) do { \ - a[0] b[0] s; \ - a[1] b[1] s; \ - a[2] b[2] s; \ - } while(0) - -#define VVV(a, b, c) do { \ - a[0] b[0] c[0]; \ - a[1] b[1] c[1]; \ - a[2] b[2] c[2]; \ - } while(0) - -#define VVVV(a, b, c, d) do { \ - a[0] b[0] c[0] d[0]; \ - a[1] b[1] c[1] d[1]; \ - a[2] b[2] c[2] d[2]; \ - } while(0) - - -#define VVVS(a, b, c, s) do { \ - a[0] b[0] c[0] s; \ - a[1] b[1] c[1] s; \ - a[2] b[2] c[2] s; \ - } while(0) - -#define VVVVS(a, b, c, d, s) do { \ - a[0] b[0] c[0] d[0] s; \ - a[1] b[1] c[1] d[1] s; \ - a[2] b[2] c[2] d[2] s; \ - } while(0) - - -#define VVVVV(a, b, c, d, e) do { \ - a[0] b[0] c[0] d[0] e[0]; \ - a[1] b[1] c[1] d[1] e[1]; \ - a[2] b[2] c[2] d[2] e[2]; \ - } while(0) - -#define VVVVVS(a, b, c, d, e, s) do { \ - a[0] b[0] c[0] d[0] e[0] s; \ - a[1] b[1] c[1] d[1] e[1] s; \ - a[2] b[2] c[2] d[2] e[2] s; \ - } while(0) - -#define VVVVVV(a, b, c, d, e, f) do { \ - a[0] b[0] c[0] d[0] e[0] f[0]; \ - a[1] b[1] c[1] d[1] e[1] f[1]; \ - a[2] b[2] c[2] d[2] e[2] f[2]; \ - } while(0) - -/* Eleven args! */ -#define Velv(a, b, c, d, e, f, g, h, i, j, k) do { \ - a[0] b[0] c[0] d[0] e[0] f[0] g[0] h[0] i[0] j[0] k[0]; \ - a[1] b[1] c[1] d[1] e[1] f[1] g[1] h[1] i[1] j[1] k[1]; \ - a[2] b[2] c[2] d[2] e[2] f[2] g[2] h[2] i[2] j[2] k[2]; \ - } while(0) - -/* And a couple of matrix operations to support gsw. */ -#define MS(a, b) do { \ - a[0][0] b; \ - a[0][1] b; \ - a[0][2] b; \ - a[1][0] b; \ - a[1][1] b; \ - a[1][2] b; \ - a[2][0] b; \ - a[2][1] b; \ - a[2][2] b; \ - } while(0) - -#define MVV(a, b, c) do { \ - a[0][0] b[0] c[0]; \ - a[0][1] b[0] c[1]; \ - a[0][2] b[0] c[2]; \ - a[1][0] b[1] c[0]; \ - a[1][1] b[1] c[1]; \ - a[1][2] b[1] c[2]; \ - a[2][0] b[2] c[0]; \ - a[2][1] b[2] c[1]; \ - a[2][2] b[2] c[2]; \ - } while(0) - -#define Vdecl(type, v) type v[NDIM] - -#define Dotx(a, b) \ - (GLUE(a,0)*GLUE(b,0) + GLUE(a,1)*GLUE(b,1) + GLUE(a,2)*GLUE(b,2)) - -/* Use for declarations */ -#define Vxd(a) \ - GLUE(a,0); \ - GLUE(a,1); \ - GLUE(a,2) - -/* Use in prototypes */ -#define Vxp(a) \ - GLUE(a,0), \ - GLUE(a,1), \ - GLUE(a,2) - -#define VxS(a, b) do { \ - GLUE(a,0) b; \ - GLUE(a,1) b; \ - GLUE(a,2) b; \ - } while(0) - -#define VxV(a, b) do { \ - GLUE(a,0) b[0]; \ - GLUE(a,1) b[1]; \ - GLUE(a,2) b[2]; \ - } while(0) - -#define VxdV(a, b) \ - GLUE(a,0) b[0]; \ - GLUE(a,1) b[1]; \ - GLUE(a,2) b[2] - -#define VVx(a, b) do { \ - a[0] GLUE(b,0); \ - a[1] GLUE(b,1); \ - a[2] GLUE(b,2); \ - } while(0) - -#define VxVx(a, b) do { \ - GLUE(a,0) GLUE(b,0); \ - GLUE(a,1) GLUE(b,1); \ - GLUE(a,2) GLUE(b,2); \ - } while(0) - - -#define VxVV(a, b, c) do { \ - GLUE(a,0) b[0] c[0]; \ - GLUE(a,1) b[1] c[1]; \ - GLUE(a,2) b[2] c[2]; \ - } while(0) - -#define VxVVS(a, b, c, s) do { \ - GLUE(a,0) b[0] c[0] s; \ - GLUE(a,1) b[1] c[1] s; \ - GLUE(a,2) b[2] c[2] s; \ - } while(0) - -#define VxVVx(a, b, c) do { \ - GLUE(a,0) b[0] GLUE(c,0); \ - GLUE(a,1) b[1] GLUE(c,1); \ - GLUE(a,2) b[2] GLUE(c,2); \ - } while(0) - -#define VxVxV(a, b, c) do { \ - GLUE(a,0) GLUE(b,0) c[0]; \ - GLUE(a,1) GLUE(b,1) c[1]; \ - GLUE(a,2) GLUE(b,2) c[2]; \ - } while(0) - -#define VxVxVx(a, b, c) do { \ - GLUE(a,0) GLUE(b,0) GLUE(c,0); \ - GLUE(a,1) GLUE(b,1) GLUE(c,1); \ - GLUE(a,2) GLUE(b,2) GLUE(c,2); \ - } while(0) - -#define VVxVx(a, b, c) do{ \ - a[0] GLUE(b,0) GLUE(c,0); \ - a[1] GLUE(b,1) GLUE(c,1); \ - a[2] GLUE(b,2) GLUE(c,2); \ - } while(0) - -#endif /* NDIM == 3 */ - -#if (NDIM==2) - -#define Sinfix(s, op) s op s -#define Vinfix(a, op) a[0] op a[1] -#define VVinfix(a, b, op) a[0] b[0] op a[1] b[1] -/* Usage: printf(Sinfix("%g", " "), Vinfix(pos, COMMA)) */ - -#define VS(a, b) do { \ - a[0] b; \ - a[1] b; \ - } while(0) - -#define VV(a, b) do { \ - a[0] b[0]; \ - a[1] b[1]; \ - } while(0) - -#define VVS(a, b, s) do { \ - a[0] b[0] s; \ - a[1] b[1] s; \ - a[2] b[2] s; \ - } while(0) - -#define VVV(a, b, c) do { \ - a[0] b[0] c[0]; \ - a[1] b[1] c[1]; \ - } while(0) - -#define VVVS(a, b, c, s) do { \ - a[0] b[0] c[0] s; \ - a[1] b[1] c[1] s; \ - } while(0) - -#define VVVVS(a, b, c, d, s) do { \ - a[0] b[0] c[0] d[0] s; \ - a[1] b[1] c[1] d[1] s; \ - } while(0) - -#define VVVV(a, b, c, d) do { \ - a[0] b[0] c[0] d[0]; \ - a[1] b[1] c[1] d[1]; \ - } while(0) - -#define VVVVV(a, b, c, d, e) do { \ - a[0] b[0] c[0] d[0] e[0]; \ - a[1] b[1] c[1] d[1] e[1]; \ - } while(0) - -#define Vdecl(type, v) type v[NDIM] - -#define Dotx(a, b) \ - (GLUE(a,0)*GLUE(b,0) + GLUE(a,1)*GLUE(b,1)) - -#define Vxd(a) \ - GLUE(a,0); \ - GLUE(a,1) - -#define VxS(a, b) do { \ - GLUE(a,0) b; \ - GLUE(a,1) b; \ - } while(0) - -#define VxV(a, b) do { \ - GLUE(a,0) b[0]; \ - GLUE(a,1) b[1]; \ - } while(0) - -#define VxdV(a, b) \ - GLUE(a,0) b[0]; \ - GLUE(a,1) b[1] - -#define VVx(a, b) do { \ - a[0] GLUE(b,0); \ - a[1] GLUE(b,1); \ - } while(0) - -#define VxVx(a, b) do { \ - GLUE(a,0) GLUE(b,0); \ - GLUE(a,1) GLUE(b,1); \ - } while(0) - - -#define VxVV(a, b, c) do { \ - GLUE(a,0) b[0] c[0]; \ - GLUE(a,1) b[1] c[1]; \ - } while(0) - -#define VxVVS(a, b, c, s) do { \ - GLUE(a,0) b[0] c[0] s; \ - GLUE(a,1) b[1] c[1] s; \ - } while(0) - -#define VxVVx(a, b, c) do { \ - GLUE(a,0) b[0] GLUE(c,0); \ - GLUE(a,1) b[1] GLUE(c,1); \ - } while(0) - -#define VxVVS(a, b, c, s) do { \ - GLUE(a,0) b[0] c[0] s; \ - GLUE(a,1) b[1] c[1] s; \ - } while(0) - -#define VVxVx(a, b, c) do{ \ - a[0] GLUE(b,0) GLUE(c,0); \ - a[1] GLUE(b,1) GLUE(c,1); \ - } while(0) - -#define VxVxV(a, b, c) do { \ - GLUE(a,0) GLUE(b,0) c[0]; \ - GLUE(a,1) GLUE(b,1) c[1]; \ - } while(0) - -#define VxVxVx(a, b, c) do { \ - GLUE(a,0) GLUE(b,0) GLUE(c,0); \ - GLUE(a,1) GLUE(b,1) GLUE(c,1); \ - } while(0) - -#endif /* NDIM == 2 */ diff --git a/external/libsdf/libSDF/ChangeLog.14 b/external/libsdf/libSDF/ChangeLog.14 deleted file mode 100644 index bee9043..0000000 --- a/external/libsdf/libSDF/ChangeLog.14 +++ /dev/null @@ -1,313 +0,0 @@ -Fri Jan 7 13:50:53 1994 John Salmon (johns@haggis) - - * Terminate this ChangeLog. Future changes to be logged - in the parent directory. - -Wed Dec 29 08:57:39 1993 John Salmon (johns@sampson) - - * fseekrd.c (fseekrd): #include protos.h and error.h - -Mon Dec 27 18:05:36 1993 John Salmon (johns@lux) - - * fseekrd.c: Bail out with Error in the event of an error. - -Sun Oct 10 21:02:27 1993 John Salmon (johns@sockeye) - - * SDFget.c: Added protos.h. Silenced a warning. - -Tue Jul 13 11:19:20 1993 John Salmon (johns@lux) - - * libSDF/: changed some formats to silence complaints about - incorrect argument passing to printf. These SHOULD all be - changed to singlWarning. - -Thu Jun 10 15:34:01 1993 John Salmon (johns@haggis) - - * SDF.h, SDFget.c: Added the functions SDFgetint, SDFgetdouble - SDFgetfloat and SDFgetstring to the library. In addition, added - the macros SDFget*OrDie and SDFget*OrDefault to SDF.h. The macros - use Error and singlWarning, which can be found in the swutils - library, or which the user may redefine to taste. - -Thu Jun 3 16:32:18 1993 John Salmon (johns at haggis) - - * Revert back to the i860_utils style of managing the PGI, - IPSC_XDEV, etc. environment variables. "The management apologizes - for the inconvenience." The reason is that i860_target doesn't - interact well with Make running inside emacs. - -Tue Jun 1 20:51:16 1993 John Salmon (johns@sockeye) - - * (../SDF): Changed Make.common so it creates libraries in, e.g., - sun4/libSDF.a. Make the old-style SDF_sun4.a a symbolic link to - the new file. Use of /libSDF.a is encouraged. - -Tue Jun 1 20:47:04 1993 John Salmon (johns at haggis) - - * Added (this) ChangeLog to the list of docs copied into .tar files! - -Wed May 26 20:02:14 1993 John Salmon (johns at sampson) - - * Removed the -delta flags from Make.delta. Use the i860_target - technology instead. - - * Fixed two bugs related to ascii data. On line 399 of - SDF-parse.y and line 646 of SDFfuncs.c. Recompiled sun4 and delta - versions. It should now correctly handle ascii data. - -Tue Mar 2 20:26:09 1993 John Salmon (johns at sampson) - - * Conditionalized the #define YYDEBUG 1 so it won't get linked on - the delta. It surely can't do us any good! - - * Added a comment (but no code) to SDF-parse.y that worries about - what to do when a string constant is too long to fit in a char array. - - * Changed SDFtst.c so it prints the first element of every vector - in the file it reads. Just another diagnostic that might show up - an error... - -Wed Feb 10 20:12:15 1993 John Salmon (johns at sampson) - - * Don't close stdin in SDFissdf! - -Wed Dec 9 11:36:53 1992 John Salmon (johns at haggis) - - * Changed the #ifdef SEEK_SET conditionals in SDF.h. Now - the 'preferred' usage is SDF_SEEK_SET, etc., but they are - almost guaranteed to be the same as SEEK_SET from stdio.h. - If they aren't, complete and untraceable confusion will surely - result. Changed SEEK_SET, etc. in SDFfuncs.c to SDF_SEEK_SET, - etc. - -Wed Dec 2 17:55:08 1992 John Salmon (johns at pollux) - - * Added ncube2 support. This means setting up a Make.ncube2, - and getting alloca.c (unmodified) from the emacs distribution, - and saying 'extrasrc:=alloca.c' in Make.ncube2. Also added - a call to alloca(0) to SDFopen just after yyparse, which should - clean up any mess left behind by the C alloca. - -Fri Nov 13 18:42:33 1992 John Salmon (johns at sampson) - - * Reset yylineno in SDFyyprepare(). Otherwise error message - line numbers accumulate! - -Tue Nov 10 20:21:11 1992 John Salmon (johns at haggis) - - * Changed the typedef for SDF in SDF.h. It still doesn't tell - you what's really going on in an SDF hdr, but at least prototypes - get checked for correctness, and printing an SDF* under gdb might - even tell you most of what you care to know. - -Tue Oct 27 12:24:50 1992 John Salmon (johns at haggis) - - * Fixed a bug in SDF-lex.l that didn't recognize signed - integer constants. How did this last for so long?! The - {Sign} specifier was simply missing from the regex. - -Fri Oct 16 11:10:13 1992 John Salmon (johns at haggis) - - * Added halocenterx, halocentery and halocenterz to the - generic tree.sdfh and tree_ap.sdfh files. These are used - by the isothermal halo integrator (i.e., Carl). - -Thu Oct 15 21:34:20 1992 John Salmon (johns at haggis) - - * Try to be even more defensive in SDFclose, in order to not - get SEGV when bailing out of a parse error. This is not - a finished project! Careful cleanup should be attempted in - yyerror(). - -Fri Oct 9 08:34:50 1992 John Salmon (johns at delilah) - - * SDF now only uses SEEK_CUR to reposition itself in the file. - fseekrd() will work with SEEK_CUR and any positive offset by - freading into a junk buffer, regardless of whether the file is - seekable. Thus, operations on unseekable files need not be - sequential. They must still be "monotonic increasing". - -Thu Oct 8 10:06:49 1992 John Salmon (johns at delilah) - - * Added support for reading from unseekable files. This means - keeping track of the "seek pointer" ourselves, and checking - whether seeking is really necessary to accomodate requests. If - the caller doesn't require us to seek, then we don't. If he does, - then we fail. - - * Added SDFsetbufsz/SDFgetbufsz, which induce SDF to malloc a - buffer and call setvbuf in all subsequent SDFopen's. Use for - tuning access to tape devices and pipes. - -Wed Sep 16 11:12:40 1992 John Salmon (johns at haggis) - - * Added the keyword "long" to the set of possible types. - It behaves EXACTLY the same as "int". There is no corresponding - SDF_LONG. Is this really a good idea (the same was done for unsigned). - - * Fixed a bug in SDF-parse.y which caused miscounting the - lengths of implicit arrays, e.g., char greeting[] = "hello"; - - * Added Const to many of the arguments in SDF.h. - -Tue Sep 15 17:10:48 1992 John Salmon (johns at haggis) - - * Eliminated the huge redundancy in SDFrdvecsarr, and made it - call SDFseekrdvecsarr. This not only shortens the code, but it - probably means more reasonable behavior on return from errors. - Ever wonder what would happen if you do an SDFrdvecsarr and the - last "name" you give it doesn't exist? Well it's much better now. - -Wed Sep 2 15:12:06 1992 John Salmon (johns at haggis) - - * Changed the strategy for grabbing temporary space in SDFrdvecsarr - and SDFseekrdvecsarr. Now if malloc fails, we try successively - smaller requests until we get something. We only give up with - an error if we can't get enough for a single "record" (i.e., - struct). The memory is freed at the end of the execution of - SDF*rdvecsarr. - - * In the interests of reducing namespace pollution, changed the enum - names in SDF_type_enum to be SDF_INT, SDF_FLOAT, etc. This will - break some old codes. Old codes can be made to compile by - adding a #define OLD_ENUM_NAMES before #include "SDF.h". - - * Changed the external name of swapn to SDFswapn. This should - not effect anything. - -Tue Sep 1 10:13:05 1992 John Salmon (johns at haggis) - - * Added an if( hdr==NULL ) test to each of the exported SDF - functions. This should cut down on memory faults from users - who don't check the return from SDFopen. It might even be - worthwhile to put a magic number in the SDF hdr. - -Mon Aug 31 17:43:25 1992 John Salmon (johns at haggis) - - * Fixed a typo in SDF-lex.l and recompiled delta and sun4. - - * Checked the return of realloc against NULL in the middle of - SDFrdvecsarr and SDFseekrdvecsarr. The program now fails with - a message rather than getting a Segv. It is probably not recoverable. - We really should reduce the size of some of these buffers by - staging them. - -Tue Jun 30 02:39:30 1992 John Salmon (johns at haggis) - - * Removed some spurious newlines from the ends of the .sdfh files. - These make trouble if you try to do "cat tree.sdfh foo.tree > foo.sdf" - - * INCOMPATIBLE CHANGE: changed the calling convention for - SDFopen. Now we pass in two char strings, both filenames, one - for the header and one for the data. This has a number of - beneficial effects: - 1) It means we don't have to 'agree' on what kind of FILE is - in use with the 'user'. (e.g., CUBIX, NX, SRV, etc.) All the nasty - business gets handled inside SDF in the Makefile and such. - 2) It's easier for a 'user' to specify a header that comes from a - file. The user doesn't have to stat the file, malloc space, read - it in and then call SDFopen with the contents as an arg. - 3) SDF is reasonably careful about checking out whether fopen - returns NULL. This means less obscure failure when a bad name - is provided. - - If the hdrname is NULL, or if it is empty or if it strcmp's - equal to the datafname, then the data file is treated as an - SDF file with a header attached. - - * Made a similar change to SDFissdf, so that one calls it with - a name rather than a FILE *. "-" is stdin. - -Tue Jun 9 17:30:13 1992 John Salmon (johns at delilah) - - * Created SDF_sun4.a SDF_risc6000.a and SDF_delta.a. - - * Added some new functions to SDF.h and SDFfuncs.c: - SDFissdf, SDFbyteorder, SDFswap, SDFnoswap, SDFisswapping. - - These make it simpler to use generic header files for things - like pjq, tree, etc. files. The nbio_ routines are no longer - the preferred way to read old-style files. It might be worth - writing a function that reads an alternative header directly - from disk, rather than from a string. It really is a shame - that there is no portable way to treat a string as a FILE *. - -Sat Apr 4 09:34:16 1992 John Salmon (johns at haggis) - - * Created SDF_risc6000.a. - - * Changed the declaration of do_value_param so it DOES NOT say - Static int do_value_param(...., const_t const); - This caused the AIX compiler to fail in a very obscure way! - -Thu Mar 26 05:20:04 1992 John Salmon (johns at kastor) - - * Some minor surgery on SDF-parse.y to deal with zero-length - blocks at the end of the data file. We now try to fstat the - file to figure out how many records will fit in the file. This - should make writing generic tree-file readers easier, because - "npart" is implicit. - -Tue Mar 24 09:32:01 1992 John Salmon (johns at haggis) - - * "Released" v1.2.0. - - * Changed the Makefile, SDFfuncs.c and SDF-parse.y so the - bison-generated externals now start with SDFyy, i.e., - SDFyyparse, SDFyyerror, etc. This makes it easier to merge - SDF with programs like sm. - -Thu Mar 19 05:05:12 1992 John Salmon (johns at haggis) - - * Removed #pragma once from the rest of the .h files - - * Changed malloc to calloc in SDFopen. - -Fri Mar 13 08:24:32 1992 John Salmon (johns at haggis) - - * Rebuilt SDF_delta.a and SDF_sun4.a - - * Removed #pragma once from all the .h files. - - * Added dependency for SDF-lex.c and SDF-parse.o to Makefile - so changes to SDF-lex.l are understood by make. - - * Added the 'unsigned' keyword to SDF-lex.l. It's a total - no-op. It may make it somewhat easier (and dangerous?) to - convert C structs into SDF headers. - - * Changed the definition of the end-of-header symbol. - Now it's any comment line containing the string SDF-EOH. - The newline is the last character in the header. It is - highly recommended that users add their own form-feeds - to this line, but it is now at the user's discretion. - -Thu Mar 12 22:23:37 1992 Mike Warren (msw at sampson) - - * (nbio_open) Added a break to the case NBIO_SDF_TYPE: - -Sun Feb 9 13:26:20 1992 John Salmon (johns at haggis) - - * Added some more error reporting to nbio. On most errors, - something is now written into nbio_errstring. If the error - is detected by SDF, then we (usually) copy SDFerrstring too. - - * Added the SDFhasname() and nbio_hasname() functions to test - for the existence of a name in a file. - -Fri Feb 7 18:32:04 1992 John Salmon (johns at haggis) - - * Added missing ';' in the "parameter byteorder=blaa; " - strings in nbio.c - - * Added the char nbio_errstring[] array for messages. - - * Added the char *nbio_type_names[] array. - - * Added the "seekrd" functions to SDF and nbio, which use the - fseekrd(...) "primitive". Hopefully, this will be supported - by servix on all future parallel machines. - - * Fiddled around with the header files. There's now only - one copy of the prototypes in the "public" files, nbio.h and - SDF.h. diff --git a/external/libsdf/libSDF/GNUmakefile b/external/libsdf/libSDF/GNUmakefile deleted file mode 100644 index 94db107..0000000 --- a/external/libsdf/libSDF/GNUmakefile +++ /dev/null @@ -1,112 +0,0 @@ -# Make.$(ARCH) sets many of the variables used below including: -# CC, CFLAGS, AS, RANLIB, objdir, objsuf, asmdir - -treedir=.. -treedir_sed=\.\. -appexcludes= -# Put everything into the libsw library!!! -libname=libsw - -# The "SDF" library -src:= \ -SDF-parse.c SDFfuncs.c SDFget.c SDFhdrio.c - -include $(treedir)/Make-common/Make.$(ARCH) - -include $(treedir)/Make-common/Make.generic - -# These rules are slight modifications of the builtin ones -%.c : %.y - -($(YACC.y) $<; mv -f y.tab.c $@) - -%.c : %.l -# commands to execute (built-in): - -($(LEX) $(LEX.L) $<; mv -f lex.yy.c $@) - -# Makedepends can't pick these up... -$(objdir)/SDF-parse$(objsuf): SDF-private.h SDF-lex.c SDF-parse.c - (cd $(objdir); $(CC) $(CFLAGS) -I../../../include/libsdf -I../.. -c ../../SDF-parse.c) - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): $(treedir)/include/libsdf/protos.h $(treedir)/include/libsdf/Msgs.h -$(objdir)/SDF-parse$(objsuf): $(treedir)/include/libsdf/gccextensions.h SDF-private.h stdio.h -$(objdir)/SDF-parse$(objsuf): $(treedir)/include/libsdf/mpmy_io.h -$(objdir)/SDF-parse$(objsuf): $(treedir)/include/libsdf/SDF.h $(treedir)/include/libsdf/Malloc.h -$(objdir)/SDF-parse$(objsuf): $(treedir)/include/libsdf/error.h SDF-lex.c -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDF-parse$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFfuncs$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/SDFfuncs$(objsuf): stdio.h $(treedir)/include/libsdf/mpmy_io.h SDF-private.h -$(objdir)/SDFfuncs$(objsuf): $(treedir)/include/libsdf/SDF.h -$(objdir)/SDFfuncs$(objsuf): $(treedir)/include/libsdf/byteswap.h $(treedir)/include/libsdf/Malloc.h -$(objdir)/SDFfuncs$(objsuf): $(treedir)/include/libsdf/error.h $(treedir)/include/libsdf/protos.h -$(objdir)/SDFfuncs$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/SDFfuncs$(objsuf): -$(objdir)/SDFget$(objsuf): stdio.h $(treedir)/include/libsdf/mpmy_io.h -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): -$(objdir)/SDFget$(objsuf): $(treedir)/include/libsdf/error.h -$(objdir)/SDFget$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/SDF.h -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/SDFhdrio$(objsuf): $(treedir)/include/libsdf/error.h SDF-private.h -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): stdio.h $(treedir)/include/libsdf/mpmy_io.h -$(objdir)/SDFhdrio$(objsuf): -$(objdir)/SDFhdrio$(objsuf): $(treedir)/include/libsdf/SDF.h diff --git a/external/libsdf/libSDF/README b/external/libsdf/libSDF/README deleted file mode 100644 index 787d10a..0000000 --- a/external/libsdf/libSDF/README +++ /dev/null @@ -1,199 +0,0 @@ ---------README from 1.3 ------------- - -This is version 1.3 of SDF. This version has been de-stdio-ized. It -uses MY* functions in lieu of all stdio functions. Unless I've missed -something, the only stdio function that remains is sprintf. Because -lex is brain-damaged and insists on writing #include "stdio.h" into -its output, I created a "./stdio.h" to override the system one. This -is not strictly ANSI, but then, what is? - ---------README from 1.2------- - -This is version 1.2 of SDF ("Self Describing Files" or "Super-Duper -Files, depending on how impressed you are). It is the first version -of the last i/o package you'll ever need. SDF files are binary data -files with an optional header which contains 1) a description of the -layout of the data, and 2) optional ascii constants. There is no -output capability because the sdf files are so easy to write :-). -This document is completely unstructured, and probably -incomprehensible to anyone but the author. It's a -stream-of-consciousness first-draft. Be generous. - -The user-callable SDF programs are declared with prototypes in SDF.h. -I refuse to consider systems that can't deal with prototypes, - and the ellipsis for variadic functions and enum types. If -you don't have gcc on your Sun, then call up Sun and give them a piece -of your mind, and then go get gcc. The ANSI standard has been out for -long enough now. Accept no substitutes. The object modules are in -the library SDF_.a. I have tried to keep the "name-space -pollution" to a minimum. Unfortunately, there are a few additional -external names used by the SDF package that do not appear explicitly in -SDF.h. These include anything starting with "obstack_" (SDF uses the -gnu obstack package) and all names starting with "SDF". - -There are no provisions for writing SDF files. The reason is that -it would be more complicated to go through a programmatic interface than -to just create the files with fprintf() and fwrite(). The basic -idea behind SDF files is that they are self-describing. That is, they -have an ASCII header (human-readable, machine-parseable), which describes -the contents of the file. The ascii header may contain explicit -values, like: - -float npart = 200000.; -int int_npart = 200000; -char text[] = "Perhaps a few words about the file's pedigree could go here"; - -Notice the similarity to C declarations. - -In addition, the header contains declarations for the binary -data that appears immediately after it. The allowed data -types are char, short, int, float and double, arrays of same, and -structs containing the basic types and arrays. (Multi-dimensional arrays -are not supported. Nor are nested structures. But some kinds of two -dimensional arrays can be captured by an array of structs, c.f., the -'id' vector in .tree files. These limitations may be relaxed in the -future.) - -The header is terminated by a comment of the form - -# SDF-EOH \n - -That is, any comment containing the string SDF-EOH. -The final new-line is the last character of the header. The -binary data follows immediately after the new-line character. -It is strongly recommended that the terminal comment contain -one or more form-feeds (ctrl-L, \f in ANSI, \014 (octal), 0xc (hex), -12 (decimal)). That way, 'more' or similar programs can be -used on the file without getting confused by the binary data. -Similarly, it is strongly recommended that the first line -of an SDF file contain the comment: - -# SDF \n - -This makes it easy for a modified version of 'file', as well as -other utilities to figure out that they are dealing with an SDF file. - -Thus, the header for the output of an nbody simulation might look like: - -# SDF -float npart; -float iter; -float time; -... -char tree_header_text[384]; -struct {float mass; - float x, y, z; - char id[4]; - float vx, vy, vz; - } []; -# SDF-EOH ^L^L - -This header means that the floats npart, iter, time, etc. are stored -as binary data following the header. Then comes a 384 byte character -array, followed by an array (of unspecified length) containing the -vectors mass, x, y, z, id, vx, vy, vz. Only the last array in the -header may be of unspecifiec length. It means that when the file is -read, the array is assumed to extend to the end of the file. SDF -routines figure out the length of the file by asking the OS, and hence -can determine the number of elements in arrays of unspecified length. -Specifications with unknown length are useful for creating generic SDF -headers, i.e., headers that describe binary files that you may already -be using. - -If one were writing out a new SDF file, it is possible to write a -header exactly as above, followed by the identical binary data. -However, it would be much more convenient to write the "scalar" data -as ascii values into the header. A new SDF file might look like: - -# SDF -/* Comments may be between C-like comment delimiters */ -# Or they follow the shell-like comment delimiter to end-of-line -# This file was created by dave@h9k.hal.com on January 12, 1992... -float npart = 200000.; -int int_npart = 200000; -float Gnewt = 1.0; -float iter = 17.; -float masstot = 1.1; -float epsilon = 0.02; -... -struct {float mass; - float x, y, z; - char id[4]; - float vx, vy, vz;} [200000]; -# SDF-EOH ^L^L - -This has the great advantage that most of the file's parameters are -now both human-readable and machine-readable. A disadvantage to -putting "history" information into comments is that it becomes -inaccessable to programs (since SDF doesn't record comments). Another -option is to put it in a character string: - -char history[] = -"This file created by ... on ... -200000 body torqued Jaffe model constructed using: -cubix ... -"; - -Don't bother with C-syntax for newlines, etc in character strings. -SDF just scans till it hits another " character. It doesn't do any -escape-interpretation, so don't bother with '\n' and especially don't -try to put the double-quote character inside strings. - -Byte order is another headache. The function SDFcpubyteorder() -returns an unsigned int which "describes" the host-cpu's byte order, -in a format which may be placed into an SDF header with the. -"parameter byteorder" keyword. - -parameter byteorder = 0x12345678; - -You can make this line in a C program with: -fprintf(fp, "parameter byteorder = 0x%x;\n", SDFcpubyteorder()); - -If such a parameter is in the header, then SDFread functions will -assume that the binary data is written in the file in the byte order -specified by the parameter. If the machine doing the reading has a -different byte order, then bytes are swapped automatically. If there -is no such parameter, you can tell the read functions to swap with -SDFswapon(). Similarly, you can turn off swapping (for whatever -reason) with SDFswapoff(), and you can inquire about swapping with -SDFisswapping(); - -Non-ieee floats are completely out of the question. Don't even -mention them in my presence. - -Dictionaries ------------- - -Nbody files contain a number of scalars, and a number of vectors. The -names of these objects must be agreed upon between the entity creating -the file and the entity reading the file. Since the creators of pjq, -tree and tree_ap files could barely agree that the sun rises in the -east and sets in the west, I have created a set of names for the items -in common amongst these file types. The list is in the file -"./dictionary". SDF files name their own contents. It's important -that the names continue to agree with the names in ./dictionary. -Thus, with the current dictionary it is agreed that the name "npart" -refers to a float value equal to the number of bodies in the file. -Similarly, the name "masstot" refers to the total mass of the file. -These are the strings that you have to pass as names to SDFread routines in -order to extract the appropriate values from a file. What you call -these quantities inside your program is completely irrelevant, but if -you create another SDF file, it's important to use the same names. - -The SDFopen function now takes two char* arguments, one for the -filename of the header and one for the data. If they strcmp the same, -or if the header is NULL or if the header is "", the descriptor is -found at the beginning of the data file. If the name is "-", then -stdin is used. If you really must open a file called "-", then you -can do it by opening "./-". SDF will not gratuitously do random seeks -around the file. In fact, it will struggle mightily to read the file -sequentially. In many cases, SDFread will succeed on files that are -not seekable. However, there are some requests that simply require -rewinding the file. If your program does such a thing, then it MUST -be possible to do arbitrary seeks on the data file, so taking stdin -from a tty or a pipe would be a bad idea. - -You're supposed to get an error message in SDFerrstring for this (and -all other) errors. Segmentation violations are increasingly rare. I'm -certain that bugs still remain which will blow SDF right away, but -they're getting harder to find every day. diff --git a/external/libsdf/libSDF/SDF-lex.c b/external/libsdf/libSDF/SDF-lex.c deleted file mode 100644 index 0b45156..0000000 --- a/external/libsdf/libSDF/SDF-lex.c +++ /dev/null @@ -1,2069 +0,0 @@ - -#line 3 "lex.yy.c" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 35 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -extern int yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 26 -#define YY_END_OF_BUFFER 27 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[119] = - { 0, - 0, 0, 27, 25, 3, 3, 25, 2, 25, 24, - 25, 25, 23, 23, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 0, 17, 2, 2, 0, 23, - 19, 4, 18, 22, 0, 0, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 2, 0, 18, - 0, 0, 20, 21, 16, 16, 16, 16, 7, 16, - 16, 16, 16, 16, 2, 0, 19, 0, 0, 18, - 16, 5, 16, 16, 16, 8, 16, 16, 16, 16, - 2, 0, 18, 16, 16, 10, 16, 16, 6, 16, - 16, 2, 16, 11, 16, 16, 12, 16, 2, 16, - - 9, 16, 16, 1, 16, 16, 13, 1, 1, 15, - 14, 1, 1, 1, 1, 1, 1, 0 - } ; - -static yyconst flex_int32_t yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 4, 5, 1, 1, 1, 1, 1, - 1, 6, 7, 8, 9, 10, 11, 12, 13, 13, - 13, 14, 13, 15, 13, 16, 16, 1, 17, 1, - 18, 1, 1, 1, 19, 19, 19, 20, 21, 22, - 23, 24, 23, 23, 23, 23, 23, 23, 25, 23, - 23, 23, 26, 23, 23, 23, 23, 23, 23, 23, - 27, 1, 28, 1, 29, 1, 30, 31, 32, 33, - - 34, 35, 36, 37, 38, 23, 23, 39, 40, 41, - 42, 43, 23, 44, 45, 46, 47, 23, 23, 48, - 49, 23, 50, 1, 51, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst flex_int32_t yy_meta[52] = - { 0, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 3, - 1, 4, 4, 4, 4, 4, 1, 1, 5, 5, - 4, 5, 6, 6, 6, 6, 1, 1, 6, 5, - 5, 5, 5, 4, 5, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 1, - 1 - } ; - -static yyconst flex_int16_t yy_base[125] = - { 0, - 0, 0, 281, 282, 282, 282, 276, 253, 42, 282, - 47, 272, 54, 55, 0, 228, 239, 233, 235, 232, - 230, 241, 34, 229, 265, 282, 242, 52, 69, 69, - 79, 282, 93, 219, 103, 0, 0, 220, 235, 217, - 221, 216, 220, 216, 217, 214, 212, 51, 116, 121, - 131, 136, 144, 0, 222, 211, 223, 223, 237, 215, - 220, 205, 201, 209, 78, 149, 154, 164, 169, 174, - 204, 0, 206, 198, 229, 0, 202, 195, 208, 203, - 75, 179, 184, 194, 203, 0, 207, 201, 0, 188, - 192, 72, 195, 0, 169, 159, 0, 170, 96, 169, - - 0, 141, 106, 85, 55, 42, 0, 48, 181, 0, - 0, 180, 115, 100, 128, 148, 27, 282, 207, 213, - 217, 218, 221, 226 - } ; - -static yyconst flex_int16_t yy_def[125] = - { 0, - 118, 1, 118, 118, 118, 118, 119, 120, 118, 118, - 118, 118, 118, 121, 122, 122, 122, 122, 122, 122, - 122, 122, 122, 122, 119, 118, 120, 120, 118, 121, - 118, 118, 118, 13, 118, 123, 122, 122, 122, 122, - 122, 122, 122, 122, 122, 122, 122, 120, 118, 118, - 118, 118, 118, 123, 122, 122, 122, 122, 122, 122, - 122, 122, 122, 122, 120, 118, 118, 118, 118, 118, - 122, 122, 122, 122, 122, 122, 122, 122, 122, 122, - 120, 118, 118, 122, 122, 122, 122, 122, 122, 122, - 122, 120, 122, 122, 122, 122, 122, 122, 120, 122, - - 122, 122, 122, 124, 122, 122, 122, 124, 124, 122, - 122, 124, 124, 124, 124, 124, 124, 0, 118, 118, - 118, 118, 118, 118 - } ; - -static yyconst flex_int16_t yy_nxt[334] = - { 0, - 4, 5, 6, 7, 8, 4, 9, 10, 9, 11, - 12, 13, 14, 14, 14, 14, 10, 10, 15, 15, - 15, 15, 15, 15, 15, 15, 10, 10, 15, 15, - 16, 17, 18, 15, 19, 15, 15, 20, 21, 15, - 15, 15, 22, 15, 23, 15, 24, 15, 15, 10, - 10, 29, 109, 30, 30, 30, 30, 30, 31, 31, - 31, 31, 31, 33, 33, 34, 34, 34, 34, 30, - 45, 48, 65, 109, 35, 35, 28, 28, 33, 46, - 31, 31, 31, 31, 31, 111, 81, 35, 35, 35, - 31, 31, 31, 31, 31, 92, 99, 28, 110, 49, - - 28, 36, 35, 28, 50, 50, 50, 50, 50, 52, - 109, 52, 49, 51, 53, 53, 53, 53, 53, 104, - 115, 28, 66, 114, 66, 109, 51, 67, 67, 67, - 67, 67, 50, 50, 50, 50, 50, 69, 107, 69, - 109, 68, 70, 70, 70, 70, 70, 53, 53, 53, - 53, 53, 116, 109, 68, 53, 53, 53, 53, 53, - 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, - 82, 117, 82, 109, 106, 83, 83, 83, 83, 83, - 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - - 112, 113, 105, 103, 102, 109, 109, 25, 25, 25, - 25, 25, 25, 27, 101, 27, 27, 27, 27, 30, - 30, 37, 37, 37, 54, 54, 108, 100, 108, 108, - 108, 108, 98, 97, 96, 95, 94, 93, 91, 90, - 89, 88, 87, 86, 85, 84, 80, 79, 78, 77, - 76, 75, 74, 73, 72, 71, 64, 63, 62, 61, - 60, 59, 58, 57, 56, 55, 118, 28, 26, 47, - 44, 43, 42, 41, 40, 39, 38, 32, 28, 26, - 118, 3, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118 - } ; - -static yyconst flex_int16_t yy_chk[334] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 9, 117, 9, 9, 9, 9, 9, 11, 11, - 11, 11, 11, 13, 14, 13, 13, 13, 13, 13, - 23, 28, 48, 108, 13, 14, 48, 28, 30, 23, - 29, 29, 29, 29, 29, 106, 65, 13, 14, 30, - 31, 31, 31, 31, 31, 81, 92, 92, 105, 31, - - 81, 13, 30, 65, 33, 33, 33, 33, 33, 35, - 104, 35, 31, 33, 35, 35, 35, 35, 35, 99, - 114, 99, 49, 113, 49, 114, 33, 49, 49, 49, - 49, 49, 50, 50, 50, 50, 50, 51, 103, 51, - 113, 50, 51, 51, 51, 51, 51, 52, 52, 52, - 52, 52, 115, 115, 50, 53, 53, 53, 53, 53, - 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, - 68, 116, 68, 116, 102, 68, 68, 68, 68, 68, - 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, - 82, 82, 82, 82, 82, 83, 83, 83, 83, 83, - - 109, 112, 100, 98, 96, 112, 109, 119, 119, 119, - 119, 119, 119, 120, 95, 120, 120, 120, 120, 121, - 121, 122, 122, 122, 123, 123, 124, 93, 124, 124, - 124, 124, 91, 90, 88, 87, 85, 84, 80, 79, - 78, 77, 75, 74, 73, 71, 64, 63, 62, 61, - 60, 59, 58, 57, 56, 55, 47, 46, 45, 44, - 43, 42, 41, 40, 39, 38, 34, 27, 25, 24, - 22, 21, 20, 19, 18, 17, 16, 12, 8, 7, - 3, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "SDF-lex.l" -#line 2 "SDF-lex.l" -/* - SDF Library for reading Self-Describing Files - Copyright (C) 1991,1992 John K. Salmon - - Terms and conditions are specified in the file "copyright.h", - and more precisely in the file COPYING.LIB which you should have - received with this library. -*/ -#include -/* This define means we don't have to link with the lex library! */ -#define YY_SKIP_YYWRAP -#define yywrap() 1 - -/* This one is ugly. - Lex's output contains fprintf(yyout, of various error messages. - We try here to redirect them to a Msg_doalist. */ -#include -#include "Msgs.h" -#undef fprintf -#define fprintf MYFprintf -void MYFprintf(int *junk, const char *fmt, ...){ - va_list alist; - va_start(alist, fmt); - Msg_doalist(fmt, alist); - va_end(alist); -} - -#ifdef FLEX_SCANNER -/* Flex DOES have a much better way to handle non-standard input strategies. - This doesn't have to be this twisted to work with Flex, but if we are - going to continue to support lex, it's easiest to just follow along */ -#define YY_INPUT(buf, result, maxsize) \ - { \ - int c = SDF_Hdrgetc(); \ - /* Msgf(("YY_INPUT: c=%c\n", c)); */\ - result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); \ - } -/* Flex also has some new-and-different behavior AFTER YY_INPUT has returned - NULL. In particular, all subsequent calls to yylex will immediately - return NULL unless yyrestart is called. If we were always using Flex, - I could attach this to the BEGIN rule, but I can't do that with lex, - so I have to call it from outside, e.g., in SDFyyprepare. */ -void SDFlexprepare(void){ - yyrestart(NULL); -} -#else /* Not FLEX_SCANNER */ -void SDFlexprepare(void){} -#endif -#line 620 "lex.yy.c" - -#define INITIAL 0 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals (void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy (void ); - -int yyget_debug (void ); - -void yyset_debug (int debug_flag ); - -YY_EXTRA_TYPE yyget_extra (void ); - -void yyset_extra (YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in (void ); - -void yyset_in (FILE * in_str ); - -FILE *yyget_out (void ); - -void yyset_out (FILE * out_str ); - -int yyget_leng (void ); - -char *yyget_text (void ); - -int yyget_lineno (void ); - -void yyset_lineno (int line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - - static void yyunput (int c,char *buf_ptr ); - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - -#line 60 "SDF-lex.l" - -#line 809 "lex.yy.c" - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 119 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 282 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 61 "SDF-lex.l" -{SDFlineno++; return EOHDR;} /* Terminate the header on a comment line */ - YY_BREAK -case 2: -YY_RULE_SETUP -#line 62 "SDF-lex.l" -{SDFlineno++;} /* Otherwise, skip comments from '#' to eol. */ - YY_BREAK -case 3: -/* rule 3 can match eol */ -YY_RULE_SETUP -#line 63 "SDF-lex.l" -{if(yytext[0] == '\n') SDFlineno++;} /* skip white space. count lines*/ - YY_BREAK -case 4: -YY_RULE_SETUP -#line 64 "SDF-lex.l" -{ int c; - loop: - while((c=input()) != '*') {if(c=='\n') SDFlineno++;} - switch(input()){ - case '/': break; - case '*': unput('*'); - default: goto loop; - } - } /* Skip normal C comments. (no nesting) */ - YY_BREAK -case 5: -YY_RULE_SETUP -#line 73 "SDF-lex.l" -{yylval.type = SDF_CHAR; return TYPE;} - YY_BREAK -case 6: -YY_RULE_SETUP -#line 74 "SDF-lex.l" -{yylval.type = SDF_SHORT; return TYPE;} - YY_BREAK -case 7: -YY_RULE_SETUP -#line 75 "SDF-lex.l" -{yylval.type = SDF_INT; return TYPE;} - YY_BREAK -case 8: -YY_RULE_SETUP -#line 76 "SDF-lex.l" -{yylval.type = SDF_LONG; return TYPE;} - YY_BREAK -case 9: -YY_RULE_SETUP -#line 77 "SDF-lex.l" -{yylval.type = SDF_INT64; return TYPE;} - YY_BREAK -case 10: -YY_RULE_SETUP -#line 78 "SDF-lex.l" -{yylval.type = SDF_FLOAT; return TYPE;} - YY_BREAK -case 11: -YY_RULE_SETUP -#line 79 "SDF-lex.l" -{yylval.type = SDF_DOUBLE; return TYPE;} - YY_BREAK -case 12: -YY_RULE_SETUP -#line 80 "SDF-lex.l" -{return STRUCT;} - YY_BREAK -case 13: -YY_RULE_SETUP -#line 81 "SDF-lex.l" -; /* WARNING. The keyword 'unsigned' is skipped entirely. */ - YY_BREAK -case 14: -YY_RULE_SETUP -#line 82 "SDF-lex.l" -{return PARAMETER;} - YY_BREAK -case 15: -YY_RULE_SETUP -#line 83 "SDF-lex.l" -{yylval.valueparam = BYTEORDER; return VALUEPARAM;} - YY_BREAK -case 16: -YY_RULE_SETUP -#line 84 "SDF-lex.l" -{yylval.string = Malloc(yyleng+1); - strcpy(yylval.string, (char *)yytext); -#if YYDEBUG - if(yydebug) - printf("lex-malloc(%d) at 0x%lx\n", - yyleng+1, (unsigned long)yylval.string); -#endif - return NAME;} - YY_BREAK -case 17: -/* rule 17 can match eol */ -YY_RULE_SETUP -#line 92 "SDF-lex.l" -{ - /* strings extend to the next double-quote. */ - /* there are no escapes, and no exceptions. */ - /* We fiddle with the yyleng so we only get the contents in yylval. */ - /* Newlines embedded in strings will be missed by SDFlineno! */ - yylval.constant.u.stringval = Malloc(yyleng-1); - strncpy(yylval.constant.u.stringval, (char *)yytext+1, yyleng-2); - yylval.constant.u.stringval[yyleng-2] = '\0'; - yylval.constant.type = SDF_STRING; -#if YYDEBUG - if(yydebug) - printf("lex-malloc(%d) = 0x%lx\n", yyleng-1, - (unsigned long)yylval.constant.u.stringval); -#endif - return CONST;} - YY_BREAK -case 18: -#line 108 "SDF-lex.l" -case 19: -#line 109 "SDF-lex.l" -case 20: -YY_RULE_SETUP -#line 109 "SDF-lex.l" -{ - yylval.constant.type = SDF_DOUBLE; - sscanf((char *)yytext, "%lf", &yylval.constant.u.doubleval); - return CONST;} - YY_BREAK -case 21: -YY_RULE_SETUP -#line 113 "SDF-lex.l" -{ - yylval.constant.type = SDF_INT64; -#if __WORDSIZE==64 - sscanf((char *)yytext+2, "%lx", &yylval.constant.u.int64val); -#else - sscanf((char *)yytext+2, "%llx", &yylval.constant.u.int64val); -#endif - return CONST;} - YY_BREAK -case 22: -YY_RULE_SETUP -#line 121 "SDF-lex.l" -{ - yylval.constant.type = SDF_INT64; -#if __WORDSIZE==64 - sscanf((char *)yytext+1, "%lo", &yylval.constant.u.int64val); -#else - sscanf((char *)yytext+1, "%llo", &yylval.constant.u.int64val); -#endif - return CONST;} - YY_BREAK -case 23: -YY_RULE_SETUP -#line 129 "SDF-lex.l" -{ - yylval.constant.type = SDF_INT64; -#if __WORDSIZE==64 - sscanf((char *)yytext, "%ld", &yylval.constant.u.int64val); -#else - sscanf((char *)yytext, "%lld", &yylval.constant.u.int64val); -#endif - return CONST;} - YY_BREAK -case 24: -YY_RULE_SETUP -#line 137 "SDF-lex.l" -{return yytext[0];} - YY_BREAK -case 25: -YY_RULE_SETUP -#line 138 "SDF-lex.l" -{yyerror("lexer confusion on char: <%c>, line: %d\n", (yytext[0])?yytext[0]:'?', - SDFlineno); return LEXERROR;} - YY_BREAK -case 26: -YY_RULE_SETUP -#line 140 "SDF-lex.l" -ECHO; - YY_BREAK -#line 1072 "lex.yy.c" -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), (size_t) num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 119 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 119 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 118); - - return yy_is_jam ? 0 : yy_current_state; -} - - static void yyunput (int c, register char * yy_bp ) -{ - register char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -#ifndef __cplusplus -extern int isatty (int ); -#endif /* __cplusplus */ - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - int num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) -{ - - return yy_scan_bytes(yystr,strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -int yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param line_number - * - */ -void yyset_lineno (int line_number ) -{ - - yylineno = line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * in_str ) -{ - yyin = in_str ; -} - -void yyset_out (FILE * out_str ) -{ - yyout = out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int bdebug ) -{ - yy_flex_debug = bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = (FILE *) 0; - yyout = (FILE *) 0; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 140 "SDF-lex.l" diff --git a/external/libsdf/libSDF/SDF-lex.l b/external/libsdf/libSDF/SDF-lex.l deleted file mode 100644 index b2905ed..0000000 --- a/external/libsdf/libSDF/SDF-lex.l +++ /dev/null @@ -1,139 +0,0 @@ -%{ -/* - SDF Library for reading Self-Describing Files - Copyright (C) 1991,1992 John K. Salmon - - Terms and conditions are specified in the file "copyright.h", - and more precisely in the file COPYING.LIB which you should have - received with this library. -*/ -#include -/* This define means we don't have to link with the lex library! */ -#define YY_SKIP_YYWRAP -#define yywrap() 1 - -/* This one is ugly. - Lex's output contains fprintf(yyout, of various error messages. - We try here to redirect them to a Msg_doalist. */ -#include -#include "Msgs.h" -#undef fprintf -#define fprintf MYFprintf -void MYFprintf(int *junk, const char *fmt, ...){ - va_list alist; - va_start(alist, fmt); - Msg_doalist(fmt, alist); - va_end(alist); -} - -#ifdef FLEX_SCANNER -/* Flex DOES have a much better way to handle non-standard input strategies. - This doesn't have to be this twisted to work with Flex, but if we are - going to continue to support lex, it's easiest to just follow along */ -#define YY_INPUT(buf, result, maxsize) \ - { \ - int c = SDF_Hdrgetc(); \ - /* Msgf(("YY_INPUT: c=%c\n", c)); */\ - result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); \ - } -/* Flex also has some new-and-different behavior AFTER YY_INPUT has returned - NULL. In particular, all subsequent calls to yylex will immediately - return NULL unless yyrestart is called. If we were always using Flex, - I could attach this to the BEGIN rule, but I can't do that with lex, - so I have to call it from outside, e.g., in SDFyyprepare. */ -void SDFlexprepare(void){ - yyrestart(NULL); -} -#else /* Not FLEX_SCANNER */ -void SDFlexprepare(void){} -#endif -%} -White [ \f\t\n] -Dig [0-9] -Alpha [A-Za-z_] -Hex [A-Fa-f0-9] -Octal [0-7] -Alphanum [A-Za-z0-9_] -Expon [Ee]{Sign}{Dig}+ -Punct "="|"["|"]"|"{"|"}"|";"|"," -Sign [-+]? -%% -#.*SDF-EOH.* {SDFlineno++; return EOHDR;} /* Terminate the header on a comment line */ -#.* {SDFlineno++;} /* Otherwise, skip comments from '#' to eol. */ -{White} {if(yytext[0] == '\n') SDFlineno++;} /* skip white space. count lines*/ -"/*" { int c; - loop: - while((c=input()) != '*') {if(c=='\n') SDFlineno++;} - switch(input()){ - case '/': break; - case '*': unput('*'); - default: goto loop; - } - } /* Skip normal C comments. (no nesting) */ -char {yylval.type = SDF_CHAR; return TYPE;} -short {yylval.type = SDF_SHORT; return TYPE;} -int {yylval.type = SDF_INT; return TYPE;} -long {yylval.type = SDF_LONG; return TYPE;} -int64_t {yylval.type = SDF_INT64; return TYPE;} -float {yylval.type = SDF_FLOAT; return TYPE;} -double {yylval.type = SDF_DOUBLE; return TYPE;} -struct {return STRUCT;} -unsigned ; /* WARNING. The keyword 'unsigned' is skipped entirely. */ -parameter {return PARAMETER;} -byteorder {yylval.valueparam = BYTEORDER; return VALUEPARAM;} -{Alpha}{Alphanum}* {yylval.string = Malloc(yyleng+1); - strcpy(yylval.string, (char *)yytext); -#if YYDEBUG - if(yydebug) - printf("lex-malloc(%d) at 0x%lx\n", - yyleng+1, (unsigned long)yylval.string); -#endif - return NAME;} -\"[^"]*\" { - /* strings extend to the next double-quote. */ - /* there are no escapes, and no exceptions. */ - /* We fiddle with the yyleng so we only get the contents in yylval. */ - /* Newlines embedded in strings will be missed by SDFlineno! */ - yylval.constant.u.stringval = Malloc(yyleng-1); - strncpy(yylval.constant.u.stringval, (char *)yytext+1, yyleng-2); - yylval.constant.u.stringval[yyleng-2] = '\0'; - yylval.constant.type = SDF_STRING; -#if YYDEBUG - if(yydebug) - printf("lex-malloc(%d) = 0x%lx\n", yyleng-1, - (unsigned long)yylval.constant.u.stringval); -#endif - return CONST;} -{Sign}{Dig}+"."{Dig}*({Expon})? | -{Sign}{Dig}*"."{Dig}+({Expon})? | -{Sign}{Dig}+{Expon} { - yylval.constant.type = SDF_DOUBLE; - sscanf((char *)yytext, "%lf", &yylval.constant.u.doubleval); - return CONST;} -0x{Hex}+ { - yylval.constant.type = SDF_INT64; -#if __WORDSIZE==64 - sscanf((char *)yytext+2, "%lx", &yylval.constant.u.int64val); -#else - sscanf((char *)yytext+2, "%llx", &yylval.constant.u.int64val); -#endif - return CONST;} -0{Octal}+ { - yylval.constant.type = SDF_INT64; -#if __WORDSIZE==64 - sscanf((char *)yytext+1, "%lo", &yylval.constant.u.int64val); -#else - sscanf((char *)yytext+1, "%llo", &yylval.constant.u.int64val); -#endif - return CONST;} -{Sign}{Dig}+ { - yylval.constant.type = SDF_INT64; -#if __WORDSIZE==64 - sscanf((char *)yytext, "%ld", &yylval.constant.u.int64val); -#else - sscanf((char *)yytext, "%lld", &yylval.constant.u.int64val); -#endif - return CONST;} -{Punct} {return yytext[0];} -. {yyerror("lexer confusion on char: <%c>, line: %d\n", (yytext[0])?yytext[0]:'?', - SDFlineno); return LEXERROR;} diff --git a/external/libsdf/libSDF/SDF-parse.c b/external/libsdf/libSDF/SDF-parse.c deleted file mode 100644 index f1a2fc7..0000000 --- a/external/libsdf/libSDF/SDF-parse.c +++ /dev/null @@ -1,2476 +0,0 @@ -/* A Bison parser, made by GNU Bison 2.5. */ - -/* Bison implementation for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. - - 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 . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* C LALR(1) parser skeleton written by Richard Stallman, by - simplifying the original so-called "semantic" parser. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "2.5" - -/* Skeleton name. */ -#define YYSKELETON_NAME "yacc.c" - -/* Pure parsers. */ -#define YYPURE 0 - -/* Push parsers. */ -#define YYPUSH 0 - -/* Pull parsers. */ -#define YYPULL 1 - -/* Using locations. */ -#define YYLSP_NEEDED 0 - - - -/* Copy the first part of user declarations. */ - -/* Line 268 of yacc.c */ -#line 1 "SDF-parse.y" - -/* - SDF Library for reading Self-Describing Files - Copyright (C) 1991,1992 John K. Salmon - - Terms and conditions are specified in the file "copyright.h", - and more precisely in the file COPYING.LIB which you should have - received with this library. -*/ - -/* We don't rely on bison's -p argument any more. - Instead, just #define the name changes ourselves. These are taken - from the beginning of bison -p output. These are far from a complete - set of external 'yy' names, as a quick run throug 'nm' will show. Maybe - all the others come from lex. I dunno. In any event, the namespace is only - partially cleaned up. Perhaps we should apply for Superfund money - to finish the cleanup? bison -p does no better. -*/ -#define yyparse SDFyyparse -#define yylex SDFyylex -#define yyerror SDFyyerror -#define yylval SDFyylval -#define yychar SDFyychar -#define yydebug SDFyydebug -#define yynerrs SDFyynerrs - -#include -#include -#include -#include -#include "protos.h" -#include "Msgs.h" -#include "SDF-private.h" -#include "obstack.h" -#include "Malloc.h" - -#ifndef __DELTA__ -#define YYDEBUG 1 -#endif - -#if YYDEBUG -/* yacc sends its debug output throught printf. We change that... */ -#define printf Msg_do /* MUST be after protos.h!!! */ -#endif - -#ifdef cray -/* This wants to be a long on the cray?? */ -extern long int yydebug; -#else -extern int yydebug; -#endif -extern void yyerror(char *fmt, ...); - - -static enum SDF_type_enum curtype; -static blk_descrip_t cur_blk; -static int cur_file_offset; -static int cur_data_offset; -static SDF *cur_hdr; -static int no_more_data_blks; -static int zero_len_blknum; - -char *SDFtype_names[] = {"notype", "char", "short", "int", "long", "int64_t", - "float", "double", "string"}; - - int SDFtype_sizes[] = {0, sizeof(char), sizeof(short), sizeof(int), sizeof(long), - sizeof(int64_t), sizeof(float), sizeof(double), sizeof(char *)}; - -static int do_value_param(enum value_param_enum type, const_t value); -static int data_dcl(declaration_t dcl); -static int const_dcl(declaration_t dcl, const_list_t consts); -static void finish_curblk(void); -static const_t convert_const(const_t *cp, enum SDF_type_enum type); -static int finish_parse(void); - - - -/* Line 268 of yacc.c */ -#line 149 "y.tab.c" - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 -#endif - - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - STRUCT = 258, - NAME = 259, - TYPE = 260, - CONST = 261, - VALUEPARAM = 262, - PARAMETER = 263, - EOHDR = 264, - LEXERROR = 265 - }; -#endif -/* Tokens. */ -#define STRUCT 258 -#define NAME 259 -#define TYPE 260 -#define CONST 261 -#define VALUEPARAM 262 -#define PARAMETER 263 -#define EOHDR 264 -#define LEXERROR 265 - - - - -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -{ - -/* Line 293 of yacc.c */ -#line 90 "SDF-parse.y" - - enum SDF_type_enum type; - enum value_param_enum valueparam; - char *string; - const_t constant; - declaration_t declaration; - dcl_list_t dcl_list; - one_dcl_t one_dcl; - const_list_t const_list; - - - -/* Line 293 of yacc.c */ -#line 218 "y.tab.c" -} YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 -#endif - - -/* Copy the second part of user declarations. */ - - -/* Line 343 of yacc.c */ -#line 230 "y.tab.c" - -#ifdef short -# undef short -#endif - -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; -#endif - -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#elif (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -typedef signed char yytype_int8; -#else -typedef short int yytype_int8; -#endif - -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short int yytype_uint16; -#endif - -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; -#else -typedef short int yytype_int16; -#endif - -#ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif -#endif - -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) - -#ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) -# endif -# endif -# ifndef YY_ -# define YY_(msgid) msgid -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) -#else -# define YYUSE(e) /* empty */ -#endif - -/* Identity function, used to suppress warnings about constant conditions. */ -#ifndef lint -# define YYID(n) (n) -#else -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static int -YYID (int yyi) -#else -static int -YYID (yyi) - int yyi; -#endif -{ - return yyi; -} -#endif - -#if ! defined yyoverflow || YYERROR_VERBOSE - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - - -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - yytype_int16 yyss_alloc; - YYSTYPE yyvs_alloc; -}; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -# define YYCOPY_NEEDED 1 - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (YYID (0)) - -#endif - -#if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif -#endif /* !YYCOPY_NEEDED */ - -/* YYFINAL -- State number of the termination state. */ -#define YYFINAL 13 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 44 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 18 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 12 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 26 -/* YYNRULES -- Number of states. */ -#define YYNSTATES 48 - -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 265 - -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) - -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 17, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, - 2, 12, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 13, 2, 14, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 15, 2, 16, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10 -}; - -#if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const yytype_uint8 yyprhs[] = -{ - 0, 0, 3, 5, 8, 10, 12, 15, 18, 23, - 29, 31, 37, 46, 54, 56, 60, 61, 65, 67, - 71, 73, 78, 82, 84, 88, 90 -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yytype_int8 yyrhs[] = -{ - 19, 0, -1, 20, -1, 20, 9, -1, 10, -1, - 21, -1, 20, 21, -1, 22, 11, -1, 22, 12, - 28, 11, -1, 8, 7, 12, 6, 11, -1, 24, - -1, 3, 15, 23, 11, 16, -1, 3, 15, 23, - 11, 16, 13, 6, 14, -1, 3, 15, 23, 11, - 16, 13, 14, -1, 24, -1, 23, 11, 24, -1, - -1, 5, 25, 26, -1, 27, -1, 26, 17, 27, - -1, 4, -1, 4, 13, 6, 14, -1, 4, 13, - 14, -1, 6, -1, 15, 29, 16, -1, 6, -1, - 29, 17, 6, -1 -}; - -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ -static const yytype_uint8 yyrline[] = -{ - 0, 101, 101, 102, 103, 106, 107, 110, 111, 112, - 115, 116, 117, 126, 130, 131, 143, 143, 146, 152, - 160, 161, 170, 173, 179, 182, 188 -}; -#endif - -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE -/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "STRUCT", "NAME", "TYPE", "CONST", - "VALUEPARAM", "PARAMETER", "EOHDR", "LEXERROR", "';'", "'='", "'['", - "']'", "'{'", "'}'", "','", "$accept", "hdr", "hdr1", "stmt", - "declaration", "many_typed_dcl_list", "typed_dcl_list", "$@1", - "comma_sep_dcls", "dcl1", "const_lst", "comma_sep_consts", 0 -}; -#endif - -# ifdef YYPRINT -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to - token YYLEX-NUM. */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 59, 61, 91, 93, 123, 125, 44 -}; -# endif - -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 18, 19, 19, 19, 20, 20, 21, 21, 21, - 22, 22, 22, 22, 23, 23, 25, 24, 26, 26, - 27, 27, 27, 28, 28, 29, 29 -}; - -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 1, 2, 1, 1, 2, 2, 4, 5, - 1, 5, 8, 7, 1, 3, 0, 3, 1, 3, - 1, 4, 3, 1, 3, 1, 3 -}; - -/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 0, 0, 16, 0, 4, 0, 2, 5, 0, 10, - 0, 0, 0, 1, 3, 6, 7, 0, 0, 14, - 20, 17, 18, 0, 23, 0, 0, 0, 0, 0, - 0, 25, 0, 8, 11, 15, 0, 22, 19, 9, - 24, 0, 0, 21, 26, 0, 13, 12 -}; - -/* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int8 yydefgoto[] = -{ - -1, 5, 6, 7, 8, 18, 9, 11, 21, 22, - 26, 32 -}; - -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF -14 -static const yytype_int8 yypact[] = -{ - 13, -13, -14, 2, -14, 5, 17, -14, 16, -14, - 10, 6, 7, -14, -14, -14, -14, -2, 18, -14, - 11, 14, -14, 24, -14, 26, 22, -4, -3, 6, - 23, -14, -9, -14, 25, -14, 21, -14, -14, -14, - -14, 30, 0, -14, -14, 27, -14, -14 -}; - -/* YYPGOTO[NTERM-NUM]. */ -static const yytype_int8 yypgoto[] = -{ - -14, -14, -14, 31, -14, -14, -10, -14, -14, 15, - -14, -14 -}; - -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -1 -static const yytype_uint8 yytable[] = -{ - 19, 2, 10, 36, 24, 13, 45, 40, 41, 12, - 20, 37, 34, 25, 46, 2, 1, 35, 2, 23, - 1, 3, 2, 4, 28, 3, 14, 16, 17, 27, - 30, 29, 31, 33, 39, 43, 44, 15, 42, 0, - 0, 47, 0, 0, 38 -}; - -#define yypact_value_is_default(yystate) \ - ((yystate) == (-14)) - -#define yytable_value_is_error(yytable_value) \ - YYID (0) - -static const yytype_int8 yycheck[] = -{ - 10, 5, 15, 6, 6, 0, 6, 16, 17, 7, - 4, 14, 16, 15, 14, 5, 3, 27, 5, 12, - 3, 8, 5, 10, 13, 8, 9, 11, 12, 11, - 6, 17, 6, 11, 11, 14, 6, 6, 13, -1, - -1, 14, -1, -1, 29 -}; - -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 3, 5, 8, 10, 19, 20, 21, 22, 24, - 15, 25, 7, 0, 9, 21, 11, 12, 23, 24, - 4, 26, 27, 12, 6, 15, 28, 11, 13, 17, - 6, 6, 29, 11, 16, 24, 6, 14, 27, 11, - 16, 17, 13, 14, 6, 6, 14, 14 -}; - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. However, - YYFAIL appears to be in use. Nevertheless, it is formally deprecated - in Bison 2.4.2's NEWS entry, where a plan to phase it out is - discussed. */ - -#define YYFAIL goto yyerrlab -#if defined YYFAIL - /* This is here to suppress warnings from the GCC cpp's - -Wunused-macros. Normally we don't worry about that warning, but - some users do, and we want to make it easy for users to remove - YYFAIL uses, which will produce warnings from Bison 2.5. */ -#endif - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (YYID (0)) - - -#define YYTERROR 1 -#define YYERRCODE 256 - - -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ - while (YYID (0)) -#endif - - -/* This macro is provided for backward compatibility. */ - -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif - - -/* YYLEX -- calling `yylex' with the right arguments. */ - -#ifdef YYLEX_PARAM -# define YYLEX yylex (YYLEX_PARAM) -#else -# define YYLEX yylex () -#endif - -/* Enable debugging if requested. */ -#if YYDEBUG - -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (YYID (0)) - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (YYID (0)) - - -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif -{ - if (!yyvaluep) - return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# else - YYUSE (yyoutput); -# endif - switch (yytype) - { - default: - break; - } -} - - -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif -{ - if (yytype < YYNTOKENS) - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - - yy_symbol_value_print (yyoutput, yytype, yyvaluep); - YYFPRINTF (yyoutput, ")"); -} - -/*------------------------------------------------------------------. -| yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (included). | -`------------------------------------------------------------------*/ - -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) -#else -static void -yy_stack_print (yybottom, yytop) - yytype_int16 *yybottom; - yytype_int16 *yytop; -#endif -{ - YYFPRINTF (stderr, "Stack now"); - for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); -} - -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (YYID (0)) - - -/*------------------------------------------------. -| Report that the YYRULE is going to be reduced. | -`------------------------------------------------*/ - -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule) -#else -static void -yy_reduce_print (yyvsp, yyrule) - YYSTYPE *yyvsp; - int yyrule; -#endif -{ - int yynrhs = yyr2[yyrule]; - int yyi; - unsigned long int yylno = yyrline[yyrule]; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); - /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); - YYFPRINTF (stderr, "\n"); - } -} - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyvsp, Rule); \ -} while (YYID (0)) - -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ - - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - - -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static YYSIZE_T -yystrlen (const char *yystr) -#else -static YYSIZE_T -yystrlen (yystr) - const char *yystr; -#endif -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif - -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static char * -yystpcpy (char *yydest, const char *yysrc) -#else -static char * -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -#endif -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (! yyres) - return yystrlen (yystr); - - return yystpcpy (yyres, yystr) - yyres; -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = 0; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - Assume YYFAIL is not used. It's too flawed to consider. See - - for details. YYERROR is fine as it does not invoke this - function. - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ - -/*-----------------------------------------------. -| Release the memory associated to this symbol. | -`-----------------------------------------------*/ - -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) -#else -static void -yydestruct (yymsg, yytype, yyvaluep) - const char *yymsg; - int yytype; - YYSTYPE *yyvaluep; -#endif -{ - YYUSE (yyvaluep); - - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - - switch (yytype) - { - - default: - break; - } -} - - -/* Prevent warnings from -Wmissing-prototypes. */ -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ - - -/* The lookahead symbol. */ -int yychar; - -/* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; - -/* Number of syntax errors so far. */ -int yynerrs; - - -/*----------. -| yyparse. | -`----------*/ - -#ifdef YYPARSE_PARAM -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -int -yyparse (void *YYPARSE_PARAM) -#else -int -yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -#endif -#else /* ! YYPARSE_PARAM */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -int -yyparse (void) -#else -int -yyparse () - -#endif -#endif -{ - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - - /* The stacks and their tools: - `yyss': related to states. - `yyvs': related to semantic values. - - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; - - YYSIZE_T yystacksize; - - int yyn; - int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken; - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif - -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; - - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; - yystacksize = YYINITDEPTH; - - YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - - goto yysetstate; - -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. So pushing a state here evens the stacks. */ - yyssp++; - - yysetstate: - *yyssp = yystate; - - if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; - -#ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif -#endif /* no yyoverflow */ - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); - - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - - if (yystate == YYFINAL) - YYACCEPT; - - goto yybackup; - -/*-----------. -| yybackup. | -`-----------*/ -yybackup: - - /* Do appropriate processing given the current state. Read a - lookahead token if we need one and don't already have one. */ - - /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - - /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - - yystate = yyn; - *++yyvsp = yylval; - - goto yynewstate; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- Do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 2: - -/* Line 1806 of yacc.c */ -#line 101 "SDF-parse.y" - {if(finish_parse()) YYERROR;} - break; - - case 3: - -/* Line 1806 of yacc.c */ -#line 102 "SDF-parse.y" - {if(finish_parse()) YYERROR; else YYACCEPT;} - break; - - case 4: - -/* Line 1806 of yacc.c */ -#line 103 "SDF-parse.y" - {YYERROR;} - break; - - case 7: - -/* Line 1806 of yacc.c */ -#line 110 "SDF-parse.y" - {if(data_dcl((yyvsp[(1) - (2)].declaration))) YYERROR;} - break; - - case 8: - -/* Line 1806 of yacc.c */ -#line 111 "SDF-parse.y" - {if(const_dcl((yyvsp[(1) - (4)].declaration), (yyvsp[(3) - (4)].const_list))) YYERROR;} - break; - - case 9: - -/* Line 1806 of yacc.c */ -#line 112 "SDF-parse.y" - {if(do_value_param((yyvsp[(2) - (5)].valueparam), (yyvsp[(4) - (5)].constant))) YYERROR;} - break; - - case 10: - -/* Line 1806 of yacc.c */ -#line 115 "SDF-parse.y" - {(yyval.declaration).dcl_list = (yyvsp[(1) - (1)].dcl_list); (yyval.declaration).Nrec = 1;} - break; - - case 11: - -/* Line 1806 of yacc.c */ -#line 116 "SDF-parse.y" - {(yyval.declaration).dcl_list=(yyvsp[(3) - (5)].dcl_list); (yyval.declaration).Nrec=1;} - break; - - case 12: - -/* Line 1806 of yacc.c */ -#line 118 "SDF-parse.y" - { - if( (yyvsp[(7) - (8)].constant).type != SDF_INT64 ){ - yyerror("Expected integer constant"); - YYERROR; - }else{ - (yyval.declaration).dcl_list = (yyvsp[(3) - (8)].dcl_list); (yyval.declaration).Nrec = (yyvsp[(7) - (8)].constant).u.int64val; - } - } - break; - - case 13: - -/* Line 1806 of yacc.c */ -#line 127 "SDF-parse.y" - { (yyval.declaration).dcl_list = (yyvsp[(3) - (7)].dcl_list); (yyval.declaration).Nrec = 0;} - break; - - case 14: - -/* Line 1806 of yacc.c */ -#line 130 "SDF-parse.y" - {(yyval.dcl_list) = (yyvsp[(1) - (1)].dcl_list);} - break; - - case 15: - -/* Line 1806 of yacc.c */ -#line 132 "SDF-parse.y" - { - int sz; - - (yyval.dcl_list).ndcl = (yyvsp[(1) - (3)].dcl_list).ndcl + (yyvsp[(3) - (3)].dcl_list).ndcl; - (yyval.dcl_list).obs = (yyvsp[(1) - (3)].dcl_list).obs; - sz = obstack_object_size(&(yyvsp[(3) - (3)].dcl_list).obs); - (void)obstack_grow(&(yyval.dcl_list).obs, obstack_finish(&(yyvsp[(3) - (3)].dcl_list).obs), sz); - (void)obstack_free(&(yyvsp[(3) - (3)].dcl_list).obs, NULL); - } - break; - - case 16: - -/* Line 1806 of yacc.c */ -#line 143 "SDF-parse.y" - {curtype = (yyvsp[(1) - (1)].type);} - break; - - case 17: - -/* Line 1806 of yacc.c */ -#line 143 "SDF-parse.y" - {(yyval.dcl_list) = (yyvsp[(3) - (3)].dcl_list);} - break; - - case 18: - -/* Line 1806 of yacc.c */ -#line 147 "SDF-parse.y" - { - obstack_begin(&(yyval.dcl_list).obs, 16*sizeof((yyvsp[(1) - (1)].one_dcl))); - (yyval.dcl_list).ndcl = 1; - (void)obstack_grow(&(yyval.dcl_list).obs, &(yyvsp[(1) - (1)].one_dcl), sizeof((yyvsp[(1) - (1)].one_dcl))); - } - break; - - case 19: - -/* Line 1806 of yacc.c */ -#line 153 "SDF-parse.y" - { - (yyval.dcl_list) = (yyvsp[(1) - (3)].dcl_list); - (yyval.dcl_list).ndcl += 1; - (void)obstack_grow(&(yyval.dcl_list).obs, &(yyvsp[(3) - (3)].one_dcl), sizeof((yyvsp[(3) - (3)].one_dcl))); - } - break; - - case 20: - -/* Line 1806 of yacc.c */ -#line 160 "SDF-parse.y" - {(yyval.one_dcl).name = (yyvsp[(1) - (1)].string); (yyval.one_dcl).type = curtype; (yyval.one_dcl).arrcnt = 1;} - break; - - case 21: - -/* Line 1806 of yacc.c */ -#line 162 "SDF-parse.y" - { - if( (yyvsp[(3) - (4)].constant).type != SDF_INT64 ){ - yyerror("Expected integer constant"); - YYERROR; - }else{ - (yyval.one_dcl).name = (yyvsp[(1) - (4)].string); (yyval.one_dcl).type = curtype; (yyval.one_dcl).arrcnt = (yyvsp[(3) - (4)].constant).u.int64val; - } - } - break; - - case 22: - -/* Line 1806 of yacc.c */ -#line 170 "SDF-parse.y" - {(yyval.one_dcl).name=(yyvsp[(1) - (3)].string); (yyval.one_dcl).type=curtype; (yyval.one_dcl).arrcnt = 0;} - break; - - case 23: - -/* Line 1806 of yacc.c */ -#line 174 "SDF-parse.y" - { - (yyval.const_list).nconst = 1; - obstack_begin(&(yyval.const_list).obs, 16*sizeof((yyvsp[(1) - (1)].constant))); - (void)obstack_grow(&(yyval.const_list).obs, &(yyvsp[(1) - (1)].constant), sizeof((yyvsp[(1) - (1)].constant))); - } - break; - - case 24: - -/* Line 1806 of yacc.c */ -#line 179 "SDF-parse.y" - {(yyval.const_list) = (yyvsp[(2) - (3)].const_list);} - break; - - case 25: - -/* Line 1806 of yacc.c */ -#line 183 "SDF-parse.y" - { - (yyval.const_list).nconst = 1; - obstack_begin(&(yyval.const_list).obs, 16*sizeof((yyvsp[(1) - (1)].constant))); - (void)obstack_grow(&(yyval.const_list).obs, &(yyvsp[(1) - (1)].constant), sizeof((yyvsp[(1) - (1)].constant))); - } - break; - - case 26: - -/* Line 1806 of yacc.c */ -#line 189 "SDF-parse.y" - { - (yyval.const_list) = (yyvsp[(1) - (3)].const_list); - (yyval.const_list).nconst += 1; - (void)obstack_grow(&(yyval.const_list).obs, &(yyvsp[(3) - (3)].constant), sizeof((yyvsp[(3) - (3)].constant))); - } - break; - - - -/* Line 1806 of yacc.c */ -#line 1686 "y.tab.c" - default: break; - } - /* User semantic actions sometimes alter yychar, and that requires - that yytoken be updated with the new translation. We take the - approach of translating immediately before every use of yytoken. - One alternative is translating here after every semantic action, - but that translation would be missed if the semantic action invokes - YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or - if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an - incorrect destructor might then be invoked immediately. In the - case of YYERROR or YYBACKUP, subsequent parser actions might lead - to an incorrect destructor call or verbose syntax error message - before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); - - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - - *++yyvsp = yyval; - - /* Now `shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; - - goto yynewstate; - - -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ -yyerrlab: - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif - } - - - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; - } - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - - -/*---------------------------------------------------. -| yyerrorlab -- error raised explicitly by YYERROR. | -`---------------------------------------------------*/ -yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; - - /* Do not reclaim the symbols of the rule which action triggered - this YYERROR. */ - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - yystate = *yyssp; - goto yyerrlab1; - - -/*-------------------------------------------------------------. -| yyerrlab1 -- common code for both syntax error and YYERROR. | -`-------------------------------------------------------------*/ -yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; - - - yydestruct ("Error: popping", - yystos[yystate], yyvsp); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } - - *++yyvsp = yylval; - - - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - -#if !defined(yyoverflow) || YYERROR_VERBOSE -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ -yyexhaustedlab: - yyerror (YY_("memory exhausted")); - yyresult = 2; - /* Fall through. */ -#endif - -yyreturn: - if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - } - /* Do not reclaim the symbols of the rule which action triggered - this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); - while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); - YYPOPSTACK (1); - } -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif - /* Make sure YYID is used. */ - return YYID (yyresult); -} - - - -/* Line 2067 of yacc.c */ -#line 196 "SDF-parse.y" - -static int SDFlineno; - -static const char *Dataname, *Hdrname; - -#ifdef STANDALONE -char SDFerrstring[512]; -unsigned int SDFcpubyteorder(void){return 0;} - -main(int argc, char **argv) -{ - SDF hdr; - - if(argc > 1){ - yydebug = 1; - }else{ - yydebug = 0; - } - SDFyyprepare(&hdr, "-", "-"); - if(yyparse()){ - printf("Terminated on error. \n"); - exit(1); - } - exit(0); -} -#endif - -static int SDF_iomode = MPMY_RDONLY | MPMY_MULTI; - -void SDFsetiomode(int mode) -{ - if (mode == SDF_SINGL) { - SDF_iomode = MPMY_RDONLY | MPMY_SINGL; - } else { - SDF_iomode = MPMY_RDONLY | MPMY_MULTI; - } -} - - - -void SDFyyerror(char *fmt, ...) -{ - char *p; - va_list ap; - - va_start(ap, fmt); - vsprintf(SDFerrstring, fmt, ap); - p = SDFerrstring + strlen(SDFerrstring); - sprintf(p, " lineno = %d\n", SDFlineno); - va_end(ap); -} - -int SDFyyprepare(SDF *hdr, const char *hdrname, const char *dataname) -{ - no_more_data_blks = 0; - - cur_file_offset = 0; - cur_data_offset = 0; - - cur_blk.Nrec = 1; - cur_blk.inmem = 1; - cur_blk.begin_offset = 0; - cur_blk.reclen = 0; - - cur_hdr = hdr; - cur_hdr->nblks = 0; - cur_hdr->nvecs = 0; - /* Assume that MPMY_Fopen does the 'right' thing with "-" */ - if( SDF_Hdropen(hdrname) < 0 ){ - sprintf(SDFerrstring, "SDFopen: could not open %s\n", hdrname); - return -1; - } - Dataname = dataname; - Hdrname = hdrname; - SDFlineno = 0; /* or 1? It's always +-1 anyway */ - SDFlexprepare(); - - obstack_begin(&cur_hdr->blks_obs, 16*sizeof(blk_descrip_t)); - obstack_begin(&cur_hdr->vecs_obs, 32*sizeof(vec_descrip_t)); - obstack_begin(&cur_hdr->data_obs, 2048); - return 0; -} - -static int finish_parse(void) -{ - int i; - - finish_curblk(); - cur_hdr->blks = (blk_descrip_t *)obstack_finish(&cur_hdr->blks_obs); - cur_hdr->vecs = (vec_descrip_t *)obstack_finish(&cur_hdr->vecs_obs); - cur_hdr->data = obstack_finish(&cur_hdr->data_obs); - cur_hdr->vec_names = Malloc(cur_hdr->nvecs * sizeof(char *)); - for(i=0; invecs; i++){ - cur_hdr->vec_names[i] = cur_hdr->vecs[i].name; - } - - if( (Dataname == NULL) || (Dataname[0] == '\0') - || (strcmp(Hdrname, Dataname)==0)){ - cur_hdr->begin_file_offset = SDF_Hdroffset(); - if( cur_hdr->begin_file_offset < 0 ){ - yyerror("Can't get offset of end of header\n"); - return -1; - } - }else{ - cur_hdr->begin_file_offset = 0; - } - SDF_Hdrclose(); - - /* cur_hdr->datafp = MPMY_Fopen(Dataname, MPMY_RDONLY); */ - /* If we come up with a better model for IO, call it here.. */ - cur_hdr->datafp = MPMY_Fopen(Dataname, SDF_iomode); - - Msgf(("cur_hdr->datafp = %p\n", cur_hdr->datafp)); - - if( cur_hdr->datafp == NULL ){ - sprintf(SDFerrstring, "SDFopen: could not open data file: %s\n", - Dataname); - return -1; - } - - if(no_more_data_blks){ - blk_descrip_t *zerolenblk; - off_t bytesleft, recsleft; - off_t datalen; - - zerolenblk = &cur_hdr->blks[zero_len_blknum]; - if(zerolenblk->Nrec != 0){ - yyerror("Zero length block has non-zero length!?\n"); - return -1; - } - if( cur_hdr->begin_file_offset < 0 ){ - yyerror("Can't have zero-len blk in an unseekable file\n"); - return -1; - } - Msgf(("About to call MPMY_Flen\n")); - if( (datalen = MPMY_Flen(cur_hdr->datafp)) < 0 ){ - yyerror("Could not get length of data file.\n"); - return -1; - } - bytesleft = datalen - - (zerolenblk->begin_offset + cur_hdr->begin_file_offset); - Msgf(("datalen = %ld, butesleft = %ld\n", - (long)datalen, (long)bytesleft)); - if( bytesleft < 0 ){ - yyerror("File too short.\n"); - return -1; - } - recsleft = bytesleft/zerolenblk->reclen; - if( recsleft*zerolenblk->reclen != bytesleft ){ - printf("datalen is %ld, bytesleft is %ld\n", (long)datalen, (long)bytesleft); - yyerror("File ends between record boundaries\n"); - return -1; - } - zerolenblk->Nrec = recsleft; - } - return 0; -} - -static int do_value_param(enum value_param_enum param, const_t value) -{ - switch(param){ - case BYTEORDER: - if( value.type != SDF_INT64 ) - return -1; - cur_hdr->byteorder = value.u.int64val; - cur_hdr->swapping = (cur_hdr->byteorder != SDFcpubyteorder()); - break; - } - return 0; -} - - -static int data_dcl(declaration_t dcl) -{ - dcl_list_t *dcl_list; - one_dcl_t *base, *dclp; - int i, offset; - vec_descrip_t vec_descrip; - -#if YYDEBUG - if(yydebug) - printf("Declaration of %ld records:\n", dcl.Nrec); -#endif - if(no_more_data_blks){ - yyerror("You can't have data following an implicit-length dcl.\n"); - return -1; - } - - /* Test to see if we can append this dcl to the current */ - /* block. */ - if(cur_blk.inmem || cur_blk.Nrec != 1 || dcl.Nrec != 1){ - finish_curblk(); - cur_blk.Nrec = dcl.Nrec; - cur_blk.reclen = 0; - cur_blk.inmem = 0; - cur_blk.begin_offset = cur_file_offset; -#if YYDEBUG - if(yydebug) - printf("New block (%d) at offset %d in file\n", - cur_hdr->nblks, cur_file_offset); -#endif - } - - if(dcl.Nrec == 0){ - no_more_data_blks = 1; - zero_len_blknum = cur_hdr->nblks; - } - - offset = cur_blk.reclen; - - dcl_list = &dcl.dcl_list; - base = (one_dcl_t *)obstack_base(&dcl_list->obs); - for(i=0; indcl; i++){ - dclp = &base[i]; - vec_descrip.name = dclp->name; - vec_descrip.arrcnt = dclp->arrcnt; - vec_descrip.type = dclp->type; - vec_descrip.blk_off = offset; - vec_descrip.blk_num = cur_hdr->nblks; - vec_descrip.nread = 0; - offset += SDFtype_sizes[dclp->type] * dclp->arrcnt; - cur_hdr->nvecs++; - (void)obstack_grow(&cur_hdr->vecs_obs, - &vec_descrip, sizeof(vec_descrip)); -#if YYDEBUG - if(yydebug){ - printf("\t %s %s[%d]", SDFtype_names[dclp->type], dclp->name, - dclp->arrcnt); - printf(" in block %ld at offset %ld\n", - vec_descrip.blk_num, vec_descrip.blk_off); - } -#endif - } - (void)obstack_free(&dcl_list->obs, NULL); - cur_blk.reclen = offset; - return 0; -} - -static void finish_curblk(void) -{ - cur_hdr->nblks++; - (void)obstack_grow(&cur_hdr->blks_obs, &cur_blk, sizeof(cur_blk)); - if(cur_blk.inmem){ - cur_data_offset += cur_blk.reclen * cur_blk.Nrec; - }else{ - cur_file_offset += cur_blk.reclen * cur_blk.Nrec; - } -} - -static int const_dcl(declaration_t dcl, const_list_t consts) -{ - dcl_list_t *dcl_list; - one_dcl_t *dclbase, *dclp; - const_t *cp, *cbase, converted; - vec_descrip_t vec_descrip; - int i, j, k; - int offset; - void *to; - - dcl_list = &dcl.dcl_list; - if(dcl.Nrec == 0){ - dcl.Nrec = consts.nconst; -#if 0 /* Was it really this easy?? */ - yyerror("Cannot deal with implicit length constant dcls."); - return -1; -#endif - } - - /* Test to see if we can append this dcl to the current */ - /* block. */ - if(!cur_blk.inmem || cur_blk.Nrec != 1 || dcl.Nrec != 1){ - finish_curblk(); - cur_blk.Nrec = dcl.Nrec; - cur_blk.reclen = 0; - cur_blk.inmem = 1; - cur_blk.begin_offset = cur_data_offset; -#if YYDEBUG - if(yydebug) - printf("New block (%d) at offset %d in data\n", - cur_hdr->nblks, cur_data_offset); -#endif - } - - offset = cur_blk.reclen; - cbase = (const_t *)obstack_base(&consts.obs); - dclbase = (one_dcl_t *)obstack_base(&dcl_list->obs); - - for(i=0; indcl; i++){ - dclp = &dclbase[i]; - if(dclp->arrcnt == 0){ - if(dclp->type == SDF_CHAR - && cbase[i].type == SDF_STRING - && dcl.Nrec == 1){ - dclp->arrcnt = strlen(cbase[i].u.stringval)+1; - /* Round up for padding purposes. */ - dclp->arrcnt = (dclp->arrcnt + 7)& (~0x7); - }else if(i == dcl_list->ndcl-1 && dcl.Nrec == 1){ - dclp->arrcnt = consts.nconst - i; - }else{ - yyerror("Can't figure out implicit dcl from context."); - return -1; - } - } - - vec_descrip.name = dclp->name; - vec_descrip.arrcnt = dclp->arrcnt; - vec_descrip.type = dclp->type; - vec_descrip.blk_off = offset; - vec_descrip.blk_num = cur_hdr->nblks; - vec_descrip.nread = 0; - offset += SDFtype_sizes[dclp->type] * dclp->arrcnt; - cur_hdr->nvecs++; - (void)obstack_grow(&cur_hdr->vecs_obs, - &vec_descrip, sizeof(vec_descrip)); -#if YYDEBUG - if(yydebug){ - printf("\t %s %s[%d]", SDFtype_names[dclp->type], dclp->name, - dclp->arrcnt); - printf(" in block %ld at offset %ld\n", - vec_descrip.blk_num, vec_descrip.blk_off); - } -#endif - } - cur_blk.reclen = offset; - - cp = cbase; - for(i=0; indcl; j++){ - dclp = &dclbase[j]; -#if YYDEBUG - if(yydebug) - printf("\t %s %s[%d] (%d) = ", - SDFtype_names[dclp->type], dclp->name, - dclp->arrcnt, i); -#endif - if( dclp->type == SDF_CHAR && cp->type == SDF_STRING){ -#if YYDEBUG - if(yydebug) - printf("\"%s\"\n", cp->u.stringval); -#endif - to = obstack_next_free(&cur_hdr->data_obs); - (void)obstack_blank(&cur_hdr->data_obs, dclp->arrcnt); - /* Should we warn - if strlen(cp->u.stringval) > dclp->arrcnt ???? - It implies that the 'string' won't be null-terminated? */ - (void)strncpy(to, cp->u.stringval, dclp->arrcnt); -#ifdef YYDEBUG - if(yydebug) - printf("Freeing const string 0x%lx\n", - (unsigned long)cp->u.stringval); -#endif - Free(cp->u.stringval); - cp++; - continue; - } - - for(k=0; karrcnt; k++){ - converted = convert_const(cp, dclp->type); - if(converted.type == SDF_NOTYPE){ - yyerror("Failed constant conversion."); - return -1; - } - (void)obstack_grow(&cur_hdr->data_obs, &converted.u, - SDFtype_sizes[converted.type]); - -#ifdef YYDEBUG - if(yydebug){ - printf("(%s)", SDFtype_names[cp->type]); - switch(converted.type){ - case SDF_CHAR: - printf("%c", converted.u.charval); - break; - case SDF_SHORT: - printf("%d", converted.u.shortval); - break; - case SDF_INT: - printf("%d", converted.u.intval); - break; - case SDF_LONG: - printf("%ld", converted.u.longval); - break; - case SDF_INT64: -#if __WORDSIZE==64 - printf("%ld", converted.u.int64val); -#else - printf("%lld", converted.u.int64val); -#endif - break; - case SDF_FLOAT: - printf("%.7g", converted.u.floatval); - break; - case SDF_DOUBLE: - printf("%.17g", converted.u.doubleval); - break; - default: - printf("Unrecognized type: %d\n", converted.type); - break; - } - if(k == dclp->arrcnt-1){ - printf("\n"); - }else{ - printf(", "); - } - } -#endif - cp++; - } - } - } - (void)obstack_free(&dcl_list->obs, NULL); - (void)obstack_free(&consts.obs, NULL); - return 0; -} - -static const_t convert_const(const_t *cp, enum SDF_type_enum newtype) -/* Return a constant of type NEWTYPE, with the same value as */ -/* *CP. If the conversion does not preserve value, then */ -/* return a constant of NOTYPE, with garbage value. */ -{ - const_t value; - double dval = 0.; - int64_t ival = 0; - - if(cp->type == newtype){ - /* IRIX -32 bug fix */ - memcpy(&value, cp, sizeof(value)); - /* value = *cp; */ - return value; - } - - if(cp->type == SDF_STRING || newtype == SDF_STRING){ - value.type = SDF_NOTYPE; - yyerror("Cannot do const conversions with strings.\n"); - return value; - } - - /* Now rely on the fact that a double can faithfully hold */ - /* any other arithmetic type (except long ints on 64-bit archs). */ - switch(cp->type){ - case SDF_CHAR: - dval = (double)cp->u.charval; - break; - case SDF_SHORT: - dval = (double)cp->u.shortval; - break; - case SDF_INT: - dval = (double)cp->u.intval; - ival = cp->u.intval; - break; - case SDF_LONG: - dval = (double)cp->u.longval; - ival = cp->u.longval; - break; - case SDF_INT64: - dval = (double)cp->u.int64val; - ival = cp->u.int64val; - break; - case SDF_FLOAT: - dval = cp->u.floatval; - break; - case SDF_DOUBLE: - dval = cp->u.doubleval; - break; - default: - dval = 0.0; - yyerror("Cannot do const conversions with strings.\n"); - } - - value.type = newtype; - switch(newtype){ - case SDF_CHAR: - value.u.charval = (char)dval; - if( value.u.charval != dval ){ - yyerror("Can't fit value into char."); - value.type = SDF_NOTYPE; - } - break; - case SDF_SHORT: - value.u.shortval = (short)dval; - if( value.u.shortval != dval ){ - yyerror("Can't fit value into short."); - value.type = SDF_NOTYPE; - } - break; - case SDF_INT: - value.u.intval = (int)dval; - if( value.u.intval != dval ){ - value.u.intval = ival; - if( value.u.intval != ival ){ - yyerror("Can't fit value into int."); - value.type = SDF_NOTYPE; - } - break; - } - break; - case SDF_LONG: - value.u.longval = (long)dval; - if( value.u.longval != dval ){ - value.u.longval = ival; - if( value.u.longval != ival ){ - yyerror("Can't fit value into long."); - value.type = SDF_NOTYPE; - } - break; - } - break; - case SDF_INT64: - value.u.int64val = (int64_t)dval; - if( value.u.int64val != dval ){ - value.u.int64val = ival; - if( value.u.int64val != ival ){ - yyerror("Can't fit value into int64_t."); - value.type = SDF_NOTYPE; - } - break; - } - break; - case SDF_FLOAT: - if(dval > FLT_MAX || dval < -FLT_MAX){ - yyerror("Can't fit value into float."); - value.type = SDF_NOTYPE; - } - value.u.floatval = dval; - break; - case SDF_DOUBLE: - value.u.doubleval = dval; - break; - default: - yyerror("Impossible case.\n"); - break; - } - return value; -} - -void *SDFobstack_chunk_alloc(size_t n) -{ - void *p = Malloc(n); -#if YYDEBUG - if(yydebug) - printf("malloc(%ld) = 0x%lx\n", (long)n, (unsigned long)p); -#endif - return p; -} - -void SDFobstack_chunk_free(void *p) -{ -#if YYDEBUG - if(yydebug) - printf("free(0x%lx)\n", (unsigned long)p); -#endif - Free(p); -} - -/* This symbol tells a Flex-based scanner not to bother trying to - call isatty to figure out whether to do char-at-a-time input. The - actual behavior is under our explicit control anyway (see SDF-lex.l), - but linking against fileno() and isatty() can be annoying. */ -#define YY_ALWAYS_INTERACTIVE 1 -#include "SDF-lex.c" - diff --git a/external/libsdf/libSDF/SDF-parse.y b/external/libsdf/libSDF/SDF-parse.y deleted file mode 100644 index eab6ea2..0000000 --- a/external/libsdf/libSDF/SDF-parse.y +++ /dev/null @@ -1,754 +0,0 @@ -%{ -/* - SDF Library for reading Self-Describing Files - Copyright (C) 1991,1992 John K. Salmon - - Terms and conditions are specified in the file "copyright.h", - and more precisely in the file COPYING.LIB which you should have - received with this library. -*/ - -/* We don't rely on bison's -p argument any more. - Instead, just #define the name changes ourselves. These are taken - from the beginning of bison -p output. These are far from a complete - set of external 'yy' names, as a quick run throug 'nm' will show. Maybe - all the others come from lex. I dunno. In any event, the namespace is only - partially cleaned up. Perhaps we should apply for Superfund money - to finish the cleanup? bison -p does no better. -*/ -#define yyparse SDFyyparse -#define yylex SDFyylex -#define yyerror SDFyyerror -#define yylval SDFyylval -#define yychar SDFyychar -#define yydebug SDFyydebug -#define yynerrs SDFyynerrs - -#include -#include -#include -#include -#include "protos.h" -#include "Msgs.h" -#include "SDF-private.h" -#include "obstack.h" -#include "Malloc.h" - -#ifndef __DELTA__ -#define YYDEBUG 1 -#endif - -#if YYDEBUG -/* yacc sends its debug output throught printf. We change that... */ -#define printf Msg_do /* MUST be after protos.h!!! */ -#endif - -#ifdef cray -/* This wants to be a long on the cray?? */ -extern long int yydebug; -#else -extern int yydebug; -#endif -extern void yyerror(char *fmt, ...); - - -static enum SDF_type_enum curtype; -static blk_descrip_t cur_blk; -static int cur_file_offset; -static int cur_data_offset; -static SDF *cur_hdr; -static int no_more_data_blks; -static int zero_len_blknum; - -char *SDFtype_names[] = {"notype", "char", "short", "int", "long", "int64_t", - "float", "double", "string"}; - - int SDFtype_sizes[] = {0, sizeof(char), sizeof(short), sizeof(int), sizeof(long), - sizeof(int64_t), sizeof(float), sizeof(double), sizeof(char *)}; - -static int do_value_param(enum value_param_enum type, const_t value); -static int data_dcl(declaration_t dcl); -static int const_dcl(declaration_t dcl, const_list_t consts); -static void finish_curblk(void); -static const_t convert_const(const_t *cp, enum SDF_type_enum type); -static int finish_parse(void); - -%} - -%token STRUCT -%token NAME -%token TYPE -%token CONST -%token VALUEPARAM -%token PARAMETER -%token EOHDR LEXERROR -%token ';' '=' '[' ']' '{' '}' ',' -%type declaration -%type dcl1 -%type const_lst comma_sep_consts -%type comma_sep_dcls typed_dcl_list many_typed_dcl_list -%union{ - enum SDF_type_enum type; - enum value_param_enum valueparam; - char *string; - const_t constant; - declaration_t declaration; - dcl_list_t dcl_list; - one_dcl_t one_dcl; - const_list_t const_list; -} -%% -hdr : hdr1 {if(finish_parse()) YYERROR;} - | hdr1 EOHDR {if(finish_parse()) YYERROR; else YYACCEPT;} - | LEXERROR {YYERROR;} - ; - -hdr1 : stmt - | hdr1 stmt - ; - -stmt : declaration ';' {if(data_dcl($1)) YYERROR;} - | declaration '=' const_lst ';' {if(const_dcl($1, $3)) YYERROR;} - | PARAMETER VALUEPARAM '=' CONST ';' {if(do_value_param($2, $4)) YYERROR;} - ; - -declaration : typed_dcl_list {$$.dcl_list = $1; $$.Nrec = 1;} - | STRUCT '{' many_typed_dcl_list ';' '}' {$$.dcl_list=$3; $$.Nrec=1;} - | STRUCT '{' many_typed_dcl_list ';' '}' '[' CONST ']' - { - if( $7.type != SDF_INT64 ){ - yyerror("Expected integer constant"); - YYERROR; - }else{ - $$.dcl_list = $3; $$.Nrec = $7.u.int64val; - } - } - | STRUCT '{' many_typed_dcl_list ';' '}' '[' ']' - { $$.dcl_list = $3; $$.Nrec = 0;} - ; - -many_typed_dcl_list : typed_dcl_list {$$ = $1;} - | many_typed_dcl_list ';' typed_dcl_list - { - int sz; - - $$.ndcl = $1.ndcl + $3.ndcl; - $$.obs = $1.obs; - sz = obstack_object_size(&$3.obs); - (void)obstack_grow(&$$.obs, obstack_finish(&$3.obs), sz); - (void)obstack_free(&$3.obs, NULL); - } - ; - -typed_dcl_list: TYPE {curtype = $1;} comma_sep_dcls {$$ = $3;} - ; - -comma_sep_dcls: dcl1 - { - obstack_begin(&$$.obs, 16*sizeof($1)); - $$.ndcl = 1; - (void)obstack_grow(&$$.obs, &$1, sizeof($1)); - } - | comma_sep_dcls ',' dcl1 - { - $$ = $1; - $$.ndcl += 1; - (void)obstack_grow(&$$.obs, &$3, sizeof($3)); - } - ; - -dcl1 : NAME {$$.name = $1; $$.type = curtype; $$.arrcnt = 1;} - | NAME '[' CONST ']' - { - if( $3.type != SDF_INT64 ){ - yyerror("Expected integer constant"); - YYERROR; - }else{ - $$.name = $1; $$.type = curtype; $$.arrcnt = $3.u.int64val; - } - } - | NAME '[' ']' {$$.name=$1; $$.type=curtype; $$.arrcnt = 0;} - ; - -const_lst : CONST - { - $$.nconst = 1; - obstack_begin(&$$.obs, 16*sizeof($1)); - (void)obstack_grow(&$$.obs, &$1, sizeof($1)); - } - | '{' comma_sep_consts '}' {$$ = $2;} - ; - -comma_sep_consts : CONST - { - $$.nconst = 1; - obstack_begin(&$$.obs, 16*sizeof($1)); - (void)obstack_grow(&$$.obs, &$1, sizeof($1)); - } - | comma_sep_consts ',' CONST - { - $$ = $1; - $$.nconst += 1; - (void)obstack_grow(&$$.obs, &$3, sizeof($3)); - } - ; - -%% -static int SDFlineno; - -static const char *Dataname, *Hdrname; - -#ifdef STANDALONE -char SDFerrstring[512]; -unsigned int SDFcpubyteorder(void){return 0;} - -main(int argc, char **argv) -{ - SDF hdr; - - if(argc > 1){ - yydebug = 1; - }else{ - yydebug = 0; - } - SDFyyprepare(&hdr, "-", "-"); - if(yyparse()){ - printf("Terminated on error. \n"); - exit(1); - } - exit(0); -} -#endif - -static int SDF_iomode = MPMY_RDONLY | MPMY_MULTI; - -void SDFsetiomode(int mode) -{ - if (mode == SDF_SINGL) { - SDF_iomode = MPMY_RDONLY | MPMY_SINGL; - } else { - SDF_iomode = MPMY_RDONLY | MPMY_MULTI; - } -} - - - -void SDFyyerror(char *fmt, ...) -{ - char *p; - va_list ap; - - va_start(ap, fmt); - vsprintf(SDFerrstring, fmt, ap); - p = SDFerrstring + strlen(SDFerrstring); - sprintf(p, " lineno = %d\n", SDFlineno); - va_end(ap); -} - -int SDFyyprepare(SDF *hdr, const char *hdrname, const char *dataname) -{ - no_more_data_blks = 0; - - cur_file_offset = 0; - cur_data_offset = 0; - - cur_blk.Nrec = 1; - cur_blk.inmem = 1; - cur_blk.begin_offset = 0; - cur_blk.reclen = 0; - - cur_hdr = hdr; - cur_hdr->nblks = 0; - cur_hdr->nvecs = 0; - /* Assume that MPMY_Fopen does the 'right' thing with "-" */ - if( SDF_Hdropen(hdrname) < 0 ){ - sprintf(SDFerrstring, "SDFopen: could not open %s\n", hdrname); - return -1; - } - Dataname = dataname; - Hdrname = hdrname; - SDFlineno = 0; /* or 1? It's always +-1 anyway */ - SDFlexprepare(); - - obstack_begin(&cur_hdr->blks_obs, 16*sizeof(blk_descrip_t)); - obstack_begin(&cur_hdr->vecs_obs, 32*sizeof(vec_descrip_t)); - obstack_begin(&cur_hdr->data_obs, 2048); - return 0; -} - -static int finish_parse(void) -{ - int i; - - finish_curblk(); - cur_hdr->blks = (blk_descrip_t *)obstack_finish(&cur_hdr->blks_obs); - cur_hdr->vecs = (vec_descrip_t *)obstack_finish(&cur_hdr->vecs_obs); - cur_hdr->data = obstack_finish(&cur_hdr->data_obs); - cur_hdr->vec_names = Malloc(cur_hdr->nvecs * sizeof(char *)); - for(i=0; invecs; i++){ - cur_hdr->vec_names[i] = cur_hdr->vecs[i].name; - } - - if( (Dataname == NULL) || (Dataname[0] == '\0') - || (strcmp(Hdrname, Dataname)==0)){ - cur_hdr->begin_file_offset = SDF_Hdroffset(); - if( cur_hdr->begin_file_offset < 0 ){ - yyerror("Can't get offset of end of header\n"); - return -1; - } - }else{ - cur_hdr->begin_file_offset = 0; - } - SDF_Hdrclose(); - - /* cur_hdr->datafp = MPMY_Fopen(Dataname, MPMY_RDONLY); */ - /* If we come up with a better model for IO, call it here.. */ - cur_hdr->datafp = MPMY_Fopen(Dataname, SDF_iomode); - - Msgf(("cur_hdr->datafp = %p\n", cur_hdr->datafp)); - - if( cur_hdr->datafp == NULL ){ - sprintf(SDFerrstring, "SDFopen: could not open data file: %s\n", - Dataname); - return -1; - } - - if(no_more_data_blks){ - blk_descrip_t *zerolenblk; - off_t bytesleft, recsleft; - off_t datalen; - - zerolenblk = &cur_hdr->blks[zero_len_blknum]; - if(zerolenblk->Nrec != 0){ - yyerror("Zero length block has non-zero length!?\n"); - return -1; - } - if( cur_hdr->begin_file_offset < 0 ){ - yyerror("Can't have zero-len blk in an unseekable file\n"); - return -1; - } - Msgf(("About to call MPMY_Flen\n")); - if( (datalen = MPMY_Flen(cur_hdr->datafp)) < 0 ){ - yyerror("Could not get length of data file.\n"); - return -1; - } - bytesleft = datalen - - (zerolenblk->begin_offset + cur_hdr->begin_file_offset); - Msgf(("datalen = %ld, butesleft = %ld\n", - (long)datalen, (long)bytesleft)); - if( bytesleft < 0 ){ - yyerror("File too short.\n"); - return -1; - } - recsleft = bytesleft/zerolenblk->reclen; - if( recsleft*zerolenblk->reclen != bytesleft ){ - printf("datalen is %ld, bytesleft is %ld\n", (long)datalen, (long)bytesleft); - yyerror("File ends between record boundaries\n"); - return -1; - } - zerolenblk->Nrec = recsleft; - } - return 0; -} - -static int do_value_param(enum value_param_enum param, const_t value) -{ - switch(param){ - case BYTEORDER: - if( value.type != SDF_INT64 ) - return -1; - cur_hdr->byteorder = value.u.int64val; - cur_hdr->swapping = (cur_hdr->byteorder != SDFcpubyteorder()); - break; - } - return 0; -} - - -static int data_dcl(declaration_t dcl) -{ - dcl_list_t *dcl_list; - one_dcl_t *base, *dclp; - int i, offset; - vec_descrip_t vec_descrip; - -#if YYDEBUG - if(yydebug) - printf("Declaration of %ld records:\n", dcl.Nrec); -#endif - if(no_more_data_blks){ - yyerror("You can't have data following an implicit-length dcl.\n"); - return -1; - } - - /* Test to see if we can append this dcl to the current */ - /* block. */ - if(cur_blk.inmem || cur_blk.Nrec != 1 || dcl.Nrec != 1){ - finish_curblk(); - cur_blk.Nrec = dcl.Nrec; - cur_blk.reclen = 0; - cur_blk.inmem = 0; - cur_blk.begin_offset = cur_file_offset; -#if YYDEBUG - if(yydebug) - printf("New block (%d) at offset %d in file\n", - cur_hdr->nblks, cur_file_offset); -#endif - } - - if(dcl.Nrec == 0){ - no_more_data_blks = 1; - zero_len_blknum = cur_hdr->nblks; - } - - offset = cur_blk.reclen; - - dcl_list = &dcl.dcl_list; - base = (one_dcl_t *)obstack_base(&dcl_list->obs); - for(i=0; indcl; i++){ - dclp = &base[i]; - vec_descrip.name = dclp->name; - vec_descrip.arrcnt = dclp->arrcnt; - vec_descrip.type = dclp->type; - vec_descrip.blk_off = offset; - vec_descrip.blk_num = cur_hdr->nblks; - vec_descrip.nread = 0; - offset += SDFtype_sizes[dclp->type] * dclp->arrcnt; - cur_hdr->nvecs++; - (void)obstack_grow(&cur_hdr->vecs_obs, - &vec_descrip, sizeof(vec_descrip)); -#if YYDEBUG - if(yydebug){ - printf("\t %s %s[%d]", SDFtype_names[dclp->type], dclp->name, - dclp->arrcnt); - printf(" in block %ld at offset %ld\n", - vec_descrip.blk_num, vec_descrip.blk_off); - } -#endif - } - (void)obstack_free(&dcl_list->obs, NULL); - cur_blk.reclen = offset; - return 0; -} - -static void finish_curblk(void) -{ - cur_hdr->nblks++; - (void)obstack_grow(&cur_hdr->blks_obs, &cur_blk, sizeof(cur_blk)); - if(cur_blk.inmem){ - cur_data_offset += cur_blk.reclen * cur_blk.Nrec; - }else{ - cur_file_offset += cur_blk.reclen * cur_blk.Nrec; - } -} - -static int const_dcl(declaration_t dcl, const_list_t consts) -{ - dcl_list_t *dcl_list; - one_dcl_t *dclbase, *dclp; - const_t *cp, *cbase, converted; - vec_descrip_t vec_descrip; - int i, j, k; - int offset; - void *to; - - dcl_list = &dcl.dcl_list; - if(dcl.Nrec == 0){ - dcl.Nrec = consts.nconst; -#if 0 /* Was it really this easy?? */ - yyerror("Cannot deal with implicit length constant dcls."); - return -1; -#endif - } - - /* Test to see if we can append this dcl to the current */ - /* block. */ - if(!cur_blk.inmem || cur_blk.Nrec != 1 || dcl.Nrec != 1){ - finish_curblk(); - cur_blk.Nrec = dcl.Nrec; - cur_blk.reclen = 0; - cur_blk.inmem = 1; - cur_blk.begin_offset = cur_data_offset; -#if YYDEBUG - if(yydebug) - printf("New block (%d) at offset %d in data\n", - cur_hdr->nblks, cur_data_offset); -#endif - } - - offset = cur_blk.reclen; - cbase = (const_t *)obstack_base(&consts.obs); - dclbase = (one_dcl_t *)obstack_base(&dcl_list->obs); - - for(i=0; indcl; i++){ - dclp = &dclbase[i]; - if(dclp->arrcnt == 0){ - if(dclp->type == SDF_CHAR - && cbase[i].type == SDF_STRING - && dcl.Nrec == 1){ - dclp->arrcnt = strlen(cbase[i].u.stringval)+1; - /* Round up for padding purposes. */ - dclp->arrcnt = (dclp->arrcnt + 7)& (~0x7); - }else if(i == dcl_list->ndcl-1 && dcl.Nrec == 1){ - dclp->arrcnt = consts.nconst - i; - }else{ - yyerror("Can't figure out implicit dcl from context."); - return -1; - } - } - - vec_descrip.name = dclp->name; - vec_descrip.arrcnt = dclp->arrcnt; - vec_descrip.type = dclp->type; - vec_descrip.blk_off = offset; - vec_descrip.blk_num = cur_hdr->nblks; - vec_descrip.nread = 0; - offset += SDFtype_sizes[dclp->type] * dclp->arrcnt; - cur_hdr->nvecs++; - (void)obstack_grow(&cur_hdr->vecs_obs, - &vec_descrip, sizeof(vec_descrip)); -#if YYDEBUG - if(yydebug){ - printf("\t %s %s[%d]", SDFtype_names[dclp->type], dclp->name, - dclp->arrcnt); - printf(" in block %ld at offset %ld\n", - vec_descrip.blk_num, vec_descrip.blk_off); - } -#endif - } - cur_blk.reclen = offset; - - cp = cbase; - for(i=0; indcl; j++){ - dclp = &dclbase[j]; -#if YYDEBUG - if(yydebug) - printf("\t %s %s[%d] (%d) = ", - SDFtype_names[dclp->type], dclp->name, - dclp->arrcnt, i); -#endif - if( dclp->type == SDF_CHAR && cp->type == SDF_STRING){ -#if YYDEBUG - if(yydebug) - printf("\"%s\"\n", cp->u.stringval); -#endif - to = obstack_next_free(&cur_hdr->data_obs); - (void)obstack_blank(&cur_hdr->data_obs, dclp->arrcnt); - /* Should we warn - if strlen(cp->u.stringval) > dclp->arrcnt ???? - It implies that the 'string' won't be null-terminated? */ - (void)strncpy(to, cp->u.stringval, dclp->arrcnt); -#ifdef YYDEBUG - if(yydebug) - printf("Freeing const string 0x%lx\n", - (unsigned long)cp->u.stringval); -#endif - Free(cp->u.stringval); - cp++; - continue; - } - - for(k=0; karrcnt; k++){ - converted = convert_const(cp, dclp->type); - if(converted.type == SDF_NOTYPE){ - yyerror("Failed constant conversion."); - return -1; - } - (void)obstack_grow(&cur_hdr->data_obs, &converted.u, - SDFtype_sizes[converted.type]); - -#ifdef YYDEBUG - if(yydebug){ - printf("(%s)", SDFtype_names[cp->type]); - switch(converted.type){ - case SDF_CHAR: - printf("%c", converted.u.charval); - break; - case SDF_SHORT: - printf("%d", converted.u.shortval); - break; - case SDF_INT: - printf("%d", converted.u.intval); - break; - case SDF_LONG: - printf("%ld", converted.u.longval); - break; - case SDF_INT64: -#if __WORDSIZE==64 - printf("%ld", converted.u.int64val); -#else - printf("%lld", converted.u.int64val); -#endif - break; - case SDF_FLOAT: - printf("%.7g", converted.u.floatval); - break; - case SDF_DOUBLE: - printf("%.17g", converted.u.doubleval); - break; - default: - printf("Unrecognized type: %d\n", converted.type); - break; - } - if(k == dclp->arrcnt-1){ - printf("\n"); - }else{ - printf(", "); - } - } -#endif - cp++; - } - } - } - (void)obstack_free(&dcl_list->obs, NULL); - (void)obstack_free(&consts.obs, NULL); - return 0; -} - -static const_t convert_const(const_t *cp, enum SDF_type_enum newtype) -/* Return a constant of type NEWTYPE, with the same value as */ -/* *CP. If the conversion does not preserve value, then */ -/* return a constant of NOTYPE, with garbage value. */ -{ - const_t value; - double dval = 0.; - int64_t ival = 0; - - if(cp->type == newtype){ - /* IRIX -32 bug fix */ - memcpy(&value, cp, sizeof(value)); - /* value = *cp; */ - return value; - } - - if(cp->type == SDF_STRING || newtype == SDF_STRING){ - value.type = SDF_NOTYPE; - yyerror("Cannot do const conversions with strings.\n"); - return value; - } - - /* Now rely on the fact that a double can faithfully hold */ - /* any other arithmetic type (except long ints on 64-bit archs). */ - switch(cp->type){ - case SDF_CHAR: - dval = (double)cp->u.charval; - break; - case SDF_SHORT: - dval = (double)cp->u.shortval; - break; - case SDF_INT: - dval = (double)cp->u.intval; - ival = cp->u.intval; - break; - case SDF_LONG: - dval = (double)cp->u.longval; - ival = cp->u.longval; - break; - case SDF_INT64: - dval = (double)cp->u.int64val; - ival = cp->u.int64val; - break; - case SDF_FLOAT: - dval = cp->u.floatval; - break; - case SDF_DOUBLE: - dval = cp->u.doubleval; - break; - default: - dval = 0.0; - yyerror("Cannot do const conversions with strings.\n"); - } - - value.type = newtype; - switch(newtype){ - case SDF_CHAR: - value.u.charval = (char)dval; - if( value.u.charval != dval ){ - yyerror("Can't fit value into char."); - value.type = SDF_NOTYPE; - } - break; - case SDF_SHORT: - value.u.shortval = (short)dval; - if( value.u.shortval != dval ){ - yyerror("Can't fit value into short."); - value.type = SDF_NOTYPE; - } - break; - case SDF_INT: - value.u.intval = (int)dval; - if( value.u.intval != dval ){ - value.u.intval = ival; - if( value.u.intval != ival ){ - yyerror("Can't fit value into int."); - value.type = SDF_NOTYPE; - } - break; - } - break; - case SDF_LONG: - value.u.longval = (long)dval; - if( value.u.longval != dval ){ - value.u.longval = ival; - if( value.u.longval != ival ){ - yyerror("Can't fit value into long."); - value.type = SDF_NOTYPE; - } - break; - } - break; - case SDF_INT64: - value.u.int64val = (int64_t)dval; - if( value.u.int64val != dval ){ - value.u.int64val = ival; - if( value.u.int64val != ival ){ - yyerror("Can't fit value into int64_t."); - value.type = SDF_NOTYPE; - } - break; - } - break; - case SDF_FLOAT: - if(dval > FLT_MAX || dval < -FLT_MAX){ - yyerror("Can't fit value into float."); - value.type = SDF_NOTYPE; - } - value.u.floatval = dval; - break; - case SDF_DOUBLE: - value.u.doubleval = dval; - break; - default: - yyerror("Impossible case.\n"); - break; - } - return value; -} - -void *SDFobstack_chunk_alloc(size_t n) -{ - void *p = Malloc(n); -#if YYDEBUG - if(yydebug) - printf("malloc(%ld) = 0x%lx\n", (long)n, (unsigned long)p); -#endif - return p; -} - -void SDFobstack_chunk_free(void *p) -{ -#if YYDEBUG - if(yydebug) - printf("free(0x%lx)\n", (unsigned long)p); -#endif - Free(p); -} - -/* This symbol tells a Flex-based scanner not to bother trying to - call isatty to figure out whether to do char-at-a-time input. The - actual behavior is under our explicit control anyway (see SDF-lex.l), - but linking against fileno() and isatty() can be annoying. */ -#define YY_ALWAYS_INTERACTIVE 1 -#include "SDF-lex.c" diff --git a/external/libsdf/libSDF/SDF-private.h b/external/libsdf/libSDF/SDF-private.h deleted file mode 100644 index a154976..0000000 --- a/external/libsdf/libSDF/SDF-private.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - SDF Library for reading Self-Describing Files - Copyright (C) 1991,1992 John K. Salmon - - Terms and conditions are specified in the file "copyright.h", - and more precisely in the file COPYING.LIB which you should have - received with this library. -*/ -#ifndef sdfprivateDOTh -#define sdfprivateDOTh -#include -#include -#include "stdio.h" /* from this directory!! */ -#include "obstack.h" - -/* Exact copy of declaration in SDF.h */ -enum SDF_type_enum{SDF_NOTYPE, - SDF_CHAR, - SDF_SHORT, - SDF_INT, - SDF_LONG, - SDF_INT64, - SDF_FLOAT, - SDF_DOUBLE, - SDF_STRING}; - -extern char SDFerrstring[]; - -enum toggle_param_enum{NOTHING}; - -enum value_param_enum{BYTEORDER}; - -/* How the lexical analyzer returns constants. */ -typedef struct{ - enum SDF_type_enum type; - union{ - char charval; - short shortval; - int intval; - long longval; - int64_t int64val; - float floatval; - double doubleval; - char *stringval; - } u; -} const_t; - -typedef struct{ - int nconst; - struct obstack obs; -} const_list_t; - -typedef struct{ - char *name; - enum SDF_type_enum type; - int arrcnt; -} one_dcl_t; - -typedef struct{ - int ndcl; - struct obstack obs; -} dcl_list_t; - -typedef struct{ - dcl_list_t dcl_list; - int64_t Nrec; -} declaration_t; - -typedef struct{ - char *name; - enum SDF_type_enum type; - int arrcnt; - int64_t blk_off; - int64_t blk_num; - int64_t nread; -} vec_descrip_t; - -typedef struct{ - int reclen; - int inmem; - int64_t Nrec; - int64_t begin_offset; -} blk_descrip_t; - -typedef struct{ - int nblks; - struct obstack blks_obs; - blk_descrip_t *blks; - int nvecs; - struct obstack vecs_obs; - vec_descrip_t *vecs; - char **vec_names; - struct obstack data_obs; - void *data; - MPMYFile *datafp; - int64_t begin_file_offset; - int byteorder; - int swapping; - int hashsz; - vec_descrip_t **hashtbl; -} SDF; - -void SDFlexprepare(void); -int SDFyyprepare(SDF *hdr, const char *hdrname, const char *dataname); -void SDFobstack_chunk_free(void *p); -void *SDFobstack_chunk_alloc(size_t n); - -int SDF_Hdropen(const char *name); -void SDF_Hdrclose(void); -int SDF_Hdroffset(void); -int SDF_Hdrgetc(); - -#define obstack_chunk_alloc SDFobstack_chunk_alloc -#define obstack_chunk_free SDFobstack_chunk_free - -#include "SDF.h" - - -#endif /* sdfprivateDOTh */ diff --git a/external/libsdf/libSDF/SDFfuncs.c b/external/libsdf/libSDF/SDFfuncs.c deleted file mode 100644 index fb10319..0000000 --- a/external/libsdf/libSDF/SDFfuncs.c +++ /dev/null @@ -1,941 +0,0 @@ -/* - SDF Library for reading Self-Describing Files - Copyright (C) 1991,1992 John K. Salmon - - Terms and conditions are specified in the file "copyright.h", - and more precisely in the file COPYING.LIB which you should have - received with this library. -*/ -/* Implement the user-visible functions that make up the */ -/* SDF package. */ - -/* Using alloca reduces memory fragmentation, and allows the halo */ -/* finder to work on larger datasets */ -#define USE_ALLOCA - -#include -#include -#include -#include -#include -#ifdef USE_ALLOCA -#include -#endif -#include "Msgs.h" -#include "stdio.h" /* for sprintf, etc. No 'real' stdio */ -#include "SDF-private.h" -#include "obstack.h" -#include "byteswap.h" -#include "Malloc.h" -#include "protos.h" -#include "mpmy.h" -#include "mpmy_io.h" - -/* max_bufsz is the maximum read-buffer that we will attempt to - malloc. The code in rdvecs is capable of requesting arbitrarily - large blocks and scaling back (in powers of 2) until malloc returns - non-NULL. That doesn't seem like a good idea on virtual systems, - though, so the maximum first attempt is dynamically settable with - SDFsetmaxbufsz. Setting it to zero will remove the limit. This is - the initial value. */ -#define DEFAULT_MAX_BUFSZ (256LL*1024*1024) - -static void buildhash(SDF *hdr); -static vec_descrip_t *lookup(const char *name, SDF *hdr); -static int compar_func(const void *p1, const void *p2); -static vec_descrip_t **compar_vds; -static unsigned char junk[4] = {0x12, 0x34, 0x56, 0x78}; -static unsigned int *cpubyteorder = (unsigned int *)&junk[0]; -static int max_bufsz = DEFAULT_MAX_BUFSZ; - -char SDFerrstring[256]; -extern int SDFyyparse(void); - -/* This is a non-guaranteed way to test if a file is SDF or not. */ -/* It really only tests the initial comment! This is not fail-safe! */ -int SDFissdf(const char *name){ - MPMYFile *fp; - int result = 1; - int c; - char buf[64]; - int bufcnt = 0; - - if( MPMY_Initialized() == 0 ){ - MPMY_Init(0, NULL); - } - /* Assume we do the 'right' thing with "-" */ - /* but what IS the right thing?? (see below) */ - fp = MPMY_Fopen(name, MPMY_RDONLY | MPMY_SINGL | MPMY_IOZERO); - if( fp == NULL ) - return 0; - - buf[bufcnt] = 0; /* In case read returns nothing */ - MPMY_Fread(buf, 1, 64, fp); - if( (c=buf[bufcnt++]) != '#' ){ result=0; goto done;} - while( isspace(c = buf[bufcnt++]) && c != '\n' ); - if( c == '\n' ) { result=0; goto done; } - if( c != 'S' ) { result=0; goto done; } - if( buf[bufcnt++] != 'D' ) { result=0; goto done; } - if( buf[bufcnt++] != 'F' ) { result=0; goto done; } - done: - MPMY_Fclose(fp); - - return result; -} - -SDF *SDFopen(const char *hdrfname, const char *datafname) -{ - SDF *hdr; - int parseerr; - - /* Is this a good idea? Does it promote sloppy programming? Or does - it allow a program that has no interest in MPMY to behave as - expected? Or does it belong in MPMY_Fopen instead? */ - if( MPMY_Initialized() == 0 ){ - MPMY_Init(0, NULL); - } - - if( datafname == NULL ){ - sprintf(SDFerrstring, "SDFopen: NULL data file %s\n", datafname); - return NULL; - } - - hdr = Calloc(1, sizeof(SDF)); - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFopen: could not calloc space for hdr\n"); - return NULL; - } - /* Handle the case of only one name in the arg list. */ - /* Don't worry about which one it is. Is this right? */ - if( hdrfname == NULL || hdrfname[0] == '\0' ) - hdrfname = datafname; - if( datafname == NULL || datafname[0] == '\0' ) - datafname = hdrfname; - - Msgf(("SDFopen: Calling SDFyyprepare(ptr, hdr=%s, data=%s)\n", hdrfname, datafname)); - if( SDFyyprepare(hdr, hdrfname, datafname) < 0 ){ - /* Hopefully, errstring was already set... */ - Free(hdr); - return NULL; - } - - parseerr= SDFyyparse(); - - if(parseerr){ - /* Try to free up whatever's been allocated inside the hdr */ - SDFclose(hdr); - return NULL; - }else{ - Msgf(("SDFopen: SDFyyparse completed ok\n")); - /* buildhash belongs in SDF_finishparse, but then I'd need to add - a bunch more externals... Yuck. */ - buildhash(hdr); - return hdr; - } -} - -int SDFclose(SDF *hdr) -{ - int i; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFclose: not an SDF hdr\n"); - return -1; - } - /* The check here is necessary in case we are trying to bail */ - /* out from inside SDFopen on a parse error. Cleaning up the */ - /* mess after a parse error still needs work! */ - if( hdr->vecs ){ - for(i=0; invecs; i++){ - Free(hdr->vecs[i].name); - } - } - obstack_free(&hdr->blks_obs, NULL); - obstack_free(&hdr->vecs_obs, NULL); - obstack_free(&hdr->data_obs, NULL); - if( hdr->vec_names ) - Free(hdr->vec_names); - if( hdr->datafp ) - MPMY_Fclose(hdr->datafp); - if( hdr->hashtbl ) - Free(hdr->hashtbl); - Free(hdr); - return 0; -} - -int SDFnvecs(SDF *hdr) -{ - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFnvecs: not an SDF hdr\n"); - return -1; - } - return hdr->nvecs; -} - -int SDFseekable(SDF *hdr) -{ - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFseekable: not an SDF hdr\n"); - return -1; - } - return (MPMY_Fseek(hdr->datafp, 0, MPMY_SEEK_CUR) >= 0); -} - -int SDFhasname(const char *name, SDF *hdr) -{ - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFhasname: not an SDF hdr\n"); - return -1; - } - return (lookup(name, hdr)) ? 1 : 0; -} - -char **SDFvecnames(SDF *hdr) -{ - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFvecnames: not an SDF hdr\n"); - return NULL; - } - return hdr->vec_names; -} - -int64_t SDFnrecs(const char *name, SDF *hdr) -{ - vec_descrip_t *desc; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFnrecs: not an SDF hdr\n"); - return -1; - } - desc = lookup(name, hdr); - if(desc) - return hdr->blks[desc->blk_num].Nrec; - else - return 0; -} - -int SDFarrcnt(const char *name, SDF *hdr) -{ - vec_descrip_t *desc; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFarrcnt: not an SDF hdr\n"); - return -1; - } - desc = lookup(name, hdr); - if(desc) - return desc->arrcnt; - else - return 0; -} - -enum SDF_type_enum SDFtype(const char *name, SDF *hdr) -{ - vec_descrip_t *desc; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFtype: not an SDF hdr\n"); - return SDF_NOTYPE; - } - desc = lookup(name, hdr); - if(desc) - return desc->type; - else - return SDF_NOTYPE; -} - -int SDFtell(const char *name, SDF *hdr) -{ - vec_descrip_t *desc; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFtell: not an SDF hdr\n"); - return -1; - } - desc = lookup(name, hdr); - if(desc) - return desc->nread; - else - return -1; -} - -int SDFseek(const char *name, int64_t offset, int whence, SDF *hdr) -{ - vec_descrip_t *desc; - int64_t nrec; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFseek: not an SDF hdr\n"); - return -1; - } - desc = lookup(name, hdr); - if(desc == NULL) - return -1; - - switch(whence){ - case SDF_SEEK_SET: - desc->nread = offset; - break; - case SDF_SEEK_CUR: - desc->nread += offset; - break; - case SDF_SEEK_END: - nrec = hdr->blks[desc->blk_num].Nrec ; - if(nrec == 0) - return -1; - desc->nread = nrec + offset; - } - return 0; -} - -/* SDFfileoffset and SDFfilestride are for those who think they */ -/* can outsmart SDF*rdvecs*. They tell you the offset of the FIRST */ -/* element of NAME in the file, and the stride between successive */ -/* elements. They do not pay any attention to the current seek pointer. */ -/* We do not provide SDFfilefp because we don't want you to mess with */ -/* our file pointer. Open the file yourself if you're so smart... */ -int64_t SDFfileoffset(const char *name, SDF *hdr){ - vec_descrip_t *desc; - blk_descrip_t *blk; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFfileoffset: not an SDF hdr\n"); - return -1; - } - if( hdr->begin_file_offset < 0 ){ - sprintf(SDFerrstring, "SDFfileoffset: unseekable file\n"); - return -1; - } - - desc = lookup(name, hdr); - if(desc == NULL) - return -1; - blk = &hdr->blks[desc->blk_num]; - if( blk->inmem ){ - sprintf(SDFerrstring, "SDFfileoffset: %s not in data segment\n", name); - return -1; - } - return blk->begin_offset + desc->blk_off + hdr->begin_file_offset; -} - -int64_t SDFfilestride(const char *name, SDF *hdr){ - vec_descrip_t *desc; - blk_descrip_t *blk; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFfilestride: not an SDF hdr\n"); - return -1; - } - desc = lookup(name, hdr); - if(desc == NULL) - return -1; - blk = &hdr->blks[desc->blk_num]; - if( blk->inmem ){ - sprintf(SDFerrstring, "SDFfilestride: %s not in data segment\n", name); - return -1; - } - return blk->reclen; -} - -unsigned int SDFcpubyteorder(void){ - return *cpubyteorder; -} - -unsigned int SDFbyteorder(SDF *hdr){ - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFbyteorder: not an SDF hdr\n"); - return -1; - } - /* This is either 0 or the value set by a 'parameter byteorder=' stmt */ - return hdr->byteorder; -} - -int SDFswap(SDF *hdr){ - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFswap: not an SDF hdr\n"); - return -1; - } - hdr->swapping = 1; - return 0; -} - -int SDFnoswap(SDF *hdr){ - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFnoswap: not an SDF hdr\n"); - return -1; - } - hdr->swapping = 0; - return 0; -} - -int SDFisswapping(SDF *hdr){ - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFisswapping: not an SDF hdr\n"); - return -1; - } - return hdr->swapping; -} - -int SDFsetmaxbufsz(int new){ - int ret = max_bufsz; - max_bufsz = new; - return ret; -} - -int SDFrdvecs(SDF *hdr, ... - /* char *name, int n, void *address, int stride, ... */ ) -{ - va_list ap; - int ret; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFrdvecs: not an SDF hdr\n"); - return -1; - } - va_start(ap, hdr); - ret = SDFrdvecsv(hdr, ap); - va_end(ap); - return ret; -} - -int SDFrdvecsv(SDF *hdr, va_list ap) -{ - int *narray; - char **namearray; - void **addressarray; - int *stridearray; - struct obstack nobs; - struct obstack nameobs; - struct obstack addressobs; - struct obstack strideobs; - int nrequests; - char *name; - int stride, n; - void *address; - int ret; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFrdvecsv: not an SDF hdr\n"); - return -1; - } - obstack_begin(&nameobs, 32*sizeof(char *)); - obstack_begin(&strideobs, 32*sizeof(int)); - obstack_begin(&nobs, 32*sizeof(int)); - obstack_begin(&addressobs, 32*sizeof(void *)); - - nrequests = 0; - while( (name = va_arg(ap, char *)) ){ - nrequests++; - obstack_ptr_grow(&nameobs, name); - n = va_arg(ap, int); - obstack_int_grow(&nobs, n); - address = va_arg(ap, void *); - obstack_ptr_grow(&addressobs, address); - stride = va_arg(ap, int); - obstack_int_grow(&strideobs, stride); - } - obstack_int_grow(&nobs, 0); - obstack_int_grow(&strideobs, 0); - obstack_ptr_grow(&nameobs, NULL); - obstack_ptr_grow(&addressobs, NULL); - - narray = (int *)obstack_finish(&nobs); - namearray = (char **)obstack_finish(&nameobs); - addressarray = (void **)obstack_finish(&addressobs); - stridearray = (int *)obstack_finish(&strideobs); - ret = SDFrdvecsarr(hdr, nrequests, - namearray, narray, addressarray, stridearray); - obstack_free(&nobs, NULL); - obstack_free(&nameobs, NULL); - obstack_free(&addressobs, NULL); - obstack_free(&strideobs, NULL); - return ret; -} - -int SDFrdvecsarr(SDF *hdr, int nreq, - char **names, int *ns, void **addresses, int *strides) -{ - int64_t *starts; - int i; - int ret; - vec_descrip_t *descrip; - - starts = Malloc(nreq*sizeof(int64_t)); - if( starts == NULL && nreq>0 ){ - sprintf(SDFerrstring, "Could not malloc tmp space in SDFrdvecsarr\n"); - return -1; - } - - for(i=0; inread; - } - if( (ret = SDFseekrdvecsarr(hdr, nreq, names, - starts, ns, addresses, strides)) ){ - goto outahere; - } - /* At this point, we have successfully looked up all */ - /* the names twice (at least). */ - for(i=0; inread += ns[i]; - } - outahere: - Free(starts); - return ret; -} - -int SDFseekrdvecs(SDF *hdr, ... - /* char *name, int start, int n, void *addr, int stride, ... */ ) -{ - va_list ap; - int ret; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFseekrdvecs: not an SDF hdr\n"); - return -1; - } - va_start(ap, hdr); - ret = SDFseekrdvecsv(hdr, ap); - va_end(ap); - return ret; -} - -int SDFseekrdvecsv(SDF *hdr, va_list ap) -{ - int *narray; - int64_t *startarray; - char **namearray; - void **addressarray; - int *stridearray; - struct obstack nobs; - struct obstack nameobs; - struct obstack startobs; - struct obstack addressobs; - struct obstack strideobs; - int nrequests; - char *name; - int64_t start; - int64_t zero64 = 0; - int stride, n; - void *address; - int ret; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFseekrdvecsv: not an SDF hdr\n"); - return -1; - } - obstack_begin(&nameobs, 32*sizeof(char *)); - obstack_begin(&startobs, 32*sizeof(int64_t)); - obstack_begin(&strideobs, 32*sizeof(int)); - obstack_begin(&nobs, 32*sizeof(int)); - obstack_begin(&addressobs, 32*sizeof(void *)); - - nrequests = 0; - while( (name = va_arg(ap, char *)) ){ - nrequests++; - obstack_ptr_grow(&nameobs, name); - start = va_arg(ap, int64_t); - obstack_grow(&startobs, &start, sizeof(int64_t)); - n = va_arg(ap, int); - obstack_int_grow(&nobs, n); - address = va_arg(ap, void *); - obstack_ptr_grow(&addressobs, address); - stride = va_arg(ap, int); - obstack_int_grow(&strideobs, stride); - } - obstack_int_grow(&nobs, 0); - obstack_grow(&startobs, &zero64, sizeof(int64_t)); - obstack_int_grow(&strideobs, 0); - obstack_ptr_grow(&nameobs, NULL); - obstack_ptr_grow(&addressobs, NULL); - - narray = (int *)obstack_finish(&nobs); - namearray = (char **)obstack_finish(&nameobs); - startarray = (int64_t *)obstack_finish(&startobs); - addressarray = (void **)obstack_finish(&addressobs); - stridearray = (int *)obstack_finish(&strideobs); - ret = SDFseekrdvecsarr(hdr, nrequests, - namearray, startarray, narray, addressarray, stridearray); - obstack_free(&nobs, NULL); - obstack_free(&nameobs, NULL); - obstack_free(&startobs, NULL); - obstack_free(&addressobs, NULL); - obstack_free(&strideobs, NULL); - return ret; -} - -static -void no_problem(const char *fmt, ...){ - /* Pass this to the MallocHandler function to tell Malloc that we - know what we're doing, and we really can recover from malloc - returning null! */ - return; -} - -int SDFseekrdvecsarr(SDF *hdr, int nreq, - char **names, int64_t *starts, int *ns, void **addresses, int *strides) -{ - int nn; - off_t fileoffset; - int i; - int64_t nrec; - int vecnum, first; - int next_blknum; - int last_blknum; - int64_t sz_needed; - int *sort_index; - vec_descrip_t *descrip, **vd_array; - char *fromptr, *toptr; - char *recptr, *buf; - int64_t buf_sz; - int64_t last_rec, first_rec, new_last_rec; - blk_descrip_t *blk; - int stride, sz; - int ret; - int64_t nread, rec_cnt, rec_left, ncopy, ntry; - int64_t *nleft, *seekto; - char **toptr_arr; - int64_t whole_sz; - Error_t oldmallochandler; - - if( hdr == NULL ){ - sprintf(SDFerrstring, "SDFseekrdvecsarr: not an SDF hdr\n"); - return -1; - } - buf = NULL; - buf_sz = 0; -#ifdef USE_ALLOCA - sort_index = alloca(nreq*sizeof(int)); - vd_array = alloca(nreq*sizeof(vec_descrip_t *)); - nleft = alloca(nreq*sizeof(int64_t)); - toptr_arr = alloca(nreq*sizeof(char *)); - seekto = alloca(nreq*sizeof(int64_t)); -#else - sort_index = Malloc(nreq*sizeof(int)); - vd_array = Malloc(nreq*sizeof(vec_descrip_t *)); - nleft = Malloc(nreq*sizeof(int64_t)); - toptr_arr = Malloc(nreq*sizeof(char *)); - seekto = Malloc(nreq*sizeof(int64_t)); -#endif - - if( nreq>0 && (sort_index == NULL - || vd_array == NULL || nleft == NULL || toptr_arr == NULL - || seekto == NULL) ){ - sprintf(SDFerrstring, - "SDFseekrdvecsarr: Malloc failed\n" - "sort_index(%lu) = 0x%lx, vd_array(%lu) = 0x%lx\n", - (unsigned long)nreq*sizeof(int), (unsigned long)sort_index, - (unsigned long)nreq*sizeof(vec_descrip_t), - (unsigned long)vd_array); - ret = -1; - goto outahere; - } - - for(i=0; iblks[vd_array[i]->blk_num].Nrec; - if(nrec > 0 && starts[i] + ns[i] > nrec){ - ret = -1; - Msg_do("nrec %ld i %d starts[i] %ld ns[i] %d\n", - nrec, i, starts[i], ns[i]); - sprintf(SDFerrstring, - "SDFseekrdvecsarr: attempt to read past end of vector \"%s\"", - names[i]); - goto outahere; - } - } - - compar_vds = vd_array; - qsort(sort_index, nreq, sizeof(sort_index[0]), compar_func); - /* Now the descrip_list is sorted so that we can do all the */ - /* vectors in the same block at once. */ - - vecnum = 0; - while( vecnum < nreq ){ - descrip = vd_array[sort_index[vecnum]]; - first = vecnum; - next_blknum = descrip->blk_num; - blk = &hdr->blks[next_blknum]; - first_rec = starts[sort_index[vecnum]]; - last_rec = first_rec; - do{ - new_last_rec = ns[sort_index[vecnum]] + starts[sort_index[vecnum]]; - if(new_last_rec > last_rec) - last_rec = new_last_rec; - last_blknum = next_blknum; - if(++vecnum == nreq) - break; - descrip = vd_array[sort_index[vecnum]]; - next_blknum = descrip->blk_num; - }while( last_blknum==next_blknum ); - - /* We are going to do all the vectors between first and vecnum */ - /* all at once. They all point at the same block. */ - rec_left = rec_cnt = last_rec - first_rec; - for(i=first; iinmem){ - recptr = ((char *)hdr->data) + blk->begin_offset + blk->reclen*first_rec; - fileoffset = 0; /* not necessary, but it quiets a warning */ - }else{ - whole_sz = blk->reclen * rec_left; - if( max_bufsz > 0 && whole_sz > max_bufsz ){ - sz_needed = (max_bufsz/blk->reclen)*blk->reclen; - if( sz_needed < blk->reclen ) - sz_needed = blk->reclen; - }else{ - sz_needed = whole_sz; - } - if( sz_needed > buf_sz ){ - oldmallochandler = MallocHandler(no_problem); - if( buf ) - Free(buf); - buf_sz = sz_needed; - buf = Malloc(buf_sz); - while( buf == NULL && buf_sz >= blk->reclen ){ - buf_sz >>= 1; - buf = Malloc(buf_sz); - } - MallocHandler(oldmallochandler); - if( buf == NULL ){ - sprintf(SDFerrstring, "SDFrdvecsarr: no space!\n"); - ret = -1; - goto outahere; - } - } - recptr = buf; - /* Repaired by msw Mon Jul 11 14:35:19 PDT 1994 */ - /* Repaired again by johns Tue Jun 27 14:55:42 EST 1995 */ - fileoffset = blk->begin_offset + (off_t)blk->reclen * first_rec - + hdr->begin_file_offset; - Msgf(("blk->reclen %d, first_rec %ld\n", blk->reclen, first_rec)); - Msgf(("fileoffset is %ld\n", fileoffset)); - Msgf(("buf_sz is %ld\n", buf_sz)); - } - - while( rec_left > 0 ){ - if(blk->inmem){ - nread = rec_left; - rec_left = 0; - }else{ - if( blk->reclen > buf_sz ){ - sprintf(SDFerrstring, "SDFrdvecsarr: not enough for one record!\n"); - ret = -1; - goto outahere; - } - whole_sz = blk->reclen * rec_left; - if( whole_sz > buf_sz ){ - ntry = (buf_sz-blk->reclen)/blk->reclen + 1; - }else{ - ntry = rec_left; - } - - /* SDFlib2 model has one file pointer, thus use SEEK_SET */ - if((nread = MPMY_Fseekrd(hdr->datafp, fileoffset, - MPMY_SEEK_SET, buf, blk->reclen, ntry)) - != ntry ){ - ret = -1; - sprintf(SDFerrstring, - "SDFrdvecsarr: fseekrd(offset=%ld, SEEK_CUR, reclen=%d, ntry=%ld) only got %ld, errno=%d\n", - fileoffset, blk->reclen, ntry, nread, errno); - goto outahere; - } - rec_left -= nread; - fileoffset += blk->reclen * (off_t)nread; - } - - for(i=first; i (first_rec + nread) || nleft[i] == 0 ) - continue; - fromptr = recptr + (seekto[i] - first_rec)*blk->reclen - + descrip->blk_off; - ncopy = nread - (seekto[i] - first_rec); - if( ncopy > nleft[i] ){ - ncopy = nleft[i]; - } - toptr = toptr_arr[i]; - stride = strides[sort_index[i]]; - sz = SDFtype_sizes[descrip->type]; - if( stride == 0 ) - stride = sz*descrip->arrcnt; - if( sz*descrip->arrcnt > stride ){ - /* This could have been checked earlier!!! */ - sprintf(SDFerrstring, "stride for %s not long enough to step over successive elements. arrcnt=%d, unit_sz=%d, stride=%d\n", - descrip->name, descrip->arrcnt, sz, stride); - ret = -1; - goto outahere; - } - for(nn=0; nn< ncopy; nn++){ - if(!blk->inmem && hdr->swapping){ - if(Byteswap( sz, descrip->arrcnt, fromptr, toptr)){ - sprintf(SDFerrstring, "SDFswapn(%d, %d, 0x%lx, 0x%lx) Failed", - sz, descrip->arrcnt, - (unsigned long)fromptr, - (unsigned long)toptr); - /* There's probably more cleaning up to do! */ - ret = -1; - goto outahere; - } - }else{ - (void)memcpy( toptr, fromptr, sz * descrip->arrcnt); - } - fromptr += blk->reclen; - toptr += stride; - } - seekto[i] += ncopy; - nleft[i] -= ncopy; - toptr_arr[i] = toptr; - } - first_rec += nread; - } - } - ret = 0; - outahere: - /* alloca would be simpler! */ - /* The tests are not necessary according to ANSI... */ -#ifndef USE_ALLOCA - if( seekto ) Free(seekto); - if( toptr_arr ) Free(toptr_arr); - if( nleft ) Free(nleft); - if( vd_array ) Free(vd_array); - if( sort_index ) Free(sort_index); -#endif - if( buf ) Free(buf); - return ret; -} - -static int compar_func(const void *p1, const void *p2){ - int i1 = *(int *)p1; - int i2 = *(int *)p2; - vec_descrip_t *d1 = compar_vds[i1]; - vec_descrip_t *d2 = compar_vds[i2]; - - if(d1->blk_num < d2->blk_num) - return -1; - else if(d1->blk_num > d2->blk_num) - return 1; - else if(d1->nread < d2->nread) - return -1; - else if(d1->nread > d2->nread) - return 1; - else if(d1->blk_off < d2->blk_off) - return -1; - else if(d1->blk_off > d2->blk_off) - return 1; - else - return 0; -} - -/* a few prime numbers chosen entirely at random... */ -#define NCOEF (sizeof(hashcoef)/sizeof(*hashcoef)) -static int hashcoef[] = { 17, 37, 3, 97, 57, 23, 151, 7, 41 }; - -/* - This completely bogus hash function computes a linear combination of - characters in the word. -*/ -static int SDFhash(const char *word, SDF *hdr){ - int i; - const char *p; - int sum = 0; - - p = word; - i = 0; - while(*p){ - sum += hashcoef[i] * *p; - p++; - if( ++i == NCOEF ) - i = 0; - } - Msgf(("hash(%s) = %d%%%d = %d\n", word, sum, hdr->hashsz, sum%hdr->hashsz)); - return sum % hdr->hashsz; -} - -static int isprime(int n){ - int d; - /* this only needs to work for small O(few hundred) values of n */ - /* first make sure it's not even */ - if( (n&1) == 0 ) - return 0; - /* Extremely naive. Now check all odd potential divisors up to sqrt(n) */ - for(d = 3; d*d<=n ; d+=2){ - if( n%d == 0 ) - return 0; - } - return 1; -} - -static int nextprime(int n){ - Msgf(("nextprime(%d) = ", n)); - if( (n&1) == 0 ) - n++; - while(!isprime(n)) n+=2; - Msgf(("%d\n", n)); - return n; -} - -static void buildhash(SDF *hdr){ - int sz; - int i, h; - - sz = nextprime(5*hdr->nvecs); - Msgf(("hash table of size %d\n", sz)); - hdr->hashsz = sz; - hdr->hashtbl = Calloc(sz, sizeof(*hdr->hashtbl)); - - for(i=0; invecs; i++){ - h = SDFhash(hdr->vecs[i].name, hdr); - while( hdr->hashtbl[h] != NULL ){ - Msgf(("build: hcollision between %s and %s in name-space\n", - hdr->hashtbl[h]->name, hdr->vecs[i].name)); - h++; - if(h==sz) /* wrap */ - h = 0; - } - hdr->hashtbl[h] = &hdr->vecs[i]; - } -} - -static vec_descrip_t *lookup(const char *name, SDF *hdr) -{ - int i, istart; - vec_descrip_t *possible; - - i = istart = SDFhash(name, hdr); - do{ - possible = hdr->hashtbl[i]; - if( possible == NULL ){ - break; - } - if( strcmp(possible->name, name) == 0 ) - return possible; - - Msgf(("lookup: hcollision i=%d, name=%s, tblname=%s\n", - i, name, possible->name)); - i++; - if( i==hdr->hashsz ) /* wrap */ - i = 0; - /* It ought to be imposible to fall off the bottom of this loop */ - }while(i!= istart); - - sprintf(SDFerrstring, "No such name, \"%s\" in file.", name); - return NULL; -} diff --git a/external/libsdf/libSDF/SDFget.c b/external/libsdf/libSDF/SDFget.c deleted file mode 100644 index 2dfe7b1..0000000 --- a/external/libsdf/libSDF/SDFget.c +++ /dev/null @@ -1,278 +0,0 @@ -#include -/* stdio only needed for sprintf proto */ -#include -#include "error.h" -#include "SDF.h" -/* - -These routines return 0 on success and 1 on failure. They set -SDFerrstring if they think something strange is happening. They -don't change the value under the VALUE argument until they are sure -that everything is OK, so it's possible (but what would Henry Spencer -say?) to use them by setting a default value, then calling the routine, -and not worrying about the error condition. - -*/ - -/* An abbreviation used many times... */ - -#define SDFget(sdfp, name, addr) \ - if(SDFseekrdvecs(sdfp, name, 0, 1, addr, 0, NULL)) return -1 - -/* I'll resist the temptation to make one macro to cover all these cases */ -/* Should we check for loss of precision in float too? */ -int -SDFgetfloat(SDF *sdfp, char *name, float *value) -{ - double double_value; - int int_value; - long long_value; - int64_t int64_value; - float float_value; - - if( sdfp == NULL || !SDFhasname(name, sdfp) ){ - return -1; - } - switch(SDFtype(name, sdfp)){ - case SDF_FLOAT: - SDFget(sdfp, name, &float_value); - *value = float_value; - return 0; - case SDF_DOUBLE: - SDFget(sdfp, name, &double_value); - *value = (float) double_value; - return 0; - case SDF_INT: - SDFget(sdfp, name, &int_value); - *value = (float) int_value; - return 0; - case SDF_LONG: - SDFget(sdfp, name, &long_value); - *value = (float) long_value; - return 0; - case SDF_INT64: - SDFget(sdfp, name, &int64_value); - *value = (float) int64_value; - return 0; - default: - sprintf(SDFerrstring, - "SDFgetfloat: \"%s\" must be either float or int.\n", name); - return -1; - } -} - -int -SDFgetdouble(SDF *sdfp, char *name, double *value) -{ - double double_value; - float float_value; - int int_value; - long long_value; - int64_t int64_value; - - if( sdfp == NULL || !SDFhasname(name, sdfp) ){ - return -1; - } - switch(SDFtype(name, sdfp)){ - case SDF_DOUBLE: - SDFget(sdfp, name, &double_value); - *value = double_value; - return 0; - case SDF_FLOAT: - SDFget(sdfp, name, &float_value); - *value = (double) float_value; - return 0; - case SDF_INT: - SDFget(sdfp, name, &int_value); - *value = (double) int_value; - return 0; - case SDF_LONG: - SDFget(sdfp, name, &long_value); - *value = (double) long_value; - return 0; - case SDF_INT64: - SDFget(sdfp, name, &int64_value); - *value = (double) int64_value; - return 0; - default: - sprintf(SDFerrstring, - "SDFgetdouble: \"%s\" must be either float or int.\n", name); - return -1; - } -} - -int -SDFgetint(SDF *sdfp, char *name, int *value) -{ - int int_value; - float float_value; - double double_value; - - if( sdfp == NULL || !SDFhasname(name, sdfp) ){ - return -1; - } - switch(SDFtype(name, sdfp)){ - case SDF_INT: - SDFget(sdfp, name, &int_value); - *value = int_value; - return 0; - case SDF_DOUBLE: - SDFget(sdfp, name, &double_value); - int_value = (int) double_value; - if ((double)int_value != double_value){ - sprintf(SDFerrstring, - "SDFgetint: \"%s\" has lost precision\n", name); - return -1; - } - *value = int_value; - return 0; - case SDF_FLOAT: - SDFget(sdfp, name, &float_value); - int_value = (int) float_value; - if ((float)int_value != float_value){ - Warning("SDFgetint: \"%s\" has lost precision\n", name); - return -1; - } - *value = int_value; - return 0; - default: - sprintf(SDFerrstring, "SDFgetint: \"%s\" must be either float or int.\n", name); - return -1; - } -} - -int -SDFgetlong(SDF *sdfp, char *name, long *value) -{ - int int_value; - float float_value; - double double_value; - long long_value; - int64_t int64_value; - - if( sdfp == NULL || !SDFhasname(name, sdfp) ){ - return -1; - } - switch(SDFtype(name, sdfp)){ - case SDF_INT: - SDFget(sdfp, name, &int_value); - *value = int_value; - return 0; - case SDF_LONG: - SDFget(sdfp, name, &long_value); - *value = long_value; - return 0; - case SDF_INT64: - SDFget(sdfp, name, &int64_value); - long_value = (long) int64_value; - if ((int64_t)long_value != int64_value){ - sprintf(SDFerrstring, - "SDFgetint: \"%s\" has lost precision\n", name); - return -1; - } - *value = int64_value; - return 0; - case SDF_DOUBLE: - SDFget(sdfp, name, &double_value); - long_value = (long) double_value; - if ((double)int_value != double_value){ - sprintf(SDFerrstring, - "SDFgetlong: \"%s\" has lost precision\n", name); - return -1; - } - *value = int_value; - return 0; - case SDF_FLOAT: - SDFget(sdfp, name, &float_value); - long_value = (long) float_value; - if ((float)long_value != float_value){ - Warning("SDFgetlong: \"%s\" has lost precision\n", name); - return -1; - } - *value = long_value; - return 0; - default: - sprintf(SDFerrstring, "SDFgetint: \"%s\" must be either float or int.\n", name); - return -1; - } -} - -int -SDFgetint64(SDF *sdfp, char *name, int64_t *value) -{ - int int_value; - float float_value; - double double_value; - long long_value; - int64_t int64_value; - - if( sdfp == NULL || !SDFhasname(name, sdfp) ){ - return -1; - } - switch(SDFtype(name, sdfp)){ - case SDF_INT: - SDFget(sdfp, name, &int_value); - *value = int_value; - return 0; - case SDF_LONG: - SDFget(sdfp, name, &long_value); - *value = long_value; - return 0; - case SDF_INT64: - SDFget(sdfp, name, &int64_value); - *value = int64_value; - return 0; - case SDF_DOUBLE: - SDFget(sdfp, name, &double_value); - int64_value = (int64_t) double_value; - if ((double)int64_value != double_value){ - sprintf(SDFerrstring, - "SDFgetint64: \"%s\" has lost precision\n", name); - return -1; - } - *value = int64_value; - return 0; - case SDF_FLOAT: - SDFget(sdfp, name, &float_value); - int64_value = (int64_t) float_value; - if ((float)int64_value != float_value){ - Warning("SDFgetint64: \"%s\" has lost precision\n", name); - return -1; - } - *value = int64_value; - return 0; - default: - sprintf(SDFerrstring, "SDFgetint: \"%s\" must be either float or int.\n", name); - return -1; - } -} - -int -SDFgetstring(SDF *sdfp, const char *name, char *string, int size){ - int len; - int ret; - - if( sdfp == NULL ){ - sprintf(SDFerrstring, "SDFgetint: NULL sdfp\n"); - return -1; - } - if( !SDFhasname(name, sdfp) ){ - return -1; - } - if( SDFtype(name, sdfp) != SDF_CHAR ){ - return -1; - } - if( (len=SDFarrcnt(name, sdfp)) >= size ){ - return -1; - } - - ret = SDFseekrdvecs(sdfp, name, 0, 1, string, 0, NULL); - if( string[len-1] != '\0' ){ - sprintf(SDFerrstring, - "Read non-terminated string in SDFgetstring(\"%s\")\n", name); - string[len] = '\0'; - } - return ret; -} - - diff --git a/external/libsdf/libSDF/SDFhdrio.c b/external/libsdf/libSDF/SDFhdrio.c deleted file mode 100644 index dccb38a..0000000 --- a/external/libsdf/libSDF/SDFhdrio.c +++ /dev/null @@ -1,86 +0,0 @@ -/* An implementation of getc, using MPMY functions. */ - -#include -#include -#include "Msgs.h" -#include "error.h" -#include "SDF-private.h" -#include "stdio.h" -#include "mpmy_io.h" - -#define MYBUFSZ 4096 - -/* Assumption: we can only have one header at a time being read. - The header is opened, read anc closed, all during the course of SDFopen - so we don't have to screw around with multiple open files, etc. */ - -static MPMYFile *fp; -static char buf[MYBUFSZ]; -static char *ptr; -static char *endbuf; -static int buf_offset; - - -int SDF_Hdropen(const char *name){ - fp = MPMY_Fopen(name, MPMY_RDONLY|MPMY_SINGL); - if( fp == NULL ) - return -1; - endbuf = ptr = buf; - buf_offset = 0; - Msg("SDF", ("SDFhdropen: return fp=%p\n", fp)); - return 0; -} - -void SDF_Hdrclose(void){ - Msg("SDF", ("SDFhdrclose called\n")); - MPMY_Fclose(fp); - endbuf = ptr = NULL; - fp = NULL; - buf_offset = -1; -} - -int SDF_Hdroffset(void){ - if( ptr == NULL ) - return -1; - return buf_offset + (ptr - buf); -} - -int SDF_Hdrgetc(){ - int nread; - - if( ptr == NULL ){ - Msgf(("SDFhdrgetc: Returning EOF, ptr==NULL\n")); - return EOF; - } - - if( ptr < endbuf ){ - if( *ptr == '\0' ){ - SinglWarning("Returning NULL at char %d in SDFhdrio\n", (int)(ptr-buf)); - } - Msgf(("SDF_hdrgetc: %c\n", *ptr)); - return *ptr++; - } - - nread = MPMY_Fread(buf, 1, MYBUFSZ, fp); - {int i; - int sum = 0; - for(i=0; iptr */ - return SDF_Hdrgetc(); -} - diff --git a/external/libsdf/libSDF/dictionary b/external/libsdf/libSDF/dictionary deleted file mode 100644 index 301e818..0000000 --- a/external/libsdf/libSDF/dictionary +++ /dev/null @@ -1,54 +0,0 @@ -This is a dictionary of "known" names in nbody files. -It will be extended as the need arises. - -The first few come from the headers: - -float npart -float iter -float time -float ke -float pe -float masstot -float l_ang -float Gnewt -float epsilon -float zinitial -float omega -float hubble -float box_size -float znow -float initial_rsize -float initial_rmin_x -float initial_rmin_y -float initial_rmin_z -float veltime -float sizeof_ext -float alpha -float beta -float curvature -float lambda -float cosm_integral -float radius -int int_npart -int int_sizeof_ext -char tree_header_text[384]; - -The following arrays are of length (int)nbody. Unfortunately, -in order to maintain historical compatibilty, the length of the -array is stored as a binary float in the files, so consider using -nbio_rd_double(..., "nbody") to figure out how long these vectors are. - -float x[], y[], z[] -float vx[], vy[], vz[] -float mass[] - -From the msw .ap files, we also have -float acc[] -float phi[] - -Presumably, we should also reserve: -float ax[], ay[], az[] - -The char id[][4] is specified by tree and tree_ap files. - -There will undoubtedly be others. \ No newline at end of file diff --git a/external/libsdf/libSDF/stdio.h b/external/libsdf/libSDF/stdio.h deleted file mode 100644 index b4bf00b..0000000 --- a/external/libsdf/libSDF/stdio.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is a replacement for the few parts of stdio.h */ -/* that are assumed by the output of lex and yacc. */ -/* It is here because lex's output contains #include "stdio.h" */ -/* and we don't want to be contaminated by the system stdio.h */ - -#ifndef MYSTDIOdotH -#define MYSTDIOdotH -#include "mpmy_io.h" - -/* These are replacements for stdio */ -#undef getc -#define getc(fp) SDF_Hdrgetc() -/* Putc is used by 'output'. This is the easiest way to deal with it */ -#undef putc -#define putc(c, fp) (Msg_do("%c", c)) -#undef FILE -#define FILE MPMYFile -#undef stdin -#define stdin NULL -#undef stdout -#define stdout NULL -#undef stderr -#define stderr NULL -#undef EOF -#define EOF (-1) -#undef BUFSIZ -#define BUFSIZ 512 - -/* A couple of prototypes that are in stdio are also needed */ -#include -int sscanf(const char *, const char *, ...); -int vsprintf(char *, const char *, va_list); -int sprintf(char *, const char *, ...); - -#endif diff --git a/external/libsdf/libmpmy/GNUmakefile b/external/libsdf/libmpmy/GNUmakefile deleted file mode 100644 index 69ab885..0000000 --- a/external/libsdf/libmpmy/GNUmakefile +++ /dev/null @@ -1,151 +0,0 @@ -# Make.$(ARCH) sets many of the variables used below including: -# CC, CFLAGS, AS, RANLIB, objdir, objsuf, asmdir - -# This Makefile is 'non-standard' because we are trying to create a .o -# file in the '$(libdir)' directory. Furthermore, the name of the -# file we are creating can't be determined until after we have 'include'd -# the $(ARCH)-specific makefile (so we can use the default PAROS). -# -# The dependencies are even more unreliable than usual. -# -# It's amazing that it works at all... - -treedir=.. -treedir_sed=\.\. -appexcludes= -libname=NO_NAME -# This is here only to allow 'make depends' to work. -src=mpmy_seq.c mpmy_lsv.c mpmy_nx.c mpmy_vertex.c mpmy_sunmos.c mpmy_mpi.c mpmy_eui.c mpmy_pvm.c mpmy_craypvm.c - -special_rule_for_all=YES -all: special - -include $(treedir)/Make-common/Make.$(ARCH) - -include $(treedir)/Make-common/Make.generic - -override CFLAGS:=$(PAROSCFLAGS) $(CFLAGS) - -# I think these should be handled with PAROSCFLAGS -# So sue me! -#ifeq ($(PAROS),eui) -#CFLAGS:=-I/usr/lpp/euih/eui $(CFLAGS) -#endif - -#ifeq ($(PAROS),mpi) -#CFLAGS:=-I/usr/lpp/mpif $(CFLAGS) -#endif - -#ifeq ($(PAROS),srv) -#CFLAGS:=-I$(SRVHOME)/include/cros3 $(CFLAGS) -#endif - -#ifeq ($(PAROS),pvm) -#CFLAGS:=-I$(PVM_ROOT)/include $(CFLAGS) -#endif - -# order is important here. We need to make $(libdir) -special: $(libdir)/mpmy_$(PAROS)$(objsuf) - -$(libdir)/mpmy_$(PAROS)$(objsuf) : $(objdir)/mpmy_$(PAROS)$(objsuf) $(libdir) - cp $< $@ - -$(objdir)/mpmy_$(PAROS)$(objsuf) : $(objdir) - -# If there's a default PAROS for this architecture, then we put -# mpmy_$(PAROS).o into libsw.a. To override it, it is -# necessary to list mpmy_$(alternative).o AHEAD of libsw.a in the -# link command. But if you just want the defaults (typically _seq), then -# the only thing to link against is libsw.a. -ifeq ($(PAROS),$(defaultPAROS)) -special: $(libdir)/libsw$(libext)($(objdir)/mpmy_$(PAROS)$(objsuf)) - $(RANLIB) $(libdir)/libsw$(libext) - -$(libdir)/libsw$(libext)($(objdir)/mpmy_$(PAROS)$(objsuf)) : $(libdir) - -endif - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/Assert.h $(treedir)/include/libsdf/error.h -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/mpmy_io.h -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/mpmy_time.h -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/mpmy_abnormal.h timers_hwclock.c -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/chn.h -$(objdir)/mpmy_seq$(objsuf): mpmy_io.c -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/protos.h -$(objdir)/mpmy_seq$(objsuf): iozero.h iozero.c io_generic.c mpmy_abnormal.c -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): -$(objdir)/mpmy_seq$(objsuf): $(treedir)/include/libsdf/singlio.h mpmy_generic.c -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/mpmy_abnormal.h -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/chn.h $(treedir)/include/libsdf/mpmy.h -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/timers.h -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/Assert.h -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/memfile.h -$(objdir)/mpmy_mpi$(objsuf): timers_hwclock.c -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/mpmy_time.h mpmy_mpiio.c -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/protos.h $(treedir)/include/libsdf/mpmy_io.h -$(objdir)/mpmy_mpi$(objsuf): io_generic.c mpmy_abnormal.c -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): -$(objdir)/mpmy_mpi$(objsuf): $(treedir)/include/libsdf/singlio.h -$(objdir)/mpmy_mpi$(objsuf): mpmy_generic.c diff --git a/external/libsdf/libmpmy/io_generic.c b/external/libsdf/libmpmy/io_generic.c deleted file mode 100644 index 244116c..0000000 --- a/external/libsdf/libmpmy/io_generic.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Some i/o routines that are likely to be common... */ - -#ifndef HAVE_MPMY_FPRINTF - -int MPMY_Fprintf(MPMYFile *fp, const char *fmt, ...){ - int ret; - va_list ap; - va_start(ap, fmt); - ret = MPMY_Vfprintf(fp, fmt, ap); - va_end(ap); - return ret; -} -#endif - -#ifndef HAVE_MPMY_VFPRINTF -#include -#include - -static char buf[1024]; - -int MPMY_Vfprintf(MPMYFile *fp, const char *fmt, va_list args){ - /* What a pain. Sometimes sprintf returns a char* and sometimes - it returns an int. There's no good way to tell, but this - should do.*/ - long ret = (long)vsprintf(buf, fmt, args); - - /* Broken versions of sprintf return their first arg... */ - if( ret == (long)buf ) - ret = strlen(buf); - - if( ret < 0 ){ - return ret; - } - if( ret >= sizeof(buf) ){ - /* This is serious. We've probably scribbled over memory. - Maybe we should just bail out now? - */ - static int recursion; - if( recursion++ == 0 ) - Error("MPMY_Vfprintf overflow. Data corruption likely!\n"); - recursion--; - } - - if( MPMY_Fwrite(buf, 1, ret, fp) != ret ){ - return -1; - } - return ret; -} -#endif - -#ifndef HAVE_MPMY_FLUSH - -/* This is here just for completeness... The higher levels all do - their I/O using unbuffered primitives (read/write/open/close), so - we don't have to do anything special to flush output */ -int MPMY_Fflush(MPMYFile *fp){ - return 0; -} -#endif diff --git a/external/libsdf/libmpmy/iozero.c b/external/libsdf/libmpmy/iozero.c deleted file mode 100644 index 279c3aa..0000000 --- a/external/libsdf/libmpmy/iozero.c +++ /dev/null @@ -1,360 +0,0 @@ -/* More include madness. This is such good stuff, that I can't resist */ -/* just "#include"ing it into all the mpmy_??io.c files...*/ - -/* Try to use different tags for the different kinds of broadcasts... */ -#define BCAST_CLOSE 0x3579 -#define BCAST_OPEN 0x3779 -#define BCAST_READ1 0x3979 -#define BCAST_READ2 0x3b79 -#define BCAST_WRITE 0x3d79 -#define BCAST_LSEEK 0x3f79 -#define BCAST_TELL 0x4179 -#define BCAST_FLEN 0x4379 -#define BCAST_MKDIR 0x4579 - -static int -open0(const char *path, int flags, int mode) -{ - int ret; - - /* paragon left the const out of the prototype */ - Msgf(("open0(path=%s, flags=%#x, mode=%#x\n", path, flags, mode)); - if (MPMY_Procnum() == 0){ - ret = open((char *)path, flags, mode); - Msgf(("open returns %d on node 0\n", ret)); - } - MPMY_BcastTag(&ret, 1, MPMY_INT, 0, BCAST_OPEN); - Msgf(("open0 returning %d\n", ret)); - return ret; -} - -static int -close0(int fd) -{ - int ret; - - if (MPMY_Procnum() == 0) ret = close(fd); - MPMY_BcastTag(&ret, 1, MPMY_INT, 0, BCAST_CLOSE); - return ret; -} - -static long -read0(int fd, void *buf, unsigned long nbytes) -{ - long ret; - - if (MPMY_Procnum() == 0){ - ret = read(fd, buf, nbytes); - Msgf(("read0: read(fd=%d, nbytes=%ld) returns %ld\n", - fd, nbytes, ret)); - } - MPMY_BcastTag(&ret, 1, MPMY_LONG, 0, BCAST_READ1); - Msgf(("read0: after Bcast ret = %ld\n", ret)); - if( ret > 0 ) - MPMY_BcastTag(buf, ret, MPMY_CHAR, 0, BCAST_READ2); - if( Msg_test(__FILE__)){ - int i; - int sum = 0; - char *cbuf = buf; - for(i=0; i 0) { - off_t nwrite = (nbytes > MAX_IOBUF) ? MAX_IOBUF : nbytes; - off_t wrote; - wrote = write(fd, buf+ret, nwrite); - if (wrote != nwrite) Shout("write failed, errno=%d\n", errno); - ret += wrote; - nbytes -= wrote; - } - Msgf(("write0 %ld\n", ret)); - if (nproc > 1) { - tmpbuf = Malloc(nbytes); - for (i = procnum+1; i < nproc; i++) { - /* This could be double-buffered */ - tmpbuf = Realloc(tmpbuf, sizes[i]); - /* Avoid deluge of messages by sync */ - MPMY_send(&sync, sizeof(int), i, MPMY_IOTAG); - MPMY_recvn(tmpbuf, sizes[i], i, MPMY_IOTAG); - n = write(fd, tmpbuf, sizes[i]); - if (n != sizes[i]) Shout("write failed, errno=%d\n", errno); - Msgf(("write%d %d\n", i, n)); - /* should we send errno as well? */ - MPMY_send(&n, sizeof(int), i, MPMY_IOTAG); - } - Free(tmpbuf); - } - Free(sizes); - } else { - MPMY_Gather(&nbytes, 1, MPMY_OFFT, NULL, 0); - MPMY_recvn(&sync, sizeof(int), 0, MPMY_IOTAG); - Msgf(("sending %ld bytes\n", nbytes)); - MPMY_send(buf, nbytes, 0, MPMY_IOTAG); - MPMY_recvn(&ret, sizeof(int), 0, MPMY_IOTAG); - } - return ret; -} - -static long -read0_multi(int fd, void *buf, off_t nbytes) -{ - int ret; - off_t *sizes; - int i, n; - char *tmpbuf; - int nproc = MPMY_Nproc(); - int procnum = MPMY_Procnum(); - - if (sizeof(off_t) != sizeof(long long)) { - Error("Type problem in write0_multi\n"); - } - if (procnum == 0) { - sizes = Malloc(sizeof(off_t)*nproc); - MPMY_Gather(&nbytes, 1, MPMY_OFFT, sizes, 0); - ret = read(fd, buf, nbytes); - if (ret != nbytes) Shout("read failed, errno=%d\n", errno); - Msgf(("read0 %d\n", ret)); - if (nproc > 1) { - tmpbuf = Malloc(nbytes); - for (i = procnum+1; i < nproc; i++) { - /* This could be double-buffered */ - tmpbuf = Realloc(tmpbuf, sizes[i]); - n = read(fd, tmpbuf, sizes[i]); - MPMY_send(tmpbuf, n, i, MPMY_IOTAG); - if (n != sizes[i]) Shout("read failed, errno=%d\n", errno); - Msgf(("read%d %d\n", i, n)); - } - Free(tmpbuf); - } - Free(sizes); - } else { - MPMY_Status stat; - MPMY_Comm_request req; - - MPMY_Gather(&nbytes, 1, MPMY_OFFT, NULL, 0); - MPMY_Irecv(buf, nbytes, 0, MPMY_IOTAG, &req); - MPMY_Wait(req, &stat); - ret = MPMY_Count(&stat); - } - return ret; -} - - diff --git a/external/libsdf/libmpmy/iozero.h b/external/libsdf/libmpmy/iozero.h deleted file mode 100644 index 4ea2f48..0000000 --- a/external/libsdf/libmpmy/iozero.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef IOzeroDOTh -#define IOzeroDOTh - -#define MPMY_IOTAG (0x183) -#define IoZero(fp) (fp->flags & MPMY_IOZERO) - -static int open0(const char *path, int flags, int mode); -static int close0(int fd); -static int mkdir0(const char *path, int mode); -static long read0(int fd, void *buf, unsigned long nbytes); -static long write0(int fd, const void *buf, unsigned long nbytes); -static off_t lseek0(int fd, off_t offset, int whence); -static off_t tell0(int fd); -static off_t flen(int fd); -static off_t flen0(int fd); -static long fseekrd0(int fd, off_t offset, int whence, void *buf, - int reclen, int nrecs); -static long write0_multi(int fd, const void *buf, off_t nbytes); -static long read0_multi(int fd, void *buf, off_t nbytes); -#endif diff --git a/external/libsdf/libmpmy/mpmy-private.h b/external/libsdf/libmpmy/mpmy-private.h deleted file mode 100644 index 139597f..0000000 --- a/external/libsdf/libmpmy/mpmy-private.h +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/external/libsdf/libmpmy/mpmy_abnormal.c b/external/libsdf/libmpmy/mpmy_abnormal.c deleted file mode 100644 index 44f53c1..0000000 --- a/external/libsdf/libmpmy/mpmy_abnormal.c +++ /dev/null @@ -1,259 +0,0 @@ -/* Yet another attempt to rationalize the abnormal termination of - parallel programs. - - Issues to consider: - - Do core files exist, and are they useful. - - Do we need to chdir before dumping a core file. - - Exactly how do we go about dumping a core file. - - Do we want to do anything else before quitting. - - Sometimes we get the most information when we just return - from a signal handler (delta). - - Parts will need to be over-ridden by mpmy_.c, but - duplication of code should be minimized. - - include files, values of signals, etc. are all wildly system - specific. -*/ - -#include -#include -#include "singlio.h" -#include "Msgs.h" -#include "mpmy_abnormal.h" - -#ifndef MPMY_ABORT -void MPMY_Abort(void){ - MPMY_RaiseAbnormal(SIGABRT); - MPMY_SystemAbort(); -} -#endif - -#ifdef _AIX - /* dje says AIX dumps core fine, but the debuggers are confused by - the signal handlers. Another way of achieving this might be - to set absiglist and MPMY_HAVE_ABSIGLIST in the mpmy_paros.c file. */ -#define NO_SIGNALS -#endif - -#if !defined( HAVE_ABSIG_LIST ) && !defined(NO_SIGNALS) -static int absiglist[]={ -#if 0 && defined(SIGABRT) /* ANSI */ -/* DO NOT TRAP SIGABRT! Just leave it completely alone. We studiously - avoid calling abort in our code, so we should just let SIGABRT do its - normal, unmodified thing. */ -SIGABRT, -#endif -#ifdef SIGFPE /* ANSI */ -SIGFPE, -#endif -#ifdef SIGIILL /* ANSI */ -SIGILL, -#endif -#ifdef SIGIOT /* ANSI */ -SIGIOT, -#endif -#ifdef SIGSEGV /* ANSI */ -SIGSEGV, -#endif -#ifdef SIGQUIT -SIGQUIT, -#endif -#ifdef SIGTRAP -SIGTRAP, -#endif -#ifdef SIGEMT -SIGEMT, -#endif -#ifdef SIGKILL -SIGKILL, /* for form's sake */ -#endif -#ifdef SIGBUS -SIGBUS, -#endif -#ifdef SIGSYS -SIGSYS, -#endif -#ifdef SIGPIPE -SIGPIPE, -#endif -/* Do we need to worry about a trailing comma?? */ -}; -#endif /* HAVE_ABSIGLIST */ - -#ifndef HAVE_SETUP_ABSIGS -void _MPMY_setup_absigs(void){ - int i; -#if !defined(NO_SIGNALS) - for(i=0; i< sizeof(absiglist)/sizeof(*absiglist); i++){ - signal(absiglist[i], MPMY_RaiseAbnormal); - } -#endif -} -#endif - -#ifndef HAVE_ABNORMAL -#define MAXUSERFUNCS 64 - -static int nuserfuncs = 0; -static Abhndlr userfuncs[MAXUSERFUNCS]; -/* Lots of functions are suitable for use as userfuncs to be called in - the event of abnormal termination. These might include: - malloc_print(); - PrintMemfile(); - PrintMPMYDiags(); - Msg_flush(); - MPMY_abchdir(); (with MPMY_abchdir_arg set beforehand) - MPMY_SystemAbort(); - MPMY_SystemExit(); (with MPMY_exit_arg set beforehand) - MPMY_Abannounce(); - - They are called in the reverse chronological order, so later functions - might 'override' earlier ones. This isn't perfect, but it's better than - the monolithic handler we had before. -*/ - -void MPMY_OnAbnormal(Abhndlr hndlr){ - if(nuserfuncs < MAXUSERFUNCS) - userfuncs[nuserfuncs++] = hndlr; -} - -int MPMY_Abnormal_signum; -int MPMY_stop_abnormal_processing; -void MPMY_RaiseAbnormal(int sig){ - int i; - - MPMY_Abnormal_signum = sig; - MPMY_stop_abnormal_processing = 0; - /* Just cycle through the 'user' functions. */ - for(i=nuserfuncs-1; i>=0 && !MPMY_stop_abnormal_processing; i--){ - (*userfuncs[i])(); - } - MPMY_Abnormal_signum = 0; -} -#endif - -#ifndef HAVE_SYSTEM_ABORT -void MPMY_SystemAbort(void){ - /* This should be unnecessary, since we didn't trap SIGABRT above. */ - signal(SIGABRT, SIG_DFL); - abort(); -} -#endif - -#ifndef HAVE_SYSTEM_EXIT -int MPMY_exit_arg = 0; -void MPMY_SystemExit(void){ - exit(MPMY_exit_arg); -} -#endif - -#ifndef HAVE_MPMY_CHDIR -/* This is pretty generic, but if the system can't even link against - mkdir and chdir, then it will be necessary to override this with - a noop in the PAROS-specific file. */ -#include -#ifndef __INTEL_SSD__ /* Intel's headers aren't safe for multiple inclusion! */ -#include -#endif -#include -char MPMY_Abchdir_arg[128]; - -/* Suitable for use as a userfunc */ -void MPMY_Abchdir(void){ - if( strlen(MPMY_Abchdir_arg) ){ - errno=0; - if( mkdir(MPMY_Abchdir_arg, 0777) && errno != EEXIST ){ - Msg_do("Can't mkdir(\"%s\"): %d\n", MPMY_Abchdir_arg, errno); - } - errno = 0; - if( chdir(MPMY_Abchdir_arg) ){ - Msg_do("Can't chdir(\"%s\"): %d\n", MPMY_Abchdir_arg, errno); - }else{ - Msg_do("New directory: \"%s\"\n", MPMY_Abchdir_arg); - } - } -} -#endif - -#ifndef HAVE_ABANNOUNCE -void MPMY_Abannounce(void){ - static int announced; - /* Don't repeat yourself! */ - if (!announced){ - Msg_do("MPMY_ABNORMAL_SIGNUM: %d\n", MPMY_Abnormal_signum); - MPMY_Diagnostic(Msg_do); - } - Msg_flush(); - announced = 1; -} -#endif - -#ifndef HAVE_PRINTMPMY_DIAGS -void PrintMPMYDiags(void){ - MPMY_Diagnostic(Msg_do); -} -#endif - -#ifndef HAVE_MPMY_TIMEOUT -/* Aieeee!!! Some systems can link alarm, but when the execute it, - they die (cm5). Other systems can't even link it (sunmos, ap1000). - Others will crash mysteriously if they use alarm (lsv). This isn't - really a PAROS thing, and it's not really ARCH either. Aargh. */ -#ifdef CANT_USE_ALARM -#define HAVE_MPMY_TIMEOUT -void -MPMY_TimeoutSet(int n){ - SinglWarning("Can't use alarm(). Timeout not set!\n"); -} - -void -MPMY_TimeoutReset(int n){ - return; -} - -void -MPMY_TimeoutCancel(void){ - return; -} - -#else /* CANT_USE_ALARM */ - -static int nt; -static void -alrm_hndlr(int sig) -{ - /* Should this be Shout followed by MPMY_RaiseAbnormal()?? */ - Error("Exceeded timeout (%d sec)\n", nt); -} - -void -MPMY_TimeoutSet(int n) -{ - void (*prev_sig)(int); - prev_sig = signal(SIGALRM, alrm_hndlr); - if( prev_sig == SIG_DFL || prev_sig == NULL || prev_sig == SIG_IGN ){ - singlPrintf("Setting timeout to %d seconds.\n", n); - alarm(n); - nt = n; - }else{ - singlPrintf("There is already a handler for SIGALRM at %p\n", - prev_sig); - singlPrintf("NOT setting timeout!\n"); - signal(SIGALRM, prev_sig); - } -} - -void -MPMY_TimeoutReset(int n) -{ - alarm(n); - nt = n; -} - -void -MPMY_TimeoutCancel(void) -{ - alarm(0); - signal(SIGALRM, SIG_DFL); -} -#endif /* CANT_USE_ALARM */ -#endif /* HAVE_MPMY_TIMEOUT */ diff --git a/external/libsdf/libmpmy/mpmy_generic.c b/external/libsdf/libmpmy/mpmy_generic.c deleted file mode 100644 index c3dd30e..0000000 --- a/external/libsdf/libmpmy/mpmy_generic.c +++ /dev/null @@ -1,286 +0,0 @@ -/* This file is included in most (all?) of the mpmy_PAROS files. - It defines several of the required mpmy functions in terms of a - more primitive set. In some cases, however, there will be a PAROS - specific way to achieve these results defined in the mpmy_PAROS file - When that happens, the mpmy_PAROS file will also - #define HAVE_MPMY_FUNCNAME -so we know that we shouldn't define it here. */ - -/* These are set to the "right" thing on a uniprocessor, where it is - most likely that we will neglect to call MPMY_Init, but where - we really can proceed without any problems. I tried - setting them to -1, but that just led to hard-to-understand - crashes. We really should test occasionally that MPMY_Init has - been called. But I'll leave that for another day... */ -int _MPMY_procnum_ = 0; -int _MPMY_nproc_ = 1; -int _MPMY_procs_per_node_ = 1; -int _MPMY_initialized_ = 0; - -Counter_t MPMYSendCnt; -Counter_t MPMYRecvCnt; -Counter_t MPMYDoneCnt; - -#ifndef HAVE_MPMY_FLICK -int MPMY_Flick(void){return MPMY_SUCCESS;} -#endif /* HAVE_MPMY_FLICK */ - -#ifndef HAVE_MPMY_IRSEND -int MPMY_Irsend(const void *buf, int cnt, int dest, int tag, MPMY_Comm_request *req){ - return MPMY_Isend(buf, cnt, dest, tag, req); -} -#endif /* HAVE_MPMY_IRSEND */ - -#ifndef HAVE_MPMY_SHIFT -/* An implementation of shift that just uses mpmy_isend/irecv */ -/* Some systems will have a better option, but this should always work. */ - -#define SHIFT_TAG 0x1492 -/* Because NX can't distinguish different sources when reading */ -/* messages, we help it out by adding processor info to the tag. */ -/* Is this really necessary for the "generic" implementation? */ -int MPMY_Shift(int proc, void *recvbuf, int recvcnt, - const void *sendbuf, int sendcnt, MPMY_Status *stat){ - MPMY_Comm_request inreq, outreq; - Msgf(("Starting MPMY_Shift(proc=%d, recvcnt=%d, sendcnt=%d:\n", - proc, recvcnt, sendcnt)); - if (proc > _MPMY_procnum_) { - MPMY_Irecv(recvbuf, recvcnt, proc, SHIFT_TAG+proc, &inreq); - Msgf(("Irecv posted\n")); - MPMY_Wait(inreq, stat); - Msgf(("Irecv done\n")); - MPMY_Isend(sendbuf, sendcnt, proc, SHIFT_TAG+MPMY_Procnum(), &outreq); - Msgf(("Isend posted\n")); - MPMY_Wait(outreq, NULL); - Msgf(("Isend done\n")); - } else { - MPMY_Isend(sendbuf, sendcnt, proc, SHIFT_TAG+MPMY_Procnum(), &outreq); - Msgf(("Isend posted\n")); - MPMY_Wait(outreq, NULL); - Msgf(("Isend done\n")); - MPMY_Irecv(recvbuf, recvcnt, proc, SHIFT_TAG+proc, &inreq); - Msgf(("Irecv posted\n")); - MPMY_Wait(inreq, stat); - Msgf(("Irecv done\n")); - } - - Msgf(("Finished MPMY_Shift\n")); - return MPMY_SUCCESS; -} -#endif /* HAVE_MPMY_SHIFT */ - -/* - This could be smarter. In particular, it could recover gracefully - from malloc failing to deliver. - */ -#ifndef HAVE_MPMY_SHIFT_OVERLAP -#include "Malloc.h" -#include - -int MPMY_Shift_overlap(int proc, void *recvbuf, int recvcnt, - const void *sendbuf, int sendcnt, MPMY_Status *stat){ - void *tmp = Malloc(sendcnt); - int ret; - - if( tmp == NULL && sendcnt>0 ) - return MPMY_FAILED; - memcpy(tmp, sendbuf, sendcnt); - ret = MPMY_Shift(proc, recvbuf, recvcnt, tmp, sendcnt, stat); - Free(tmp); - return ret; -} -#endif /* HAVE_MPMY_SHIFT_OVERLAP */ - -#ifndef HAVE_MPMY_SYNC -/* Implementation of MPMY_Sync in terms of the 'combine' functions. */ -/* Some systems might provide a more useful interface. */ - -int MPMY_Sync(void){ - int junk=0; - - /* I'm sure this is overkill! */ - return MPMY_Combine(&junk, &junk, 1, MPMY_INT, MPMY_BOR); -} -#endif - -#ifndef HAVE_MPMY_FINALIZE -/* Any system specific stuff gets handled by a system-specific finalizer */ -int MPMY_Finalize(void){ - return MPMY_SUCCESS; -} -#endif - -#ifndef HAVE_MPMY_WAIT -/* An implementation of mpmy_wait that just busy-waits on MPMY_Test. */ -/* Some systems will have a better option, but this should always work. */ - -int MPMY_Wait(MPMY_Comm_request req, MPMY_Status *stat){ - /* Should we do a 'MPMY_Flick'' ? */ - int flag = 0; - int ret; - - do{ - MPMY_Flick(); - ret = MPMY_Test(req, &flag, stat); - }while( ret == MPMY_SUCCESS && flag==0 ); - return ret; -} -#endif /* HAVE_MPMY_WAIT */ - -#ifndef HAVE_MPMY_WAIT2 -int MPMY_Wait2(MPMY_Comm_request req1, MPMY_Status *stat1, - MPMY_Comm_request req2, MPMY_Status *stat2){ - /* Should we do a 'MPMY_Flick'' ? */ - int done1, done2; - int ret; - - done1 = done2 = 0; - do{ /* loop until at least one is finished */ - MPMY_Flick(); - ret = MPMY_Test(req1, &done1, stat1); - if( ret != MPMY_SUCCESS ) - return ret; - ret = MPMY_Test(req2, &done2, stat2); - if( ret != MPMY_SUCCESS ) - return ret; - }while( done1 == 0 && done2 == 0 ); - - /* Now there's only one left, so we can call MPMY_Wait */ - if( !done1 ){ - ret = MPMY_Wait(req1, stat1); - if( ret != MPMY_SUCCESS ) - return ret; - } - if( !done2 ){ - ret = MPMY_Wait(req2, stat2); - if( ret != MPMY_SUCCESS ) - return ret; - } - return MPMY_SUCCESS; -} -#endif - - -#ifndef HAVE_MPMY_DIAGNOSTIC -void MPMY_Diagnostic(int (*printflike)(const char *, ...)){ - (*printflike)("No Diagnostic info for this MPMY\n"); -} -#endif - -#ifndef HAVE_MPMY_INITIALIZED -int MPMY_Initialized(void){ - return _MPMY_initialized_; -} -#endif - -#ifndef HAVE_MPMY_PHYSNODE -const char *MPMY_Physnode(void){ - return "?"; -} -#endif - -#ifndef HAVE_MPMY_TIMERS -/* This is a nightmare! Timers should really be ARCH dependent */ -/* but because of the CM5's special closeness to ARCH=sun4, they */ -/* are PAROS dependent, instead. That means that we would otherwise */ -/* repeat this code block in lots of mpmy_PAROS.c files */ -#ifdef _AIX -/* No longer working?? Nov 3 1994 - # include "timers_readrtc.c" */ -#if !defined(USE_HWCLOCK) && !defined(USE_GETTIME) -#include "timers_posix.c" -#endif -/* it's not inconceivable to compile sequentially for the intels */ -/* However, we won't necessarily be linking against, e.g, hwclock -#elif defined(__INTEL_SSD__) -# include "timers_nx.c" -*/ -#else -#if !defined(USE_HWCLOCK) && !defined(USE_GETTIME) -# include "timers_posix.c" -#endif -#endif /* _AIX */ -#endif /* HAVE_MPMY_TIMERS */ - -static time_t job_start; -static time_t job_end; -static time_t checkpoint_last; -static time_t checkpoint_next; -static time_t checkpoint_interval; -static int checkpoint_setup; - -void -MPMY_CheckpointSetup(int job_seconds, int interval_seconds, int step_seconds) -{ - if (MPMY_Procnum() == 0) { - job_start = time(NULL); - if (job_seconds == -1) job_end = -1; - else job_end = job_start + job_seconds - step_seconds; - checkpoint_interval = interval_seconds - step_seconds; - checkpoint_last = job_start; - checkpoint_next = job_start + checkpoint_interval; - Msg_do("Checkpoint Setup interval %ld start %ld next %ld end %ld\n", - checkpoint_interval, job_start, checkpoint_next, job_end); - } - checkpoint_setup = 1; -} - -int -MPMY_CheckpointDue(int next_output_seconds) -{ - time_t t; - int retval = 0; - - if (MPMY_Procnum() == 0) { - t = time(NULL); - if (t >= checkpoint_next) retval = 1; - if (next_output_seconds < checkpoint_interval/4) { - Msg_do("Postponing checkpoint since output expected in %d seconds\n", - next_output_seconds); - retval = 0; - } - if (job_end > 0 && t >= job_end) retval = 1; - } - if (retval) Msg_do("Checkpoint Due\n"); - MPMY_Bcast(&retval, 1, MPMY_INT, 0); - return retval; -} - -void -MPMY_CheckpointFinished(void) -{ - time_t t; - - if (MPMY_Procnum() == 0) { - t = time(NULL); - checkpoint_last = t; - checkpoint_next = t + checkpoint_interval; - if (job_end > 0 && checkpoint_next > job_end) checkpoint_next = job_end; - Msg_do("next checkpoint %ld (%ld from now)\n", checkpoint_next, checkpoint_next-t); - } -} - -int -MPMY_JobDone(void) -{ - time_t t; - int retval = 0; - - if (MPMY_Procnum() == 0) { - t = time(NULL); - if (job_end > 0 && t >= job_end) { - retval = 1; - Msg_do("Job Done\n"); - } - } - MPMY_Bcast(&retval, 1, MPMY_INT, 0); - return retval; -} - -#ifndef HAVE_MPMY_JOBREMAINING -int -MPMY_JobRemaining(void) -{ - return -1; -} -#endif diff --git a/external/libsdf/libmpmy/mpmy_io.c b/external/libsdf/libmpmy/mpmy_io.c deleted file mode 100644 index f7dd2ef..0000000 --- a/external/libsdf/libmpmy/mpmy_io.c +++ /dev/null @@ -1,525 +0,0 @@ - -/* The default I/O model here is that only proc 0 can read/write etc. */ -/* There are two I/O modes for read and write, MULTI and SINGL */ -/* All other functions do not have an I/O mode associated with them */ -/* All calls must be loosely synchronous. There is a single file pointer */ -/* This model works on all machines, but it may not be the most efficient */ - -/* MPMY_NFILE extends the mpmy_io model to include multiple file segments */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "Assert.h" -#include "protos.h" -#include "mpmy.h" -#include "mpmy_io.h" -#include "Msgs.h" -#include "Malloc.h" -#include "iozero.h" - -#ifndef EINVAL -/* just in case... */ -#define EINVAL 0 -#endif - -#define NFILES 4096 -static struct _File{ - int fd; - int iomode; - int iotype; -} _files[NFILES]; - -#define DEFAULT_PERMS 0644 -static int do_nfileio; - -int -MPMY_Nfileio(int val){ - int oldval = do_nfileio; - do_nfileio = val; - return oldval; -} - -int -MPMY_SetIOMode(MPMYFile *Fp, int iomode) -{ - struct _File *fp = (struct _File *)Fp; - - fp->iomode = iomode; - return 0; -} - -MPMYFile * -MPMY_Fopen(const char *path, int mpmy_flags) -{ - int fd; - int flags = 0; - int iomode = MPMY_SINGL; - int iotype = 0; - - Msgf(("Fopen %s\n", path)); - if (mpmy_flags & MPMY_RDONLY) flags |= O_RDONLY; - if (mpmy_flags & MPMY_WRONLY) flags |= O_WRONLY; - if (mpmy_flags & MPMY_RDWR) flags |= O_RDWR; - if (mpmy_flags & MPMY_APPEND) flags |= O_APPEND; - if (mpmy_flags & MPMY_TRUNC) flags |= O_TRUNC; - if (mpmy_flags & MPMY_CREAT) flags |= O_CREAT; - - if (mpmy_flags & MPMY_MULTI) iomode = MPMY_MULTI; - if (mpmy_flags & MPMY_SINGL) iomode = MPMY_SINGL; - - /* This is a sub-mode which can work with either of the above */ - if (mpmy_flags & MPMY_NFILE) iotype = MPMY_NFILE; - - if (mpmy_flags & MPMY_INDEPENDENT) { - iotype = MPMY_INDEPENDENT; - iomode = MPMY_MULTI; - } - - /* We need an external control for nfile mode */ - if (do_nfileio) iotype = MPMY_NFILE; - - if (iotype == MPMY_NFILE) { - char real_path[256]; - sprintf(real_path, "%s.p%03d", path, MPMY_Procnum()); - fd = open(real_path, flags, DEFAULT_PERMS); - } else if (iotype == MPMY_INDEPENDENT) { - fd = open(path, flags, DEFAULT_PERMS); - } else { - if( strcmp(path, "-") != 0 ){ - fd = open0(path, flags, DEFAULT_PERMS); - }else{ - /* Be very afraid. */ - /* We made MPMY_RDONLY zero because O_RDONLY==0. But why - did 'they' do that?! */ - if ( (mpmy_flags & MPMY_RDWR) ) - Error("Can't open '-' RDWR\n"); -#if MPMY_RDONLY != 0 - # error Aargh. -#endif - if(mpmy_flags & MPMY_WRONLY ) - fd = 1; /* stdout */ - else /* we can't test for MPMY_RDONLY! */ - fd = 0; /* stdout */ - } - } - - if (fd >= NFILES) Error("fd too large (%d)\n", fd); - if(fd >= 0){ - _files[fd].iomode = iomode; - _files[fd].iotype = iotype; - _files[fd].fd = fd; - Msgf(("Fopen returns %d, iomode=%d, flags=0x%x\n", fd, iomode, flags)); - return &(_files[fd]); - }else{ - Msgf(("Fopen fails, errno=%d\n", errno)); - return NULL; - } -} - -int -MPMY_Fclose(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - int ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iotype & MPMY_NFILE || fp->iotype & MPMY_INDEPENDENT) { - ret = close(fp->fd); - } else { - ret = close0(fp->fd); - } - fp->fd = -1; - Msgf(("Close returns %d\n", ret)); - return ret; -} - -int -MPMY_Mkdir(const char *path, int mode){ - return mkdir0(path, mode); -} - -size_t -MPMY_Fread(void *ptr, size_t size, size_t nitems, MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - ssize_t ret = -1; - - Msgf(("Fread(ptr=%p, size=%ld, nitems=%ld, FILE=%p)\n", - ptr, size, nitems, Fp)); - Msg_flush(); - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - - switch (fp->iomode) { - case MPMY_SINGL: - ret = read0(fp->fd, ptr, (long)size*nitems); - break; - case MPMY_MULTI: - if (fp->iotype & MPMY_NFILE || fp->iotype & MPMY_INDEPENDENT) - ret = read(fp->fd, ptr, (long)size*nitems); - else - ret = read0_multi(fp->fd, ptr, (long)size*nitems); - break; - default: - ret = -1; - break; - } - - Msgf(("Fread returns %ld.\n", ret)); - if( ret < 0 ){ - Warning("MPMY_Fread: read returns %ld, errno=%d\n", ret, errno); - return -1; - } - if (ret % size) - Shout("MPMY_Fread has a problem, ret=%ld, size=%ld\n", ret, size); - return ret/size; -} - -size_t -MPMY_Fwrite(const void *ptr, size_t size, size_t nitems, MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - ssize_t ret = -1; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - - switch (fp->iomode) { - case MPMY_SINGL: - ret = write0(fp->fd, ptr, size*nitems); - break; - case MPMY_MULTI: - if (fp->iotype & MPMY_NFILE || fp->iotype & MPMY_INDEPENDENT) - ret = write(fp->fd, ptr, size*nitems); - else - ret = write0_multi(fp->fd, ptr, size*nitems); - break; - default: - ret = -1; - Shout("Bad iomode in Fwrite\n"); - } - - Msgf(("Fwrite returns %ld.\n", ret)); - if( ret < 0 ){ - Warning("MPMY_Fwrite: write returns %ld, errno=%d\n", ret, errno); - return -1; - } - if (ret % size) - Shout("MPMY_Fwrite has a problem: ret=%ld, size=%ld\n", ret, size); - return ret/size; -} - -off_t -MPMY_Fseek(MPMYFile *Fp, off_t offset, int whence) -{ - struct _File *fp = (struct _File *)Fp; - off_t ret; - int real_whence = 0; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - - if (whence == MPMY_SEEK_SET) real_whence = SEEK_SET; - if (whence == MPMY_SEEK_CUR) real_whence = SEEK_CUR; - if (whence == MPMY_SEEK_END) real_whence = SEEK_END; - - if (fp->iotype == MPMY_INDEPENDENT) { - ret = lseek(fp->fd, offset, real_whence); - } else { - ret = lseek0(fp->fd, offset, real_whence); - } - if (ret != -1) ret = 0; - Msgf(("Fseek returns %ld\n", (long)ret)); - return ret; -} - -off_t -MPMY_Ftell(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - off_t ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iotype == MPMY_INDEPENDENT) { - ret = lseek(fp->fd, 0L, SEEK_CUR); - } else { - ret = tell0(fp->fd); - } - Msgf(("Ftell returns %ld\n", (long)ret)); - return ret; -} - -off_t -MPMY_Flen(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - off_t ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iotype & MPMY_NFILE) { - ret = flen(fp->fd); - Msgf(("flen segment %ld\n", (long)ret)); - if (sizeof(ret) != sizeof(long)) { - Error("Bad types in MPMY_Flen\n"); - } - MPMY_Combine(&ret, &ret, 1, MPMY_LONG, MPMY_SUM); - } else if (fp->iotype == MPMY_INDEPENDENT) { - ret = flen(fp->fd); - } else { - ret = flen0(fp->fd); - } - Msgf(("Flen returns %ld\n", (long)ret)); - return ret; -} - -#define MAXREQ 4 - -static int -fseekrd_nfile(int fd, off_t offset, int whence, void *buf, int reclen, - int nrecs) -{ - off_t offend; - void *tmpbuf = 0; /* realloc null first time */ - int i; - off_t nread; - long size; - struct { - off_t offset; - off_t flen; - off_t start; - long reclen; - long nrecs; - } parbuf, *allbuf; - MPMY_Status stat; - MPMY_Comm_request req[MAXREQ]; /* should be dynamic? */ - int nreq = 0; - int procnum = MPMY_Procnum(); - off_t my_start, my_size, my_end; - int nproc = MPMY_Nproc(); - - if (whence != MPMY_SEEK_SET) - Error("Fseekrd Nfiles must use SEEK_SET\n"); - - parbuf.offset = offset; - parbuf.reclen = reclen; - parbuf.nrecs = nrecs; - parbuf.flen = flen(fd); - - allbuf = Malloc(sizeof(parbuf)*nproc); - - MPMY_AllGather(&parbuf, sizeof(parbuf)/sizeof(long), MPMY_LONG, allbuf); - - my_start = 0; - for (i = 0; i < nproc; i++) { - allbuf[i].start = my_start; - my_start += allbuf[i].flen; - } - offend = offset+nrecs*reclen; - my_start = allbuf[procnum].start; - my_size = allbuf[procnum].flen; - my_end = my_start+my_size; - - Msgf(("reclen %d\n", reclen)); - Msgf(("offset %ld\n", offset)); - Msgf(("nrecs*reclen %d\n", nrecs*reclen)); - Msgf(("my_start %ld\n", my_start)); - Msgf(("my_size %ld\n", my_size)); - Msgf(("my_end %ld\n", my_end)); - - /* post Irecvs for my data */ - for (i = 0; i < nproc; i++) { - if (allbuf[i].start<=offset && offset reclen*nrecs) size = reclen*nrecs; - Msgf(("irecv %ld from %d\n", size, i)); - if (nreq >= MAXREQ) Error("Too many Irecvs in fseekrd\n"); - MPMY_Irecv(buf, size, i, MPMY_IOTAG, &req[nreq]); - ++nreq; - } else if (offset <= allbuf[i].start && offend > allbuf[i].start+allbuf[i].flen) { - size = allbuf[i].flen; - Msgf(("irecv %ld from %d\n", size, i)); - if (nreq >= MAXREQ) Error("Too many Irecvs in fseekrd\n"); - MPMY_Irecv((char *)buf+allbuf[i-1].start+allbuf[i-1].flen-offset, - size, i, MPMY_IOTAG+2, &req[nreq]); - ++nreq; - } else if (allbuf[i].start= MAXREQ) Error("Too many Irecvs in fseekrd\n"); - MPMY_Irecv((char *)buf+reclen*nrecs-size, size, i, - MPMY_IOTAG+1, &req[nreq]); - ++nreq; - } - } - - for (i = 0; i < nproc; i++) { - offset = allbuf[i].offset; - reclen = allbuf[i].reclen; - nrecs = allbuf[i].nrecs; - offend = offset+reclen*nrecs; - - if (my_start <= offset && offset < my_end) { - size = my_end-offset; - if (size > reclen*nrecs) size = reclen*nrecs; - lseek(fd, offset-my_start, SEEK_SET); - tmpbuf = Realloc(tmpbuf, size); - nread = read(fd, tmpbuf, size); - Msgf(("send %ld to %d\n", size, i)); - MPMY_send(tmpbuf, size, i, MPMY_IOTAG); - } else if (offset <= my_start && offend > my_end) { - size = my_end-my_start; - lseek(fd, 0, SEEK_SET); - tmpbuf = Realloc(tmpbuf, size); - nread = read(fd, tmpbuf, size); - Msgf(("send %ld to %d\n", size, i)); - MPMY_send(tmpbuf, size, i, MPMY_IOTAG+2); - } else if (my_start < offend && offend <= my_end) { - size = offend-my_start; - lseek(fd, 0, SEEK_SET); - tmpbuf = Realloc(tmpbuf, size); - nread = read(fd, tmpbuf, size); - Msgf(("send %ld to %d\n", size, i)); - MPMY_send(tmpbuf, size, i, MPMY_IOTAG+1); - } - } - Free(tmpbuf); - Free(allbuf); - nread = 0; - Msg_flush(); -#if 0 - for (i = 0; i < nreq; i++) { - MPMY_Wait(req[i], &stat); - Msgf(("Got %d from %d\n", stat.count, stat.src)); - nread += stat.count; - } -#else - i = 0; - while( nreq ){ - int done; - /* Msgf(("Testing req[%d] = %p\n", i, req[i])); */ - MPMY_Test(req[i], &done, &stat); - if( done ){ - Msgf(("Got %d from %d\n", stat.count, stat.src)); - nread += stat.count; - Msgf(("Moving req[%d] = req[%d] = ", i, nreq-1)); - req[i] = req[--nreq]; - Msgf(("%p\n", req[i])); - }else{ - /* Msgf(("Req[%d] not done yet\n", i)); */ - i++; - } - assert(i <= nreq ); - if( i == nreq ) - i = 0; - } -#endif - Msgf(("fseekrd_nfile returning = %ld\n", nread/reclen)); - return nread/reclen; -} - -/* This should be called from fseekrd0 instead of replicating code */ - -static int -fseekrd(int fd, off_t offset, int whence, void *buf, int reclen, - int nrecs) -{ - int doseek; - int real_whence; - off_t nread = 0; - off_t len; - - if( whence == SEEK_CUR ){ - doseek = (offset != 0); - }else if( whence == SEEK_SET ){ - /* don't worry about errors. If ftell returns -1, */ - /* doseek will be turned on, and the fseek below will */ - /* (probably) fail */ - doseek = (lseek(fd, 0L, SEEK_CUR) != offset); - }else{ - doseek = 1; - } - - if( doseek ){ - switch(whence){ - case MPMY_SEEK_SET: - real_whence = SEEK_SET; - break; - case MPMY_SEEK_CUR: - real_whence = SEEK_CUR; - break; - case MPMY_SEEK_END: - real_whence = SEEK_END; - break; - default: - Shout("Illegal value of whence (%d) in fseekrd\n", whence); - return -1; - } - if (lseek(fd, offset, real_whence) == -1) { - Error("fseekrd: lseek(%d, %ld, %d) failed, errno=%d\n", - fd, (long)offset, whence, errno); - return -1; - } - } - len = 0; - while (len < reclen*nrecs) { - nread = read(fd, (char *)buf+len, reclen*nrecs-len); - if (nread == -1) { - Error("fseekrd: read(%d, %ld) failed, errno=%d\n", - fd, (long)reclen*nrecs-len, errno); - return -1; - } else if (nread == 0) { - Error("fseekrd: read(%d, %ld) got EOF\n", - fd, (long)reclen*nrecs-len); - return -1; - } else { - printf("%d fseekrd(%d): got %ld\n", fd, MPMY_Procnum(), (long)nread); - len += nread; - } - } - if (len != reclen*nrecs) Error("fseekrd: Wrong amount of data\n"); - return nread/reclen; -} - -size_t -MPMY_Fseekrd(MPMYFile *Fp, off_t offset, int whence, void *buf, size_t reclen, - size_t nrecs) -{ - struct _File *fp = (struct _File *)Fp; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iotype & MPMY_NFILE) { - nrecs = fseekrd_nfile(fp->fd, offset, whence, buf, reclen, nrecs); - } else if (fp->iotype == MPMY_INDEPENDENT) { - nrecs = fseekrd(fp->fd, offset, whence, buf, reclen, nrecs); - } else { - nrecs = fseekrd0(fp->fd, offset, whence, buf, reclen, nrecs); - } - return nrecs; -} - -#include "iozero.c" -#include "io_generic.c" diff --git a/external/libsdf/libmpmy/mpmy_mpi.c b/external/libsdf/libmpmy/mpmy_mpi.c deleted file mode 100644 index 6218dd8..0000000 --- a/external/libsdf/libmpmy/mpmy_mpi.c +++ /dev/null @@ -1,399 +0,0 @@ -#ifdef _SWAMPI -#include -#else -#include -#endif -#include "mpmy_abnormal.h" - -#include "Malloc.h" - -#include "chn.h" -#include "mpmy.h" -#include "Assert.h" -#include "timers.h" -#include "Msgs.h" -#include "error.h" -#include "memfile.h" - -struct comm_s { - MPI_Request hndl; - int inout; -}; - -static Chn commchn; -#define NCOMM 2048 -#define IN 1 -#define OUT 2 - -int MPMY_Isend(const void *buf, int cnt, int dest, int tag, - MPMY_Comm_request *reqp) { - struct comm_s *comm = ChnAlloc(&commchn); - - Msgf(("Isend: buf=%p, cnt=%d, dest=%d, tag=%d\n", - buf, cnt, dest, tag)); - if (MPI_Isend((void *)buf, cnt, MPI_BYTE, dest, tag, MPI_COMM_WORLD, - &comm->hndl) != MPI_SUCCESS) - Error("MPMY_Isend MPI_Isend failed\n"); - comm->inout = OUT; - Msgf(("Isend: hndl=%ld\n", (long) comm->hndl)); - *reqp = comm; - return MPMY_SUCCESS; -} - -#if 0 -#define HAVE_MPMY_IRSEND -int MPMY_Irsend(const void *buf, int cnt, int dest, int tag, - MPMY_Comm_request *reqp) { - struct comm_s *comm = ChnAlloc(&commchn); - - Msgf(("Irsend: buf=%p, dest=%d, tag=%d\n", - buf, dest, tag)); - if (MPI_Irsend(buf, cnt, MPI_BYTE, dest, tag, MPI_COMM_WORLD, - &comm->hndl) != MPI_SUCCESS) - Error("MPMY_Isend MPI_Irsend failed\n"); - comm->inout = OUT; - Msgf(("Irsend: hndl=%d\n", (int) comm->hndl)); - *reqp = comm; - return MPMY_SUCCESS; -} -#endif /* 0 */ - -int MPMY_Irecv(void *buf, int cnt, int src, int tag, MPMY_Comm_request *reqp) { - struct comm_s *comm = ChnAlloc(&commchn); - - if (tag == MPMY_TAG_ANY) tag = MPI_ANY_TAG; - if (src == MPMY_SOURCE_ANY) { - src = MPI_ANY_SOURCE; - } else if (src < 0 || src >= MPMY_Nproc()) { - Error("Bad src (%d) in Irecv\n", src); - } - Msgf(("Irecv: buf=%p, src=%d, tag=%d\n", - buf, src, tag)); - if (MPI_Irecv(buf, cnt, MPI_BYTE, src, tag, MPI_COMM_WORLD, - &comm->hndl) != MPI_SUCCESS) - Error("MPMY_Irecv MPI_Irecv failed\n"); - comm->inout = IN; - Msgf(("Irecv: hndl=%ld\n", (long) comm->hndl)); - *reqp = comm; - return MPMY_SUCCESS; -} - -int MPMY_Test(MPMY_Comm_request req, int *flag, MPMY_Status *stat) { - struct comm_s *comm = req; - MPI_Status status; - int cnt; - int ret = 0; - - Msgf(("MPMY_Test hndl=%ld at %p\n", (long) comm->hndl, &comm->hndl)); - if ((ret = MPI_Test(&comm->hndl, flag, &status)) != MPI_SUCCESS) { - Error("MPMY_Test MPI_Test failed (%d), MPI_ERROR %d, hndl=%ld at %p, flag=%p, status=%p\n", - ret, status.MPI_ERROR, (long)comm->hndl, &comm->hndl, flag, &status); - } - Msgf(("Tested (%s), %d\n", - (comm->inout==IN)?"in":"out", *flag)); - if (*flag) { - if(comm->inout == IN) { - MPI_Get_count(&status, MPI_BYTE, &cnt); - Msgf(("Recvd(T) from %d, tag %d, count: %d\n", - status.MPI_SOURCE, status.MPI_TAG, cnt)); - if (stat) { - stat->src = status.MPI_SOURCE; - stat->tag = status.MPI_TAG; - stat->count = cnt; - } - } - ChnFree(&commchn, comm); - } - return MPMY_SUCCESS; -} - -#define HAVE_MPMY_WAIT -int MPMY_Wait(MPMY_Comm_request req, MPMY_Status *stat) { - struct comm_s *comm = req; - MPI_Status status; - int cnt; - - Msgf(("Wait for %ld\n", (long) comm->hndl)); - if (MPI_Wait(&comm->hndl, &status) != MPI_SUCCESS) - Error("MPMY_Wait MPI_Wait failed\n"); - Msgf(("Waited for (%s), deallocated\n", - (comm->inout==IN)?"in":"out")); - if(comm->inout == IN) { - MPI_Get_count(&status, MPI_BYTE, &cnt); - Msgf(("Recvd(W) from %d, tag %d, count: %d\n", - status.MPI_SOURCE, status.MPI_TAG, cnt)); - if (stat) { - stat->src = status.MPI_SOURCE; - stat->tag = status.MPI_TAG; - stat->count = cnt; - } - } - ChnFree(&commchn, comm); - return MPMY_SUCCESS; -} - -#define HAVE_MPMY_SHIFT -#define SHIFT_TAG 0x1492 -int MPMY_Shift(int proc, void *recvbuf, int recvcnt, - const void *sendbuf, int sendcnt, MPMY_Status *stat) { - MPI_Status status; - int count; - - Msgf(("Starting MPMY_Shift(proc=%d, recvcnt=%d, sendcnt=%d, recvbuf=%p, sendbuf=%p\n", - proc, recvcnt, sendcnt, recvbuf, sendbuf)); - - if (MPI_Sendrecv((void *)sendbuf, sendcnt, MPI_BYTE, proc, SHIFT_TAG, - recvbuf, recvcnt, MPI_BYTE, proc, SHIFT_TAG, - MPI_COMM_WORLD, &status) != MPI_SUCCESS) - Error("MPMY_Shift MPI_Sendrecv failed\n"); - MPI_Get_count(&status, MPI_BYTE, &count); - Msgf(("MPMY_Shift done, received=%d\n", count)); - if (stat) { - stat->count = count; - stat->src = status.MPI_SOURCE; - stat->tag = status.MPI_TAG; - } - return MPMY_SUCCESS; -} - -int -Native_MPMY_Alltoall(void *sendbuf, int sendcount, MPMY_Datatype sendtype, - void *recvbuf, int recvcount, MPMY_Datatype recvtype) -{ - MPI_Datatype st, rt; - - switch (sendtype){ - case MPMY_FLOAT: - st = MPI_FLOAT; - break; - case MPMY_DOUBLE: - st = MPI_DOUBLE; - break; - case MPMY_INT: - st = MPI_INT; - break; - case MPMY_CHAR: - st = MPI_CHAR; - break; - default: - Error("No type match in alltoall\n"); - } - switch (recvtype){ - case MPMY_FLOAT: - rt = MPI_FLOAT; - break; - case MPMY_DOUBLE: - rt = MPI_DOUBLE; - break; - case MPMY_INT: - rt = MPI_INT; - break; - case MPMY_CHAR: - rt = MPI_CHAR; - break; - default: - Error("No type match in alltoall\n"); - } - MPI_Alltoall(sendbuf, sendcount, st, - recvbuf, recvcount, rt, MPI_COMM_WORLD); - return MPMY_SUCCESS; -} - -int -Native_MPMY_Alltoallv(void *sendbuf, int *sendcounts, int *sendoffsets, MPMY_Datatype sendtype, - void *recvbuf, int *recvcounts, int *recvoffsets, MPMY_Datatype recvtype) -{ - MPI_Datatype st, rt; - - switch (sendtype){ - case MPMY_FLOAT: - st = MPI_FLOAT; - break; - case MPMY_DOUBLE: - st = MPI_DOUBLE; - break; - case MPMY_INT: - st = MPI_INT; - break; - case MPMY_CHAR: - st = MPI_CHAR; - break; - case MPMY_SHORT: - st = MPI_SHORT; - break; - case MPMY_LONG: - st = MPI_LONG; - break; - default: - Error("No type match in alltoallv\n"); - } - switch (recvtype){ - case MPMY_FLOAT: - rt = MPI_FLOAT; - break; - case MPMY_DOUBLE: - rt = MPI_DOUBLE; - break; - case MPMY_INT: - rt = MPI_INT; - break; - case MPMY_CHAR: - rt = MPI_CHAR; - break; - case MPMY_SHORT: - rt = MPI_SHORT; - break; - case MPMY_LONG: - rt = MPI_LONG; - break; - default: - Error("No type match in alltoallv\n"); - } - MPI_Alltoallv(sendbuf, sendcounts, sendoffsets, st, - recvbuf, recvcounts, recvoffsets, rt, MPI_COMM_WORLD); - return MPMY_SUCCESS; -} - -int -Native_MPMY_Allgather(void *sendbuf, int sendcount, MPMY_Datatype type, void *recvbuf) -{ - MPI_Datatype st, rt; - int recvcount = sendcount; - - switch (type){ - case MPMY_FLOAT: - st = MPI_FLOAT; - break; - case MPMY_DOUBLE: - st = MPI_DOUBLE; - break; - case MPMY_INT: - st = MPI_INT; - break; - case MPMY_CHAR: - st = MPI_CHAR; - break; - case MPMY_SHORT: - st = MPI_SHORT; - break; - case MPMY_LONG: - st = MPI_LONG; - break; - default: - Error("No type match in allgather\n"); - } - rt = st; - MPI_Allgather(sendbuf, sendcount, st, - recvbuf, recvcount, rt, MPI_COMM_WORLD); - return MPMY_SUCCESS; -} - -int -Native_MPMY_Allgatherv(void *sendbuf, int sendcount, MPMY_Datatype type, void *recvbuf, - int *rcounts, int *roffsets) -{ - MPI_Datatype st, rt; - - switch (type){ - case MPMY_FLOAT: - st = MPI_FLOAT; - break; - case MPMY_DOUBLE: - st = MPI_DOUBLE; - break; - case MPMY_INT: - st = MPI_INT; - break; - case MPMY_CHAR: - st = MPI_CHAR; - break; - case MPMY_SHORT: - st = MPI_SHORT; - break; - case MPMY_LONG: - st = MPI_LONG; - break; - default: - Error("No type match in allgather\n"); - } - rt = st; - MPI_Allgatherv(sendbuf, sendcount, st, - recvbuf, rcounts, roffsets, rt, MPI_COMM_WORLD); - return MPMY_SUCCESS; -} - - -#define HAVE_MPMY_SYNC -int MPMY_Sync(void) { - MPI_Barrier(MPI_COMM_WORLD); - return MPMY_SUCCESS; -} - -int MPMY_Init(int *argcp, char ***argvp) { - ChnInit(&commchn, sizeof(struct comm_s), NCOMM, Realloc_f); - ChnMoreMem(&commchn); /* alloc now to prevent heap fragmentation later */ - if (MPI_Init(argcp, argvp) != MPI_SUCCESS) - Error("MPMY_Init MPI_Init failed\n"); - if (MPI_Comm_size(MPI_COMM_WORLD, &_MPMY_nproc_) != MPI_SUCCESS) - Error("MPMY_Init MPI_Comm_size failed\n"); - if (MPI_Comm_rank(MPI_COMM_WORLD, &_MPMY_procnum_) != MPI_SUCCESS) - Error("MPMY_Init MPI_Comm_rank failed\n"); -#ifdef PROCS_PER_NODE - _MPMY_procs_per_node_ = PROCS_PER_NODE; -#else - _MPMY_procs_per_node_ = 1; -#endif - _MPMY_setup_absigs(); - MPMY_OnAbnormal(MPMY_SystemAbort); - MPMY_OnAbnormal(MPMY_Abannounce); - MPMY_OnAbnormal(PrintMemfile); - _MPMY_initialized_ = 1; - return MPMY_SUCCESS; -} - -#define HAVE_MPMY_FINALIZE -int MPMY_Finalize(void){ - return (MPI_Finalize() == MPI_SUCCESS) ? MPMY_SUCCESS : MPMY_FAILED ; -} - -#define HAVE_MPMY_FLICK -int MPMY_Flick(void){ - return MPMY_SUCCESS; -} - -#define HAVE_MPMY_JOBREMAINING -int -MPMY_JobRemaining(void) -{ - /* returns -1 for failure, or if not a slurm job */ - return -1; -} - - -#ifdef USE_HWCLOCK -#include "timers_hwclock.c" -#endif - -#ifdef USE_GETTIME -#include "timers_gettime.c" -#endif - -#if !defined(USE_HWCLOCK) && !defined(USE_GETTIME) -#define HAVE_MPMY_TIMERS -#include "timers_mpi.c" -#endif - -#if defined(__CM5__) || defined(_AIX) || defined(__AP1000__) -#define CANT_USE_ALARM -#endif -#if defined(__CM5__) || defined(__INTEL_SSD__) -#include "mpmy_pario.c" -#else -#if defined(USE_MPIIO) -#include "mpmy_mpiio.c" -#else -#include "mpmy_io.c" -#endif -#endif -#include "mpmy_abnormal.c" -#include "mpmy_generic.c" diff --git a/external/libsdf/libmpmy/mpmy_mpiio.1.c b/external/libsdf/libmpmy/mpmy_mpiio.1.c deleted file mode 100644 index 84b59c6..0000000 --- a/external/libsdf/libmpmy/mpmy_mpiio.1.c +++ /dev/null @@ -1,292 +0,0 @@ -/* This file contains the parallel I/O suitable for CMMD and NX. - It wouldn't be hard to add cubix-syntax as well. Are there any - other options? Would they fit in this structure? The only - difference between CMMD and NX is in Fopen, where one - system calls gopen() and the other calls CMMD_set_io_mode(). - We use a pre-processor symbol (__INTEL_SSD__) or (__CM5__) to decide - which one to use. __INTEL_SSD__ is set by the ARCH-specific Makefiles, - while __CM5__ is set by mpmy_cm5.c, which #includes this file. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef OPEN_MPI -#include -#endif -#include "protos.h" -#include "mpmy.h" -#include "mpmy_io.h" -#include "Msgs.h" - -#ifndef EINVAL -/* just in case... */ -#define EINVAL 0 -#endif - -#define NFILES 4096 - -static struct _File{ - MPI_File fd; - int iomode; -} _files[NFILES]; - -static int files; /* need dynamic storage */ - -static int do_nfileio; - -MPMYFile * -MPMY_Fopen(const char *path, int flags) -{ - MPI_File fd; - MPI_Info info; - int iomode = MPMY_SINGL; /* default */ - int real_flags = MPI_MODE_RDONLY; /* if no flags specified */ - int ret; - - Msgf(("Fopen %s, flags = 0x%x\n", path, flags)); - if (flags & MPMY_RDONLY) real_flags = MPI_MODE_RDONLY; - if (flags & MPMY_WRONLY) real_flags = MPI_MODE_WRONLY; - if (flags & MPMY_RDWR) real_flags = MPI_MODE_RDWR; - if (flags & MPMY_APPEND) real_flags |= MPI_MODE_APPEND; - if (flags & MPMY_TRUNC && ((flags & MPMY_WRONLY) || (flags & MPMY_RDWR))) { - int fd; - if (MPMY_Procnum() == 0) { - fd = open(path, O_RDWR|O_TRUNC, 0644); - if (fd < 0) Msgf(("Fopen fails, errno=%d\n", errno)); - else close(fd); - MPMY_Sync(); - } else { - MPMY_Sync(); - } - } - if (flags & MPMY_CREAT) real_flags |= MPI_MODE_CREATE; - - /* Panasas optimizations */ - real_flags |= MPI_MODE_UNIQUE_OPEN; /* dangerous? */ - MPI_Info_create(&info); - MPI_Info_set(info, "panfs_concurrent_write", "1"); - - /* Should we make sure that only one of them is on?? */ - if (flags & MPMY_MULTI) iomode = MPMY_MULTI; - if (flags & MPMY_SINGL) iomode = MPMY_SINGL; - - if (flags & MPMY_NFILE) Error("MPMY_NFILE not supported\n"); - if (flags & MPMY_IOZERO) Error("MPMY_IOZERO not supported\n"); - if (flags & MPMY_INDEPENDENT) Error("MPMY_INDEPENDENT not supported\n"); - - if (flags & MPMY_SINGL) { - Msgf(("Fopen %s in SINGL mode\n", path)); - } else { - Msgf(("Fopen %s in MULTI mode\n", path)); - } - Msgf(("MPI_File_open %s with flags = 0x%x\n", path, real_flags)); - ret = MPI_File_open(MPI_COMM_WORLD, (char *)path, real_flags, info, &fd); - - if (files >= NFILES) Error("files too large\n"); - if (ret == 0) { - _files[files].iomode = iomode; - _files[files].fd = fd; - Msgf(("Fopen returns fd %p, iomode=%d, flags=0x%x\n", - fd, iomode, flags)); - return &(_files[files++]); - } else { - Msgf(("Fopen fails, errno=%d\n", errno)); - return NULL; - } -} - -int -MPMY_Nfileio(int val){ - int oldval = do_nfileio; - do_nfileio = val; - return oldval; -} - -int -MPMY_Fclose(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - int ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - Msgf(("Fclose %p\n", fp->fd)); - ret = MPI_File_close(&fp->fd); - return ret; -} - -int -MPMY_Mkdir(const char *path, int mode) -{ - int ret; - - if( MPMY_Procnum() == 0 ){ - ret = mkdir(path, mode); - if( ret && errno == EEXIST ){ - /* Let's just pretend we really made it... */ - ret = 0; - } - } - MPMY_BcastTag(&ret, 1, MPMY_INT, 0, 0x4579 ); - return ret; -} - -size_t -MPMY_Fread(void *ptr, size_t size, size_t nitems, MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Status status; - int cnt; - size_t nread = size*nitems; - const char *p = ptr; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - MPI_File_read_all(fp->fd, (void *)p, nread, MPI_CHAR, &status); - } else { - MPI_File_read_ordered(fp->fd, (void *)p, nread, MPI_CHAR, &status); - } - MPI_Get_count(&status, MPI_BYTE, &cnt); - if (cnt != nread) Error("MPMY_Fread has a problem\n"); - Msgf(("MPI_File_read from %p returns %d\n", fp->fd, cnt)); - return nitems; -} - -size_t -MPMY_Fwrite(const void *ptr, size_t size, size_t nitems, MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Status status; - int cnt; - size_t nwrite = size*nitems; - const char *p = ptr; - - Msgf(("MPMY_Fwrite %ld %ld\n", size, nitems)); - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - MPI_File_write_all(fp->fd, (void *)p, nwrite, MPI_CHAR, &status); - } else { - MPI_File_write_ordered(fp->fd, (void *)p, nwrite, MPI_CHAR, &status); - } - MPI_Get_count(&status, MPI_BYTE, &cnt); - if (cnt != nwrite) Error("MPMY_Fread has a problem\n"); - Msgf(("MPI_File_write from %p returns %d\n", fp->fd, cnt)); - return nitems; -} - -int -MPMY_Fseek(MPMYFile *Fp, off_t offset, int whence) -{ - struct _File *fp = (struct _File *)Fp; - int ret; - MPI_Offset mpi_offset; - int real_whence = 0; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - - if (whence == MPMY_SEEK_SET) real_whence = MPI_SEEK_SET; - if (whence == MPMY_SEEK_CUR) real_whence = MPI_SEEK_CUR; - if (whence == MPMY_SEEK_END) real_whence = MPI_SEEK_END; - - mpi_offset = offset; /* potential conversion problem */ - if (fp->iomode == MPMY_SINGL) { - ret = MPI_File_seek_shared(fp->fd, mpi_offset, real_whence); - } else { - ret = MPI_File_seek(fp->fd, mpi_offset, real_whence); - } - if (ret != -1) ret = 0; - Msgf(("Fseek to %ld returns %d\n", (long)mpi_offset, ret)); - return ret; -} - -off_t -MPMY_Ftell(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Offset mpi_offset; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - MPI_File_get_position_shared(fp->fd, &mpi_offset); - } else { - MPI_File_get_position(fp->fd, &mpi_offset); - } - Msgf(("Ftell returns %ld\n", (long)mpi_offset)); - return mpi_offset; -} - -off_t -MPMY_Flen(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Offset mpi_offset_current, mpi_offset_end; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - MPI_File_get_position_shared(fp->fd, &mpi_offset_current); - MPI_File_seek_shared(fp->fd, mpi_offset_current, MPI_SEEK_END); - MPI_File_get_position_shared(fp->fd, &mpi_offset_end); - MPI_File_seek_shared(fp->fd, mpi_offset_current, MPI_SEEK_SET); - } else { - MPI_File_get_position(fp->fd, &mpi_offset_current); - MPI_File_seek(fp->fd, mpi_offset_current, MPI_SEEK_END); - MPI_File_get_position(fp->fd, &mpi_offset_end); - MPI_File_seek(fp->fd, mpi_offset_current, MPI_SEEK_SET); - } - Msgf(("Flen returns %ld\n", (long)mpi_offset_end)); - return mpi_offset_end; -} - -size_t -MPMY_Fseekrd(MPMYFile *Fp, off_t offset, int whence, void *buf, size_t reclen, - size_t nrecs) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Offset mpi_offset; - MPI_Status status; - int cnt; - size_t nread = reclen*nrecs; - const char *p = buf; - - Msgf(("Fseekrd %ld at %ld\n", (size_t)reclen*nrecs, offset)); - mpi_offset = offset; - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - MPI_File_read_at_all(fp->fd, mpi_offset, (void *)p, nread, MPI_BYTE, &status); - } else { - MPI_File_read_at(fp->fd, mpi_offset, (void *)p, nread, MPI_BYTE, &status); - } - MPI_Get_count(&status, MPI_BYTE, &cnt); - if (cnt != nread) Error("MPMY_Fseekrd has a problem, got %d expected %ld\n", - cnt, nread); - return nrecs; -} - -#include "io_generic.c" diff --git a/external/libsdf/libmpmy/mpmy_mpiio.c b/external/libsdf/libmpmy/mpmy_mpiio.c deleted file mode 100644 index f1c1c93..0000000 --- a/external/libsdf/libmpmy/mpmy_mpiio.c +++ /dev/null @@ -1,346 +0,0 @@ -/* This file contains the parallel I/O suitable for CMMD and NX. - It wouldn't be hard to add cubix-syntax as well. Are there any - other options? Would they fit in this structure? The only - difference between CMMD and NX is in Fopen, where one - system calls gopen() and the other calls CMMD_set_io_mode(). - We use a pre-processor symbol (__INTEL_SSD__) or (__CM5__) to decide - which one to use. __INTEL_SSD__ is set by the ARCH-specific Makefiles, - while __CM5__ is set by mpmy_cm5.c, which #includes this file. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef OPEN_MPI -#include -#endif -#include "protos.h" -#include "mpmy.h" -#include "mpmy_io.h" -#include "Msgs.h" - -#ifndef EINVAL -/* just in case... */ -#define EINVAL 0 -#endif - -#define NFILES 4096 - -/* MPI only allows 2GB buffer sizes, and MPI_Get_Count uses an int */ -#define MAXIOSIZE (256*1024*1024) - -static struct _File{ - MPI_File fd; - int iomode; -} _files[NFILES]; - -static int files; /* need dynamic storage */ - -static int do_nfileio; - -MPMYFile * -MPMY_Fopen(const char *path, int flags) -{ - MPI_File fd; - MPI_Info info; - int iomode = MPMY_SINGL; /* default */ - int real_flags = MPI_MODE_RDONLY; /* if no flags specified */ - int ret; - - Msgf(("Fopen %s, flags = 0x%x\n", path, flags)); - if (flags & MPMY_RDONLY) real_flags = MPI_MODE_RDONLY; - if (flags & MPMY_WRONLY) real_flags = MPI_MODE_WRONLY; - if (flags & MPMY_RDWR) real_flags = MPI_MODE_RDWR; - if (flags & MPMY_APPEND) real_flags |= MPI_MODE_APPEND; - if (flags & MPMY_TRUNC && ((flags & MPMY_WRONLY) || (flags & MPMY_RDWR))) { - int fd; - if (MPMY_Procnum() == 0) { - fd = open(path, O_RDWR|O_TRUNC, 0644); - if (fd < 0) Msgf(("Fopen fails, errno=%d\n", errno)); - else close(fd); - MPMY_Sync(); - } else { - MPMY_Sync(); - } - } - if (flags & MPMY_CREAT) real_flags |= MPI_MODE_CREATE; - - /* Panasas optimizations */ - if (!(flags & MPMY_RDONLY)) - real_flags |= MPI_MODE_UNIQUE_OPEN; /* dangerous? */ - MPI_Info_create(&info); - MPI_Info_set(info, "panfs_concurrent_write", "1"); - - /* Should we make sure that only one of them is on?? */ - if (flags & MPMY_MULTI) iomode = MPMY_MULTI; - if (flags & MPMY_SINGL) iomode = MPMY_SINGL; - - if (flags & MPMY_NFILE) Error("MPMY_NFILE not supported\n"); - if (flags & MPMY_IOZERO) Error("MPMY_IOZERO not supported\n"); - if (flags & MPMY_INDEPENDENT) Error("MPMY_INDEPENDENT not supported\n"); - - if (flags & MPMY_SINGL) { - Msgf(("Fopen %s in SINGL mode\n", path)); - } else { - Msgf(("Fopen %s in MULTI mode\n", path)); - } - Msgf(("MPI_File_open %s with flags = 0x%x\n", path, real_flags)); - ret = MPI_File_open(MPI_COMM_WORLD, (char *)path, real_flags, info, &fd); - - if (files >= NFILES) Error("files too large\n"); - if (ret == 0) { - _files[files].iomode = iomode; - _files[files].fd = fd; - Msgf(("Fopen returns fd %p, iomode=%d, flags=0x%x\n", - fd, iomode, flags)); - return &(_files[files++]); - } else { - Msgf(("Fopen fails, errno=%d\n", errno)); - return NULL; - } -} - -int -MPMY_Nfileio(int val){ - int oldval = do_nfileio; - do_nfileio = val; - return oldval; -} - -int -MPMY_Fclose(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - int ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - Msgf(("Fclose %p\n", fp->fd)); - ret = MPI_File_close(&fp->fd); - return ret; -} - -int -MPMY_Mkdir(const char *path, int mode) -{ - int ret; - - if( MPMY_Procnum() == 0 ){ - ret = mkdir(path, mode); - if( ret && errno == EEXIST ){ - /* Let's just pretend we really made it... */ - ret = 0; - } - } - MPMY_BcastTag(&ret, 1, MPMY_INT, 0, 0x4579 ); - return ret; -} - -size_t -MPMY_Fread(void *ptr, size_t size, size_t nitems, MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Status status; - int cnt; - size_t nread = size*nitems; - const char *p = ptr; - - Msgf(("MPMY_Fread %ld %ld\n", size, nitems)); - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - if (nread >= (1 << 31)) Error("MPMY_SINGL does not yet support large reads\n"); - MPI_File_read_all(fp->fd, (void *)p, nread, MPI_CHAR, &status); - MPI_Get_count(&status, MPI_CHAR, &cnt); - } else { - MPI_Offset mpi_offset; - size_t left, *sizes; - int i; - assert(sizeof(size_t) == MPMY_Datasize[MPMY_LONG]); - sizes = Malloc(sizeof(size_t)*MPMY_Nproc()); - /* Use scan instead? */ - Native_MPMY_Allgather(&nread, 1, MPMY_LONG, sizes); - MPI_File_get_position(fp->fd, &mpi_offset); - Msgf(("Starting offset in MPMY_Fread is %lld\n", mpi_offset)); - for (i = 0; i < MPMY_Procnum(); i++) { - mpi_offset += sizes[i]; - } - Msgf(("My offset in MPMY_Fread is %lld\n", mpi_offset)); - Free(sizes); - left = nread; - while (left > 0) { - nread = (left < MAXIOSIZE) ? left : MAXIOSIZE; - Msgf(("read %ld at %lld\n", nread, mpi_offset)); - Msg_flush(); - MPI_File_read_at(fp->fd, mpi_offset, (void *)p, nread, MPI_CHAR, &status); - left -= nread; - p += nread; - mpi_offset += nread; - MPI_Get_count(&status, MPI_CHAR, &cnt); - } - } - return cnt/size; -} - -size_t -MPMY_Fwrite(const void *ptr, size_t size, size_t nitems, MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Status status; - int cnt; - size_t nwrite = size*nitems; - const char *p = ptr; - - Msgf(("MPMY_Fwrite %ld %ld\n", size, nitems)); - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - if (nwrite >= (1 << 31)) Error("MPMY_SINGL does not yet support large writes\n"); - MPI_File_write_all(fp->fd, (void *)p, nwrite, MPI_CHAR, &status); - MPI_Get_count(&status, MPI_CHAR, &cnt); - if (cnt != nwrite) Error("MPMY_Fwrite has a problem, wrote %d of %ld\n", - cnt, nwrite); - } else { - MPI_Offset mpi_offset; - size_t left, *sizes; - int i; - assert(sizeof(size_t) == MPMY_Datasize[MPMY_LONG]); - sizes = Malloc(sizeof(size_t)*MPMY_Nproc()); - Native_MPMY_Allgather(&nwrite, 1, MPMY_LONG, sizes); - MPI_File_get_position(fp->fd, &mpi_offset); - Msgf(("Starting offset in MPMY_Fwrite is %lld\n", mpi_offset)); - for (i = 0; i < MPMY_Procnum(); i++) { - mpi_offset += sizes[i]; - } - Msgf(("My offset in MPMY_Fwrite is %lld\n", mpi_offset)); - Free(sizes); - left = nwrite; - while (left > 0) { - nwrite = (left < MAXIOSIZE) ? left : MAXIOSIZE; - Msgf(("write %ld at %lld\n", nwrite, mpi_offset)); - Msg_flush(); - MPI_File_write_at(fp->fd, mpi_offset, (void *)p, nwrite, MPI_CHAR, &status); - left -= nwrite; - p += nwrite; - mpi_offset += nwrite; - MPI_Get_count(&status, MPI_CHAR, &cnt); - if (cnt != nwrite) Error("MPMY_Fwrite has a problem, wrote %d of %ld\n", - cnt, nwrite); - } - } - return nitems; -} - -off_t -MPMY_Fseek(MPMYFile *Fp, off_t offset, int whence) -{ - struct _File *fp = (struct _File *)Fp; - int ret; - MPI_Offset mpi_offset; - int real_whence = 0; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - - if (whence == MPMY_SEEK_SET) real_whence = MPI_SEEK_SET; - if (whence == MPMY_SEEK_CUR) real_whence = MPI_SEEK_CUR; - if (whence == MPMY_SEEK_END) real_whence = MPI_SEEK_END; - - mpi_offset = offset; /* potential conversion problem */ - if (fp->iomode == MPMY_SINGL) { - ret = MPI_File_seek_shared(fp->fd, mpi_offset, real_whence); - } else { - ret = MPI_File_seek(fp->fd, mpi_offset, real_whence); - } - if (ret != -1) ret = 0; - Msgf(("Fseek to %ld returns %d\n", (long)mpi_offset, ret)); - return ret; -} - -off_t -MPMY_Ftell(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Offset mpi_offset; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - MPI_File_get_position_shared(fp->fd, &mpi_offset); - } else { - MPI_File_get_position(fp->fd, &mpi_offset); - } - Msgf(("Ftell returns %ld\n", (long)mpi_offset)); - return mpi_offset; -} - -off_t -MPMY_Flen(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Offset mpi_offset_current, mpi_offset_end; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - MPI_File_get_position_shared(fp->fd, &mpi_offset_current); - MPI_File_seek_shared(fp->fd, mpi_offset_current, MPI_SEEK_END); - MPI_File_get_position_shared(fp->fd, &mpi_offset_end); - MPI_File_seek_shared(fp->fd, mpi_offset_current, MPI_SEEK_SET); - } else { - MPI_File_get_position(fp->fd, &mpi_offset_current); - MPI_File_seek(fp->fd, mpi_offset_current, MPI_SEEK_END); - MPI_File_get_position(fp->fd, &mpi_offset_end); - MPI_File_seek(fp->fd, mpi_offset_current, MPI_SEEK_SET); - } - Msgf(("Flen returns %ld\n", (long)mpi_offset_end)); - return mpi_offset_end; -} - -size_t -MPMY_Fseekrd(MPMYFile *Fp, off_t offset, int whence, void *buf, size_t reclen, - size_t nrecs) -{ - struct _File *fp = (struct _File *)Fp; - MPI_Offset mpi_offset; - MPI_Status status; - int cnt; - size_t nread = reclen*nrecs; - const char *p = buf; - - Msgf(("Fseekrd %ld at %ld\n", (size_t)reclen*nrecs, offset)); - mpi_offset = offset; - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - MPI_File_read_at_all(fp->fd, mpi_offset, (void *)p, nread, MPI_BYTE, &status); - } else { - MPI_File_read_at(fp->fd, mpi_offset, (void *)p, nread, MPI_BYTE, &status); - } - MPI_Get_count(&status, MPI_BYTE, &cnt); - if (cnt != nread) Error("MPMY_Fseekrd has a problem, got %d expected %ld\n", - cnt, nread); - return nrecs; -} - -#include "io_generic.c" diff --git a/external/libsdf/libmpmy/mpmy_panio.c b/external/libsdf/libmpmy/mpmy_panio.c deleted file mode 100644 index 730a4dd..0000000 --- a/external/libsdf/libmpmy/mpmy_panio.c +++ /dev/null @@ -1,281 +0,0 @@ -/* This file contains the parallel I/O suitable for CMMD and NX. - It wouldn't be hard to add cubix-syntax as well. Are there any - other options? Would they fit in this structure? The only - difference between CMMD and NX is in Fopen, where one - system calls gopen() and the other calls CMMD_set_io_mode(). - We use a pre-processor symbol (__INTEL_SSD__) or (__CM5__) to decide - which one to use. __INTEL_SSD__ is set by the ARCH-specific Makefiles, - while __CM5__ is set by mpmy_cm5.c, which #includes this file. -*/ -#include -#include -#include -#include -#include -#include -#include -#include "protos.h" -#include "mpmy.h" -#include "mpmy_io.h" -#include "Msgs.h" -#include "iozero.h" - -#ifndef EINVAL -/* just in case... */ -#define EINVAL 0 -#endif - -#define NFILES 4096 -static struct _File{ - int fd; - int iomode; - int iotype; - int flags; -} _files[NFILES]; - -static int do_nfileio; - -MPMYFile * -MPMY_Fopen(const char *path, int flags) -{ - int fd; - int mode = 0644; - int iomode = MPMY_SINGL; /* default */ - int iotype = 0; - int real_flags = 0; - - Msgf(("Fopen %s\n", path)); - if (flags & MPMY_RDONLY) real_flags |= O_RDONLY; - if (flags & MPMY_WRONLY) real_flags |= O_WRONLY; - if (flags & MPMY_RDWR) real_flags |= O_RDWR; - if (flags & MPMY_APPEND) real_flags |= O_APPEND; - if (flags & MPMY_TRUNC) real_flags |= O_TRUNC; - if (flags & MPMY_CREAT) real_flags |= O_CREAT; - - /* Should we make sure that only one of them is on?? */ - if (flags & MPMY_MULTI) iomode = MPMY_MULTI; - if (flags & MPMY_SINGL) iomode = MPMY_SINGL; - - if (flags & MPMY_NFILE) iotype = MPMY_NFILE; - if (flags & MPMY_IOZERO) Error("MPMY_IOZERO not supported\n"); - if (flags & MPMY_INDEPENDENT) Error("MPMY_INDEPENDENT not supported\n"); - - if (iotype == MPMY_NFILE) { - char real_path[256]; - sprintf(real_path, "%s.p%03d", path, MPMY_Procnum()); - Msgf(("Fopen %s in NFILE mode\n", path)); - fd = open(real_path, real_flags, mode); - } else if (flags & MPMY_SINGL) { - Msgf(("Fopen %s in SINGL mode\n", path)); - fd = open(path, real_flags, mode); - } else { - Msgf(("Fopen %s in MULTI mode\n", path)); - fd = open(path, real_flags, mode); - } - - if (fd >= NFILES) Error("fd too large (%d)\n", fd); - if( fd >= 0 ){ - _files[fd].iomode = iomode; - _files[fd].iotype = iotype; - Msgf(("Fopen returns %d, iomode=%d, flags=0x%x\n", fd, iomode, flags)); - return &(_files[fd]); - }else{ - Msgf(("Fopen fails, errno=%d\n", errno)); - return NULL; - } -} - -int -MPMY_Nfileio(int val){ - int oldval = do_nfileio; - do_nfileio = val; - return oldval; -} - -int -MPMY_Fclose(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - int ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) ret = close0(fp->fd); - else ret = close(fp->fd); - Msgf(("Fclose of %d returns %d\n", fp->fd, ret)); - return ret; -} - -int -MPMY_Mkdir(const char *path, int mode){ - return mkdir0(path, mode); -} - -int -MPMY_Fread(void *ptr, int size, int nitems, MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - int ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) ret = read0(fp->fd, ptr, size*nitems); - else ret = read(fp->fd, ptr, size*nitems); - - Msgf(("Fread from %d returns %d\n", fp->fd, ret)); - if (ret % size) Error("MPMY_Fread has a problem\n"); - return ret/size; -} - -int -MPMY_Fwrite(const void *ptr, int size, int nitems, MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - int ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) ret= write0(fp->fd, ptr, size*nitems); - else ret = write(fp->fd, ptr, size*nitems); - /* Msgf(("Fwrite to %d returns %d.\n", fp->fd, ret)); */ - if (ret % size) Error("MPMY_Fwrite has a problem\n"); - return ret/size; -} - -int -MPMY_Fseek(MPMYFile *Fp, off_t offset, int whence) -{ - struct _File *fp = (struct _File *)Fp; - off_t ret; - int real_whence = 0; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - - if (whence == MPMY_SEEK_SET) real_whence = SEEK_SET; - if (whence == MPMY_SEEK_CUR) real_whence = SEEK_CUR; - if (whence == MPMY_SEEK_END) real_whence = SEEK_END; - - if (fp->iotype == MPMY_SINGL) { - ret = lseek0(fp->fd, offset, real_whence); - } else { - ret = lseek(fp->fd, offset, real_whence); - } - if (ret != -1) ret = 0; - Msgf(("Fseek returns %ld\n", (long)ret)); - return ret; -} - -int -MPMY_Ftell(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - off_t ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iotype == MPMY_SINGL) { - ret = tell0(fp->fd); - } else { - ret = lseek(fp->fd, 0L, SEEK_CUR); - } - Msgf(("Ftell returns %ld\n", (long)ret)); - return ret; -} - -off_t -MPMY_Flen(MPMYFile *Fp) -{ - struct _File *fp = (struct _File *)Fp; - off_t ret; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iotype & MPMY_NFILE) { - ret = flen(fp->fd); - Msgf(("flen segment %ld\n", (long)ret)); - if (sizeof(ret) != sizeof(long)) { - Error("Bad types in MPMY_Flen\n"); - } - MPMY_Combine(&ret, &ret, 1, MPMY_LONG, MPMY_SUM); - } else if (fp->iotype == MPMY_SINGL) { - ret = flen0(fp->fd); - } else { - ret = flen(fp->fd); - } - Msgf(("Flen returns %ld\n", (long)ret)); - return ret; -} - -int -MPMY_Fseekrd(MPMYFile *Fp, off_t offset, int whence, void *buf, int reclen, - int nrecs) -{ - struct _File *fp = (struct _File *)Fp; - int doseek; - - if( fp == NULL ){ - errno = EINVAL; - return -1; - } - if (fp->iomode == MPMY_SINGL) { - nrecs = fseekrd0(fp->fd, offset, whence, buf, reclen, nrecs); - return nrecs; - } - - if( whence == MPMY_SEEK_CUR ){ - doseek = (offset != 0); - }else if( whence == MPMY_SEEK_SET ){ - /* don't worry about errors. If ftell returns -1, */ - /* doseek will be turned on, and the fseek below will */ - /* (probably) fail */ - doseek = (MPMY_Ftell(Fp) != offset); - }else{ - doseek = 1; - } - - if( doseek ){ - if( MPMY_Fseek(Fp, offset, whence) ){ - if( whence == MPMY_SEEK_CUR && offset > 0 ){ - /* Make a final heroic effort to seek by reading forward! */ - char junk[BUFSIZ]; - int nleft = offset; - while( nleft ){ - int ntry = ( nleft > sizeof(junk) ) ? sizeof(junk) : nleft; - if( MPMY_Fread(junk, ntry, 1, Fp) != 1 ){ - Error("fseekrd: incremental fread(%#lx, %d, 1, %#lx) failed, errno=%d\n", - (unsigned long)junk, ntry, - (unsigned long)fp, errno); - return -1; - } - nleft -= ntry; - } - }else{ - Error("fseekrd: fseek(%#lx, %lld, %d) failed, errno=%d\n", - (unsigned long)fp, offset, whence, errno); - return -1; - } - } - } - if( MPMY_Fread(buf, reclen, nrecs, Fp) != nrecs ){ - Error("fseekrd: fread(%#lx, %d, %d, %#lx) failed, errno=%d\n", - (unsigned long)buf, reclen, nrecs, (unsigned long)fp, errno); - return -1; - } - return nrecs; -} - -#include "iozero.c" -#include "io_generic.c" diff --git a/external/libsdf/libmpmy/mpmy_seq.c b/external/libsdf/libmpmy/mpmy_seq.c deleted file mode 100644 index c1bd98d..0000000 --- a/external/libsdf/libmpmy/mpmy_seq.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - Not-so-trivial implementation of the mpmy interface for a single process(or) - that handles messages sent to itself. - - This is not designed for speed. In fact, it's not designed at all. It's - just meant to limp along. I think it's a bad idea to be sending a lot - of messages to yourself. -*/ -#include -#include "Msgs.h" -#include "mpmy.h" -#include "Assert.h" -#include "mpmy_io.h" -#include "mpmy_time.h" -#include "mpmy_abnormal.h" - -#define IN 1 -#define OUT 2 - -#ifdef __SUN4__ -/* ARCH=sun4 code may have been compiled and linked with __CM5VU__, which - means that if we're not careful we'll hit some illegal instructions when - we try to call do_grav. This variable sidesteps those Vector-Unit - calls at run-time. It's twisted, but it's the price we pay for using - ARCH=sun4 for the CM5. */ -int have_vu = 0; -void *VUHeap; -int VUaux_allocated; - -#if 0 -void *aux_alloc_heap(int n){ - Error("aux_alloc_heap: You shouldn't reach this on a non-cm5 processor!\n"); -} -#endif - -#endif - -struct comm_s{ - int cnt; - int tag; - void *buf; - int inout; - int finished; -}; - -/* These do a little more than mpmy_alloc_generic. It lets us search */ -/* the list of allocated requests too. Unfortunately, it takes O(Nreq) */ -/* time to do a Dealloc or a Match. I'm sure there's something simpler than */ -/* hashing that would do better, but I'm being dense. */ - -#define MAXCOMM 200 -static struct comm_s _comms[MAXCOMM]; -static int freecomm[MAXCOMM]; -static int usedcomm[MAXCOMM]; -static int mpmy_nfree = 0; -static int mpmy_nused = 0; - -static void CommInit(void){ - int i; - for(i=0; i= 0 ){ - ret = freecomm[--mpmy_nfree]; - usedcomm[mpmy_nused++] = ret; - return ret; - }else - return -1; -} - -static void CommDealloc(int req){ - int i; - assert(mpmy_nfree < MAXCOMM); - for(i=0; ifinished - && (comm->tag == tag || tag == MPMY_TAG_ANY || comm->tag == MPMY_TAG_ANY) - && comm->inout == inout ) - return ui; - } - return -1; -} - -int MPMY_Isend(const void *buf, int cnt, int dest, int tag, MPMY_Comm_request *reqp){ - struct comm_s *comm; - int req; - - if( dest != 0 ) - return MPMY_FAILED; - req = CommAlloc(); - if( req < 0 ) - return MPMY_FAILED; - - comm = &_comms[req]; - comm->inout = OUT; - comm->cnt = cnt; - comm->tag = tag; - comm->buf = (void *)buf; /* drop const. modifier */ - comm->finished = 0; - *reqp = comm; - IncrCounter(&MPMYSendCnt); - return MPMY_SUCCESS; -} - -int MPMY_Irecv(void *buf, int cnt, int src, int tag, MPMY_Comm_request *reqp){ - struct comm_s *comm; - int req; - - if( src != 0 && src != MPMY_SOURCE_ANY ) - return MPMY_FAILED; - req = CommAlloc(); - if( req < 0 ) - return MPMY_FAILED; - - comm = &_comms[req]; - comm->inout = IN; - comm->cnt = cnt; - comm->tag = tag; - comm->buf = buf; - comm->finished = 0; - *reqp = comm; - IncrCounter(&MPMYRecvCnt); - return MPMY_SUCCESS; -} - -int MPMY_Test(MPMY_Comm_request req, int *flag, MPMY_Status *stat){ - struct comm_s *comm = req; - struct comm_s *mcomm; - int match; - int ireq = comm - _comms; - - if( comm->finished ){ - *flag = 1; - if( comm->inout == IN && stat ){ - stat->count = comm->cnt; - stat->tag = comm->tag; - stat->src = 0; - } - CommDealloc(ireq); - IncrCounter(&MPMYDoneCnt); - return MPMY_SUCCESS; - } - if( comm->inout == IN ){ - match = find_match(OUT, comm->tag); - if( match >= 0 ){ - mcomm = &_comms[match]; - if( mcomm->cnt > comm->cnt ){ - SeriousWarning("MPMY_Test message too long\n"); - CommDealloc(ireq); - return MPMY_FAILED; - } - memcpy(comm->buf, mcomm->buf, mcomm->cnt); - if( stat ){ - stat->count = mcomm->cnt; - stat->tag = mcomm->tag; - stat->src = 0; - } - mcomm->finished = 1; - *flag = 1; - IncrCounter(&MPMYDoneCnt); - CommDealloc(ireq); - return MPMY_SUCCESS; - }else{ - *flag = 0; - return MPMY_SUCCESS; - } - }else{ - match = find_match(IN, comm->tag); - if( match >= 0 ){ - mcomm = &_comms[match]; - if( comm->cnt > mcomm->cnt ){ - SeriousWarning("MPMY_Test message too long\n"); - CommDealloc(ireq); - return MPMY_FAILED; - } - memcpy(mcomm->buf, comm->buf, comm->cnt); - mcomm->cnt = comm->cnt; - mcomm->tag = comm->tag; - mcomm->finished = 1; - *flag = 1; - IncrCounter(&MPMYDoneCnt); - CommDealloc(ireq); - return MPMY_SUCCESS; - }else{ - *flag = 0; - return MPMY_SUCCESS; - } - } -} - -int -Native_MPMY_Alltoall(void *sendbuf, int sendcount, MPMY_Datatype sendtype, - void *recvbuf, int recvcount, MPMY_Datatype recvtype) -{ - memcpy(recvbuf, sendbuf, sendcount*MPMY_Datasize[sendtype]); - return MPMY_SUCCESS; -} - -int -Native_MPMY_Allgather(void *sendbuf, int sendcount, MPMY_Datatype type, void *recvbuf) -{ - memcpy(recvbuf, sendbuf, sendcount*MPMY_Datasize[type]); - return MPMY_SUCCESS; -} - -int -Native_MPMY_Allgatherv(void *sendbuf, int sendcount, MPMY_Datatype type, void *recvbuf, - int *rcounts, int *roffsets) -{ - memcpy(recvbuf, sendbuf, sendcount*MPMY_Datasize[type]); - return MPMY_SUCCESS; -} - - - -int MPMY_Init(int *argcp, char ***argvp){ - CommInit(); - _MPMY_nproc_ = 1; - _MPMY_procnum_ = 0; - _MPMY_initialized_ = 1; - /* There should really be a better way to opt out of MPMY abnormal - signal handling. For now, this will work for programs that might - use SDF, but which have their own carefully crafted signal handlers, - e.g., SM */ - if( argcp ) - _MPMY_setup_absigs(); - MPMY_OnAbnormal(MPMY_SystemAbort); - MPMY_OnAbnormal(MPMY_Abannounce); - return MPMY_SUCCESS; -} - -#ifdef USE_GETTIME -#include "timers_gettime.c" -#endif - -#ifdef USE_HWCLOCK -#include "timers_hwclock.c" -#endif - -#include "mpmy_io.c" -#include "mpmy_abnormal.c" -#include "mpmy_generic.c" diff --git a/external/libsdf/libmpmy/timers_gettime.c b/external/libsdf/libmpmy/timers_gettime.c deleted file mode 100644 index d36709a..0000000 --- a/external/libsdf/libmpmy/timers_gettime.c +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include "mpmy_time.h" -#include "Malloc.h" -#include "chn.h" - -static Chn timer_chn; -static int initialized; - -typedef struct { - int type; - struct timespec cpu_start; - double cpu_accum; - struct timespec wc_start; - double wc_accum; -} MPMY_Timer; - -void *MPMY_CreateTimer(int type){ - MPMY_Timer *ret; - - if( initialized == 0 ){ - ChnInit(&timer_chn, sizeof(MPMY_Timer), 40, Realloc_f); - initialized = 1; - } - - ret = ChnAlloc(&timer_chn); - ret->type = type; - MPMY_ClearTimer(ret); - return (void *)ret; -} - -int MPMY_DestroyTimer(void *p){ - ChnFree(&timer_chn, p); - return MPMY_SUCCESS; -} - -int MPMY_StartTimer(void *p){ - MPMY_Timer *t = p; - - switch(t->type){ - case MPMY_CPU_TIME: - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t->cpu_start); - break; - case MPMY_WC_TIME: - clock_gettime(CLOCK_REALTIME, &t->wc_start); - break; - } - return MPMY_SUCCESS; -} - -int MPMY_StopTimer(void *p){ - MPMY_Timer *t = p; - struct timespec tnow; - - switch(t->type){ - case MPMY_CPU_TIME: - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tnow); - t->cpu_accum += (tnow.tv_sec - t->cpu_start.tv_sec) + (tnow.tv_nsec - t->cpu_start.tv_nsec) * 1e-9; - break; - case MPMY_WC_TIME: - clock_gettime(CLOCK_REALTIME, &tnow); - t->wc_accum += (tnow.tv_sec - t->wc_start.tv_sec) + (tnow.tv_nsec - t->wc_start.tv_nsec) * 1e-9; - break; - } - return MPMY_SUCCESS; -} - -int MPMY_ClearTimer(void *p){ - MPMY_Timer *t = p; - - t->cpu_accum = 0.0; - t->wc_accum = 0.0; - return MPMY_SUCCESS; -} - -double MPMY_ReadTimer(void *p){ - MPMY_Timer *t = p; - - switch(t->type){ - case MPMY_CPU_TIME: - return t->cpu_accum; - case MPMY_WC_TIME: - return t->wc_accum; - } - return -1.0; -} diff --git a/external/libsdf/libmpmy/timers_hwclock.c b/external/libsdf/libmpmy/timers_hwclock.c deleted file mode 100644 index b9d5d90..0000000 --- a/external/libsdf/libmpmy/timers_hwclock.c +++ /dev/null @@ -1,106 +0,0 @@ -#include -#include "mpmy_time.h" -#include "Malloc.h" -#include "chn.h" - -static Chn timer_chn; -static int initialized; - -typedef struct { - unsigned long long start; - unsigned long long accum; - struct timespec wc_start; - double wc_accum; - int type; -} MPMY_Timer; - -#ifdef AMD6100 -#define DEFAULT_MHZ 2300.0e6 -#else -#define DEFAULT_MHZ 2668.0e6 -#endif - -static __inline__ unsigned long long rdtsc(void) -{ - unsigned hi, lo; - __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); - return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); -} - -void *MPMY_CreateTimer(int type){ - MPMY_Timer *ret; - - if( initialized == 0 ){ - ChnInit(&timer_chn, sizeof(MPMY_Timer), 40, Realloc_f); - initialized = 1; - } - - ret = ChnAlloc(&timer_chn); - ret->type = type; - MPMY_ClearTimer(ret); - return (void *)ret; -} - -int MPMY_DestroyTimer(void *p){ - ChnFree(&timer_chn, p); - return MPMY_SUCCESS; -} - -int MPMY_CopyTimer(void *p, void *q) -{ - MPMY_Timer *t = p; - MPMY_Timer *u = q; - - *u = *t; - return MPMY_SUCCESS; -} - -int MPMY_StartTimer(void *p){ - MPMY_Timer *t = p; - - switch(t->type){ - case MPMY_CPU_TIME: - t->start = rdtsc(); - break; - case MPMY_WC_TIME: - clock_gettime(CLOCK_REALTIME, &t->wc_start); - break; - } - return MPMY_SUCCESS; -} - -int MPMY_StopTimer(void *p){ - MPMY_Timer *t = p; - struct timespec tnow; - - switch(t->type){ - case MPMY_CPU_TIME: - t->accum += rdtsc()-t->start; - break; - case MPMY_WC_TIME: - clock_gettime(CLOCK_REALTIME, &tnow); - t->wc_accum += (tnow.tv_sec - t->wc_start.tv_sec) + (tnow.tv_nsec - t->wc_start.tv_nsec) * 1e-9; - break; - } - return MPMY_SUCCESS; -} - -int MPMY_ClearTimer(void *p){ - MPMY_Timer *t = p; - - t->accum = 0; - t->wc_accum = 0.0; - return MPMY_SUCCESS; -} - -double MPMY_ReadTimer(void *p){ - MPMY_Timer *t = p; - - switch(t->type){ - case MPMY_CPU_TIME: - return t->accum/DEFAULT_MHZ; - case MPMY_WC_TIME: - return t->wc_accum; - } - return -1.0; -} diff --git a/external/libsdf/libmpmy/timers_mpi.c b/external/libsdf/libmpmy/timers_mpi.c deleted file mode 100644 index 9bb6c5e..0000000 --- a/external/libsdf/libmpmy/timers_mpi.c +++ /dev/null @@ -1,59 +0,0 @@ -/* This file tries to use only MPI-approved timer constructs. */ - -/* time.h should define CLOCKS_PER_SECOND and prototype clock() and time() - and it should have typedefs for time_t and clock_t. */ -#include "mpmy_time.h" -#include "chn.h" - -static Chn timer_chn; -static int initialized; - -typedef struct { - int type; - double wc_start, wc_accum; -} MPMY_Timer; - -void *MPMY_CreateTimer(int type){ - MPMY_Timer *ret; - - if( initialized == 0 ){ - ChnInit(&timer_chn, sizeof(MPMY_Timer), 40, Realloc_f); - initialized = 1; - } - - ret = ChnAlloc(&timer_chn); - ret->type = type; - return (void *)ret; -} - -int MPMY_DestroyTimer(void *p){ - ChnFree(&timer_chn, p); - return MPMY_SUCCESS; -} - -int MPMY_StartTimer(void *p){ - MPMY_Timer *t = p; - - t->wc_start = MPI_Wtime(); - return MPMY_SUCCESS; -} - -int MPMY_StopTimer(void *p){ - MPMY_Timer *t = p; - - t->wc_accum += MPI_Wtime() - t->wc_start; - return MPMY_SUCCESS; -} - -int MPMY_ClearTimer(void *p){ - MPMY_Timer *t = p; - - t->wc_accum = 0.; - return MPMY_SUCCESS; -} - -double MPMY_ReadTimer(void *p){ - MPMY_Timer *t = p; - - return (double)t->wc_accum; -} diff --git a/external/libsdf/libmpmy/timers_posix.c b/external/libsdf/libmpmy/timers_posix.c deleted file mode 100644 index edc3403..0000000 --- a/external/libsdf/libmpmy/timers_posix.c +++ /dev/null @@ -1,139 +0,0 @@ -/* This file tries to use only ANSI/POSIX-approved timer constructs. */ -/* It should compile correctly everywhere (Ha!) */ - -/* time.h should define CLOCKS_PER_SECOND and prototype clock() and time() - and it should have typedefs for time_t and clock_t. */ -#include -#include "mpmy_time.h" -#include "chn.h" -#include "Malloc.h" - -#ifndef CLOCKS_PER_SECOND -/* We've got a non-standard time.h. At least we have a time.h...*/ -#ifdef CLOCKS_PER_SEC /* This works for linux */ -#define CLOCKS_PER_SECOND CLOCKS_PER_SEC -#else -#define CLOCKS_PER_SECOND 1000000 /* this is just a wild guess!! */ -#endif -#endif - -/* POSIX only guarantees 'time', which returns a time_t. The option - is available for the 'implementor' to make time_t a double. Does - the friendly implementor at Sun do this? Nooooo. If we want more - precision we have to use gettimeofday, which is a non-POSIX BSD-ism. - - Better still, gettimeofday has mutually incompatible definitions in - SVr4 (one argument) and XSH4.2 (two arguments). Sigh... -*/ -#if defined(sun) || defined(__INTEL_SSD__) || defined(_AIX) || defined(__x86_64__) -# define USE_GETTIMEOFDAY -# include -#else /* don't use gettimeofday. use time() instead */ -extern time_t time(time_t *); -#endif - -/* This ought to be in one of the system headers... */ -extern clock_t clock(void); - -static Chn timer_chn; -static int initialized; - -typedef struct { - int type; - clock_t cpu_start, cpu_accum; -#ifdef USE_GETTIMEOFDAY - struct timeval wc_start; - struct timeval wc_accum; -#else - time_t wc_start, wc_accum; -#endif -} MPMY_Timer; - -void *MPMY_CreateTimer(int type){ - MPMY_Timer *ret; - - if( initialized == 0 ){ - ChnInit(&timer_chn, sizeof(MPMY_Timer), 40, Realloc_f); - initialized = 1; - } - - ret = ChnAlloc(&timer_chn); - ret->type = type; - MPMY_ClearTimer(ret); - return (void *)ret; -} - -int MPMY_DestroyTimer(void *p){ - ChnFree(&timer_chn, p); - return MPMY_SUCCESS; -} - -int MPMY_StartTimer(void *p){ - MPMY_Timer *t = p; - - switch(t->type){ - case MPMY_WC_TIME: -#ifdef USE_GETTIMEOFDAY - gettimeofday(&t->wc_start, 0); -#else - t->wc_start = time(0); -#endif - break; - case MPMY_CPU_TIME: - t->cpu_start = clock(); - break; - } - return MPMY_SUCCESS; -} - -int MPMY_StopTimer(void *p){ - MPMY_Timer *t = p; - - switch(t->type){ - case MPMY_WC_TIME: -#ifdef USE_GETTIMEOFDAY - { - struct timeval tnow; - gettimeofday(&tnow, 0); - t->wc_accum.tv_sec += tnow.tv_sec - t->wc_start.tv_sec; - t->wc_accum.tv_usec += tnow.tv_usec - t->wc_start.tv_usec; - } -#else - t->wc_accum += time(0) - t->wc_start; -#endif - break; - case MPMY_CPU_TIME: - t->cpu_accum += clock() - t->cpu_start; - break; - } - return MPMY_SUCCESS; -} - -int MPMY_ClearTimer(void *p){ - MPMY_Timer *t = p; - -#ifdef USE_GETTIMEOFDAY - t->wc_accum.tv_sec = 0; - t->wc_accum.tv_usec = 0; -#else - t->wc_accum = 0; -#endif - t->cpu_accum = 0; - return MPMY_SUCCESS; -} - -double MPMY_ReadTimer(void *p){ - MPMY_Timer *t = p; - - switch(t->type){ - case MPMY_WC_TIME: -#ifdef USE_GETTIMEOFDAY - return (double)t->wc_accum.tv_sec + (double)t->wc_accum.tv_usec*1.0e-6; -#else - return (double)t->wc_accum; -#endif - case MPMY_CPU_TIME: - return (double)t->cpu_accum * (1.0/CLOCKS_PER_SECOND); - } - return -1.0; -} diff --git a/external/libsdf/libsw/GNUmakefile b/external/libsdf/libsw/GNUmakefile deleted file mode 100644 index 6890aec..0000000 --- a/external/libsdf/libsw/GNUmakefile +++ /dev/null @@ -1,469 +0,0 @@ -# Make.$(ARCH) sets many of the variables used below including: -# CC, CFLAGS, AS, RANLIB, objdir, objsuf, asmdir - -treedir=.. -treedir_sed=\.\. -appexcludes= -libname=libsw - -# The "Salmon Warren Utility library" -src:= \ -Malloc.c key.c \ -Msgs.c error.c files.c \ -chn.c dll.c \ -stk.c heap.c randoms.c \ -malloc.c gc.c byteswap.c \ -timers.c SDFwrite.c SDFread.c \ -ring.c qromo.c qromod.c \ -cosmo.c mpmy_combine.c counters.c \ -mpmy_gather.c memfile.c rsort.c \ -msgdirinit.c singlio.c abm.c \ -mpi_bcast.c mpi_reduce.c keycvt.c \ -peano.c SDFreadf.c hwclock.c - -include $(treedir)/Make-common/Make.$(ARCH) - -include $(treedir)/Make-common/Make.generic - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/Malloc$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/Malloc$(objsuf): -$(objdir)/key$(objsuf): -$(objdir)/key$(objsuf): -$(objdir)/key$(objsuf): -$(objdir)/key$(objsuf): -$(objdir)/key$(objsuf): -$(objdir)/key$(objsuf): -$(objdir)/key$(objsuf): -$(objdir)/key$(objsuf): $(treedir)/include/libsdf/protos.h -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/Msgs$(objsuf): -$(objdir)/Msgs$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/Msgs$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/Msgs.h -$(objdir)/Msgs$(objsuf): $(treedir)/include/libsdf/protos.h -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): $(treedir)/include/libsdf/error.h -$(objdir)/error$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/Msgs.h -$(objdir)/error$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/error$(objsuf): -$(objdir)/error$(objsuf): $(treedir)/include/libsdf/mpmy_abnormal.h $(treedir)/include/libsdf/protos.h -$(objdir)/error$(objsuf): $(treedir)/include/libsdf/memfile.h -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): -$(objdir)/files$(objsuf): $(treedir)/include/libsdf/protos.h -$(objdir)/files$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/files$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/mpmy.h -$(objdir)/files$(objsuf): $(treedir)/include/libsdf/timers.h -$(objdir)/files$(objsuf): -$(objdir)/chn$(objsuf): $(treedir)/include/libsdf/Assert.h $(treedir)/include/libsdf/error.h -$(objdir)/chn$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/chn.h -$(objdir)/chn$(objsuf): $(treedir)/include/libsdf/Msgs.h -$(objdir)/chn$(objsuf): -$(objdir)/chn$(objsuf): -$(objdir)/chn$(objsuf): -$(objdir)/chn$(objsuf): -$(objdir)/chn$(objsuf): -$(objdir)/chn$(objsuf): -$(objdir)/chn$(objsuf): -$(objdir)/dll$(objsuf): $(treedir)/include/libsdf/chn.h $(treedir)/include/libsdf/Malloc.h -$(objdir)/dll$(objsuf): $(treedir)/include/libsdf/error.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/stk$(objsuf): $(treedir)/include/libsdf/Assert.h $(treedir)/include/libsdf/error.h -$(objdir)/stk$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/heap$(objsuf): $(treedir)/include/libsdf/Assert.h $(treedir)/include/libsdf/error.h -$(objdir)/heap$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/Malloc.h -$(objdir)/randoms$(objsuf): $(treedir)/include/libsdf/error.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): -$(objdir)/malloc$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/gc$(objsuf): -$(objdir)/byteswap$(objsuf): -$(objdir)/byteswap$(objsuf): -$(objdir)/byteswap$(objsuf): -$(objdir)/byteswap$(objsuf): -$(objdir)/byteswap$(objsuf): $(treedir)/include/libsdf/byteswap.h -$(objdir)/timers$(objsuf): -$(objdir)/timers$(objsuf): -$(objdir)/timers$(objsuf): -$(objdir)/timers$(objsuf): -$(objdir)/timers$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/timers$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/timers.h -$(objdir)/timers$(objsuf): -$(objdir)/timers$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/mpmy_time.h -$(objdir)/timers$(objsuf): $(treedir)/include/libsdf/Assert.h -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): -$(objdir)/SDFwrite$(objsuf): $(treedir)/include/libsdf/SDF.h $(treedir)/include/libsdf/SDFwrite.h -$(objdir)/SDFwrite$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/SDFwrite$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/mpmy.h -$(objdir)/SDFwrite$(objsuf): $(treedir)/include/libsdf/timers.h -$(objdir)/SDFwrite$(objsuf): $(treedir)/include/libsdf/mpmy_io.h -$(objdir)/SDFwrite$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/protos.h -$(objdir)/SDFwrite$(objsuf): $(treedir)/include/libsdf/singlio.h -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/SDFread$(objsuf): -$(objdir)/SDFread$(objsuf): $(treedir)/include/libsdf/SDF.h $(treedir)/include/libsdf/Assert.h -$(objdir)/SDFread$(objsuf): $(treedir)/include/libsdf/error.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/SDFread$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/Msgs.h -$(objdir)/SDFread$(objsuf): $(treedir)/include/libsdf/SDFread.h $(treedir)/include/libsdf/singlio.h -$(objdir)/ring$(objsuf): -$(objdir)/ring$(objsuf): -$(objdir)/ring$(objsuf): -$(objdir)/ring$(objsuf): -$(objdir)/ring$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/ring$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/mpmy.h -$(objdir)/ring$(objsuf): $(treedir)/include/libsdf/timers.h -$(objdir)/ring$(objsuf): $(treedir)/include/libsdf/Msgs.h -$(objdir)/ring$(objsuf): $(treedir)/include/libsdf/singlio.h -$(objdir)/qromo$(objsuf): -$(objdir)/qromo$(objsuf): -$(objdir)/qromo$(objsuf): -$(objdir)/qromo$(objsuf): -$(objdir)/qromo$(objsuf): -$(objdir)/qromo$(objsuf): -$(objdir)/qromo$(objsuf): -$(objdir)/qromo$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/qromo$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/qromod$(objsuf): -$(objdir)/qromod$(objsuf): -$(objdir)/qromod$(objsuf): -$(objdir)/qromod$(objsuf): -$(objdir)/qromod$(objsuf): -$(objdir)/qromod$(objsuf): -$(objdir)/qromod$(objsuf): -$(objdir)/qromod$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/qromod$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): -$(objdir)/cosmo$(objsuf): $(treedir)/include/libsdf/Msgs.h -$(objdir)/cosmo$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/cosmo.h -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/mpmy_combine$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/mpmy_combine$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/mpmy_combine$(objsuf): -$(objdir)/mpmy_combine$(objsuf): $(treedir)/include/libsdf/Msgs.h op_template.c -$(objdir)/counters$(objsuf): -$(objdir)/counters$(objsuf): -$(objdir)/counters$(objsuf): -$(objdir)/counters$(objsuf): -$(objdir)/counters$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/counters$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/counters$(objsuf): $(treedir)/include/libsdf/timers.h -$(objdir)/counters$(objsuf): $(treedir)/include/libsdf/mpmy.h -$(objdir)/counters$(objsuf): $(treedir)/include/libsdf/Assert.h -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/mpmy_gather$(objsuf): -$(objdir)/mpmy_gather$(objsuf): $(treedir)/include/libsdf/Msgs.h -$(objdir)/mpmy_gather$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/mpmy_gather$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/error.h -$(objdir)/memfile$(objsuf): -$(objdir)/memfile$(objsuf): -$(objdir)/memfile$(objsuf): -$(objdir)/memfile$(objsuf): -$(objdir)/memfile$(objsuf): -$(objdir)/memfile$(objsuf): -$(objdir)/memfile$(objsuf): -$(objdir)/memfile$(objsuf): -$(objdir)/memfile$(objsuf): $(treedir)/include/libsdf/Malloc.h -$(objdir)/memfile$(objsuf): $(treedir)/include/libsdf/error.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/memfile$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/protos.h -$(objdir)/memfile$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/memfile$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): -$(objdir)/rsort$(objsuf): $(treedir)/include/libsdf/Malloc.h -$(objdir)/rsort$(objsuf): $(treedir)/include/libsdf/error.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): $(treedir)/include/libsdf/Malloc.h -$(objdir)/msgdirinit$(objsuf): $(treedir)/include/libsdf/error.h -$(objdir)/msgdirinit$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/msgdirinit$(objsuf): $(treedir)/include/libsdf/mpmy_abnormal.h -$(objdir)/msgdirinit$(objsuf): $(treedir)/include/libsdf/protos.h $(treedir)/include/libsdf/Msgs.h -$(objdir)/msgdirinit$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/msgdirinit$(objsuf): -$(objdir)/msgdirinit$(objsuf): $(treedir)/include/libsdf/mpmy_io.h -$(objdir)/singlio$(objsuf): -$(objdir)/singlio$(objsuf): -$(objdir)/singlio$(objsuf): -$(objdir)/singlio$(objsuf): -$(objdir)/singlio$(objsuf): -$(objdir)/singlio$(objsuf): -$(objdir)/singlio$(objsuf): -$(objdir)/singlio$(objsuf): $(treedir)/include/libsdf/protos.h -$(objdir)/singlio$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/singlio$(objsuf): -$(objdir)/singlio$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/singlio$(objsuf): $(treedir)/include/libsdf/singlio.h -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): $(treedir)/include/libsdf/protos.h $(treedir)/include/libsdf/Assert.h -$(objdir)/abm$(objsuf): $(treedir)/include/libsdf/error.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/abm$(objsuf): $(treedir)/include/libsdf/mpmy.h $(treedir)/include/libsdf/timers.h -$(objdir)/abm$(objsuf): -$(objdir)/abm$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/Msgs.h -$(objdir)/mpi_bcast$(objsuf): $(treedir)/include/libsdf/Msgs.h -$(objdir)/mpi_bcast$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/mpi_bcast$(objsuf): $(treedir)/include/libsdf/error.h -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): -$(objdir)/mpi_reduce$(objsuf): $(treedir)/include/libsdf/Msgs.h -$(objdir)/mpi_reduce$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/mpi_reduce$(objsuf): $(treedir)/include/libsdf/error.h mpi_template.c -$(objdir)/keycvt$(objsuf): $(treedir)/include/libsdf/protos.h $(treedir)/include/libsdf/mpmy.h -$(objdir)/keycvt$(objsuf): $(treedir)/include/libsdf/timers.h -$(objdir)/keycvt$(objsuf): -$(objdir)/keycvt$(objsuf): -$(objdir)/keycvt$(objsuf): -$(objdir)/keycvt$(objsuf): $(treedir)/include/libsdf/Msgs.h -$(objdir)/keycvt$(objsuf): $(treedir)/include/libsdf/gccextensions.h $(treedir)/include/libsdf/Assert.h -$(objdir)/keycvt$(objsuf): $(treedir)/include/libsdf/error.h -$(objdir)/peano$(objsuf): $(treedir)/include/libsdf/Msgs.h $(treedir)/include/libsdf/gccextensions.h -$(objdir)/peano$(objsuf): $(treedir)/include/libsdf/Assert.h $(treedir)/include/libsdf/error.h -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): -$(objdir)/SDFreadf$(objsuf): $(treedir)/include/libsdf/mpmy.h -$(objdir)/SDFreadf$(objsuf): $(treedir)/include/libsdf/timers.h -$(objdir)/SDFreadf$(objsuf): $(treedir)/include/libsdf/SDF.h -$(objdir)/SDFreadf$(objsuf): $(treedir)/include/libsdf/Assert.h $(treedir)/include/libsdf/error.h -$(objdir)/SDFreadf$(objsuf): $(treedir)/include/libsdf/gccextensions.h -$(objdir)/SDFreadf$(objsuf): $(treedir)/include/libsdf/Malloc.h $(treedir)/include/libsdf/Msgs.h -$(objdir)/SDFreadf$(objsuf): $(treedir)/include/libsdf/SDFread.h $(treedir)/include/libsdf/singlio.h -$(objdir)/hwclock$(objsuf): -$(objdir)/hwclock$(objsuf): -$(objdir)/hwclock$(objsuf): -$(objdir)/hwclock$(objsuf): -$(objdir)/hwclock$(objsuf): -$(objdir)/hwclock$(objsuf): -$(objdir)/hwclock$(objsuf): -$(objdir)/hwclock$(objsuf): -$(objdir)/hwclock$(objsuf): $(treedir)/include/libsdf/error.h -$(objdir)/hwclock$(objsuf): $(treedir)/include/libsdf/gccextensions.h diff --git a/external/libsdf/libsw/Malloc.c b/external/libsdf/libsw/Malloc.c deleted file mode 100644 index 0c8a5d8..0000000 --- a/external/libsdf/libsw/Malloc.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 1991 Michael S. Warren and John K. Salmon. All Rights Reserved. - */ - -#include -#include -#include -#include "Msgs.h" -#include "Malloc.h" -#include "malloc.h" - -#define WARNSIZEINITIAL (1024L*1024*1024*2) -static size_t WarnSize = WARNSIZEINITIAL; - -#include "error.h" - -static void Error_and_mprint(const char *fmt, ...){ - va_list alist; - malloc_print(); - va_start(alist, fmt); - vError(fmt, alist); - va_end(alist); -} - -/* Try to do this without the typedef Error_t!!! */ -static Error_t reporter = Error_and_mprint; - -Error_t MallocHandler(Error_t new){ - Error_t ret = reporter; - reporter = new; - return ret; -} - -void -xFree(void *ptr, const char *file, int lineno) -{ - Msgf(("%s(%d): f(%#lx)\n", file, lineno, (unsigned long)ptr)); - if( ptr != (void *)0 ) - free(ptr); -} - -void * -xMalloc(size_t size, const char *file, int lineno) -{ - void *ptr; - - Msgf(("%s(%d): m(%lu)=", file, lineno, (unsigned long)size)); - if (size > WarnSize){ - Shout("Large Malloc Warning, size %ld\n", (long)size); - WarnSize *=2; - } - if (size == 0) { - Msgf(("0x0")); - return (void *)0; - } - ptr = malloc(size); - if (ptr == (void *)0 && reporter) { - reporter("%s(%d) Malloc(%ld) failed\n", file, lineno, (long)size); - } - Msgf(("%#lx\n", (unsigned long)ptr)); - return(ptr); -} - - -void * -xRealloc(void *ptr, size_t size, const char *file, int lineno) -{ - void *p1 = ptr; - - Msgf(("%s(%d): r(%#lx,%lu)=", file, lineno, (unsigned long)ptr, - (unsigned long)size)); - if (size > WarnSize){ - Shout("Large Realloc Warning, size %ld\n", (long)size); - WarnSize *= 2; - } - - if( ptr == (void *)0 ){ - Msgf(("-> malloc\n")); - return Malloc(size); - } - if( size == 0 ){ - Msgf(("-> free\n")); - Free(ptr); - return (void *)0; - } - ptr = realloc(ptr, size); - if (ptr == (void *)0 && reporter) { - reporter("%s(%d): Realloc(%p, %ld) failed\n", file, lineno, p1, (long)size); - } - Msgf(("%#lx\n", (unsigned long)ptr)); - return(ptr); -} - -void * -xCalloc(size_t n, size_t s, const char *file, int lineno) -{ - void *ptr; - - Msgf(("%s(%d): c(%lu,%lu)=", file, lineno, - (unsigned long)n, (unsigned long)s)); - if (n*s > WarnSize){ - Shout("Large Calloc Warning, size %ld\n", (long)n*s); - WarnSize *= 2; - } - if( n==0 || s==0 ){ - Msgf(("0x0\n")); - return (void *)0; - } - ptr = calloc(n,s); - if (ptr == (void *)0 && reporter) { - reporter("%s(%d): Calloc(%ld) failed\n", file, lineno, (long)n); - } - Msgf(("%#lx\n", (unsigned long)ptr)); - return(ptr); -} - -/* Use these, for example, when you pass a ptr-to-function arg */ -/* to another function. They call the macro version, which prints */ -/* a message. If you don't intend to ever use the old K&R /lib/cpp */ -/* pre-processor, then these are superfluous. You could pass, e.g. */ -/* foo(Realloc), and you could call these functions, e.g., Realloc */ -/* and everything would be fine... */ - -void *Realloc_f(void *ptr, size_t size){ - return Realloc(ptr, size); -} - -void *Malloc_f(size_t n){ - return Malloc(n); -} - -void *Calloc_f(size_t n, size_t s){ - return Calloc(n, s); -} - -void Free_f(void *p){ - Free(p); -} -/* void MallocOnNULLReturn(void (*printf_like)(const char *fmt, ...)) */ diff --git a/external/libsdf/libsw/Msgs.c b/external/libsdf/libsw/Msgs.c deleted file mode 100644 index 45754d8..0000000 --- a/external/libsdf/libsw/Msgs.c +++ /dev/null @@ -1,375 +0,0 @@ -/* - * This file implements a common mechanism for delivering messages - * to the user. It also provides a way to selectively turn - * on and off the status messages emanating from a part of the - * program. - * Call msg_on("foo"); to see all messages of the form: - * msg("foo", ("printf-format", printf-args)); - * Note how __FILE__ can be used in place of "foo"... - * - * This file does not use . This is because in the wonderful - * world of distributed parallel, figuring out whose you're getting - * and whether or not the names have been secretly scrambled is a complete - * nightmare. The solution is to make the user pass in two function pointers - * that are supposed to behave like vfprintf and fflush, and a void * which - * acts like a FILE * (when passed to the two functions). How the caller - * arranges these functions is not our problem. - * The down-side is that picky compilers may complain about not having - * prototypes for sscanf. Too bad... - */ -#include -#include -#include /* only for sscanf! */ -#include "mpmy.h" -#include "Malloc.h" -#include "Msgs.h" -#include "protos.h" - -#ifndef Static -#define Static static -#endif - -/* Don't increase MAXNAMES arbitrarily. If it grows much bigger */ -/* than O(100), a different search algorithm would be appropriate. */ -#define MAXNAMES 50 - -/* A substantially larger MAXFILES is probably a mistake. You'll run out */ -/* of file descriptors soon enough anyway. */ -#define MAXFILES 12 - -/* The sum of the lengths of all the NAMES (including terminal null). */ -#define NAMEPOOLLENGTH (MAXNAMES*32) - -Static int nnames; -Static struct nt_s{ - const char *name; - int status; - struct nt_s *next; -} name_tbl[MAXNAMES], *first; - -Static int nfiles; -Static struct ft_s{ - void *fp; - int (*vfprintf_like)(void *, const char *, va_list); - int (*fflush_like)(void *); -} file_tbl[MAXFILES]; - -char name_pool[NAMEPOOLLENGTH] ; -char *poolptr = name_pool; -char *poolend = name_pool + NAMEPOOLLENGTH; - -Static int look_name(const char *name); -Static int Msg_restriction(const char *arg); - -int _Msg_enabled = 1; - -Static int _Msg_flushalways = 0; -Static int called_addfile = 0; - -int Msg_addfile(void *fp, - int (*vfprintf_like)(void *, const char *, va_list), - int (*fflush_like)(void *)){ - if( nfiles == MAXFILES ) - return -1; - - file_tbl[nfiles].fp = fp; - file_tbl[nfiles].vfprintf_like = vfprintf_like; - file_tbl[nfiles].fflush_like = fflush_like; - nfiles++; - called_addfile = 1; - return 0; -} - -int Msg_delfile(void *fp){ - int i; - - for(i=0; ivfprintf_like)(ft->fp, fmt, args); - va_end(args); - if( _Msg_flushalways && ft->fflush_like) - (*ft->fflush_like)(ft->fp); - } -#ifndef NO_STDIO - if( nfiles == 0 && !called_addfile ){ - va_start(args, fmt); - vfprintf(stderr, fmt, args); - if( _Msg_flushalways ) - fflush(stderr); - va_end(args); - extra = 1; - } -#endif - } - --recursion; - _Msg_enabled = save; - return nfiles+extra; -} - -int -Msg_doalist(const char *fmt, va_list alist) -{ - int i; - struct ft_s *ft; - int save; - int extra = 0; - - save = _Msg_enabled; - if( recursion++ == 0 ){ - for(i=0; ivfprintf_like)(ft->fp, fmt, alist); - if( _Msg_flushalways && ft->fflush_like ) - (*ft->fflush_like)(ft->fp); - } -#ifndef NO_STDIO - if( nfiles == 0 && !called_addfile ){ - vfprintf(stderr, fmt, alist); - if( _Msg_flushalways ) - fflush(stderr); - extra = 1; - } -#endif - } - --recursion; - _Msg_enabled = save; - return nfiles+extra; -} - -void Msg_turnon(const char *msg_turn_on){ - char *copy; - char *msg_key; - - /* You can turn off msgs with a "nomsgs" or a null string or an */ - /* empty string. */ - if( msg_turn_on == NULL - || msg_turn_on[0] == '\0' - || strcmp(msg_turn_on, "nomsgs")==0 ){ - Msg_set_enable(0); - return; - } - - copy = strcpy(Malloc(strlen(msg_turn_on)+1), msg_turn_on); - /* Look for comma or space separated arguments to Msg_on */ - for(msg_key = strtok(copy, " ,\t\n"); - msg_key; - msg_key = strtok(NULL, " ,\t\n")){ - char *restriction_begin = strchr(msg_key, ':'); - if( restriction_begin ){ - if( !Msg_restriction(restriction_begin+1) ) - continue; - *restriction_begin='\0'; - } - Msg_on(msg_key); - Msg_do("Turning on Msgs for \"%s\"\n", msg_key); - /* Do we need to add "./" to the key in addition??? */ - if( strncmp( __FILE__, "./", 2) == 0 && - strncmp( msg_key, "./", 2 ) != 0 ){ - char *dot_slash_key = Malloc(strlen(msg_key)+3); - /* sprintf might be easier, but we are trying to avoid */ - /* using stdio. */ - /* sprintf(dot_slash_key, "./%s", msg_key) */ - strcpy(dot_slash_key, "./"); - strcat(dot_slash_key, msg_key); - Msg_on(dot_slash_key); - Msg_do("Turning on Msgs for \"%s\"\n", dot_slash_key); - Free(dot_slash_key); - } - } - Free(copy); -} - -int Msg_flush(void) -{ - int i, ret; - struct ft_s *ft; - int save; - - save = _Msg_enabled; - ret = 0; - if( recursion++ == 0 ){ - for(i=0; ifflush_like ) - ret |= (*ft->fflush_like)(ft->fp); - } - } - --recursion; - _Msg_enabled = save; - return ret; -} - -Static int look_name(const char *name) -{ - int i; - struct nt_s *last, *this; - unsigned int len; - - last = NULL; - this = first; - if( name == NULL ){ - Warning("look_name(NULL)\n"); - return -1; - } - while( this && this->name && strcmp(name, this->name) != 0 ) { - last = this; - this = this->next; - } - if( this ){ - if( last ){ - last->next = this->next; - this->next = first; - first = this; - } - return this - name_tbl; - }else{ - /* Create a new entry. Add it to the front. */ - /* NOTE: we never free any of this! */ - if(nnames == MAXNAMES){ - return -1; - } - len = strlen(name)+1; - if( poolptr + len >= poolend ){ - return -1; - } - i = nnames++; - strcpy(poolptr, name); - - name_tbl[i].name = poolptr; - poolptr += len; - name_tbl[i].next = first; - first = &name_tbl[i]; - return i; - } -} - -Static int Msg_restriction(const char *arg){ - int first, last; - - if( strchr(arg, '-') ){ - if( sscanf(arg, "%d-%d", &first, &last) != 2 ){ - Msg_do("Unparseable msg restriction: \"%s\"\n", arg); - return 0; - } - return MPMY_Procnum() <= last && MPMY_Procnum()>= first ; - }else{ - if( sscanf(arg, "%d", &first) != 1 ){ - Msg_do("Unparseable msg restriction: \"%s\"\n", arg); - return 0; - } - return MPMY_Procnum() == first; - } -} - -#ifdef STANDALONE -#include -/* Of course, Sun's stdio.h doesn't declare fflush or vfprintf! */ -int vfprintf(FILE *, const char *, va_list); -int fflush(FILE *); - -main(int argc, char **argv){ - FILE *aux; - - Msg_addfile(stdout, vfprintf, fflush); - - aux = fopen("Msg.out", "w"); - if( aux == NULL ){ - fprintf(stderr, "Couldn't fopen("Msg.out"), errno=%d\n", errno); - exit(1); - } - Msg_addfile(aux, vfprintf, fflush); - Msg_on("foo"); - Msg("foo", ("Hello world foo seventeen=%d\n", 17)); - Msg("bar", ("Hello bar")); - Msg_on("Msgs.c"); - Msg_on("bar"); - Msg("bar", ("Hello bar pi=%g\n", 3.14159)); - Msglno("bar", ("What was that value again??... %g\n,", 3.1415)); - Msgf(("This is a Msgf message.\n")); - Msg_off("foo"); - Msg_off(__FILE__); - Msgf(("This is a blocked Msgf message.\n")); - Msg("foo", ("Not seen.\n")); - exit(0); -} -#endif - diff --git a/external/libsdf/libsw/SDFread.c b/external/libsdf/libsw/SDFread.c deleted file mode 100644 index 121f93d..0000000 --- a/external/libsdf/libsw/SDFread.c +++ /dev/null @@ -1,290 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "mpmy.h" -#include "SDF.h" -#include "Assert.h" -#include "Malloc.h" -#include "Msgs.h" -#include "error.h" -#include "verify.h" -#include "SDFread.h" -#include "gc.h" -#include "singlio.h" -#include "timers.h" - -#define MAXNAMES 64 - -Timer_t SDFreadTm; - -/* These ought to be arguments to SDFread, but that breaks too many - things that call SDFread. The varargs makes creating a wrapper a pain. */ -char *SDFread_datafile = "datafile"; -char *SDFread_hdrfile = "hdrfile"; -char *SDFread_npart = "npart"; - -SDF *SDFread(SDF *csdfp, void **btabp, int *gnobjp, int *nobjp, - int stride, - /* char *name, offset_t offset, int *confirm */...) -{ - va_list ap; - char name[256]; - int start; - SDF *sdfp; - int gnobj, nobj; - void *btab; - int Nfiles, procs_per_file, myfile, mysection; - char hdrname[256]; - void *addrs[MAXNAMES]; - char *names[MAXNAMES]; - int strides[MAXNAMES]; - int nobjs[MAXNAMES]; - int64_t starts[MAXNAMES]; - int *confirm; - int nnames; - int sz = 0; - - EnableTimer(&SDFreadTm, "SDFread"); - StartTimer(&SDFreadTm); - - if( !SDFread_datafile || !SDFhasname(SDFread_datafile, csdfp) ){ - sdfp = csdfp; - SinglWarning("SDFread: Looking for data in 'control' file\n"); - Nfiles = 1; - }else{ - sdfp = NULL; - Nfiles = SDFnrecs(SDFread_datafile, csdfp); - if( Nfiles > MPMY_Nproc() || Nfiles < 0){ - SinglError("Sorry, bad Nfiles (%d)!\n", Nfiles); - } - } - - /* Pick out which file in the control file will be ours. */ - /* and which "section" of the file. */ - procs_per_file = MPMY_Nproc()/Nfiles; - Verify(procs_per_file*Nfiles == MPMY_Nproc()); - myfile = MPMY_Procnum()/procs_per_file; - mysection = MPMY_Procnum()%procs_per_file; - - if( sdfp == NULL ){ - VerifySX(0==SDFseekrdvecs(csdfp, - SDFread_datafile, myfile, 1, name, sizeof(name), - NULL), - SinglShout("%s", SDFerrstring)); - if( SDFread_hdrfile ) - SDFgetstringOrDefault(csdfp, SDFread_hdrfile, hdrname, sizeof(hdrname), ""); - else - hdrname[0] = '\0'; - - /* This was moved from above where it used name unitialized */ - if (hdrname[0] && SDFissdf(name) ) { - SinglWarning("Superfluous headerfile %s ignored\n", hdrname); - hdrname[0] = '\0'; - } - VerifySX(sdfp = SDFopen(hdrname, name),SinglShout("%s", SDFerrstring)); - }else{ - strncpy(name, "", sizeof(name)); - } - - if( SDFbyteorder(sdfp) == 0 ){ - int swap; - /* The data/hdr file itself doesn't specify a byte order. */ - SDFgetintOrDefault(csdfp, "swapbytes", &swap, 0); - if( swap ) - SDFswap(sdfp); - /* If there's no byteorder specified, then it won't swap */ - } - - if( SDFread_npart && SDFgetint(sdfp, SDFread_npart, &gnobj) ){ - /* Hopefully calling va_start and va_end in here won't disturb */ - /* the real loop over arguments below... */ - va_start(ap, stride); - names[0] = va_arg(ap, char *); - gnobj = SDFnrecs(names[0], sdfp); - va_end(ap); - if( MPMY_Procnum() == 0 ){ - SinglShout("%s does not have an \"%s\".\n", name, SDFread_npart); - SinglShout("Guessing %s=%d from SDFnrecs(., %s)\n", - SDFread_npart, gnobj, names[0]); - } - } - - NobjInitial(gnobj, procs_per_file, mysection, &nobj, &start); - btab = Calloc(nobj, stride); - Msgf(("Proc %d starting at %d in file, reading %d of %d\n", - MPMY_Procnum(), start, nobj, gnobj)); - - nnames = 0; - va_start(ap, stride); - while(( names[nnames] = va_arg(ap, char *)) != NULL ){ - assert(nnames < MAXNAMES); - addrs[nnames] = va_arg(ap, int) + (char *)btab; - confirm = va_arg(ap, int *); - if( !SDFhasname(names[nnames], sdfp) ){ - *confirm = 0; - Msgf(("SDF file does not have %s\n", names[nnames])); - continue; - }else{ - *confirm = 1; - } - starts[nnames] = start; - nobjs[nnames] = nobj; - sz += SDFtype_sizes[SDFtype(names[nnames], sdfp)]; - strides[nnames] = stride; - nnames++; - } - va_end(ap); - - VerifyX(0==SDFseekrdvecsarr(sdfp, nnames, - names, starts, nobjs, addrs, strides), - Shout("%s", SDFerrstring)); - - *nobjp = nobj; - MPMY_Combine(nobjp, gnobjp, 1, MPMY_INT, MPMY_SUM); - Msgf(("nobj=%d, gnobj=%d\n", *nobjp, *gnobjp)); - - *btabp = btab; - StopTimer(&SDFreadTm); - OutputTimer(&SDFreadTm, singlPrintf); /* global sync and sets timer->max */ - singlPrintf("read %ld x %d at %.0f MB/s\n", *gnobjp, sz, (*gnobjp/(100.*1000.))*(sz/ReadTimer(&SDFreadTm))); - DisableTimer(&SDFreadTm); - return sdfp; -} - -SDF *SDFread64(SDF *csdfp, void **btabp, int64_t *gnobjp, int *nobjp, - int stride, - /* char *name, offset_t offset, int *confirm */...) -{ - va_list ap; - char name[256]; - int64_t start; - SDF *sdfp; - int64_t gnobj; - int nobj; - void *btab; - int Nfiles, procs_per_file, myfile, mysection; - char hdrname[256]; - void *addrs[MAXNAMES]; - char *names[MAXNAMES]; - int strides[MAXNAMES]; - int nobjs[MAXNAMES]; - int64_t starts[MAXNAMES]; - int *confirm; - int nnames; - int sz = 0; - - EnableTimer(&SDFreadTm, "SDFread"); - StartTimer(&SDFreadTm); - - if( !SDFread_datafile || !SDFhasname(SDFread_datafile, csdfp) ){ - sdfp = csdfp; - SinglWarning("SDFread: Looking for data in 'control' file\n"); - Nfiles = 1; - }else{ - sdfp = NULL; - Nfiles = SDFnrecs(SDFread_datafile, csdfp); - if( Nfiles > MPMY_Nproc() || Nfiles < 0){ - SinglError("Sorry, bad Nfiles (%d)!\n", Nfiles); - } - } - - /* Pick out which file in the control file will be ours. */ - /* and which "section" of the file. */ - procs_per_file = MPMY_Nproc()/Nfiles; - Verify(procs_per_file*Nfiles == MPMY_Nproc()); - myfile = MPMY_Procnum()/procs_per_file; - mysection = MPMY_Procnum()%procs_per_file; - - if( sdfp == NULL ){ - VerifySX(0==SDFseekrdvecs(csdfp, - SDFread_datafile, myfile, 1, name, sizeof(name), - NULL), - SinglShout("%s", SDFerrstring)); - if( SDFread_hdrfile ) - SDFgetstringOrDefault(csdfp, SDFread_hdrfile, hdrname, sizeof(hdrname), ""); - else - hdrname[0] = '\0'; - - /* This was moved from above where it used name unitialized */ - if (hdrname[0] && SDFissdf(name) ) { - SinglWarning("Superfluous headerfile %s ignored\n", hdrname); - hdrname[0] = '\0'; - } - VerifySX(sdfp = SDFopen(hdrname, name),SinglShout("%s", SDFerrstring)); - }else{ - strncpy(name, "", sizeof(name)); - } - - if( SDFbyteorder(sdfp) == 0 ){ - int swap; - /* The data/hdr file itself doesn't specify a byte order. */ - SDFgetintOrDefault(csdfp, "swapbytes", &swap, 0); - if( swap ) - SDFswap(sdfp); - /* If there's no byteorder specified, then it won't swap */ - } - - if( SDFread_npart && SDFgetint64(sdfp, SDFread_npart, &gnobj) ){ - /* Hopefully calling va_start and va_end in here won't disturb */ - /* the real loop over arguments below... */ - va_start(ap, stride); - names[0] = va_arg(ap, char *); - gnobj = SDFnrecs(names[0], sdfp); - va_end(ap); - if( MPMY_Procnum() == 0 ){ - SinglShout("%s does not have an \"%s\".\n", name, SDFread_npart); -#if __WORDSIZE==64 - SinglShout("Guessing %s=%ld from SDFnrecs(., %s)\n", - SDFread_npart, gnobj, names[0]); -#else - SinglShout("Guessing %s=%lld from SDFnrecs(., %s)\n", - SDFread_npart, gnobj, names[0]); -#endif - } - } - - NobjInitial64(gnobj, procs_per_file, mysection, &nobj, &start); - btab = Calloc(nobj, stride); - Msgf(("Proc %d starting at %ld in file, reading %d of %ld\n", - MPMY_Procnum(), start, nobj, gnobj)); - - nnames = 0; - va_start(ap, stride); - while(( names[nnames] = va_arg(ap, char *)) != NULL ){ - assert(nnames < MAXNAMES); - addrs[nnames] = va_arg(ap, int) + (char *)btab; - confirm = va_arg(ap, int *); - if( !SDFhasname(names[nnames], sdfp) ){ - *confirm = 0; - Msgf(("SDF file does not have %s\n", names[nnames])); - continue; - }else{ - *confirm = 1; - } - starts[nnames] = start; - nobjs[nnames] = nobj; - strides[nnames] = stride; - sz += SDFtype_sizes[SDFtype(names[nnames], sdfp)]; - nnames++; - } - va_end(ap); - - VerifyX(0==SDFseekrdvecsarr(sdfp, nnames, - names, starts, nobjs, addrs, strides), - Shout("%s", SDFerrstring)); - - *gnobjp = *nobjp = nobj; - MPMY_Combine(gnobjp, gnobjp, 1, MPMY_INT64, MPMY_SUM); - Msgf(("nobj=%d, gnobj=%ld\n", *nobjp, *gnobjp)); - - *btabp = btab; - StopTimer(&SDFreadTm); - OutputTimer(&SDFreadTm, singlPrintf); /* global sync and sets timer->max */ - singlPrintf("read %ld x %d at %.0f MB/s\n", *gnobjp, sz, (*gnobjp/(1000.*1000.))*(sz/ReadTimer(&SDFreadTm))); - DisableTimer(&SDFreadTm); - return sdfp; -} - diff --git a/external/libsdf/libsw/SDFreadf.c b/external/libsdf/libsw/SDFreadf.c deleted file mode 100644 index 21f249c..0000000 --- a/external/libsdf/libsw/SDFreadf.c +++ /dev/null @@ -1,177 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "mpmy.h" -#include "SDF.h" -#include "Assert.h" -#include "Malloc.h" -#include "Msgs.h" -#include "error.h" -#include "verify.h" -#include "SDFread.h" -#include "gc.h" -#include "singlio.h" -#include "timers.h" - -#define MAXNAMES 64 - -extern Timer_t SDFreadTm; - -SDF *SDFreadf(char *hdr, char *name, void **btabp, int *gnobjp, int *nobjp, - int stride, - /* char *name, offset_t offset, int *confirm */...) -{ - va_list ap; - int start; - SDF *sdfp; - int gnobj, nobj; - void *btab; - void *addrs[MAXNAMES]; - char *names[MAXNAMES]; - int strides[MAXNAMES]; - int nobjs[MAXNAMES]; - int64_t starts[MAXNAMES]; - int *confirm; - int nnames; - - EnableTimer(&SDFreadTm, "SDFread"); - StartTimer(&SDFreadTm); - - VerifySX(sdfp = SDFopen(hdr, name),SinglShout("%s", SDFerrstring)); - - if( SDFgetint(sdfp, "npart", &gnobj) ){ - /* Hopefully calling va_start and va_end in here won't disturb */ - /* the real loop over arguments below... */ - va_start(ap, stride); - names[0] = va_arg(ap, char *); - gnobj = SDFnrecs(names[0], sdfp); - va_end(ap); - if( MPMY_Procnum() == 0 ){ - SinglShout("%s does not have an \"npart\".\n", name); - SinglShout("Guessing npart=%d from SDFnrecs(., %s)\n", - gnobj, names[0]); - } - } - - NobjInitial(gnobj, MPMY_Nproc(), MPMY_Procnum(), &nobj, &start); - btab = Calloc(nobj, stride); - Msgf(("Proc %d starting at %d in file, reading %d of %d\n", - MPMY_Procnum(), start, nobj, gnobj)); - - nnames = 0; - va_start(ap, stride); - while(( names[nnames] = va_arg(ap, char *)) != NULL ){ - assert(nnames < MAXNAMES); - addrs[nnames] = va_arg(ap, int) + (char *)btab; - confirm = va_arg(ap, int *); - if( !SDFhasname(names[nnames], sdfp) ){ - *confirm = 0; - Msgf(("SDF file does not have %s\n", names[nnames])); - continue; - }else{ - *confirm = 1; - } - starts[nnames] = start; - nobjs[nnames] = nobj; - strides[nnames] = stride; - nnames++; - } - va_end(ap); - - VerifyX(0==SDFseekrdvecsarr(sdfp, nnames, - names, starts, nobjs, addrs, strides), - Shout("%s", SDFerrstring)); - - *nobjp = nobj; - MPMY_Combine(nobjp, gnobjp, 1, MPMY_INT, MPMY_SUM); - Msgf(("nobj=%d, gnobj=%d\n", *nobjp, *gnobjp)); - - *btabp = btab; - StopTimer(&SDFreadTm); - OutputTimer(&SDFreadTm, singlPrintf); /* global sync and sets timer->max */ - singlPrintf("read speed %.0f Mb/s\n", (*gnobjp/(1024.*1024.))*(stride/SDFreadTm.max)); - DisableTimer(&SDFreadTm); - return sdfp; -} - -SDF *SDFreadf64(char *hdr, char *name, void **btabp, int64_t *gnobjp, int *nobjp, - int stride, - /* char *name, offset_t offset, int *confirm */...) -{ - va_list ap; - int64_t start; - SDF *sdfp; - int64_t gnobj; - int nobj; - void *btab; - void *addrs[MAXNAMES]; - char *names[MAXNAMES]; - int strides[MAXNAMES]; - int nobjs[MAXNAMES]; - int64_t starts[MAXNAMES]; - int *confirm; - int nnames; - - EnableTimer(&SDFreadTm, "SDFread"); - StartTimer(&SDFreadTm); - - VerifySX(sdfp = SDFopen(hdr, name),SinglShout("%s", SDFerrstring)); - - if( SDFgetint64(sdfp, "npart", &gnobj) ){ - /* Hopefully calling va_start and va_end in here won't disturb */ - /* the real loop over arguments below... */ - va_start(ap, stride); - names[0] = va_arg(ap, char *); - gnobj = SDFnrecs(names[0], sdfp); - va_end(ap); - if( MPMY_Procnum() == 0 ){ - SinglShout("%s does not have an \"npart\".\n", name); - SinglShout("Guessing npart=%ld from SDFnrecs(., %s)\n", - gnobj, names[0]); - } - } - - NobjInitial64(gnobj, MPMY_Nproc(), MPMY_Procnum(), &nobj, &start); - btab = Calloc(nobj, stride); - Msgf(("Proc %d starting at %ld in file, reading %d of %ld\n", - MPMY_Procnum(), start, nobj, gnobj)); - - nnames = 0; - va_start(ap, stride); - while(( names[nnames] = va_arg(ap, char *)) != NULL ){ - assert(nnames < MAXNAMES); - addrs[nnames] = va_arg(ap, int) + (char *)btab; - confirm = va_arg(ap, int *); - if( !SDFhasname(names[nnames], sdfp) ){ - *confirm = 0; - Msgf(("SDF file does not have %s\n", names[nnames])); - continue; - }else{ - *confirm = 1; - } - starts[nnames] = start; - nobjs[nnames] = nobj; - strides[nnames] = stride; - nnames++; - } - va_end(ap); - - VerifyX(0==SDFseekrdvecsarr(sdfp, nnames, - names, starts, nobjs, addrs, strides), - Shout("%s", SDFerrstring)); - - *gnobjp = *nobjp = nobj; - MPMY_Combine(gnobjp, gnobjp, 1, MPMY_INT64, MPMY_SUM); - Msgf(("nobj=%d, gnobj=%ld\n", *nobjp, *gnobjp)); - - *btabp = btab; - StopTimer(&SDFreadTm); - OutputTimer(&SDFreadTm, singlPrintf); /* global sync and sets timer->max */ - singlPrintf("read speed %.0f Mb/s\n", (*gnobjp/(1024.*1024.))*(stride/SDFreadTm.max)); - DisableTimer(&SDFreadTm); - return sdfp; -} - diff --git a/external/libsdf/libsw/SDFwrite.c b/external/libsdf/libsw/SDFwrite.c deleted file mode 100644 index 85c7c51..0000000 --- a/external/libsdf/libsw/SDFwrite.c +++ /dev/null @@ -1,435 +0,0 @@ -/* This subroutine writes a restricted class of SDF files. - The files contain an arbitrary set of ascii scalars, (specified in the - variable length arg-list) and an array of binary struct records. - This is good enough for our purposes at the moment. More sophisticated - interfaces will probably be needed as time goes on. -*/ -#include -#include -#include -#include -#include -#include /* for open */ -#include /* for close */ -#include "SDF.h" -#include "SDFwrite.h" -#include "Malloc.h" -#include "mpmy.h" -#include "mpmy_io.h" -#include "Msgs.h" -#include "error.h" -#include "protos.h" -#include "timers.h" -#include "singlio.h" - -Timer_t SDFwriteTm; -static char *header_buf; -static int header_size; -static int header_len; - - -/* We would like to write some headers separately from the data. */ -/* We can let SDFwritehdr set this variable, and SDFwrite_alist */ -/* will avoid writing the header if wrote_header is true */ -static int wrote_header = 0; - -/* How much to increase header buffer size when realloced */ -#define BUF_INC 4096 - -/* How big is our line buffer */ -#define LINE_LEN 512 - -/* Align the data segment on this size boundary. */ -/* It MUST be less than LINE_LEN */ -#define DATAALIGN 32 - -static void -SDFwrite_alist(const char *filename, int gnobj, int nobj, - const void *btab, int bsize, const char *bodydesc, va_list alist); - -static void -SDFwrite_alist64(const char *filename, int mode, int64_t gnobj, int64_t nobj, - const void *btab, int bsize, const char *bodydesc, va_list alist); - -static void -outstr(const char *str) - /* This is an obstack, but who's counting? */ -{ - int len; - - len = strlen(str); - if (header_size - header_len <= len) { /* <= deals with terminal null */ - header_size += BUF_INC + len; - header_buf = Realloc(header_buf, header_size); - } - strcpy(header_buf + header_len, str); - header_len += len; -} - -void -SDFwrite(const char *filename, int gnobj, int nobj, - const void *btab, int bsize, const char *bodydesc, ...){ - va_list alist; - - EnableTimer(&SDFwriteTm, "SDFwrite"); - StartTimer(&SDFwriteTm); - va_start(alist, bodydesc); - SDFwrite_alist(filename, gnobj, nobj, btab, bsize, bodydesc, alist); - va_end(alist); - StopTimer(&SDFwriteTm); - OutputTimer(&SDFwriteTm, singlPrintf); /* global sync and set timer->max */ - if (SDFwriteTm.max != 0.0) - singlPrintf("write speed %.0f MB/s\n", - (gnobj/(1000.0*1000.0))*(bsize/SDFwriteTm.max)); - DisableTimer(&SDFwriteTm); /* suppress printing again in OutputTimers */ -} - -void -SDFwrite64(const char *filename, int64_t gnobj, int64_t nobj, - const void *btab, int bsize, const char *bodydesc, ...){ - va_list alist; - int mode = MPMY_WRONLY|MPMY_CREAT|MPMY_TRUNC|MPMY_MULTI; - - EnableTimer(&SDFwriteTm, "SDFwrite"); - StartTimer(&SDFwriteTm); - va_start(alist, bodydesc); - SDFwrite_alist64(filename, mode, gnobj, nobj, btab, bsize, bodydesc, alist); - va_end(alist); - StopTimer(&SDFwriteTm); - OutputTimer(&SDFwriteTm, singlPrintf); /* global sync and set timer->max */ - if (SDFwriteTm.max != 0.0) - singlPrintf("write speed %.0f MB/s\n", - (gnobj/(1000.0*1000.0))*(bsize/SDFwriteTm.max)); - DisableTimer(&SDFwriteTm); /* suppress printing again in OutputTimers */ -} - -void -SDFappend64(const char *filename, int64_t gnobj, int64_t nobj, - const void *btab, int bsize, const char *bodydesc, ...){ - va_list alist; - int mode = MPMY_WRONLY|MPMY_MULTI; - - EnableTimer(&SDFwriteTm, "SDFwrite"); - StartTimer(&SDFwriteTm); - va_start(alist, bodydesc); - SDFwrite_alist64(filename, mode, gnobj, nobj, btab, bsize, bodydesc, alist); - va_end(alist); - wrote_header = 1; - StopTimer(&SDFwriteTm); - OutputTimer(&SDFwriteTm, singlPrintf); /* global sync and set timer->max */ - if (SDFwriteTm.max != 0.0) - singlPrintf("write speed %.0f MB/s\n", - (gnobj/(1000.0*1000.0))*(bsize/SDFwriteTm.max)); - DisableTimer(&SDFwriteTm); /* suppress printing again in OutputTimers */ -} - -void -SDFwritehdr(const char *filename, const char *bodydesc, ...){ - va_list alist; - - va_start(alist, bodydesc); - SDFwrite_alist(filename, 0, 0, NULL, 0, bodydesc, alist); - va_end(alist); - wrote_header = 1; -} - -void -SDFunsetwroteheader(void) -{ - wrote_header = 0; -} - -void -SDFsetwroteheader(void) -{ - wrote_header = 1; -} - -static void -SDFwrite_alist(const char *filename, int gnobj, int nobj, - const void *btab, int bsize, const char *bodydesc, va_list alist) -{ - MPMYFile *myfd; - int i, pad; - char line[LINE_LEN]; - int ival; - double dval; - char *sval; - char *name; - char *buf; - int len; - int mode; - int ok, allok, retried; - - Msgf(("In Wtdata\n")); - header_len = 0; - - header_size = BUF_INC; - header_buf = Malloc(header_size); - - if (MPMY_Procnum() == 0 && wrote_header == 0) { - outstr ("# SDF\n"); - sprintf(line, "parameter byteorder = 0x%x;\n", - SDFcpubyteorder()); outstr(line); - while( (name = va_arg(alist, char *)) ){ - Msgf(("name(%lx)=%s\n", (unsigned long int)name, name)); - switch( va_arg(alist, enum SDF_type_enum) ){ - case SDF_INT: - ival = va_arg(alist, int); - sprintf(line, "int %s = %d;\n", name, ival); outstr(line); - break; - case SDF_FLOAT: - dval = va_arg(alist, double); - sprintf(line, "float %s = %.8g;\n", name, dval); outstr(line); - break; - case SDF_DOUBLE: - dval = va_arg(alist, double); - sprintf(line, "double %s = %.16g;\n", name, dval); - outstr(line); - break; - case SDF_STRING: - sval = va_arg(alist, char *); - sprintf(line, "char %s[] = \"%s\";\n", name, sval); - outstr(line); - break; - default: - Shout("Unexpected type in wtdata\n"); - break; - } - } - if( bodydesc ){ - outstr(bodydesc); - if( gnobj > 0 ) - sprintf(line, "[%d];\n", gnobj); - else - sprintf(line, "[];\n"); - outstr(line); - } - outstr("#\f\n"); - outstr ("# SDF-EOH "); - /* This little bit of magic will cause the first word of data */ - /* to be aligned. This isn't required by anything, but it makes */ - /* it a lot easier to use really primitive tools like od. */ - pad = (header_len+1)%DATAALIGN; /* the +1 is to account for the '\n' */ - if( pad ) - pad = DATAALIGN - pad; - for(i=0; i 0 ) { -#if __WORDSIZE==64 - sprintf(line, "[%ld];\n", gnobj); -#else - sprintf(line, "[%lld];\n", gnobj); -#endif - } else { - sprintf(line, "[];\n"); - } - outstr(line); - } - outstr("#\f\n"); - outstr ("# SDF-EOH "); - /* This little bit of magic will cause the first word of data */ - /* to be aligned. This isn't required by anything, but it makes */ - /* it a lot easier to use really primitive tools like od. */ - pad = (header_len+1)%DATAALIGN; /* the +1 is to account for the '\n' */ - if( pad ) - pad = DATAALIGN - pad; - for(i=0; i -#include -#include -#include -#include "abm.h" -#include "protos.h" -#include "Assert.h" -#include "mpmy.h" -#include "Malloc.h" -#include "Msgs.h" -#include "verify.h" -#include "gc.h" -#include "dll.h" - -#define Ver(x) Verify((x) == MPMY_SUCCESS) - -#define ABMDONETYPE -1 -#define ABMALLDONETYPE -2 - -/* Use this for queueing entries for later packetization */ -typedef struct{ - void *arg; - int type; /* request/reply/done */ - int sz; - ABMpktz_t *func; /* how to bundle the data */ -} Qelmt_t ; - -/* Send exaclty one pkt */ -static void SendPkt(ABM *abm, void *ptr, int sz, int dest); - -/* Keep track of the resources tied up in outgoing messages */ -static void DeliveryWait(ABM *abm); -static void DeliveryTest(ABM *abm); - -/* Common subroutine between ABMPoll and ABMPollWait */ -static int ABMPoll_common(ABM *abm, MPMY_Status *status); - -/* Keep track of the messages that haven't been MPMY_Test'ed affirmative yet */ -typedef struct { - void *ptr; - MPMY_Comm_request req; -} undelivered_t; - -/* To be "safe", ABMFlushOne should also eliminate dest from destarr[], but - the precise behavior of the callers of this function make that - unnecessary. If you call ABMFlushOne, you must guarantee that - destarr[] is left in a correct state when you are done. */ -static void ABMFlushOne(ABM *abm, int dest); - -static int hist_enable; -Timer_t ABMDlvrTm; -Counter_t ABMIsendCnt; -Counter_t ABMPostCnt; -Counter_t ABMByteCnt; -Counter_t ABMHistCnt[ABMHISTLEN]; - -void -ABMHistEnable(int log2lo, int log2hi){ - int i; - char name[32]; - - /* Sanity check the args. Maybe we should assert these?? */ - if( log2lo < 0 ) - log2lo = 0; - if( log2hi >= ABMHISTLEN ) - log2hi = ABMHISTLEN-1; - if( log2lo > log2hi ) - log2lo = log2hi; - if( log2hi < log2lo ) - log2hi = log2lo; - for(i=log2lo; i<=log2hi; i++){ - sprintf(name, "Pkt(>=%d)", 1<pktsize = pktsize; - abm->nfuncs = nfuncs; - abm->hndlarray = Malloc(nfuncs*sizeof(ABMhndlr_t *)); - memcpy(abm->hndlarray, hndlarray, nfuncs*sizeof(ABMhndlr_t *)); - nproc = MPMY_Nproc(); - procnum = MPMY_Procnum(); - abm->doc = ilog2(nproc); - if (nproc != 1 << (abm->doc)) - abm->doc++; /* for non power-of-two sizes */ - /* This shouldn't require 10 lines of code... */ - if( procnum == 0 ){ - abm->allbitsdone = (1 << (abm->doc+1))-1; - }else if( lobit(procnum) == 0 ){ - abm->allbitsdone = 1; - }else{ - bit = 1<<(lobit(procnum)-1); - Msg("abmdone", ("bit=%d\n", bit)); - while( (bit^procnum) >= nproc ){ - Msg("abmdone", ("looping, bit=%d\n", bit)); - bit >>= 1; - } - abm->allbitsdone = (bit==0)? 1 : (bit<<2)-1; - } - abm->done = 0; - abm->alldone = 0; - Msg("abmdone", ("ABM:allbitsdone=%d, done=%d\n", abm->allbitsdone, abm->done)); - abm->recvbufA = abm->recvbuf1 = Malloc(pktsize); - abm->recvbufB = abm->recvbuf2 = Malloc(pktsize); - abm->tag = tag; - Ver(MPMY_Irecv(abm->recvbufA, abm->pktsize, - MPMY_SOURCE_ANY, abm->tag, &abm->Recv_Hndl)); - abm->Enqueued = Malloc(sizeof(Dll)*nproc); - abm->destarr = Malloc(sizeof(int)*nproc); - abm->cntarr = Calloc(nproc, sizeof(int)); - abm->ndests = 0; - DllCreateChn(&abm->QelmtChn, sizeof(Qelmt_t), 10); - for(i=0; iEnqueued[i], &abm->QelmtChn); - } - - DllCreateChn(&abm->undelChn, sizeof(undelivered_t), 20); - DllCreate(&abm->undeliveredLL, &abm->undelChn); -} - -void -ABMIamDone(ABM *abm){ - int i, procnum; - - procnum = MPMY_Procnum(); - if( abm->done & 1 ){ - SeriousWarning("ABMIamDone apparently called twice!\n"); - Shout("allbitsdone=%d, done=%d\n", abm->allbitsdone, abm->done); - return; - } - if( abm->alldone ){ - SeriousWarning("ABMIamDone called after alldone\n"); - Shout("allbitsdone=%d, done=%d\n", abm->allbitsdone, abm->done); - return; - } - Msg("abmdone", ("ABMIamDone\n")); - ABMPost(abm, procnum, 0, ABMDONETYPE, NULL, NULL); - ABMFlushOne(abm, procnum); - for(i=abm->ndests-1; i>=0; --i){ - if( abm->destarr[i] == procnum ){ - abm->destarr[i] = abm->destarr[--abm->ndests]; - break; - } - } - assert(i >= 0); -} - -int -ABMAllDone(ABM *abm){ - return abm->alldone; -} - -void -ABMShutdown(ABM *abm){ - int i; - int junk = 0; - MPMY_Status stat; - MPMY_Comm_request req; - - while( !ABMAllDone(abm) ){ - ABMFlush(abm); - if( ABMPoll(abm) < 0 ) - Error("AbmPoll failed in ABMShutdown!\n"); - } - /* There's still a recv outstanding in NLPoll */ - Ver(MPMY_Isend(&junk, sizeof(int), MPMY_Procnum(), abm->tag, &req)); - MPMY_Wait2(req, NULL, abm->Recv_Hndl, &stat); - assert(MPMY_Source(&stat) == MPMY_Procnum() - && MPMY_Count(&stat) == sizeof(int)); - - for(i=0; iEnqueued[i]); - } - ChnTerminate(&abm->QelmtChn); - Free(abm->hndlarray); - Free(abm->Enqueued); - Free(abm->destarr); - Free(abm->cntarr); - Free(abm->recvbuf1); - Free(abm->recvbuf2); - DllTerminate(&abm->undeliveredLL); - ChnTerminate(&abm->undelChn); -} - -static void -Donehndlr(ABM *abm, int who){ - int mask, dest, type; - int procnum= MPMY_Procnum(); - - mask = who ^ procnum; - - if( mask == 0 ) - mask = 1; - else - mask <<= 1; - Msg("abmdone", ("Donehndlr(who=%d), mask=%x\n", who, mask)); - if( (abm->done & mask) || !(abm->allbitsdone & mask)){ - SeriousWarning("Unexepected bit set in 'done' or 'allbitsdone':\n"); - Shout("done=%x, allbitsdone=%x, who=%x, procnum=%d, mask=%x\n", - abm->done, abm->allbitsdone, who, procnum, mask); - } - abm->done |= mask; - - if( abm->done == abm->allbitsdone ){ - if( procnum == 0 ){ - type = ABMALLDONETYPE; - dest = 0; - Msg("abmdone", ("Proc 0 is done. Initiatiing ALLDONE cascade\n")); - }else{ - type = ABMDONETYPE; - dest = (1<done: %d\n", abm->alldone, abm->done)); - } -} - -static void -AllDonehndlr(ABM *abm) -{ - int chan; - int procnum = MPMY_Procnum(); - int nproc = MPMY_Nproc(); - - Msg("abmdone", ("AllDonehndlr\n")); - - for (chan = hibit(MPMY_Procnum())+1; chan < abm->doc; chan++) { - int dest = procnum ^ (1 << chan); - if (!(procnum & (1 << chan)) && dest < nproc) { - Msgf(("AllDone: informing p%d\n", dest)); - ABMPost(abm, dest, 0, ABMALLDONETYPE, NULL, NULL); - ABMFlush(abm); - } - } - assert(abm->ndests == 0); - Msg("abmdone", ("Waiting for all Isends to complete\n")); - Msg_flush(); - DeliveryWait(abm); - Msg("abmdone", ("Everybody done. Everybody informed\n")); - Msg_flush(); - abm->alldone = 1; -} - -int -ABMPoll(ABM *abm){ - MPMY_Status status; - int flag; - - Ver(MPMY_Test(abm->Recv_Hndl, &flag, &status)); - if( flag == 0 ) - return 0; - return ABMPoll_common(abm, &status); -} - -int -ABMPollWait(ABM *abm){ - MPMY_Status status; - - ABMFlush(abm); - if( Msg_test(__FILE__) ){ - Msg_do("Waiting in ABMPollWait\n"); - Msg_flush(); - } - Ver(MPMY_Wait(abm->Recv_Hndl, &status)); - return ABMPoll_common(abm, &status); -} - -static int -ABMPoll_common(ABM *abm, MPMY_Status *status){ - int type; - int flag; - int len; - int sz; - int src; - char *in, *end; - int nloop = 0; - - do{ - /* Testing inside the while with a "," operator breaks the T3D */ - nloop++; - if (MPMY_Tag(status) != abm->tag) - Error("Bad tag (%d) in ABMPoll(), should be %d, source %d, len %d\n", - MPMY_Tag(status), abm->tag, MPMY_Source(status), - MPMY_Count(status)); - src = MPMY_Source(status); - len = MPMY_Count(status); - Msgf(("ABMPoll Received %d byte packet from p%d\n", len, src)); - - in = abm->recvbufA; - Ver(MPMY_Irecv(abm->recvbufB, abm->pktsize, - MPMY_SOURCE_ANY, abm->tag, &abm->Recv_Hndl)); - abm->recvbufA = abm->recvbufB; - abm->recvbufB = in; - end = in + len; - while( in < end ){ - if( abm->alldone ){ - long int *ip = (long int *)in; - SeriousWarning("message arrived after alldone.\n"); - Shout("allbitsdone=%d, done=%d\n", abm->allbitsdone, - abm->done); - Shout("src=%d, total len=%d, buf=%#lx, in=%#lx\n", - src, len, (long)abm->recvbufB, (long)in); - Shout("type=%ld, message size: %ld, contents: %#lx %#lx %#lx %#lx\n", - ip[0], ip[1], ip[2], ip[3], ip[4], ip[5]); - return -1; - } - type = *(int *)in; - in += sizeof(int); - sz = *(int *)in; - in += sizeof(int); - - switch(type){ - case ABMALLDONETYPE: - Msgf(("ABMALLDONE recvd from p%d.\n", src)); - AllDonehndlr(abm); - break; - case ABMDONETYPE: - Msgf(("ABMDONE recvd from p%d.\n", src)); - Donehndlr(abm, src); - break; - default: - Msgf(("ABMPoll type %d\n", type)); - if( type >= 0 && type < abm->nfuncs ) - abm->hndlarray[type](src, sz, in); - else{ - Error("Bad type, %d!\n", type); - } - break; - } - in += sz; - } - Ver(MPMY_Test(abm->Recv_Hndl, &flag, status)); - }while(flag); - return nloop; -} - -void -ABMPost(ABM *abm, int dest, int sz, int type, ABMpktz_t *func, void *arg){ - Dll *Q = &abm->Enqueued[dest]; - Qelmt_t *new; - - IncrCounter(&ABMPostCnt); - if( sz + 2*sizeof(int) > abm->pktsize){ - Error("Can't ABMPost a message of size %d. pktsize=%d\n", - sz, abm->pktsize); - } - if( DllLength(Q) == 0 ){ - abm->destarr[abm->ndests++] = dest; - } - if( abm->cntarr[dest] + sz + 2*sizeof(int) > abm->pktsize ){ - ABMFlushOne(abm, dest); - } - abm->cntarr[dest] += sz + 2*sizeof(int); - Msgf(("ABMPost %ld for p%d, cntarr now %d\n", sz + 2*sizeof(int), dest, abm->cntarr[dest])); - new = DllData( DllInsertAtBottom(Q) ); - new->sz = sz; - new->func = func; - new->arg = arg; - new->type = type; -} - -static int -cmp_xor(const void *p1, const void *p2){ - int d1 = *(int *)p1; - int d2 = *(int *)p2; - int procnum = MPMY_Procnum(); - - return (d1^procnum) - (d2^procnum); -} - -/* To be "safe", ABMFlushOne should also eliminate dest from destarr[], but - the precise behavior of the callers of this function make that - unnecessary. If you call this function, you must guarantee that - destarr[] is left in a correct state whey you are done. */ -static void -ABMFlushOne(ABM *abm, int dest){ - char *cp; - void *buf; - Qelmt_t *Qelmt; - Dll *Q; - Dll_elmt *q; - int szleft, used; - - Q = &abm->Enqueued[dest]; - if( DllLength(Q) == 0 ) - return; - -#if 0 - /* This loop is wasting time. If we get here from ABMFlush, then - we should already know which element in destarr is in question. - If we get here from ABMPost, then we know the very next thing - we are going to do is put the same destination back in destarr. - Thus, we can just forget this altogether! */ - for(i=0; indests; i++){ - if( abm->destarr[i] == dest ) - break; - } - assert(i < abm->ndests);; /* we actually found one! */ - abm->destarr[i] = abm->destarr[--abm->ndests]; -#endif - - Msgf(("ABMFl to p%d\n", dest)); - cp = buf = Malloc(abm->pktsize); - szleft = abm->pktsize; - - for(q = DllTop(Q); q!=DllInf(Q); q=DllDeleteDown(Q, q)){ - Qelmt = (Qelmt_t *)DllData(q); - if( Qelmt->sz + 2*sizeof(int) > szleft ){ - /* Now that ABMPost flushes automatically when the count - passes pktsize, this test may be overkill. It's not worth - simplifying. */ - used = abm->pktsize - szleft; - buf = Realloc(buf, used); - Msgf(("SendQ full packet for p%d (len=%d)\n", - dest, used)); - SendPkt(abm, buf, used, dest); - cp = buf = Malloc(abm->pktsize); - szleft = abm->pktsize; - } - /* I think it would be possible to recover here if we - introduce another TYPE of message 'NLPKTGROWTYPE' which - tells the recipient to Realloc his receive buf. A good project - for a rainy day.... */ - assert(Qelmt->sz + 2*sizeof(int) <= szleft && Qelmt->sz >= 0 ); - *(int *)cp = Qelmt->type; - cp += sizeof(int); - szleft -= sizeof(int); - *(int *)cp = Qelmt->sz; - cp += sizeof(int); - szleft -= sizeof(int); - if( Qelmt->func ){ - Qelmt->func(cp, Qelmt->arg, Qelmt->sz); - cp += Qelmt->sz; - szleft -= Qelmt->sz; - } - } - assert(szleft < abm->pktsize); - used = abm->pktsize - szleft; - Msgf(("SendQ: Remaining packet for p%d (len=%d)\n", - dest, used)); - SendPkt(abm, buf, used, dest); - abm->cntarr[dest] = 0; -} - -void -ABMFlush(ABM *abm){ - int i; - - if (abm->ndests == 0) return; /* Required to avoid huge overhead. */ - - /* reorder the destinations so everybody doesn't immediately dump on 0 ! */ - qsort(abm->destarr, abm->ndests, sizeof(int), cmp_xor); /* unnecessary? */ - - /* loop over the destinations that have something queued. */ - for(i=0; indests; i++){ - ABMFlushOne(abm, abm->destarr[i]); - } - abm->ndests = 0; - DeliveryTest(abm); -} - - -static -void SendPkt(ABM *abm, void *ptr, int sz, int dest){ - undelivered_t *new; - - new = DllData(DllInsertAtTop(&abm->undeliveredLL)); - new->ptr = ptr; - AddCounter(&ABMByteCnt, sz); - IncrCounter(&ABMIsendCnt); - if( hist_enable ){ - int h = ilog2(sz); - /* If I weren't so lazy, I'd record the outliers separately... */ - if( h < ABMHISTFIRST ) h = ABMHISTFIRST; - if( h >=ABMHISTLEN ) h = ABMHISTLEN-1; - /* We could just increment these by 1, or by sz. You learn - something slightly different either way... */ - AddCounter(&ABMHistCnt[h], sz); - } - Ver(MPMY_Isend(ptr, sz, dest, abm->tag, &new->req)); - /* Calling DeliveryTest here is not strictly necessary for correctness, - but it is a good idea to try to reduce the number of outstanding - requests. See the comment near DeliverTest for other ideas */ - DeliveryTest(abm); -} - -/* It might be useful to have two versions of this. The one called - from ABMFlush (and hence at user request) should be aggressive and try - each and every outstanding request. The one called from ABMFlushOne, - (and hence more frequently, but perhaps asynchronously), could give up - after the first failure. This would keep those machines that need - constant prodding working, without putting an unnecessary burden on - others. */ -static void DeliveryTest(ABM *abm){ - int flag; - undelivered_t *p; - Dll_elmt *pp; - - /* Another good opportunity to call Flick? This is done once per - ABMFlush. */ - StartTimer(&ABMDlvrTm); - MPMY_Flick(); - for(pp=DllBottom(&abm->undeliveredLL); - pp != DllSup(&abm->undeliveredLL); - /* pp incremented inside body */){ - p = DllData(pp); - Ver( MPMY_Test(p->req, &flag, NULL) ); - if( flag ){ - Free(p->ptr); - pp = DllDeleteUp(&abm->undeliveredLL, pp); - }else{ - pp = DllUp(pp); - } - } - StopTimer(&ABMDlvrTm); -} - -static void DeliveryWait(ABM *abm){ - Msgf(("ABMWait\n")); - while( DllLength(&abm->undeliveredLL) ){ - DeliveryTest(abm); - } -} - diff --git a/external/libsdf/libsw/alloca.c b/external/libsdf/libsw/alloca.c deleted file mode 100644 index 854abb1..0000000 --- a/external/libsdf/libsw/alloca.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - alloca -- (mostly) portable public-domain implementation -- D A Gwyn - - last edit: 93/06/06 johns - use Malloc instead of xmalloc. - - last edit: 86/05/30 rms - include config.h, since on VMS it renames some symbols. - Use xmalloc instead of malloc. - - This implementation of the PWB library alloca() function, - which is used to allocate space off the run-time stack so - that it is automatically reclaimed upon procedure exit, - was inspired by discussions with J. Q. Johnson of Cornell. - - It should work under any C implementation that uses an - actual procedure stack (as opposed to a linked list of - frames). There are some preprocessor constants that can - be defined when compiling for your specific system, for - improved efficiency; however, the defaults should be okay. - - The general concept of this implementation is to keep - track of all alloca()-allocated blocks, and reclaim any - that are found to be deeper in the stack than the current - invocation. This heuristic does not reclaim storage as - soon as it becomes invalid, but it will do so eventually. - - As a special case, alloca(0) reclaims storage without - allocating any. It is a good idea to use alloca(0) in - your main control loop, etc. to force garbage collection. -*/ -#ifndef lint -static char SCCSid[] = "@(#)alloca.c 1.1"; /* for the "what" utility */ -#endif - -#ifdef emacs -#include "config.h" -#ifdef static -/* actually, only want this if static is defined as "" - -- this is for usg, in which emacs must undefine static - in order to make unexec workable - */ -#ifndef STACK_DIRECTION -you -lose --- must know STACK_DIRECTION at compile-time -#endif /* STACK_DIRECTION undefined */ -#endif /* static */ -#endif /* emacs */ - -#ifndef alloca /* If compiling with GCC, this file's not needed. */ - -#ifdef __STDC__ -typedef void *pointer; /* generic pointer type */ -#else -typedef char *pointer; /* generic pointer type */ -#endif - -#define NULL 0 /* null pointer constant */ - -#if 0 -extern void free(); -extern pointer xmalloc(); -#else -/* Johns mods for swutils library. */ -#define xmalloc Malloc -#define free Free -#include "Malloc.h" -#endif - -/* - Define STACK_DIRECTION if you know the direction of stack - growth for your system; otherwise it will be automatically - deduced at run-time. - - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown -*/ - -#ifndef STACK_DIRECTION -#define STACK_DIRECTION 0 /* direction unknown */ -#endif - -#if STACK_DIRECTION != 0 - -#define STACK_DIR STACK_DIRECTION /* known at compile-time */ - -#else /* STACK_DIRECTION == 0; need run-time code */ - -static int stack_dir; /* 1 or -1 once known */ -#define STACK_DIR stack_dir - -static void -find_stack_direction (/* void */) -{ - static char *addr = NULL; /* address of first - `dummy', once known */ - auto char dummy; /* to get stack address */ - - if (addr == NULL) - { /* initial entry */ - addr = &dummy; - - find_stack_direction (); /* recurse once */ - } - else /* second entry */ - if (&dummy > addr) - stack_dir = 1; /* stack grew upward */ - else - stack_dir = -1; /* stack grew downward */ -} - -#endif /* STACK_DIRECTION == 0 */ - -/* - An "alloca header" is used to: - (a) chain together all alloca()ed blocks; - (b) keep track of stack depth. - - It is very important that sizeof(header) agree with malloc() - alignment chunk size. The following default should work okay. -*/ - -#ifndef ALIGN_SIZE -#define ALIGN_SIZE sizeof(double) -#endif - -typedef union hdr -{ - char align[ALIGN_SIZE]; /* to force sizeof(header) */ - struct - { - union hdr *next; /* for chaining headers */ - char *deep; /* for stack depth measure */ - } h; -} header; - -/* - alloca( size ) returns a pointer to at least `size' bytes of - storage which will be automatically reclaimed upon exit from - the procedure that called alloca(). Originally, this space - was supposed to be taken from the current stack frame of the - caller, but that method cannot be made to work for some - implementations of C, for example under Gould's UTX/32. -*/ - -static header *last_alloca_header = NULL; /* -> last alloca header */ - -pointer -alloca (size) /* returns pointer to storage */ - unsigned size; /* # bytes to allocate */ -{ - auto char probe; /* probes stack depth: */ - register char *depth = &probe; - -#if STACK_DIRECTION == 0 - if (STACK_DIR == 0) /* unknown growth direction */ - find_stack_direction (); -#endif - - /* Reclaim garbage, defined as all alloca()ed storage that - was allocated from deeper in the stack than currently. */ - - { - register header *hp; /* traverses linked list */ - - for (hp = last_alloca_header; hp != NULL;) - if ((STACK_DIR > 0 && hp->h.deep > depth) - || (STACK_DIR < 0 && hp->h.deep < depth)) - { - register header *np = hp->h.next; - - free ((pointer) hp); /* collect garbage */ - - hp = np; /* -> next header */ - } - else - break; /* rest are not deeper */ - - last_alloca_header = hp; /* -> last valid storage */ - } - - if (size == 0) - return NULL; /* no allocation required */ - - /* Allocate combined header + user data storage. */ - - { - register pointer new = xmalloc (sizeof (header) + size); - /* address of header */ - - ((header *)new)->h.next = last_alloca_header; - ((header *)new)->h.deep = depth; - - last_alloca_header = (header *)new; - - /* User storage begins just after header. */ - - return (pointer)((char *)new + sizeof(header)); - } -} - -#endif /* no alloca */ diff --git a/external/libsdf/libsw/batch.c b/external/libsdf/libsw/batch.c deleted file mode 100644 index 746dd66..0000000 --- a/external/libsdf/libsw/batch.c +++ /dev/null @@ -1,82 +0,0 @@ -/* batch.c: Collect a series of small sends into larger ones */ - -#include "batch.h" -#include "mpmy.h" -#include "stk.h" -#include "Malloc.h" -#include "Msgs.h" - -void PollWait(MPMY_Comm_request req, int tag); - -static Stk **stks; -static int tag; -static int batch_size; - -void -SetupBatch(int ttag, int size) -{ - int dest; - - Msgf(("SetupBatch: tag %d size %d\n", ttag, size)); - tag = ttag; - batch_size = size; - stks = Calloc(MPMY_Nproc(), sizeof(Stk *)); - /* allocate all memory beforehand */ - /* Otherwise the incoming poll buffer will fight with the batch stks */ - /* for heap space, and we end up with a bunch of holes in the heap */ - for (dest = 0; dest < MPMY_Nproc(); dest++) { - stks[dest] = Malloc(sizeof(Stk)); - StkInit(stks[dest], batch_size, Realloc_f, 0); - StkPushType(stks[dest], dest, int); - } -} - -void -FinishBatch(void) -{ - int i; - MPMY_Comm_request req; - int nproc = MPMY_Nproc(); - int procnum = MPMY_Procnum(); - int procs_per_node = MPMY_ProcsPerNode(); - int my_master = (procnum / procs_per_node) * procs_per_node; - int ddest; - - for (i = 0; i < nproc; i++) { - Stk *s = stks[i]; - if (StkSz(s) > sizeof(int)) { - ddest = (i / procs_per_node) * procs_per_node; - if (ddest == my_master) ddest = i; - Msgf(("SendBatch: %ld to %d via %d\n", StkSz(s), i, ddest)); - MPMY_Isend(StkBase(s), StkSz(s), ddest, tag, &req); - PollWait(req, tag); - } - StkTerminate(s); - Free(s); - } - Free(stks); - Msgf(("FinishBatch done\n")); -} - -void -SendBatch(void *outbuf, int size, int dest) -{ - Stk *s = stks[dest]; - - StkPushData(s, outbuf, size); - if (StkSz(s) > batch_size - size) { - MPMY_Comm_request req; - int ddest, my_master; - int procs_per_node = MPMY_ProcsPerNode(); - int procnum = MPMY_Procnum(); - - ddest = (dest / procs_per_node) * procs_per_node; - my_master = (procnum / procs_per_node) * procs_per_node; - if (ddest == my_master) ddest = dest; - Msgf(("SendBatch: %ld to %d via %d\n", StkSz(s), dest, ddest)); - MPMY_Isend(StkBase(s), StkSz(s), ddest, tag, &req); - PollWait(req, tag); - StkClear(s); - StkPushType(s, dest, int); - } -} diff --git a/external/libsdf/libsw/bcopy.c b/external/libsdf/libsw/bcopy.c deleted file mode 100644 index 20855f5..0000000 --- a/external/libsdf/libsw/bcopy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -void bcopy(void *b1, void *b2, int length){ - memmove(b2, b1, length); -} - diff --git a/external/libsdf/libsw/byteswap.c b/external/libsdf/libsw/byteswap.c deleted file mode 100644 index 4d2bdad..0000000 --- a/external/libsdf/libsw/byteswap.c +++ /dev/null @@ -1,127 +0,0 @@ -/* Functions to do general byte swapping: */ - -#include -#include "byteswap.h" - -static int swap2(int, void *, void *); -static int swap4(int, void *, void *); -static int swap8(int, void *, void *); -static int swapgen(int, int, void *, void *); - -/* A general, in-place, byte-swapper. */ -/* It swaps a total of unit_len*n_units bytes, unit_len bytes at a time. */ -/* Thus, you can use it for arrays of doubles with unit_len=8, or */ -/* arrays of chars with unit_len=1 (which is equivalent to memcpy). */ -/* It checks for stupid arguments. It works fine when */ -/* from and to are identical. It breaks if from and to are */ -/* almost the same. */ -int Byteswap(int unit_len, int n_units, void *from, void *to) -{ - int ptrdiff; - - if(n_units < 0 || unit_len < 0){ - return -1; - } - - /* This isn't ANSI conforming. I don't think it can be. */ - /* It's the canonical "You can't write memcpy in ANSI C because */ - /* you can't compare the pointers and learn anything reliable." */ - /* problem. The compiler is free to return nonsense for ptrdiff. */ - ptrdiff = (char *)from - (char *)to; - if( ptrdiff != 0 && (ptrdiff < unit_len*n_units && ptrdiff > -unit_len) ){ - return -1; - } - - switch(unit_len){ - case 1: - memcpy(to, from, n_units); - return 0; - case 2: - return swap2(n_units, from, to); - case 4: - return swap4(n_units, from, to); - case 8: - return swap8(n_units, from, to); - default: - return swapgen(unit_len, n_units, from, to); - } -} - -static int swap2(int n, void *from, void *to) -{ - char *fromc = from; - char *toc = to; - char tmp; - - while(n--){ - tmp = fromc[0]; - toc[0] = fromc[1]; - toc[0] = tmp; - fromc+= 2; - toc += 2; - } - return 0; -} - -static int swap4(int n, void *from, void *to) -{ - char *toc = to; - char *fromc = from; - char tmp; - - while(n--){ - tmp = fromc[3]; - toc[3] = fromc[0]; - toc[0] = tmp; - tmp = fromc[2]; - toc[2] = fromc[1]; - toc[1] = tmp; - fromc += 4; - toc += 4; - } - return 0; -} - -static int swap8(int n, void *from, void *to) -{ - char *toc = to; - char *fromc = from; - char tmp; - - while(n--){ - tmp = fromc[7]; - toc[7] = fromc[0]; - toc[0] = tmp; - tmp = fromc[6]; - toc[6] = fromc[1]; - toc[1] = tmp; - tmp = fromc[5]; - toc[5] = fromc[2]; - toc[2] = tmp; - tmp = fromc[4]; - toc[4] = fromc[3]; - toc[3] = tmp; - fromc += 8; - toc += 8; - } - return 0; -} - -static int swapgen(int unit_len, int nunits, void *from, void *to) -{ - char *toc = to; - char *fromc = from; - char tmp; - int i; - - while(nunits--){ - for(i=0; i -#include "Assert.h" -#include "chn.h" -#include "Msgs.h" -#include "malloc.h" - -/* The Chain macro is used to chain together 'freed' nodes. */ -/* We write a pointer on top of the first word and a magic */ -/* number on top of the second word. */ -#if !defined(ChnNext) || !defined(ChnMagic) || !defined(ChnMAGIC) - # error Chn macros undefined -#endif - -/* STOLEN FROM OBSTACK.C */ -#ifdef __STDC__ -#define PTR_INT_TYPE ptrdiff_t -#else -#define PTR_INT_TYPE long -#endif -/* Determine default alignment. */ -struct fooalign {char x; double d;}; -#define DEFAULT_ALIGNMENT \ - ((PTR_INT_TYPE) ((char *)&((struct fooalign *) 0)->d - (char *)0)) -/* END OF STOLEN CODE */ -#define ALIGNMENT_MASK (DEFAULT_ALIGNMENT-1) -#define Align(x) ((x)+ALIGNMENT_MASK)&(~(ALIGNMENT_MASK)) -#define ChnHDRSZ (Align(sizeof(int)+sizeof(void *))) - -void ChnInit(Chn *new, int sz, int nalloc, - void *(*realloc_like)(void *, size_t)) -{ - if(sz < ChnHDRSZ) - sz = ChnHDRSZ; - - new->sz = Align(sz); - Msgf(("chn=%#lx, sz=%d, new->sz=%d\n", (unsigned long)new, sz, new->sz)); - new->nalloc = nalloc; - new->free_list = NULL; - new->free_cnt = 0; - new->nmalloced = 0; - new->realloc_like = realloc_like; - new->first_chunk = NULL; -} - -void ChnFreeAll(Chn *id) -{ - void *chunk, *nextchunk; - - Msgf(("ChnFreeAll(%#lx)\n", (unsigned long)id)); - for(chunk=id->first_chunk; chunk ; chunk = nextchunk){ - nextchunk = ChnNext(chunk); - Msgf(("ChnFree(%#lx)\n", (unsigned long)chunk)); - id->realloc_like(chunk, 0); - } - id->free_cnt = 0; - id->free_list = NULL; - id->nmalloced = 0; -} - -void ChnTerminate(Chn *id) -{ - ChnFreeAll(id); - id->realloc_like = NULL; -} - -int ChnCheck(Chn *id) -/* Return < 0 if there is something wrong with the freelist. */ -/* Return 0 if all is ok. */ -{ - int i=0; - void *p = id->free_list; - - while(p){ - if(ChnMagic(p) != ChnMAGIC) - return -1; - if(i++ < id->free_cnt) - return -2; - p = ChnNext(p); - } - return 0; -} - -/* - * ChnMoreMem: grab some more memory for a Chn. - */ -int ChnMoreMem(Chn *id) -{ - void *newchunk; - int i, sz, nnew; - char *p; - - if( id->free_cnt == 0 && id->free_list != NULL ){ - SeriousWarning("Impossible situation in ChnMoreMem, freecnt=0, free_list = %#lx\n", (unsigned long)id->free_list); - malloc_print(); - } - - nnew = id->nalloc; - sz = id->sz; - while( (newchunk=id->realloc_like(NULL, nnew*sz + ChnHDRSZ)) == 0 && - nnew > 0 ) - nnew /= 2; - if(newchunk == 0){ - return -1; - } - Msgf(("ChnMoreMem(chn=%#lx, newsz=%ld, address=%#lx)\n", - (unsigned long)id, (unsigned long)(nnew*sz+ChnHDRSZ), - (unsigned long)newchunk)); - - id->nmalloced += nnew; - ChnNext(newchunk) = id->first_chunk; - ChnMagic(newchunk) = ChnMAGIC; - id->first_chunk = newchunk; - newchunk = (char *)newchunk + ChnHDRSZ; - - p = (char *)newchunk; - for(i=0; ifree_list; - ChnMagic(p) = ChnMAGIC; - id->free_list = newchunk; - id->free_cnt += nnew; - return 0; -} - -/* - * end of: CHN.C - */ diff --git a/external/libsdf/libsw/class_params.c b/external/libsdf/libsw/class_params.c deleted file mode 100644 index 2d89495..0000000 --- a/external/libsdf/libsw/class_params.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "class.h" -#include "cosmo.h" -#include "Malloc.h" -#include "error.h" - -#define class_fail(function, \ - error_message_from_function, \ - error_message_output) \ - do { \ - if (function == _FAILURE_) { \ - ErrorMsg Transmit_Error_Message; \ - sprintf(Transmit_Error_Message,"%s(L:%d) : error in %s;\n=>%s", \ - __func__,__LINE__,#function,error_message_from_function); \ - Error("%s",Transmit_Error_Message); \ - } \ - } while(0); - -struct class_s { - struct precision pr; /* for precision parameters */ - struct background ba; /* for cosmological background */ - struct thermo th; /* for thermodynamics */ - struct perturbs pt; /* for source functions */ - struct bessels bs; /* for bessel functions */ - struct transfers tr; /* for transfer functions */ - struct primordial pm; /* for primordial spectra */ - struct spectra sp; /* for output spectra */ - struct nonlinear nl; /* for non-linear spectra */ - struct lensing le; /* for lensed spectra */ - struct output op; /* for output files */ -}; - -void -class_params(cosmology *c, char *class_ini) -{ - struct file_content fc; - struct class_s *p; - double *pvec; - ErrorMsg errmsg; - - fc.size = 0; - - p = Calloc(1,sizeof(struct class_s)); - - class_fail(parser_read_file(class_ini,&fc,errmsg), - errmsg,errmsg); - - class_fail(input_init(&fc, &p->pr, &p->ba, &p->th, &p->pt, &p->bs, &p->tr, - &p->pm, &p->sp, &p->nl, &p->le, &p->op, errmsg), - errmsg, errmsg); - - class_fail(parser_free(&fc),errmsg,errmsg); - - p->ba.background_verbose = 0; - - class_fail(background_init(&p->pr, &p->ba),errmsg,errmsg); - - pvec = Malloc(p->ba.bg_size*sizeof(double)); - class_fail(background_functions(&p->ba, 1.0, p->ba.long_info, pvec), - errmsg, errmsg); - c->Omega0_m = pvec[p->ba.index_bg_Omega_m]; - c->Omega0_r = pvec[p->ba.index_bg_Omega_r]; - Free(pvec); - - c->Omega0 = p->ba.Omega0_g + p->ba.Omega0_b; - if (p->ba.has_cdm == _TRUE_) { - c->Omega0 += p->ba.Omega0_cdm; - } - if (p->ba.has_ncdm == _TRUE_) { - c->Omega0 += p->ba.Omega0_ncdm_tot; - } - if (p->ba.has_lambda == _TRUE_) { - c->Omega0 += p->ba.Omega0_lambda; - } - if (p->ba.has_fld == _TRUE_) { - c->Omega0 += p->ba.Omega0_fld; - } - if (p->ba.has_ur == _TRUE_) { - c->Omega0 += p->ba.Omega0_ur; - } - c->h_100 = p->ba.h; - c->H0 = p->ba.H0*_Gyr_over_Mpc_; - c->Omega0_cdm = p->ba.Omega0_cdm; - c->Omega0_ncdm_tot = p->ba.Omega0_ncdm_tot; - c->Omega0_b = p->ba.Omega0_b; - c->Omega0_g = p->ba.Omega0_g; - c->Omega0_ur = p->ba.Omega0_ur; - c->Omega0_lambda = p->ba.Omega0_lambda; - c->Omega0_fld = p->ba.Omega0_fld; - c->w0_fld = p->ba.w0_fld; - c->wa_fld = p->ba.wa_fld; - c->age = p->ba.age; - c->Gnewt = GM_cgs*(g_Msol10/g_Msol)*pow(sec_Gyr, 2)/pow(cm_kpc,3); - - class_fail(background_free(&p->ba),errmsg,errmsg); - Free(p); -} diff --git a/external/libsdf/libsw/class_wrap.c b/external/libsdf/libsw/class_wrap.c deleted file mode 100644 index dbe886b..0000000 --- a/external/libsdf/libsw/class_wrap.c +++ /dev/null @@ -1,366 +0,0 @@ -#include "class.h" -#include "cosmo.h" -#include "Malloc.h" -#include "error.h" - -#define ERRTOL 5e-8 - -#define class_fail(function, \ - error_message_from_function, \ - error_message_output) \ - do { \ - if (function == _FAILURE_) { \ - ErrorMsg Transmit_Error_Message; \ - sprintf(Transmit_Error_Message,"%s(L:%d) : error in %s;\n=>%s", \ - __func__,__LINE__,#function,error_message_from_function); \ - Error("%s",Transmit_Error_Message); \ - } \ - } while(0); - - -struct class_s { - struct precision pr; /* for precision parameters */ - struct background ba; /* for cosmological background */ - struct thermo th; /* for thermodynamics */ - struct perturbs pt; /* for source functions */ - struct bessels bs; /* for bessel functions */ - struct transfers tr; /* for transfer functions */ - struct primordial pm; /* for primordial spectra */ - struct spectra sp; /* for output spectra */ - struct nonlinear nl; /* for non-linear spectra */ - struct lensing le; /* for lensed spectra */ - struct output op; /* for output files */ -}; - -static void -class_background_at_tau(cosmology *c, double tau) -{ - struct class_s *p = c->private; - int idx; - double *pvec; - ErrorMsg errmsg; - - pvec = Malloc(p->ba.bg_size*sizeof(double)); - class_fail(background_at_tau(&p->ba, tau, p->ba.long_info, p->ba.inter_normal, - &idx, pvec), errmsg, errmsg); - - c->a = pvec[p->ba.index_bg_a]; - c->z = 1.0/c->a - 1.0; - c->t = pvec[p->ba.index_bg_time]/_Gyr_over_Mpc_; - c->tau = tau; - c->H = pvec[p->ba.index_bg_H]*_Gyr_over_Mpc_; - c->conf_distance = pvec[p->ba.index_bg_conf_distance]*1000.0; /* kpc */ - c->kick = pvec[p->ba.index_bg_kick]/_Gyr_over_Mpc_; - c->drift = pvec[p->ba.index_bg_drift]/_Gyr_over_Mpc_; - c->Omega_r = pvec[p->ba.index_bg_Omega_r]; - c->Omega_m = pvec[p->ba.index_bg_Omega_m]; - Free(pvec); -} - - -static void -class_background_at_z(cosmology *c, double z) -{ - struct class_s *p = c->private; - double tau; - double err; - ErrorMsg errmsg; - - class_fail(background_tau_of_z(&p->ba, z, &tau), errmsg, errmsg); - class_background_at_tau(c, tau); - err = (1.0+c->z)/(1.0+z) - 1.0; - if (fabs(err) > ERRTOL) - Error("Poor precision in background_at_z, relerr = %g\n", err); -} - -static void -class_background_at_t(cosmology *c, double t) -{ - struct class_s *p = c->private; - double tau; - double err; - ErrorMsg errmsg; - - class_fail(background_tau_of_t(&p->ba, t*_Gyr_over_Mpc_, &tau), - errmsg, errmsg); - class_background_at_tau(c, tau); - err = c->t/t - 1.0; - if (fabs(err) > ERRTOL) - Error("Poor precision in background_at_t, relerr = %g\n", err); -} - -static double -class_t_at_z(cosmology *c, double z) -{ - if (c->z != z) class_background_at_z(c, z); - return(c->t); -} - -static double -class_z_at_t(cosmology *c, double t) -{ - if (c->t != t) class_background_at_t(c, t); - return(c->z); -} - -static double -class_a_at_t(cosmology *c, double t) -{ - if (c->t != t) class_background_at_t(c, t); - return(c->a); -} - -static double -class_t_at_a(cosmology *c, double a) -{ - if (c->a != a) class_background_at_z(c, 1.0/a-1.0); - return(c->t); -} - -static double -class_H_at_z(cosmology *c, double z) -{ - struct class_s *p = c->private; - double *pvec; - ErrorMsg errmsg; - double a = 1.0/(1.0+z); - double H; - - pvec = Malloc(p->ba.bg_size_normal*sizeof(double)); - class_fail(background_functions(&p->ba, a, p->ba.short_info, pvec), - errmsg, errmsg); - H = pvec[p->ba.index_bg_H]*_Gyr_over_Mpc_; - Free(pvec); - return(H); -} - -static double -class_H_at_t(cosmology *c, double t) -{ - if (c->t != t) class_background_at_t(c, t); - return(c->H); -} - - -static double -class_conformal_distance_at_z(cosmology *c, double z) -{ - if (c->z != z) class_background_at_z(c, z); - return(c->conf_distance); -} - -static double -class_conformal_distance_at_t(cosmology *c, double t) -{ - if (c->t != t) class_background_at_t(c, t); - return(c->conf_distance); -} - -static double -class_angular_diameter_distance_at_z(cosmology *c, double z) -{ - if (c->z != z) class_background_at_z(c, z); - return(c->conf_distance/(1.0+z)); -} - -static double -class_angular_diameter_distance_at_t(cosmology *c, double t) -{ - if (c->t != t) class_background_at_t(c, t); - return(c->conf_distance/(1.0+c->z)); -} - -static double -class_luminosity_distance_at_z(cosmology *c, double z) -{ - if (c->z != z) class_background_at_z(c, z); - return(c->conf_distance*(1.0+z)); -} - -static double -class_luminosity_distance_at_t(cosmology *c, double t) -{ - if (c->t != t) class_background_at_t(c, t); - return(c->conf_distance*(1.0+c->z)); -} - -static double -class_growthfac_at_z(cosmology *c, double z) -{ - struct class_s *p = c->private; - double pk, pk0, *pk_ic=NULL; - double k = 1e-7; - ErrorMsg errmsg; - - class_fail(spectra_pk_at_k_and_z(&p->ba, &p->pm, &p->sp, k, 0.0, &pk0, pk_ic), - errmsg, errmsg); - - class_fail(spectra_pk_at_k_and_z(&p->ba, &p->pm, &p->sp, k, z, &pk, pk_ic), - errmsg, errmsg); - - return sqrt(pk/pk0); -} - -static double -class_growthfac_at_t(cosmology *c, double t) -{ - return(class_growthfac_at_z(c, class_z_at_t(c, t))); -} - -static double -class_kick_t0_t1(cosmology *c, double t0, double t1) -{ - double k0, k1; - class_background_at_t(c, t0); - k0 = c->kick; - class_background_at_t(c, t1); - k1 = c->kick; - return(k1-k0); -} - - -static double -class_drift_t0_t1(cosmology *c, double t0, double t1) -{ - double d0, d1; - class_background_at_t(c, t0); - d0 = c->drift; - class_background_at_t(c, t1); - d1 = c->drift; - return(d1-d0); -} - -static void -class_free(cosmology *c) -{ - struct class_s *p = c->private; - ErrorMsg errmsg; - - class_fail(spectra_free(&p->sp),errmsg,errmsg); - class_fail(primordial_free(&p->pm),errmsg,errmsg); - class_fail(transfer_free(&p->tr),errmsg,errmsg); - class_fail(perturb_free(&p->pt),errmsg,errmsg); - class_fail(thermodynamics_free(&p->th),errmsg,errmsg); - class_fail(background_free(&p->ba),errmsg,errmsg); - Free(p); -} - - -void -class_init(cosmology *c, char *class_ini, char *class_pre, double zmax) -{ - struct file_content fc; - struct file_content fc_input; - struct file_content fc_precision; - struct class_s *p; - ErrorMsg errmsg; - - fc.size = 0; - fc_input.size = 0; - fc_precision.size = 0; - - memset(c, 0, sizeof(cosmology)); - p = Calloc(1,sizeof(struct class_s)); - - if (class_ini) - class_fail(parser_read_file(class_ini,&fc_input,errmsg), - errmsg,errmsg); - - if (class_pre) - class_fail(parser_read_file(class_pre,&fc_precision,errmsg), - errmsg, errmsg); - - if (class_ini || class_pre) - class_fail(parser_cat(&fc_input,&fc_precision,&fc,errmsg), - errmsg, errmsg); - - class_fail(parser_free(&fc_input),errmsg,errmsg); - class_fail(parser_free(&fc_precision),errmsg,errmsg); - - class_fail(input_init(&fc, &p->pr, &p->ba, &p->th, &p->pt, &p->bs, &p->tr, - &p->pm, &p->sp, &p->nl, &p->le, &p->op, errmsg), - errmsg, errmsg); - - class_fail(parser_free(&fc),errmsg,errmsg); - - p->ba.background_verbose = 0; - p->th.thermodynamics_verbose = 0; - p->pt.perturbations_verbose = 0; - p->tr.transfer_verbose = 0; - p->pm.primordial_verbose = 0; - p->sp.spectra_verbose = 0; - - if (p->sp.z_max_pk < zmax) p->sp.z_max_pk = zmax; - - class_fail(background_init(&p->pr, &p->ba),errmsg,errmsg); - - class_fail(thermodynamics_init(&p->pr,&p->ba,&p->th),errmsg,errmsg); - - class_fail(perturb_init(&p->pr,&p->ba,&p->th,&p->pt),errmsg,errmsg); - - class_fail(transfer_init(&p->pr,&p->ba,&p->th,&p->pt,&p->bs,&p->tr), - errmsg,errmsg); - - class_fail(primordial_init(&p->pr,&p->pt,&p->pm),errmsg,errmsg); - - class_fail(spectra_init(&p->pr,&p->ba,&p->pt,&p->tr,&p->pm,&p->sp), - errmsg,errmsg); - - c->Omega0 = p->ba.Omega0_g + p->ba.Omega0_b; - if (p->ba.has_cdm == _TRUE_) { - c->Omega0 += p->ba.Omega0_cdm; - } - if (p->ba.has_ncdm == _TRUE_) { - c->Omega0 += p->ba.Omega0_ncdm_tot; - } - if (p->ba.has_lambda == _TRUE_) { - c->Omega0 += p->ba.Omega0_lambda; - } - if (p->ba.has_fld == _TRUE_) { - c->Omega0 += p->ba.Omega0_fld; - } - if (p->ba.has_ur == _TRUE_) { - c->Omega0 += p->ba.Omega0_ur; - } - c->h_100 = p->ba.h; - c->H0 = p->ba.H0*_Gyr_over_Mpc_; - c->Omega0_cdm = p->ba.Omega0_cdm; - c->Omega0_ncdm_tot = p->ba.Omega0_ncdm_tot; - c->Omega0_b = p->ba.Omega0_b; - c->Omega0_g = p->ba.Omega0_g; - c->Omega0_ur = p->ba.Omega0_ur; - c->Omega0_lambda = p->ba.Omega0_lambda; - c->Omega0_fld = p->ba.Omega0_fld; - c->w0_fld = p->ba.w0_fld; - c->wa_fld = p->ba.wa_fld; - c->age = p->ba.age; - c->Gnewt = GNEWT; - - c->private = p; - class_background_at_z(c, 0.0); - c->Omega0_m = c->Omega_m; - c->Omega0_r = c->Omega_r; - - /* Function pointers */ - c->background_at_z = class_background_at_z; - c->background_at_t = class_background_at_t; - c->background_at_tau = class_background_at_tau; - c->t_at_z = class_t_at_z; - c->z_at_t = class_z_at_t; - c->a_at_t = class_a_at_t; - c->t_at_a = class_t_at_a; - c->H_at_z = class_H_at_z; - c->H_at_t = class_H_at_t; - c->conformal_distance_at_z = class_conformal_distance_at_z; - c->conformal_distance_at_t = class_conformal_distance_at_t; - c->angular_diameter_distance_at_z = class_angular_diameter_distance_at_z; - c->angular_diameter_distance_at_t = class_angular_diameter_distance_at_t; - c->luminosity_distance_at_z = class_luminosity_distance_at_z; - c->luminosity_distance_at_t = class_luminosity_distance_at_t; - c->growthfac_at_z = class_growthfac_at_z; - c->growthfac_at_t = class_growthfac_at_t; - c->kick_t0_t1 = class_kick_t0_t1; - c->drift_t0_t1 = class_drift_t0_t1; - c->free = class_free; -} - diff --git a/external/libsdf/libsw/cosmo.c b/external/libsdf/libsw/cosmo.c deleted file mode 100644 index 09e84ee..0000000 --- a/external/libsdf/libsw/cosmo.c +++ /dev/null @@ -1,288 +0,0 @@ -#include -#include -#include "Msgs.h" -#include "qromo.h" -#include "cosmo.h" - -static struct cosmo_s C; - -static double -adot(double a) -{ - return C.H0*sqrt(C.Omega_m/a + C.Omega_r/(a*a) + C.Lambda*a*a + (1.0 - C.Omega0 - C.Lambda)); -} - -static double -addot(double a) -{ /* factor of a? */ - return C.H0 * C.H0 * (C.Lambda*a-C.Omega_r/(a*a*a)-0.5*C.Omega_m/(a*a)); -} - -static double -integrand(double a) -{ - double x; - - x = adot(a); - return 1.0/(x*x*x); - -} - -static double -t_integrand(double a) -{ - double x; - - x = adot(a); - return 1.0/x; -} - -static double -dp_integrand(double a) -{ - double x; - - x = adot(a); - return 1.0/(a*x); - -} - -static double -kick_integrand(double t) -{ - double a; - - a = Anow(&C, t); - return 1.0/a; - -} - -static double -drift_integrand(double t) -{ - double a; - - a = Anow(&C, t); - return 1.0/(a*a); -} - -double -growthfac_from_Z(struct cosmo_s *c, double z) -{ - double a = 1.0/(1.0+z); - C = *c; - return 2.5*c->H0*c->H0*adot(a)*qromod(integrand, 0.0, a, midpntd)/a; -} - -double -velfac_from_Z(struct cosmo_s *c, double z) -{ - double d, a_dot; - double a = 1.0/(1.0+z); - C = *c; - d = qromod(integrand, 0.0, a, midpntd); - a_dot = adot(a); - return addot(a) - *a/(a_dot*a_dot) - 1.0 + a/(a_dot*a_dot*a_dot*d); -} - -double -velfac_approx_from_Z(struct cosmo_s *c, double z) -{ - double aomega; - double a = 1.0/(1.0+z); - C = *c; - aomega = C.Omega_m + C.Omega_r/a + C.Lambda*a*a*a + (1.0 - C.Omega0 - C.Lambda)*a; - return pow(C.Omega0/aomega, 0.6); -} - -double -t_from_Z(struct cosmo_s *c, double z) -{ - double d; - double a = 1.0/(1.0+z); - C = *c; - d = qromod(t_integrand, 0.0, a, midpntd); - return (d); -} - - -double -dp_from_Z(struct cosmo_s *c, double z) -{ - double d; - double a = 1.0/(1.0+z); - if (a == 1.0) return 0.0; - C = *c; - d = qromod(dp_integrand, a, 1.0, midpntd); - return (d); -} - -double -comoving_distance_from_Z(struct cosmo_s *c, double z) -{ - return speed_of_light*(one_Gyr/one_kpc)*dp_from_Z(c, z); -} - -double -hubble_from_Z(struct cosmo_s *c, double z) -{ - double a = 1.0/(1.0+z); - C = *c; - return adot(a)/a; -} - -double -kick_delta(struct cosmo_s *c, double t0, double t1) -{ - double d; - C = *c; - Msgf(("kick_delta %lf %lf\n", t0, t1)); - if (t0 == t1) return 0.0; - d = qromod(kick_integrand, t0, t1, midpntd); - return (d); -} - -double -drift_delta(struct cosmo_s *c, double t0, double t1) -{ - double d; - C = *c; - Msgf(("drift_delta %lf %lf\n", t0, t1)); - if (t0 == t1) return 0.0; - d = qromod(drift_integrand, t0, t1, midpntd); - return (d); -} - -double -Anow(struct cosmo_s *c, double time) -{ - struct cosmo_s foo; - - foo = *c; - CosmoPush(&foo, time); - return foo.a; -} - -double -Znow(struct cosmo_s *c, double time) -{ - return 1.0/Anow(c, time) - 1.0; -} - -double -Hnow(struct cosmo_s *c, double time) -{ - struct cosmo_s foo; - - foo = *c; - CosmoPush(&foo, time); - C = *c; - return adot(foo.a)/foo.a; -} - -void CosmoPush(struct cosmo_s *p, double time) -{ - double Omega0 = p->Omega0; - double Omega_r = p->Omega_r; - double Omega_m = p->Omega_m; - double Lambda = p->Lambda; - double H0 = p->H0; - double H, a2, a3, aold, anew, a2dot; - double deltat, dt; - int i; - int nstep; - - /* The cosmo structure holds,H0, Omega0, Lambda' = Lambda/3H0^2, a - and t. We integrate (forward or backward) to the new 'time' */ - - deltat = time - p->t; - if (deltat == 0.0) - return; - - /* Felten et al do all their integrals with dt=1/(400 H0). We can - do the same by choosing Nstep appropriately. In fact, we can - do better by ensuring dt < 1/(800 H). */ - aold = p->a; - a2 = aold*aold; - H = (H0 / aold) * sqrt(Omega_m/aold + Omega_r/a2 + Lambda*a2 + (1.0 - Omega0 - Lambda)); - nstep = (int)(800.*H*fabs(deltat)) + 1; - Msgf(("Cosmo push %d steps, deltat=%g, H*deltat=%g\n", - nstep, deltat, deltat*H)); - dt = deltat/(double)nstep; - - anew = p->a; - for (i = 0; i < nstep; i++) { - aold = anew; - a2 = aold*aold; - a3 = a2*aold; - H = (H0 / aold) * sqrt(Omega_m/aold + Omega_r/a2 + Lambda*a2 + (1.0 - Omega0 - Lambda)); - /* Follow the advice of Felten et al. Do this to second-order */ - a2dot = H0*H0*(-0.5*Omega_m/a2 - Omega_r/a3 + Lambda*aold); - anew = aold + dt*H*aold + 0.5*dt*dt*a2dot; - } - Msgf(("After push Z=%g\n", 1./anew - 1.)); - p->a = anew; - p->t = time; -} - -#if 0 -/* Crays don't have acosh */ -static double Acosh(double x) -{ - return log(x + sqrt(x*x-1.0)); -} - -static double -growthfac_from_Z(double Omega0, double H0, double Z) -{ - /* This is just the growing mode */ - /* See Weinberg 15.9.27--15.9.31 or Peebles LSS 11.16 */ - double d, d0; - - if (Omega0 == 1.0) { - d = 1.0/(1.0+Z); - d0 = 1.0; - } else if(Omega0 < 1.0) { - /* Using doubles can cause roundoff problems near Omega0=1 */ - double psi, coshpsi; - coshpsi = 1.0 + 2.0*(1.0 - Omega0)/(Omega0*(1.0+Z)); - psi = Acosh(coshpsi); - d = - 3.0 * psi * sinh(psi)/((coshpsi-1.0)*(coshpsi-1.0)) - + (5.0+coshpsi)/(coshpsi-1.0); - coshpsi = 1.0 + 2.0*(1.0 - Omega0)/Omega0; - psi = Acosh(coshpsi); - d0 = - 3.0 * psi * sinh(psi)/((coshpsi-1.0)*(coshpsi-1.0)) - + (5.0+coshpsi)/(coshpsi-1.0); - } else { - double theta, costheta; - costheta = 1.0 - 2.0*(Omega0-1.0)/(Omega0*(1.0+Z)); - theta = acos(costheta); - d = - 3.0 * theta * sin(theta)/((1.0-costheta)*(1.0-costheta)) - + (5.0+costheta)/(1.0-costheta); - costheta = 1.0 - 2.0*(Omega0-1.0)/Omega0; - theta = acos(costheta); - d0 = - 3.0 * theta * sin(theta)/((1.0-costheta)*(1.0-costheta)) - + (5.0+costheta)/(1.0-costheta); - } - return d/d0; -} - -static double -t_from_Z(double Omega0, double H0, double Z) -{ - double t, theta, psi; - - if(Omega0 == 1.0){ - t = (2.0/3.0) * pow(1.0+Z, -1.5); - }else if(Omega0 < 1.0){ - psi = Acosh( 1.0 + 2.0*(1.0 - Omega0)/(Omega0*(1.0+Z)) ); - t = (Omega0/2.0)*pow(1.0-Omega0, -1.5)*(sinh(psi) - psi) ; - }else{ - theta = acos( 1.0 - 2.0*(Omega0-1.)/(Omega0*(1.0+Z)) ); - t = (Omega0/2.0)*pow(Omega0-1.0, -1.5)*(theta-sin(theta)); - } - t /= H0; - return t; -} -#endif diff --git a/external/libsdf/libsw/cosmo_tbl.c b/external/libsdf/libsw/cosmo_tbl.c deleted file mode 100644 index 5dc9de1..0000000 --- a/external/libsdf/libsw/cosmo_tbl.c +++ /dev/null @@ -1,575 +0,0 @@ -#include -#include -#include "cosmo.h" -#include "Malloc.h" -#include "error.h" -#include "macr.h" - -#define _SUCCESS_ 0 -#define _FAILURE_ 1 -#define _ERRORMSGSIZE_ 256 -typedef char ErrorMsg[_ERRORMSGSIZE_]; -#define _SPLINE_NATURAL_ 0 -#define _SPLINE_EST_DERIV_ 1 - -#define _Gyr_over_Mpc_ 3.06601394e2 - -struct tbl_s { - int bt_size, bg_size; - double *tau_tbl, *z_tbl, *t_tbl, *tbl; - double *d2tau_dz2_tbl, *d2tau_dt2_tbl, *d2b_dtau2_tbl; - ErrorMsg error_message; -}; - -static int -array_spline_table_lines( - double * x, /* vector of size x_size */ - int x_size, - double * y_array, /* array of size x_size*y_size with elements - y_array[index_x*y_size+index_y] */ - int y_size, - double * ddy_array, /* array of size x_size*y_size */ - short spline_mode, - ErrorMsg errmsg - ) { - double * p; - double * qn; - double * un; - double * u; - double sig; - int index_x; - int index_y; - double dy_first; - double dy_last; - - u = Malloc((x_size-1) * y_size * sizeof(double)); - p = Malloc(y_size * sizeof(double)); - qn = Malloc(y_size * sizeof(double)); - un = Malloc(y_size * sizeof(double)); - - index_x=0; - - if (spline_mode == _SPLINE_NATURAL_) { - for (index_y=0; index_y < y_size; index_y++) { - ddy_array[index_x*y_size+index_y] = u[index_x*y_size+index_y] = 0.0; - } - } - else { - if (spline_mode == _SPLINE_EST_DERIV_) { - - for (index_y=0; index_y < y_size; index_y++) { - - dy_first = - ((x[2]-x[0])*(x[2]-x[0])* - (y_array[1*y_size+index_y]-y_array[0*y_size+index_y])- - (x[1]-x[0])*(x[1]-x[0])* - (y_array[2*y_size+index_y]-y_array[0*y_size+index_y]))/ - ((x[2]-x[0])*(x[1]-x[0])*(x[2]-x[1])); - - ddy_array[index_x*y_size+index_y] = -0.5; - - u[index_x*y_size+index_y] = - (3./(x[1] - x[0]))* - ((y_array[1*y_size+index_y]-y_array[0*y_size+index_y])/ - (x[1] - x[0])-dy_first); - - } - } - else { - sprintf(errmsg,"%s(L:%d) Spline mode not identified: %d",__func__,__LINE__,spline_mode); - return _FAILURE_; - } - } - - - for (index_x=1; index_x < x_size-1; index_x++) { - - sig = (x[index_x] - x[index_x-1])/(x[index_x+1] - x[index_x-1]); - - for (index_y=0; index_y < y_size; index_y++) { - - p[index_y] = sig * ddy_array[(index_x-1)*y_size+index_y] + 2.0; - - ddy_array[index_x*y_size+index_y] = (sig-1.0)/p[index_y]; - - u[index_x*y_size+index_y] = - (y_array[(index_x+1)*y_size+index_y] - y_array[index_x*y_size+index_y]) - / (x[index_x+1] - x[index_x]) - - (y_array[index_x*y_size+index_y] - y_array[(index_x-1)*y_size+index_y]) - / (x[index_x] - x[index_x-1]); - - u[index_x*y_size+index_y] = (6.0 * u[index_x*y_size+index_y] / - (x[index_x+1] - x[index_x-1]) - - sig * u[(index_x-1)*y_size+index_y]) / p[index_y]; - } - - } - - if (spline_mode == _SPLINE_NATURAL_) { - - for (index_y=0; index_y < y_size; index_y++) { - qn[index_y]=un[index_y]=0.0; - } - - } - else { - if (spline_mode == _SPLINE_EST_DERIV_) { - - for (index_y=0; index_y < y_size; index_y++) { - - dy_last = - ((x[x_size-3]-x[x_size-1])*(x[x_size-3]-x[x_size-1])* - (y_array[(x_size-2)*y_size+index_y]-y_array[(x_size-1)*y_size+index_y])- - (x[x_size-2]-x[x_size-1])*(x[x_size-2]-x[x_size-1])* - (y_array[(x_size-3)*y_size+index_y]-y_array[(x_size-1)*y_size+index_y]))/ - ((x[x_size-3]-x[x_size-1])*(x[x_size-2]-x[x_size-1])*(x[x_size-3]-x[x_size-2])); - - qn[index_y]=0.5; - - un[index_y]= - (3./(x[x_size-1] - x[x_size-2]))* - (dy_last-(y_array[(x_size-1)*y_size+index_y] - y_array[(x_size-2)*y_size+index_y])/ - (x[x_size-1] - x[x_size-2])); - - } - } - else { - sprintf(errmsg,"%s(L:%d) Spline mode not identified: %d",__func__,__LINE__,spline_mode); - return _FAILURE_; - } - } - - index_x=x_size-1; - - for (index_y=0; index_y < y_size; index_y++) { - ddy_array[index_x*y_size+index_y] = - (un[index_y] - qn[index_y] * u[(index_x-1)*y_size+index_y]) / - (qn[index_y] * ddy_array[(index_x-1)*y_size+index_y] + 1.0); - } - - for (index_x=x_size-2; index_x >= 0; index_x--) { - for (index_y=0; index_y < y_size; index_y++) { - - ddy_array[index_x*y_size+index_y] = ddy_array[index_x*y_size+index_y] * - ddy_array[(index_x+1)*y_size+index_y] + u[index_x*y_size+index_y]; - - } - } - - Free(qn); - Free(un); - Free(p); - Free(u); - - return _SUCCESS_; - } - - /** - * interpolate to get y_i(x), when x and y_i are in different arrays - * - */ -static int -array_interpolate_spline( - double * x_array, - int n_lines, - double * array, - double * array_splined, - int n_columns, - double x, - int * last_index, - double * result, - int result_size, /** from 1 to n_columns */ - ErrorMsg errmsg) { - - int inf,sup,mid,i; - double h,a,b; - - inf=0; - sup=n_lines-1; - - if (x_array[inf] < x_array[sup]){ - - if (x < x_array[inf]) { - sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,x,x_array[inf]); - return _FAILURE_; - } - - if (x > x_array[sup]) { - sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,x,x_array[sup]); - return _FAILURE_; - } - - while (sup-inf > 1) { - - mid=(int)(0.5*(inf+sup)); - if (x < x_array[mid]) {sup=mid;} - else {inf=mid;} - - } - - } - - else { - - if (x < x_array[sup]) { - sprintf(errmsg,"%s(L:%d) : x=%e < x_min=%e",__func__,__LINE__,x,x_array[sup]); - return _FAILURE_; - } - - if (x > x_array[inf]) { - sprintf(errmsg,"%s(L:%d) : x=%e > x_max=%e",__func__,__LINE__,x,x_array[inf]); - return _FAILURE_; - } - - while (sup-inf > 1) { - - mid=(int)(0.5*(inf+sup)); - if (x > x_array[mid]) {sup=mid;} - else {inf=mid;} - - } - - } - - *last_index = inf; - - h = x_array[sup] - x_array[inf]; - b = (x-x_array[inf])/h; - a = 1-b; - - for (i=0; iprivate; - int last_index; - double *pvec = Malloc(p->bg_size*sizeof(double)); - - array_interpolate_spline(p->tau_tbl, - p->bt_size, - p->tbl, - p->d2b_dtau2_tbl, - p->bg_size, - tau, - &last_index, - pvec, - p->bg_size, - p->error_message); - c->z = pvec[0]; - c->t = pvec[1]/_Gyr_over_Mpc_; - c->tau = tau; - c->a = 1.0/(1.0+c->z); - c->H = pvec[2]*_Gyr_over_Mpc_; - c->conf_distance = pvec[3]*1000.0; /* kpc */ - c->kick = tau/_Gyr_over_Mpc_;; - c->drift = pvec[4]/_Gyr_over_Mpc_; - c->growthfac = pvec[5]; - /* c->velfac = pow(c->Omega0_m/(c->a*c->a*c->a)*c->H0*c->H0/(c->H*c->H), 0.6); */ - c->velfac = pvec[7]; - c->velfac2 = 2.0*pow(c->Omega0_m/(c->a*c->a*c->a)*c->H0*c->H0/(c->H*c->H), 4./7.); - Free(pvec); -} - - -static void -tbl_background_at_z(cosmology *c, double z) -{ - struct tbl_s *p = c->private; - int last_index; - double tau; - - array_interpolate_spline(p->z_tbl, - p->bt_size, - p->tau_tbl, - p->d2tau_dz2_tbl, - 1, - z, - &last_index, - &tau, - 1, - p->error_message); - tbl_background_at_tau(c, tau); -} - -static void -tbl_background_at_t(cosmology *c, double t) -{ - struct tbl_s *p = c->private; - int last_index; - double tau; - - array_interpolate_spline(p->t_tbl, - p->bt_size, - p->tau_tbl, - p->d2tau_dt2_tbl, - 1, - t*_Gyr_over_Mpc_, - &last_index, - &tau, - 1, - p->error_message); - tbl_background_at_tau(c, tau); -} - -static double -tbl_t_at_z(cosmology *c, double z) -{ - tbl_background_at_z(c, z); - return(c->t); -} - -static double -tbl_z_at_t(cosmology *c, double t) -{ - tbl_background_at_t(c, t); - return(c->z); -} - -static double -tbl_a_at_t(cosmology *c, double t) -{ - tbl_background_at_t(c, t); - return(c->a); -} - -static double -tbl_t_at_a(cosmology *c, double a) -{ - tbl_background_at_z(c, 1.0/a-1.0); - return(c->t); -} - -static double -tbl_H_at_z(cosmology *c, double z) -{ - tbl_background_at_z(c, z); - return(c->H); -} - -static double -tbl_H_at_t(cosmology *c, double t) -{ - tbl_background_at_t(c, t); - return(c->H); -} - -static double -tbl_conformal_distance_at_z(cosmology *c, double z) -{ - tbl_background_at_z(c, z); - return(c->conf_distance); -} - -static double -tbl_conformal_distance_at_t(cosmology *c, double t) -{ - tbl_background_at_t(c, t); - return(c->conf_distance); -} - -static double -tbl_angular_diameter_distance_at_z(cosmology *c, double z) -{ - tbl_background_at_z(c, z); - return(c->conf_distance/(1.0+z)); -} - -static double -tbl_angular_diameter_distance_at_t(cosmology *c, double t) -{ - tbl_background_at_t(c, t); - return(c->conf_distance/(1.0+c->z)); -} - -static double -tbl_luminosity_distance_at_z(cosmology *c, double z) -{ - tbl_background_at_z(c, z); - return(c->conf_distance*(1.0+z)); -} - -static double -tbl_luminosity_distance_at_t(cosmology *c, double t) -{ - tbl_background_at_t(c, t); - return(c->conf_distance*(1.0+c->z)); -} - -static double -tbl_growthfac_at_z(cosmology *c, double z) -{ - tbl_background_at_z(c, z); - return(c->growthfac); -} - -static double -tbl_growthfac_at_t(cosmology *c, double t) -{ - tbl_background_at_t(c, t); - return(c->growthfac); -} - -static double -tbl_velfac_at_z(cosmology *c, double z) -{ - tbl_background_at_z(c, z); - return(c->velfac); -} - -static double -tbl_velfac_at_t(cosmology *c, double t) -{ - tbl_background_at_t(c, t); - return(c->velfac); -} - -static double -tbl_kick_t0_t1(cosmology *c, double t0, double t1) -{ - double k0, k1; - tbl_background_at_t(c, t0); - k0 = c->kick; - tbl_background_at_t(c, t1); - k1 = c->kick; - return(k1-k0); -} - -static double -tbl_drift_t0_t1(cosmology *c, double t0, double t1) -{ - double d0, d1; - tbl_background_at_t(c, t0); - d0 = c->drift; - tbl_background_at_t(c, t1); - d1 = c->drift; - return(d1-d0); -} - -static void -tbl_free(cosmology *c) -{ - struct tbl_s *p = c->private; - - Free(p->d2tau_dz2_tbl); - Free(p->d2tau_dt2_tbl); - Free(p->d2b_dtau2_tbl ); - Free(p->tbl); - Free(p->t_tbl); - Free(p->z_tbl); - Free(p->tau_tbl); - Free(p); - c->private = NULL; -} - -void -tbl_init(cosmology *c, char *tbl) -{ - char line[1024]; - FILE *fp; - int i; - double tau, z, t, H, R, drift, growth, growth_cdm, velfac; - struct tbl_s *p = Malloc(sizeof(struct tbl_s)); - p->bt_size = 8192; - p->bg_size = 8; - - p->tau_tbl = Malloc(p->bt_size*sizeof(double)); - p->z_tbl = Malloc(p->bt_size*sizeof(double)); - p->t_tbl = Malloc(p->bt_size*sizeof(double)); - p->tbl = Malloc(p->bg_size*p->bt_size*sizeof(double)); - Fopen(fp, tbl, "r"); - i = 0; - while (fgets(line, sizeof(line), fp)) { - if (line[0] == '#') continue; - if (sscanf(line, "%lg %lg %lg %lg %lg %lg %lg %lg %lg\n", - &tau, &z, &t, &H, &R, &drift, &growth, &growth_cdm, &velfac) != 9) - Error("Did not parse %s", line); - p->tau_tbl[i] = tau; - p->z_tbl[i] = z; - p->t_tbl[i] = t; - p->tbl[i*p->bg_size+0] = z; - p->tbl[i*p->bg_size+1] = t; - p->tbl[i*p->bg_size+2] = H; - p->tbl[i*p->bg_size+3] = R; - p->tbl[i*p->bg_size+4] = drift; - p->tbl[i*p->bg_size+5] = growth; - p->tbl[i*p->bg_size+6] = growth_cdm; - p->tbl[i*p->bg_size+7] = velfac; - i++; - if (i >= p->bt_size) { - p->bt_size *= 2; - p->tau_tbl = Realloc(p->tau_tbl, p->bt_size*sizeof(double)); - p->z_tbl = Realloc(p->z_tbl, p->bt_size*sizeof(double)); - p->t_tbl = Realloc(p->t_tbl, p->bt_size*sizeof(double)); - p->tbl = Realloc(p->tbl, p->bg_size*p->bt_size*sizeof(double)); - } - } - Fclose(fp); - p->bt_size = i; - p->tau_tbl = Realloc(p->tau_tbl, p->bt_size*sizeof(double)); - p->z_tbl = Realloc(p->z_tbl, p->bt_size*sizeof(double)); - p->t_tbl = Realloc(p->t_tbl, p->bt_size*sizeof(double)); - p->tbl = Realloc(p->tbl, p->bg_size*p->bt_size*sizeof(double)); - - p->d2tau_dz2_tbl = Malloc(p->bt_size*sizeof(double)); - p->d2tau_dt2_tbl = Malloc(p->bt_size*sizeof(double)); - p->d2b_dtau2_tbl = Malloc(p->bg_size*p->bt_size*sizeof(double)); - - array_spline_table_lines(p->z_tbl, - p->bt_size, - p->tau_tbl, - 1, - p->d2tau_dz2_tbl, - _SPLINE_EST_DERIV_, - p->error_message); - array_spline_table_lines(p->t_tbl, - p->bt_size, - p->tau_tbl, - 1, - p->d2tau_dt2_tbl, - _SPLINE_EST_DERIV_, - p->error_message); - array_spline_table_lines(p->tau_tbl, - p->bt_size, - p->tbl, - p->bg_size, - p->d2b_dtau2_tbl, - _SPLINE_EST_DERIV_, - p->error_message); - - c->private = p; - - /* Function pointers */ - c->background_at_z = tbl_background_at_z; - c->background_at_t = tbl_background_at_t; - c->background_at_tau = tbl_background_at_tau; - c->t_at_z = tbl_t_at_z; - c->z_at_t = tbl_z_at_t; - c->a_at_t = tbl_a_at_t; - c->t_at_a = tbl_t_at_a; - c->H_at_z = tbl_H_at_z; - c->H_at_t = tbl_H_at_t; - c->conformal_distance_at_z = tbl_conformal_distance_at_z; - c->conformal_distance_at_t = tbl_conformal_distance_at_t; - c->angular_diameter_distance_at_z = tbl_angular_diameter_distance_at_z; - c->angular_diameter_distance_at_t = tbl_angular_diameter_distance_at_t; - c->luminosity_distance_at_z = tbl_luminosity_distance_at_z; - c->luminosity_distance_at_t = tbl_luminosity_distance_at_t; - c->growthfac_at_z = tbl_growthfac_at_z; - c->growthfac_at_t = tbl_growthfac_at_t; - c->velfac_at_z = tbl_velfac_at_z; - c->velfac_at_t = tbl_velfac_at_t; - c->kick_t0_t1 = tbl_kick_t0_t1; - c->drift_t0_t1 = tbl_drift_t0_t1; - c->free = tbl_free; -} diff --git a/external/libsdf/libsw/counters.c b/external/libsdf/libsw/counters.c deleted file mode 100644 index 47ec3d1..0000000 --- a/external/libsdf/libsw/counters.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include -#include "Malloc.h" -#include "timers.h" -#include "mpmy.h" -#include "Assert.h" - -#define MAXENABLED 100 - -static Counter_t *enabled_counters[MAXENABLED]; -static int nenabled_counters; - -void ClearCounter(Counter_t *c){ - c->counter = 0; -} - -void ClearEnabledCounters(void){ - int i; - for(i=0; iname = Malloc(strlen(name)+1); - strcpy(c->name, name); - c->enabled = 1; - c->counter = 0; -} - -void DisableCounter(Counter_t *t){ - int i; - - for(i=0; ienabled = 0; - Free(t->name); - t->name = NULL; - enabled_counters[i] = enabled_counters[--nenabled_counters]; -} - -void SumCounters(void){ - double nprocinv; - Counter_t *c; - int i; - MPMY_Comm_request req; - - MPMY_ICombine_Init(&req); - for(i=0; isum = c->min = c->max = c->counter; - MPMY_ICombine(&c->min, &c->min, 1, MPMY_INT64, MPMY_MIN, req); - MPMY_ICombine(&c->max, &c->max, 1, MPMY_INT64, MPMY_MAX, req); - MPMY_ICombine(&c->sum, &c->sum, 1, MPMY_DOUBLE, MPMY_SUM, req); - } - MPMY_ICombine_Wait(req); - - /* Now loop a second time and divide the mean by Nproc */ - nprocinv = 1./MPMY_Nproc(); - for(i=0; imean = c->sum * nprocinv; - } -} - -void OutputCounters(int (*Printf_Like)(const char *, ...)){ - int i; - Counter_t *c; - - SumCounters(); - Printf_Like("%12s %12s %12s %15s %14s\n", - "Counters", "Min", "Max", "Sum", "Avg"); - for (i = 0; i < nenabled_counters; i++) { - c = enabled_counters[i]; - if( c->enabled && c->name ) - Printf_Like("%12s %12ld %12ld %15.0f %14.2f\n", c->name, - c->min, c->max, c->sum, c->mean); - } -} - -void OutputIndividualCounters(int (*Printf_Like)(const char *, ...)){ - int i; - Counter_t *c; - - Printf_Like("%12s %12s\n", "Counters", "Count"); - for (i = 0; i < nenabled_counters; i++) { - c = enabled_counters[i]; - if( c->enabled && c->name ) - Printf_Like("%12s %12ld\n", c->name, c->counter); - } -} - -int64_t ReadCounter(Counter_t *c){ - return c->counter; -} - -int64_t ReadCounter64(Counter_t *c){ - return c->counter; -} - -static void SumOneCounter(Counter_t *c){ - MPMY_Comm_request req; - MPMY_ICombine_Init(&req); - c->sum = c->min = c->max = c->counter; - MPMY_ICombine(&c->min, &c->min, 1, MPMY_INT64, MPMY_MIN, req); - MPMY_ICombine(&c->max, &c->max, 1, MPMY_INT64, MPMY_MAX, req); - MPMY_ICombine(&c->sum, &c->sum, 1, MPMY_DOUBLE, MPMY_SUM, req); - MPMY_ICombine_Wait(req); - c->mean = c->sum / MPMY_Nproc(); -} - -void OutputOneCounter(Counter_t *c, int (*Printf_Like)(const char *, ...)){ - SumOneCounter(c); - Printf_Like("%12s %12ld %12ld %14.0g %14.2g\n", - (c->name)?c->name:"(noname)", - c->min, c->max, c->sum, c->mean); -} diff --git a/external/libsdf/libsw/dbg.c b/external/libsdf/libsw/dbg.c deleted file mode 100644 index 2cc9031..0000000 --- a/external/libsdf/libsw/dbg.c +++ /dev/null @@ -1,36 +0,0 @@ -#include - -#define FORCE(t) ( (t) | (1<<30)) -#define DBG_REQUEST_TYPE FORCE(0x1a2b3c4) - -#define WHAT_DBGBUF 1 -#define WHAT_MEMORY 2 -#define WHAT_STACK 3 -#define WHAT_CODE 4 - -typedef struct { - int what; -} dbg_request_t; - -void PrintMemfile(); -static dbg_request_t dbg_request; - -void -jab_dbg_handler(int proc) -{ - csend(DBG_REQUEST_TYPE, (char *)&dbg_request, sizeof(dbg_request), proc,0); -{ - -void -set_dbg_handler(void){ - hrecv(DBG_REQUEST_TYPE, (char *)&dbg_request, - sizeof(dbg_request), dbg_handler); -} - -static void -dbg_handler(long type, long count, long node, long pid) -{ - PrintMemfile(); - set_dbg_handler(); - return; -} diff --git a/external/libsdf/libsw/dll.c b/external/libsdf/libsw/dll.c deleted file mode 100644 index 6e5ac55..0000000 --- a/external/libsdf/libsw/dll.c +++ /dev/null @@ -1,237 +0,0 @@ -/* DLL: doubly linked lists. - - Support: - insertion either before or after a given element (Above, Below). - deletion. - traversal in either direction. (Up, Down) - - Use a vertical metaphor for mnemonics. You can grow the data - structure up, down, or outward from the middle. It makes - absolutely no difference. - - The implementation uses two 'sentinels'. The one above the topmost - element is called 'Sup' and the one below the lowest element is - called 'Inf'. These are good places to start and end 'for' loops, e.g., - - for(p=DllTop(dll); p!=DllInf(dll); p = DllDown(dll, p))... - - or - - for(p=DllBottom(dll); p!=DllSup(dll); p = DllUp(dll, p))... - - Space for 'user' data of size 'sz' is allocated with each element. - This is ideal if you want to allocate associate a fixed size object - with each list element. If you want more flexibility, there's - nothing stopping you from making that fixed size object a void* - that points to something else. - -*/ - -#include "chn.h" -#include "dll.h" -#include "Malloc.h" - -/* Initializing is a two step process because we have to do some - funny stuff to get a chain allocating chunks just slightly bigger than - what the user asks for. The resulting chain can be ChnTerminated - at the caller's leisure. */ -void DllCreateChn(Chn *chn, int sz, int n){ - n+=2; - if( sz > sizeof(int) ) - sz -= sizeof(int); - ChnInit(chn, sizeof(Dll_elmt)+sz, n, Realloc_f); -} - -void DllCreate(Dll *dll, Chn *chn){ - dll->chn = chn; - dll->Sup.down = &dll->Inf; - dll->Sup.up = NULL; - dll->Inf.down = NULL; - dll->Inf.up = &dll->Sup; - dll->length = 0; -} - -/* Terminate a dll */ -void DllTerminate(Dll *dll){ - /* Hmmm. There's really nothing to do since the user is now - empowered to free the chain. We can't even do a FreeAll because - there might be other stuff (other DLL's?) using the chain. */ -} - -/* Insert closer to the Top */ -Dll_elmt *DllInsertAbove(Dll *dll, Dll_elmt *down){ - Dll_elmt *new = ChnAlloc(dll->chn); - Dll_elmt *up = down->up; - - if( new == NULL ){ - Shout("ChnAlloc returns null in DllInsertAbove\n"); - return NULL; - } - dll->length++; - new->up = up; - new->down = down; - down->up = new; - up->down = new; - return new; -} - -/* Insert closer to the bottom */ -Dll_elmt *DllInsertBelow(Dll *dll, Dll_elmt *up){ - Dll_elmt *new = ChnAlloc(dll->chn); - Dll_elmt *down = up->down; - - if( new == NULL ){ - Shout("ChnAlloc returns null in DllInsertBelow\n"); - return NULL; - } - dll->length++; - new->up = up; - new->down = down; - down->up = new; - up->down = new; - return new; -} - -/* These two should be inlined, with __inline__ ... */ -/* Insert at the bottom */ -Dll_elmt *DllInsertAtBottom(Dll *dll){ - return DllInsertAbove(dll, &(dll->Inf)); -} - -/* Insert at the top */ -Dll_elmt *DllInsertAtTop(Dll *dll){ - return DllInsertBelow(dll, &(dll->Sup)); -} - -/* These three are VERY similar, but they are useful for traversals iin - different directions. Otherwise the caller needs to save the 'up' or - 'down' element */ -/* Delete an entry. Return nothing. */ -void DllDelete(Dll *dll, Dll_elmt *old){ - Dll_elmt *up = old->up; - Dll_elmt *down = old->down; - - dll->length--; - up->down = down; - down->up = up; - ChnFree(dll->chn, old); -} - -/* Delete an entry. Return the entry that used to be above it. */ -Dll_elmt *DllDeleteUp(Dll *dll, Dll_elmt *old){ - Dll_elmt *up = old->up; - Dll_elmt *down = old->down; - - dll->length--; - up->down = down; - down->up = up; - ChnFree(dll->chn, old); - return up; -} - -/* Delete an entry. Return the entry that used to be below it. */ -Dll_elmt *DllDeleteDown(Dll *dll, Dll_elmt *old){ - Dll_elmt *up = old->up; - Dll_elmt *down = old->down; - - dll->length--; - up->down = down; - down->up = up; - ChnFree(dll->chn, old); - return down; -} - -/* The next two have two plausible returns: the item directly above or - below the original position of the mover. Rather than confuse - things, I won't return either, and leave it up to the caller to keep - track of whatever he wants. */ - -/* Extract the 'mover' and place it immediately below 'up'. - Like DllDelete, followed by DllInsertBelow, but preserve the - data in the object. */ -void DllMoveBelow(Dll *dll, Dll_elmt *mover, Dll_elmt *up){ - Dll_elmt *down; - /* Extract the mover */ - mover->down->up = mover->up; - mover->up->down = mover->down; - /* Now insert it below up */ - down = up->down; - mover->up = up; - mover->down = down; - down->up = mover; - up->down = mover; -} - -/* Extract the 'mover' and place it immediately above 'down'. - Like DllDelete, followed by DllInsertAbove, but preserve the - data in the object. */ -void DllMoveAbove(Dll *dll, Dll_elmt *mover, Dll_elmt *down){ - Dll_elmt *up; - /* Extract the mover */ - mover->down->up = mover->up; - mover->up->down = mover->down; - /* Now insert it above down */ - up = down->up; - mover->up = up; - mover->down = down; - down->up = mover; - up->down = mover; -} - -/* These should be inlined... */ -/* Move to bottom */ -void DllMoveToBottom(Dll *dll, Dll_elmt *mover){ - DllMoveAbove(dll, mover, &(dll->Inf)); -} - -/* Move to top */ -void DllMoveToTop(Dll *dll, Dll_elmt *mover){ - DllMoveBelow(dll, mover, &(dll->Sup)); -} - -/* These are generally 'inlined' with appropriate #defines in dll.h. - They're simple enough to allow use of the pre-processor instead of - __inline__. */ -#undef DllLength -int DllLength(Dll *dll){ - return dll->length; -} - -#undef DllSup -Dll_elmt *DllSup(Dll *dll){ - return &dll->Sup; -} - -#undef DllInf -Dll_elmt *DllInf(Dll *dll){ - return &dll->Inf; -} - -/* The highest 'real' element */ -#undef DllTop -Dll_elmt *DllTop(Dll *dll){ - return dll->Sup.down; -} - -/* The lowest 'real' element */ -#undef DllBottom -Dll_elmt *DllBottom(Dll *dll){ - return dll->Inf.up; -} - -#undef DllData -void *DllData(Dll_elmt *elmt){ - return &elmt->stuff; -} - -#undef DllUp -Dll_elmt *DllUp(Dll_elmt *elmt){ - return elmt->up; -} - -#undef DllDown -Dll_elmt *DllDown(Dll_elmt *elmt){ - return elmt->down; -} - - diff --git a/external/libsdf/libsw/dofZ.c b/external/libsdf/libsw/dofZ.c deleted file mode 100644 index dffddf4..0000000 --- a/external/libsdf/libsw/dofZ.c +++ /dev/null @@ -1,211 +0,0 @@ -#include -#include -#include "qromo.h" -#include "dofz.h" - -static double Omega0; -static double Omega_m; -static double Omega_r; -static double Omega_de; -static double w0; -static double wa; -static double Lambda_prime; -static double H0; - -static double -adot(double a) -{ - return H0*sqrt(Omega_m/a + Omega_r/(a*a) + Lambda_prime*a*a + (1.0 - Omega0 - Lambda_prime)); -} - -static double -addot(double a) -{ - return H0 * H0 * (Lambda_prime*a-Omega_r/(a*a*a)-0.5*Omega_m/(a*a)); -} - -static double -integrand(double a) -{ - double x; - - x = adot(a); - return 1.0/(x*x*x); - -} - -static double -t_integrand(double a) -{ - double x; - - x = adot(a); - return 1.0/x; -} - -static double -dp_integrand(double a) -{ - double x; - - x = adot(a); - return 1.0/(a*x); - -} - -double -growthfac_from_Z(double omega0, double h0, double lambda_prime, double z) -{ - double z0gf; - double a = 1.0/(1.0+z); - double h = 10.0*h0*(one_kpc/one_Gyr); - Omega0 = omega0; - Omega_r = omega_r / (h * h); - Omega_m = omega0-Omega_r; - H0 = h0; - Lambda_prime = lambda_prime; - return 2.5*H0*H0*adot(a)*qromod(integrand, 0.0, a, midpntd)/a; -} - -double -velfac_from_Z(double omega0, double h0, double lambda_prime, double z) -{ - double d, a_dot; - double a = 1.0/(1.0+z); - double h = 10.0*h0*(one_kpc/one_Gyr); - Omega0 = omega0; - Omega_r = omega_r / (h * h); - Omega_m = omega0-Omega_r; - H0 = h0; - Lambda_prime = lambda_prime; - d = qromod(integrand, 0.0, a, midpntd); - a_dot = adot(a); - return addot(a) - *a/(a_dot*a_dot) - 1.0 + a/(a_dot*a_dot*a_dot*d); -} - -double -t_from_Z(double omega0, double h0, double lambda_prime, double z) -{ - double d; - double a = 1.0/(1.0+z); - double h = 10.0*h0*(one_kpc/one_Gyr); - Omega0 = omega0; - Omega_r = omega_r / (h * h); - Omega_m = omega0-Omega_r; - H0 = h0; - Lambda_prime = lambda_prime; - d = qromod(t_integrand, 0.0, a, midpntd); - return (d); -} - -double -dp_from_Z(double omega0, double h0, double lambda_prime, double z) -{ - double d; - double a = 1.0/(1.0+z); - double h = 10.0*h0*(one_kpc/one_Gyr); - if (a == 1.0) return 0.0; - Omega0 = omega0; - Omega_r = omega_r / (h * h); - Omega_m = omega0-Omega_r; - H0 = h0; - Lambda_prime = lambda_prime; - d = qromod(dp_integrand, a, 1.0, midpntd); - return (d); -} - -double -hubble_from_Z(double omega0, double h0, double lambda_prime, double z) -{ - double a = 1.0/(1.0+z); - double h = 10.0*h0*(one_kpc/one_Gyr); - Omega0 = omega0; - Omega_r = omega_r / (h * h); - Omega_m = omega0-Omega_r; - H0 = h0; - Lambda_prime = lambda_prime; - return adot(a)/a; -} - -#if 0 -/* Crays don't have acosh */ -static double Acosh(double x) -{ - return log(x + sqrt(x*x-1.0)); -} - -static double -growthfac_from_Z(double Omega0, double H0, double Z) -{ - /* This is just the growing mode */ - /* See Weinberg 15.9.27--15.9.31 or Peebles LSS 11.16 */ - double d, d0; - - if (Omega0 == 1.0) { - d = 1.0/(1.0+Z); - d0 = 1.0; - } else if(Omega0 < 1.0) { - /* Using doubles can cause roundoff problems near Omega0=1 */ - double psi, coshpsi; - coshpsi = 1.0 + 2.0*(1.0 - Omega0)/(Omega0*(1.0+Z)); - psi = Acosh(coshpsi); - d = - 3.0 * psi * sinh(psi)/((coshpsi-1.0)*(coshpsi-1.0)) - + (5.0+coshpsi)/(coshpsi-1.0); - coshpsi = 1.0 + 2.0*(1.0 - Omega0)/Omega0; - psi = Acosh(coshpsi); - d0 = - 3.0 * psi * sinh(psi)/((coshpsi-1.0)*(coshpsi-1.0)) - + (5.0+coshpsi)/(coshpsi-1.0); - } else { - double theta, costheta; - costheta = 1.0 - 2.0*(Omega0-1.0)/(Omega0*(1.0+Z)); - theta = acos(costheta); - d = - 3.0 * theta * sin(theta)/((1.0-costheta)*(1.0-costheta)) - + (5.0+costheta)/(1.0-costheta); - costheta = 1.0 - 2.0*(Omega0-1.0)/Omega0; - theta = acos(costheta); - d0 = - 3.0 * theta * sin(theta)/((1.0-costheta)*(1.0-costheta)) - + (5.0+costheta)/(1.0-costheta); - } - return d/d0; -} - -static double -t_from_Z(double Omega0, double H0, double Z) -{ - double t, theta, psi; - - if(Omega0 == 1.0){ - t = (2.0/3.0) * pow(1.0+Z, -1.5); - }else if(Omega0 < 1.0){ - psi = Acosh( 1.0 + 2.0*(1.0 - Omega0)/(Omega0*(1.0+Z)) ); - t = (Omega0/2.0)*pow(1.0-Omega0, -1.5)*(sinh(psi) - psi) ; - }else{ - theta = acos( 1.0 - 2.0*(Omega0-1.)/(Omega0*(1.0+Z)) ); - t = (Omega0/2.0)*pow(Omega0-1.0, -1.5)*(theta-sin(theta)); - } - t /= H0; - return t; -} -#endif - - -#ifdef STANDALONE - -int -main(int argc, char *argv[]) -{ - double z; - double omega0 = atof(argv[1]); - double h0 = atof(argv[2]); - double lp = atof(argv[3]); - - for (z = 0; z <= 100; z++) { - printf("%g %g %g %g %g\n", z, growthfac_from_Z(omega0, h0, lp, z), - velfac_from_Z(omega0, h0, lp, z), t_from_Z(omega0, h0, lp, z), - dp_from_Z(omega0, h0, lp, z)); - } - exit(0); -} - -#endif diff --git a/external/libsdf/libsw/error.c b/external/libsdf/libsw/error.c deleted file mode 100644 index 35698d7..0000000 --- a/external/libsdf/libsw/error.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 1991 Michael S. Warren and John K. Salmon. All Rights Reserved. - */ -#ifdef __SRV__ - # error This file should not use SRV -#endif - -#include -#include -#include -#include -#include "error.h" -#include "Msgs.h" -#include "mpmy.h" -#include "mpmy_abnormal.h" -#include "gccextensions.h" -#include "protos.h" -#include "memfile.h" - -#undef Error -#undef SinglError -#undef Warning -#undef SinglWarning -#undef SeriousWarning -#undef Shout -#undef SinglShout - -static int recursion; - -/* We call this SWError because of a namespace conflict when linking SDF - into perl5. error.h should do the switcheroo automatically... */ -void SWError(const char * mesg, ...) -{ - va_list alist; - - if( recursion++ ) - MPMY_SystemAbort(); /* errors within errors. A very bad sign */ - - va_start(alist, mesg); - fprintf(stderr, "ERROR: Node %d (%s) ", MPMY_Procnum(), MPMY_Physnode()); - vfprintf(stderr, mesg, alist); - fflush(stderr); - va_end(alist); - Msg_do("ERROR: "); - va_start(alist, mesg); - Msg_doalist(mesg, alist); - va_end(alist); - Msg_flush(); - MPMY_Abort(); -} - -/* Is this right? Is it even possible? Can I pass the same va_list - to two different subroutines? I can't use va_start and va_end because - this isn't a varargs function! It works in Msgs, so it ought to work - here too.*/ -void vError(const char * mesg, va_list alist) -{ - if( recursion++ ) - MPMY_SystemAbort(); /* errors within errors. A very bad sign */ - - fprintf(stderr, "ERROR: Node %d (%s) ", MPMY_Procnum(), MPMY_Physnode()); - vfprintf(stderr, mesg, alist); - fflush(stderr); - - Msg_do("ERROR: "); - Msg_doalist(mesg, alist); - Msg_flush(); - PrintMemfile(); - MPMY_Abort(); -} - -void SinglError(const char * mesg, ...) -{ - va_list alist; - - if( recursion++ ) - MPMY_SystemAbort(); - if( MPMY_Procnum() == 0 ){ - va_start(alist, mesg); - fprintf(stderr, "Single ERROR: "); - vfprintf(stderr, mesg, alist); - fflush(stderr); - va_end(alist); - Msg_do("Single ERROR: "); - va_start(alist, mesg); - Msg_doalist(mesg, alist); - va_end(alist); - PrintMemfile(); - Msg_flush(); - } - MPMY_Abort(); -} - -void -Warning(const char *mesg, ...) -{ - va_list alist; - - if( recursion++ ){ - --recursion; - return; - } - Msg_do("WARNING: "); - va_start(alist, mesg); - Msg_doalist(mesg, alist); - va_end(alist); - Msg_flush(); - --recursion; -} - -void -SinglWarning(const char *mesg, ...) -{ - va_list alist; - - if( recursion++ ){ - --recursion; - return; - } - if( MPMY_Procnum() == 0 ){ - /* Since there's only one, it's safe to send it to stderr too... */ - va_start(alist, mesg); - fprintf(stderr, "WARNING: (single): "); - vfprintf(stderr, mesg, alist); - fflush(stderr); - va_end(alist); - Msg_do("WARNING (Single mode): "); - va_start(alist, mesg); - Msg_doalist(mesg, alist); - va_end(alist); - Msg_flush(); - } - --recursion; -} - -/* This one goes to stderr, for all to see immediately */ -void -SeriousWarning(const char *mesg, ...) -{ - va_list alist; - - if( recursion++ ){ - --recursion; - return; - } - va_start(alist, mesg); - fprintf(stderr, "WARNING: Node %d ", MPMY_Procnum()); - vfprintf(stderr, mesg, alist); - fflush(stderr); - va_end(alist); - Msg_do("WARNING: "); - va_start(alist, mesg); - Msg_doalist(mesg, alist); - va_end(alist); - Msg_flush(); - --recursion; -} - -/* No "WARNING", no line numbers, etc... Just the arguments */ -void -Shout(const char *mesg, ...) -{ - va_list alist; - - if( recursion++ ){ - --recursion; - return; - } - va_start(alist, mesg); - vfprintf(stderr, mesg, alist); - fflush(stderr); - va_end(alist); - va_start(alist, mesg); - Msg_doalist(mesg, alist); - va_end(alist); - Msg_flush(); - --recursion; -} - -void -SinglShout(const char *mesg, ...) -{ - va_list alist; - - if( recursion++ ){ - --recursion; - return; - } - if( MPMY_Procnum() == 0 ){ - va_start(alist, mesg); - vfprintf(stderr, mesg, alist); - fflush(stderr); - va_end(alist); - va_start(alist, mesg); - Msg_doalist(mesg, alist); - va_end(alist); - Msg_flush(); - } - --recursion; -} - diff --git a/external/libsdf/libsw/files.c b/external/libsdf/libsw/files.c deleted file mode 100644 index 0dc42cc..0000000 --- a/external/libsdf/libsw/files.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Some common routines for dealing with files. */ -#include -#include -#include "protos.h" -#include "Malloc.h" -#include "mpmy.h" - -int fexists(const char *name){ - int fd, ret; - - ret = 0; - if( MPMY_Procnum() == 0 ){ - /* We could call stat, but then we'd have to deal with the */ - /* complications of different flavors of struct stat on different */ - /* machines...Yuck. */ - if( (fd=open(name, O_RDONLY)) >= 0 ){ - close(fd); - ret = 1; - } - } - MPMY_Combine(&ret, &ret, 1, MPMY_INT, MPMY_SUM); - return ret; -} - -int fexists_and_unlink(const char *name){ - int fd, ret; - - ret = 0; - if( MPMY_Procnum() == 0 ){ - /* We could call stat, but then we'd have to deal with the */ - /* complications of different flavors of struct stat on different */ - /* machines...Yuck. */ - if( (fd=open(name, O_RDONLY)) >= 0 ){ - close(fd); - ret = 1; - } - unlink(name); - } - MPMY_Combine(&ret, &ret, 1, MPMY_INT, MPMY_SUM); - return ret; -} - -int -ForceCheckpoint(void) -{ - return fexists_and_unlink("_ForceCheckpoint_") || fexists("_ForceStop_"); -} - -int -ForceOutput(void) -{ - return fexists_and_unlink("_ForceOutput_"); -} - -int -ForceStop(void) -{ - return fexists_and_unlink("_ForceStop_"); -} diff --git a/external/libsdf/libsw/finite.c b/external/libsdf/libsw/finite.c deleted file mode 100644 index 67c687e..0000000 --- a/external/libsdf/libsw/finite.c +++ /dev/null @@ -1,11 +0,0 @@ -/* This really should be implemented for us... */ -/* Nevertheless, we should do better.. */ -#include -#ifndef HUGE -#define HUGE 1.e38 -#endif - -int finite(double x){ - return x-HUGE; -} - diff --git a/external/libsdf/libsw/gc.c b/external/libsdf/libsw/gc.c deleted file mode 100644 index f142a78..0000000 --- a/external/libsdf/libsw/gc.c +++ /dev/null @@ -1,180 +0,0 @@ -/* little functions for doing gray-code stuff. */ - -#include -#include -#include "gc.h" - -/* Both parity and firstbit could be sped up with some lookup tables. */ -/* Who cares? */ -unsigned int parity(unsigned int num) -{ - unsigned int answer = 0; - while( num ){ - if( num&1 ) - answer ^= 1; - num >>= 1; - } - return answer; -} - -int hibit(unsigned int num){ - /* return the index of the highest bit in num. */ - /* -1 if num == 0 */ - int bit = -1; - - while(num) { - bit++; - num >>= 1; - } - return bit; -} - -int lobit(unsigned int num){ - /* Return the index of the lowest bit in num */ - /* Return BITS_PER_WORD in if num==0. This relies on overflow in left- - shift returning 0 */ - unsigned int m=1; - int bit = 0; - - while((num&m) != m){ - m <<= 1; - bit++; - } - return bit; -} - -int ilog2(unsigned int n){ - return hibit(n); -} - -unsigned int cksum(const void *buf, unsigned int n){ - unsigned int sum = 0; - unsigned int leftover; - const unsigned int *ip = buf; - const unsigned char *cp; - - /* Worthwhile to make the result independent of word-ordering, wordsize, - etc?? Not now... */ - leftover = n%sizeof(unsigned int); - n /= sizeof(unsigned int); - while(n--){ - sum ^= *ip++; - } - cp = (const unsigned char *)ip; - for(n=0; n>= 1)); - return ret; -} - -/* My two neighbors are obtained by : - a) toggle the lowest bit of procnum - b) toggle one past the lowest turned-on bit - ( but be careful when there are no turned on bits, or only the highest - is turned on). - */ -int Gcup(unsigned int proc, unsigned int nproc){ - if( proc == nproc>>1 ){ - return -1; - }else if( parity(proc) ){ - return proc^(1<>1); -} - -/* If you look back at the property of ^ and >>, you will notice ^ behave - like an addtion: - - x + y = y + x <-> x ^ y = y ^ x - (x + y) + z = x + (y + z) <-> (x ^ y) ^ z = x ^ (y ^ z) - - and >> behave like a linear operator L: - - L(x + y) = L(x) + L(y) <-> (x ^ y)>>1 = (x>>1) ^ (y>>1) - - Hence the bin2gray operation behave just like the linear operator: - - 1 + L - - with inverse - -1 2 3 2 4 8 - (1+L) = 1 - L + L - L + ... = (1 - L)(1 + L )(1 + L )(1 + L )... (*) - - Since x ^ y ^ y = x, addition is just the same as subaction. Furthurmore, - x>>32 = 0 for any 32 bit integer and hence all of - 32 64 - (1 + L ) , (1 + L ), .... equal to 1. - - As a result, your just need to keep the first 5 terms of RHS of (*) -*/ -unsigned long -gray2bin(unsigned long g){ - register unsigned long t = g; - t ^= t>>1; /* 1 - L */ - /* 2 */ - t ^= t>>2; /* 1 + L */ - /* 4 */ - t ^= t>>4; /* 1 + L */ - /* 8 */ - t ^= t>>8; /* 1 + L */ - /* 16 */ - t ^= t>>16; /* 1 + L */ - return t; -} diff --git a/external/libsdf/libsw/gnusort.c b/external/libsdf/libsw/gnusort.c deleted file mode 100644 index 82143a0..0000000 --- a/external/libsdf/libsw/gnusort.c +++ /dev/null @@ -1,269 +0,0 @@ -/* Use a static buffer instead of malloc for small 'size' */ -/* Fixed a bug when called with total_elems=0, ptr=NULL */ -/* The default is now to not use alloca unless ALLOCA_PREFERRED is defined */ -/* -DNO_ALLOCA and -DC_ALLOCA are equivalent. Neither uses alloca herein. */ -/* Changed alloca -> Malloc/Free (johns) */ -/* Hacked by msw for even more speed (2x - 3x) */ -/* Assumes size is a multiple of sizeof(int) */ -/* Originally from glibc-1.03.tar.Z stdlib/qsort.c */ - -/* Copyright (C) 1991 Free Software Foundation, Inc. -This file is part of the GNU C Library. -Written by Douglas C. Schmidt (schmidt@ics.uci.edu). - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#include -#include -#ifndef ALLOCA_PREFERRED -#include "Malloc.h" -static char static_pivot[128]; -#endif -#include "error.h" - -/* Int-wise swap two items of size SIZE. */ -#define SWAP(a, b, size) \ - do \ - { \ - register size_t __size = (size)/sizeof(int); \ - register int *__a = (int *)(a), *__b = (int *)(b); \ - do \ - { \ - int __tmp = *__a; \ - *__a++ = *__b; \ - *__b++ = __tmp; \ - } while (--__size > 0); \ - } while (0) - -/* Discontinue quicksort algorithm when partition gets below this size. - This particular magic number was chosen to work best on a Sun 4/260. */ -#define MAX_THRESH 4 - -/* Stack node declarations used to store unfulfilled partition obligations. */ -typedef struct - { - char *lo; - char *hi; - } stack_node; - -/* The next 4 #defines implement a very fast in-line stack abstraction. */ -#define STACK_SIZE (8 * sizeof(unsigned long int)) -#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) -#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) -#define STACK_NOT_EMPTY (stack < top) - - -/* Order size using quicksort. This implementation incorporates - four optimizations discussed in Sedgewick: - - 1. Non-recursive, using an explicit stack of pointer that store the - next array partition to sort. To save time, this maximum amount - of space required to store an array of MAX_INT is allocated on the - stack. Assuming a 32-bit integer, this needs only 32 * - sizeof(stack_node) == 136 bits. Pretty cheap, actually. - - 2. Chose the pivot element using a median-of-three decision tree. - This reduces the probability of selecting a bad pivot value and - eliminates certain extraneous comparisons. - - 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving - insertion sort to order the MAX_THRESH items within each partition. - This is a big win, since insertion sort is faster for small, mostly - sorted array segements. - - 4. The larger of the two sub-partitions is always pushed onto the - stack first, with the algorithm then concentrating on the - smaller partition. This *guarantees* no more than log (n) - stack size is needed (actually O(1) in this case)! */ - -/* STDC says it's void, but Sun knows better, but SRV knows better still... */ -#if defined(__SRV__) || defined(__SUN_CC_UNPROTO__) || defined(__SUN5__) || !defined(sparc) -void -#else -int -#endif -qsort(void *pbase, size_t total_elems, size_t size, - int (*cmp)(const void *, const void *)) -{ - register char *base_ptr = (char *) pbase; - - /* Allocating SIZE bytes for a pivot buffer facilitates a better - algorithm below since we can do comparisons directly on the pivot. */ -#ifdef ALLOCA_PREFERRED - char *pivot_buffer = (char *) alloca (size); -#else - char *pivot_buffer = (size > sizeof(static_pivot)) ? (char *)Malloc(size) : static_pivot; -#endif - const size_t max_thresh = MAX_THRESH * size; - - if (size % sizeof(int) || (int)pbase % sizeof(int)) - Error("This qsort only works on int aligned stuff\n"); - - if (total_elems > MAX_THRESH) - { - char *lo = base_ptr; - char *hi = &lo[size * (total_elems - 1)]; - /* Largest size needed for 32-bit int!!! */ - stack_node stack[STACK_SIZE]; - stack_node *top = stack + 1; - - while (STACK_NOT_EMPTY) - { - char *left_ptr; - char *right_ptr; - - char *pivot = pivot_buffer; - - /* Select median value from among LO, MID, and HI. Rearrange - LO and HI so the three values are sorted. This lowers the - probability of picking a pathological pivot value and - skips a comparison for both the LEFT_PTR and RIGHT_PTR. */ - - char *mid = lo + size * ((hi - lo) / size >> 1); - - if ((*cmp)((void *) mid, (void *) lo) < 0) - SWAP(mid, lo, size); - if ((*cmp)((void *) hi, (void *) mid) < 0) - SWAP(mid, hi, size); - else - goto jump_over; - if ((*cmp)((void *) mid, (void *) lo) < 0) - SWAP(mid, lo, size); - jump_over:; - memcpy(pivot, mid, size); - pivot = pivot_buffer; - - left_ptr = lo + size; - right_ptr = hi - size; - - /* Here's the famous ``collapse the walls'' section of quicksort. - Gotta like those tight inner loops! They are the main reason - that this algorithm runs much faster than others. */ - do - { - while ((*cmp)((void *) left_ptr, (void *) pivot) < 0) - left_ptr += size; - - while ((*cmp)((void *) pivot, (void *) right_ptr) < 0) - right_ptr -= size; - - if (left_ptr < right_ptr) - { - SWAP(left_ptr, right_ptr, size); - left_ptr += size; - right_ptr -= size; - } - else if (left_ptr == right_ptr) - { - left_ptr += size; - right_ptr -= size; - break; - } - } - while (left_ptr <= right_ptr); - - /* Set up pointers for next iteration. First determine whether - left and right partitions are below the threshold size. If so, - ignore one or both. Otherwise, push the larger partition's - bounds on the stack and continue sorting the smaller one. */ - - if ((size_t) (right_ptr - lo) <= max_thresh) - { - if ((size_t) (hi - left_ptr) <= max_thresh) - /* Ignore both small partitions. */ - POP(lo, hi); - else - /* Ignore small left partition. */ - lo = left_ptr; - } - else if ((size_t) (hi - left_ptr) <= max_thresh) - /* Ignore small right partition. */ - hi = right_ptr; - else if ((right_ptr - lo) > (hi - left_ptr)) - { - /* Push larger left partition indices. */ - PUSH(lo, right_ptr); - lo = left_ptr; - } - else - { - /* Push larger right partition indices. */ - PUSH(left_ptr, hi); - hi = right_ptr; - } - } - } - - /* Once the BASE_PTR array is partially sorted by quicksort the rest - is completely sorted using insertion sort, since this is efficient - for partitions below MAX_THRESH size. BASE_PTR points to the beginning - of the array to sort, and END_PTR points at the very last element in - the array (*not* one beyond it!). */ - -#define min(x, y) ((x) < (y) ? (x) : (y)) - - /* johns - avoid potential segfault if total_elems==0 and base_ptr == 0 !*/ - if( total_elems > 0 ) - { - char *const end_ptr = &base_ptr[size * (total_elems - 1)]; - char *tmp_ptr = base_ptr; - char *thresh = min(end_ptr, base_ptr + max_thresh); - register char *run_ptr; - - /* Find smallest element in first threshold and place it at the - array's beginning. This is the smallest array element, - and the operation speeds up insertion sort's inner loop. */ - - for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size) - if ((*cmp)((void *) run_ptr, (void *) tmp_ptr) < 0) - tmp_ptr = run_ptr; - - if (tmp_ptr != base_ptr) - SWAP(tmp_ptr, base_ptr, size); - - /* Insertion sort, running from left-hand-side up to right-hand-side. */ - - run_ptr = base_ptr + size; - while ((run_ptr += size) <= end_ptr) - { - tmp_ptr = run_ptr - size; - while ((*cmp)((void *) run_ptr, (void *) tmp_ptr) < 0) - tmp_ptr -= size; - - tmp_ptr += size; - if (tmp_ptr != run_ptr) - { - int *trav; - - trav = (int *)(run_ptr + size); - while (--trav >= (int *)run_ptr) - { - int c = *trav; - int *hi, *lo; - - for (hi = lo = trav; - (lo -= size/sizeof(int)) >= (int *)tmp_ptr; hi = lo) - *hi = *lo; - *hi = c; - } - } - } - } -#ifndef ALLOCA_PREFERRED - if( pivot_buffer != static_pivot) - Free(pivot_buffer); -#endif -} diff --git a/external/libsdf/libsw/heap.c b/external/libsdf/libsw/heap.c deleted file mode 100644 index edfeeda..0000000 --- a/external/libsdf/libsw/heap.c +++ /dev/null @@ -1,87 +0,0 @@ -/* Super-fast priority queue. ? Completely inlined by gcc. */ -/* Assume that each pointer points at */ -/* a key, AND whatever else the caller is interested in keeping. */ - -#ifndef assert -#include "Assert.h" -#endif -#include -#include -#include "Malloc.h" -#define HEAPdotC -#include "heap.h" - -#if !defined(HeapKey) || !defined(HeapLeft) - # error Heap macros undefined -#endif - -/* These save us from an extra comparison inside our loops */ -const float HeapMinf = -FLT_MAX; -const float HeapInf = FLT_MAX; - -/* I wonder if some const decls would be correct? */ -void HeapInit(Heap *hp, unsigned int sz){ - assert(sz > 0); - hp->arr = Malloc( (sz+1)*sizeof(*(hp->arr)) ); - assert(hp->arr); - hp->sz = sz; - hp->cnt = 1; - hp->arr[0] = &HeapInf; -} - -void HeapTerminate(Heap *hp){ - Free((void *)hp->arr); - hp->arr = NULL; - hp->sz = hp->cnt = 0; -} - -int HeapIsBad(const Heap *hp){ - unsigned int i, ri, li; - const float **arr = hp->arr; - - for( i=1, li=2, ri=3; - li < hp->cnt; - i++, li = HeapLeft(i), ri = li+1){ - if( HeapKey(i) < HeapKey(li) ) - return li; - if( ri < hp->cnt && HeapKey(i) < HeapKey(ri) ) - return ri; - } - return 0; -} - -#ifdef STANDALONE -#include - -float data[] = {5., 1., 3., 2., 7., 3., 4.}; - -void HeapPrint(Heap *hp){ - unsigned int i; - for(i=1; icnt; i++){ - printf("%d %g\n", i, *(hp->arr[i])); - } -} - -int main(int argc, char **argv){ - Heap H; - float *top; - unsigned int i; - unsigned int ndata; - - HeapInit(&H, 2); - ndata = sizeof(data)/sizeof(*data); - for(i=0; i -#include -#include "error.h" -#include "hwclock.h" - -static double hwtick_val; -#define two_to_32 4294967296.0 - -static double hwclock_offset; - -#if defined(__x86_64__) && defined(__GNUC__) -#define DEFAULT_MHZ 1200.e6 -static double -mhz_from_proc(){ - FILE *fp = fopen("/proc/cpuinfo", "r"); - char line[512]; - - if( fp == NULL ){ - Warning("Can't open /proc/cpuinfo\n"); - return DEFAULT_MHZ; - } - - while( fgets(line, sizeof(line), fp) ){ - char *m; - int nscan; - double mhz; - - if( (m = strstr(line, "cpu MHz")) ){ - /* sscanf should match any amount of whitespace around the : */ - nscan = sscanf(m, "cpu MHz : %lf\n", &mhz); - if( nscan == 1 ){ - fclose(fp); - return mhz*1.0e6; - }else{ - Warning("sscanf returns %d, on '%s' of /proc/cpuinfo mhz line failed\n", nscan, line); - fclose(fp); - return DEFAULT_MHZ; /* let's just guess 200Mhz */ - } - } - } - Warning("Did not find cpu MHz in /proc/cpuinfo\n"); - fclose(fp); - return DEFAULT_MHZ; -} -#endif - -/* This doesn't belong here, but I can't be bothered to figure out where - it does belong! */ -double -hwclock(void) -{ -#if defined(__x86_64__) - static int init = 1; - unsigned int counter[2]; - - __asm__("rdtsc \n\t" - "movl %%eax,%0 \n\t" - "movl %%edx,%1 \n\t" - : "=m" (((unsigned *)counter)[0]), "=m" (((unsigned *)counter)[1]) - : - : "eax" , "edx"); - - if (init) { - init = 0; - hwtick_val = 1.0/mhz_from_proc(); - hwclock_offset = hwtick_val*((double)counter[1]*two_to_32 + (double)counter[0]); - return 0.0; - } - return(hwtick_val*((double)counter[1]*two_to_32 + (double)counter[0])-hwclock_offset); -#else - { - struct timeval tp; - struct timezone tzp; - - gettimeofday(&tp,&tzp); - return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 ); - } -#endif -} - -void -zero_hwclock(void) -{ - hwclock_offset += hwclock(); -} - -double -hwtick(void) -{ - return hwtick_val; -} diff --git a/external/libsdf/libsw/ivfprintf.c b/external/libsdf/libsw/ivfprintf.c deleted file mode 100644 index 51d56a3..0000000 --- a/external/libsdf/libsw/ivfprintf.c +++ /dev/null @@ -1,54 +0,0 @@ -#ifdef __SRV__ - # error This file should not be compiled with srv -#endif - -#include -#include -#include -#ifndef FORCE_TYPE -/* mesh.h is not protected against multiple inclusion ! */ -#include -#endif - -/* Why isn't this in mesh.h? */ -extern void iowait(int); - -/* A fast asynchronous disk message primitive */ - -/* There is circumstantial evidence that the delta dies if we have many */ -/* iwrites pending and call ifflush ???? (maybe fixed - johns ) ????*/ - -static int id[] = {-1, -1, -1, -1, -1, -1, -1, -1}; -#define NID (sizeof(id)/sizeof(id[0])) -static int nid = 0; -static char buf[NID][1024]; - -void -ivfprintf(FILE *stream, const char *fmt, va_list args) -{ - if (id[nid] != -1){ - iowait(id[nid]); - } - vsprintf(buf[nid], fmt, args); - id[nid] = iwrite(fileno(stream), buf[nid], strlen(buf[nid])); - if( ++nid == NID ) - nid = 0; -} - - -void -ifflush(FILE *stream) -{ - int i; - int ii; - - /* stream not used. Just wait for all the pending i/o */ - for (ii = nid, i = 0; i < NID; i++){ - if (id[ii] != -1) { - iowait(id[ii]); - id[ii] = -1; - } - if( ++ii == NID ) - ii = 0; - } -} diff --git a/external/libsdf/libsw/key.c b/external/libsdf/libsw/key.c deleted file mode 100644 index e801fdd..0000000 --- a/external/libsdf/libsw/key.c +++ /dev/null @@ -1,79 +0,0 @@ -#define KEYdotC -/* Most of the definitions are in key.h */ -#include /* just for sprintf */ -#include "key.h" -#include "protos.h" - -/* Non-inlined definitions go here. */ - -char * -PrintKey(Key_t key) -{ - static char str[128]; - - if (NK == 1) - sprintf(str, "%lo", key.k[0]); - else { - if (key.k[1] == 0) { - sprintf(str, "%lo", key.k[0]); - } else { - /* This only works for NDIM==3 */ - sprintf(str, "%lo%01lo%021lo", key.k[1] >> 2, /* bits 66-126*/ - ((key.k[1] & 03) << 1) | (key.k[0] >> 63), /* bits 63,64,65 */ - key.k[0] & ~(1L << 63)); /* bits 0-62 */ - } - } - return str; -} - -#if 0 -int -TreeLevel(Key_t key, int ndim) -{ - int level; - int chubits = (KEYBITS-1)/ndim; - Key_t testkey; - - /* First check whether it's a 'body' (at the deepest level.) */ - /* This will save considerable time... */ - testkey = KeyLshift(KeyInt(1), chubits*ndim); - if( KeyEQ( testkey, KeyAnd(testkey, key) ) ) - return chubits; - - /* Now start looking from low levels */ - testkey = KeyInt(1); - for (level = 0; level -#include -#include "protos.h" -#include "mpmy.h" -#include "Msgs.h" -#include "Assert.h" -#include "key.h" -#include "peano.h" -#include "keycvt.h" - -#ifndef FLT_MAX -/* I wonder what they put in float.h, anyway */ -#define FLT_MAX 1.e38 -#endif - -int KeyOutOfBounds; - -/* This gives a tight bounding box around the list of positions. Note - that the result is rmin <= pos[i] and rmax >= pos[i]. The equality - can be a headache for float-to-int conversions! Consider using - InflateBbox and or CubeBbox! */ -void -TightBbox(float *pstart, int nobj, int pstride, int ndim, tbbox *bb){ - MPMY_Comm_request req; - int d; - float *pos = pstart; - float rmin[MAXNDIMKU]; - float rmax[MAXNDIMKU]; - - assert(ndim < MAXNDIMKU); - - for(d=0; dndim = ndim; - while(nobj--){ - for(d=0; d pd ) rmin[d] = pd; - if( rmax[d] < pd ) rmax[d] = pd; - } - pos = (float *)(pstride + (char *)pos); - } - MPMY_ICombine_Init(&req); - MPMY_ICombine(rmin, bb->rmin, ndim, MPMY_FLOAT, MPMY_MIN, req); - MPMY_ICombine(rmax, rmax, ndim, MPMY_FLOAT, MPMY_MAX, req); - MPMY_ICombine_Wait(req); - for(d=0; dsz[d] = rmax[d] - bb->rmin[d]; - } -} - -void -CenterBbox(tbbox *bb, float *center){ - int d; - for(d=0; dndim; d++){ - center[d] = bb->rmin[d] + 0.5F*bb->sz[d]; - } -} - -int -ContainsBbox(tbbox *bb1, tbbox *bb2){ - /* Return 1 if bb1 completely contains bb2 */ - int d; - - for(d=0; dndim; d++){ - if( bb1->rmin[d] > bb2->rmin[d] || - bb1->rmin[d] + bb1->sz[d] < bb2->rmin[d]+bb2->sz[d] ) - return 0; - } - return 1; -} - -/* Construct bbu, the 'union' of bb1 and bb2 */ -void -UnionBbox(tbbox *bb1, tbbox *bb2, tbbox *bbu){ - int d; - - bbu->ndim = bb1->ndim; - for(d=0; dndim; d++){ - float max1, max2; - float min1, min2; - - /* Read these first in case bbu is equal to bb1 or bb2! */ - min1 = bb1->rmin[d]; - min2 = bb2->rmin[d]; - bbu->rmin[d] = (min1 < min2) ? min1 : min2; - max1 = min1 + bb1->sz[d]; - max2 = min2 + bb2->sz[d]; - bbu->sz[d] = (max1 > max2) ? max1 - bbu->rmin[d] : max2 - bbu->rmin[d]; - } -} - -/* Make the bbox a cube by expanding the smaller dimensions. */ -void -CubeBbox(tbbox *bb){ - int d; - float maxs, halfmaxs; - float center[MAXNDIMKU]; - - maxs = 0.; - for(d=0; dndim; d++) { - center[d] = bb->rmin[d] + 0.5f * bb->sz[d]; - if( maxs < bb->sz[d] ) - maxs = bb->sz[d]; - } - halfmaxs = 0.5f*maxs; - for( d=0; dndim; d++){ - bb->rmin[d] = center[d] - halfmaxs; - bb->sz[d] = maxs; - } -} - -/* Increase the linear dimension by 'factor' on all sides */ -void -InflateBbox(tbbox *bb, float factor){ - float center; - int d; - for( d=0; dndim; d++){ - center = 0.5f*bb->sz[d] + bb->rmin[d]; - bb->sz[d] *= factor; - bb->rmin[d] = center - 0.5f*bb->sz[d]; - } -} - -void -GenerateKeys(float *pstart, int nobj, int pstride, tbbox *bb, - Key_t *kstart, int kstride, int order_type){ - int i, d; - float keyfactor[MAXNDIMKU]; - unsigned int ik[MAXNDIMKU]; - unsigned int chubits; - Key_t *kp; - float *pos; - unsigned int maxikey; - float fmaxikey; - Key_t (*KfI)(unsigned int *xp, int ndim, int nbits); - - chubits = ((KEYBITS-1) / bb->ndim ); - maxikey = (1U<ndim; d++){ - /* Divide by 0 ?? */ - keyfactor[d] = (1U<sz[d]); - } - pos = pstart; - kp = kstart; - switch( order_type ){ - case MORTON_ORDER: - KfI = &KeyFromInts; - break; - case PH_ORDER: - assert(bb->ndim == 3); /* assumed by the current implementation*/ - KfI = &PHKeyFromInts; - break; - default: - Error("Unrecognized order_type in GenerateKeys\n"); - } - - for(i=0; indim; d++){ - float fk = keyfactor[d] * (pos[d] - bb->rmin[d]); - if( fk < 0. ){ - KeyOutOfBounds = 1; - ik[d] = 0; - }else if( fk > fmaxikey ){ - ik[d] = maxikey; - KeyOutOfBounds = 1; - }else - ik[d] = (unsigned int)fk; - } - *kp = (*KfI)(ik, bb->ndim, chubits); - kp = (Key_t *) ( kstride + (char *)kp); - pos = (float *) ( pstride + (char *)pos); - } -} - -void -CellBBFromKey(Key_t key, tbbox *bb, tbbox *cellbb, int order_type) -{ - unsigned int icorner[MAXNDIMKU]; - unsigned int iscale; - float factor; - int d; - - switch(order_type){ - case MORTON_ORDER: - iscale = (1<ndim)); - break; - case PH_ORDER: - iscale = (1<ndim)); - break; - default: - Error("Unrecognized ordering in CellBBFromKey\n"); - } - - /* Now scale it back to "physical" units */ - cellbb->ndim = bb->ndim; - for(d=0; dndim; d++){ - factor = (bb->sz[d])/iscale; - cellbb->rmin[d] = bb->rmin[d] + factor*icorner[d]; - cellbb->sz[d] = factor; - } -} - -void -IntsFromFloats(const float *x, unsigned int *ix, tbbox *bb, int nbits){ - int d; - unsigned int iscale = 1<= CHAR_BIT*sizeof(iscale)) { - Error("nbits out of range in IntsFromFloats\n"); - } - for(d=0; dndim; d++){ - ix[d] = iscale * (x[d] - bb->rmin[d]) / (bb->sz[d]); - } -} - -void -FloatsFromInts(const int *ix, float *x, tbbox *bb, int nbits){ - unsigned int iscale = 1<= CHAR_BIT*sizeof(iscale)) { - Error("nbits out of range in FloatsFromInts\n"); - } - for(d=0; dndim; d++){ - x[d] = ix[d] * ((bb->sz[d])/iscale); - } -} - -/* These two names conflict with physics_generic.c. Good. It will - keep me from using physics_generic.c accidentally. */ -Key_t -KeyFromInts(unsigned int *xp, int ndim, int nbits){ - Key_t key; - unsigned int rshift, bits, dim; - - /* Set first bit. Important! */ - key = KeyInt(1); - for(rshift=nbits; rshift; ){ - rshift--; - bits = 0; - for(dim = 0; dim < ndim; dim++ ) - bits |= ((xp[dim]>>rshift)&1) << dim; - key = KeyOrInt(KeyLshift(key, ndim), bits); - } - return(key); -} - -/* Notice that the return value is DIFFERENT FROM physics_generic.c - Here, we return the number of bits. It's easier for the caller to do - left-shift than ilog2. */ -int -IntsFromKey(Key_t key, unsigned int *ip, int ndim){ - unsigned int iscale = 1; - unsigned int lev = 0; - int i; - - for(i=0; i= CHAR_BIT*sizeof(iscale)) { - Error("lev out of range in IntsFromKey\n"); - } - } - return lev; -} - diff --git a/external/libsdf/libsw/lsv.c b/external/libsdf/libsw/lsv.c deleted file mode 100644 index 4de9e83..0000000 --- a/external/libsdf/libsw/lsv.c +++ /dev/null @@ -1,792 +0,0 @@ -/* - * Copyright 1992,1993 Michael S. Warren. All Rights Reserved. - */ - -/* define this to skip the FIONREAD code entirely */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#ifndef FD_SET -/* Sigh. Where o' where is FD_SET found sys/types?, sys/select? */ -/* Unfortunately, sys/select doesn't always exist! */ -#include -#endif -#include "protos.h" -#include "lsv.h" -#include "error.h" -#include "Msgs.h" -#include "Assert.h" -#include "Malloc.h" - -#ifdef __DO_SWAP__ -/* There's probably a better way to do most of the multi-word swaps... */ -#include "byteswap.h" -static int _x, _y; -#define Swap(x) (_x=x, Byteswap(sizeof(int), 1, &_x, &_y), _y) -#else -#define Swap(x) x -#endif - -/* This test should be accomplished some other way!! */ -#if defined(USE_ALARM) && !( defined(__x86_64__) || defined(_AIX) || defined(__SUN5__) ) -#define HAVE_SIGVEC -#endif - -#if defined(__SUN4__) -/* These should really be prototyped somewhere else, - but this will do for now */ -int close(int); -int getpid(void); -#ifdef HAVE_SIGVEC -int sigvec(int sig, struct sigvec *vec, struct sigvec *ovec); -#endif -int ioctl(int fd, int cmd, void *p); -int gethostname(char *name, int namelen); -char *inet_ntoa(struct in_addr in); -int socket(int domain, int type, int protocol); -int bind(int s, struct sockaddr *name, int namelen); -int recvfrom(int s, void *buf, int len, int flags, - struct sockaddr *from, int *fromlen); -int sendto(int s, const void *msg, int len, - int flags, struct sockaddr *to, int tolen); -int select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout); -int getsockname(int s, struct sockaddr *name, int *namelen); -void bzero(char *b, int length); -#endif - -#if defined(__SUN5__) -/* This is a bsd-ism. It may not even exist everywhere?! */ -int gethostname(char *name, int namelen); -#endif - -#define MAXDEFER 4000 /* maximum number of messages deferred */ -#define HLEN (5*sizeof(int)) /* size of packet header */ -#define MAXLEN 8192 /* size of total packet */ -#define BLOCK (MAXLEN-HLEN) /* size of basic data packet */ -#define ACK_TYPE (-1) /* Message type for ack */ -#define H_MAGIC (0x9f07) /* Magic number for headers */ - -#define MAX_PORT_ATTEMPTS 150 /* Number of ports to try before giving up */ -#define LSV_TYPE 2 /* Type used to communicate with host */ -#define HOST_NUM (-1) /* can't redefine this without mem adjust. */ -#ifndef INADDR_NONE -#define INADDR_NONE -1 /* 'bad' return from inet_addr */ -#endif - -static int host_num = HOST_NUM; /* host integer address */ -static int my_pid; /* my process id */ -static unsigned int *seqout; /* array of outgoing sequence counters */ -static unsigned int *seqin; /* array of incoming sequence counters */ -static unsigned int *nretry; /* array of retry counts */ -static struct sockaddr_in host_addr; -static struct sockaddr_in my_addr; - -static int sock; /* file descriptor for my UDP socket */ -static struct sockaddr_in *addr; /* sockaddrs for all processors */ -static char *msgbuf[MAXDEFER]; /* pointers to deferred messages */ -static int msgcnt; /* number of deferred messages */ -#ifdef USE_ALARM -static volatile int failed; /* flag for recvfrom timeout */ -static void to_alarm(int); -#endif -static void sock_init(struct sockaddr_in *acc, int bind_flag); -static void common_init(const int n); -static int bsend(int s, const void *outbuf, int sent, int dest, int type); -static int brecv(int s, void *inb, int sent, int *dest, int type, int block); -static int chk_deferw(int type, int *src); -static void send_ack(int s, int dest, int seq, struct sockaddr_in *dest_addr); -static int chk_defer(int src, int type, int seq); - -int LSV_procnum; /* my integer address (procnum) */ -int LSV_nproc; /* how many 'elt's */ - -/* If hears nothing before its 'block' arg expires, it returns - BRECV_TIMEDOUT */ -#define BRECV_TIMEDOUT (-2) - -/* It sure would be nice to be able to set these at runtime!!! */ -/* TIMEOUT1 passed to brecv when we're 'blocking', i.e., from Srecv_block. */ -#define TIMEOUT1 200 -/* TIMEOUT2 is what we pass when we really expect something, i.e., when - we are waiting for subsequent blocks after we have received the first - one. */ -#define TIMEOUT2 50 -/* Srecv{_block} will allow retry brecv after a timeout this many - times before giving up altogether. */ -#define NRETRY 2 -/* Ssend waits for an ack from the recipient. It retries this many - times, incrementing the timer by one each time, so in the end, the - total time waited is ACK_NRETRY*(ACK_NRETRY+1)/2 seconds. Now that - the user code is free to use alarm, we can rely on the user to bail out - if things seem to be taking too long. Thus, we set this quite high. */ -#ifndef USE_ALARM -#define ACK_NRETRY 100 -#else -#define ACK_NRETRY 20 -#endif - -void -Sclose(void) -{ - close(sock); - /* Should we free some of the arrays??? */ -} - -void -Sinit_elt(void) -{ - int suspend_proc; - int pid; - int nin; - int size = sizeof(struct sockaddr_in); - int hostport; - char *hostip; - unsigned long inaddr; - - assert(getenv("LSV_PROCNUM") && getenv("LSV_NPROC") - && getenv("LSV_HOSTPORT") && getenv("LSV_HOST") ); - - LSV_procnum = atoi(getenv("LSV_PROCNUM")); - LSV_nproc = atoi(getenv("LSV_NPROC")); - hostip = getenv("LSV_HOST"); - hostport = atoi(getenv("LSV_HOSTPORT")); - - /* fill in host_addr here */ - memset(&host_addr, sizeof(host_addr), 0); - host_addr.sin_family = AF_INET; - /* Now try to figure out the host's address from hostname */ - /* Don't bother with gethostbyname here. Assume that the host - has worked out its preferred numeric IP address and passed that - to us through the environment var LSV_HOST */ - if ((inaddr = inet_addr(hostip)) != INADDR_NONE) /* it is numeric */ - host_addr.sin_addr.s_addr = inaddr; - else - Error("inet_addr(%s) failed, errno=%d\n", hostip, errno); - host_addr.sin_port = htons(hostport); - Msgf(("hostip: %s, host_addr.sin_addr %s, host_addr.sin_port: %d\n", - hostip, inet_ntoa(host_addr.sin_addr), ntohs(host_addr.sin_port))); - - sock_init(&host_addr, 0); /* get host sockaddr */ - sock_init(&my_addr, 1); /* get my sockaddr */ - Msgf(("my_addr.sin_addr: %s, my_addr.sin_port: %d\n", - inet_ntoa(my_addr.sin_addr), ntohs(my_addr.sin_port))); - - - common_init(LSV_nproc); - - Ssend(&my_addr, size, HOST_NUM, LSV_TYPE); /* send to host */ - - nin = Srecv_block(addr, LSV_nproc * size, LSV_TYPE, &host_num); - if (nin != LSV_nproc * size) - Error("Bad number of addrs received\n"); - - if( getenv("LSV_SUSPEND") && strlen(getenv("LSV_SUSPEND")) > 0 ){ - pid = getpid(); - suspend_proc = atoi(getenv("LSV_SUSPEND")); - if (suspend_proc == -1) /* suspend all */ - suspend_proc = LSV_procnum; - if (LSV_procnum == suspend_proc){ - Shout("suspending pid=%d, LSV_procnum=%d\n", - pid, LSV_procnum); - kill(pid, SIGSTOP); - } - } -} - -/* Sinit_host1 is called BEFORE the host forks off child processes. - It has to figure out its own port and hostname, so it can pass it - to the children in the environment. */ -void -Sinit_host1(int *portp, char **namep){ - char *p; - - sock_init(&host_addr, 1); - *portp = ntohs(host_addr.sin_port); - if( (p=getenv("LSV_HOST")) == NULL ){ - /* If there is no LSV_HOST in the environment, then ask the system */ - p = inet_ntoa(host_addr.sin_addr); - } - *namep = malloc(strlen(p)+1); - strcpy(*namep, p); -} - -/* Sinit_host is called after the host forks the child processes. - Its job is to communicate all the port info with them so they - can talk to one another directly. */ -void -Sinit_host(int n) /* n is how many nodes we talk to */ -{ - int i, nin; - int size = sizeof(struct sockaddr_in); - - common_init(n); - Msgf(("After common_init\n")); - LSV_procnum = HOST_NUM; - - for (i = 0; i < n; i++) { - nin = Srecv_block(&addr[i], size, LSV_TYPE, &i); - if (nin != size) - Error("Bad recv size (%d) in Sinit_host, i=%d\n", nin, i); - Msgf(("Received addr[%d]: family: %d, port: %d, addr: %s\n", - i, addr[i].sin_family, ntohs(addr[i].sin_port), - inet_ntoa(addr[i].sin_addr))); - } - Msgf(("All sockaddrs received. Broadcasting to compute processes\n")); - for (i = 0; i < n; i++) { - Ssend(addr, n * size, i, LSV_TYPE); - Msgf(("Sent addrs to %d\n", i)); - } -} - -static void -common_init(const int n) -{ -#if defined(HAVE_SIGVEC) - struct sigvec vec; -#endif - - /* to enforce sequencing */ - seqin = (unsigned int *) calloc(n+1, sizeof(unsigned int)); - seqout = (unsigned int *) calloc(n+1, sizeof(unsigned int)); - nretry = (unsigned int *) calloc(n+1, sizeof(unsigned int)); - addr = (struct sockaddr_in *) calloc(n+1, sizeof(struct sockaddr_in)); - if (seqin == NULL || seqout == NULL || nretry == NULL || addr == NULL) - Error("No more memory in Sinit\n"); - seqin++; /* allow indexing [-1:n-1] */ - seqout++; - nretry++; - addr++; - - /* We use the convention that 0, ..., n-1 are nodes, and -1 is the host */ - addr[HOST_NUM] = host_addr; /* struct assignment */ - my_pid = getpid(); - -#ifdef USE_ALARM -#if defined (HAVE_SIGVEC) - vec.sv_handler = to_alarm; - vec.sv_flags = SV_INTERRUPT; - vec.sv_mask = 0; - sigvec(SIGALRM, &vec, NULL); -#else - signal(SIGALRM, to_alarm); -#endif /* HAVE_SIGVEC */ -#endif /* USE_ALARM */ - -} - -#ifdef USE_ALARM -static void -to_alarm(int sig) -{ - assert( sig == SIGALRM ); - failed = 1; - signal(SIGALRM, to_alarm); -} -#endif - -/* dest should be last argument */ - -void -Ssend(const void *outb, int outcnt, int dest, int type) -{ - int sent; - const char *buf = outb; - int ret; - - Msgf(("Ssend: (%d) to %d len %d\n", type, dest, outcnt)); - do { - sent = (outcnt > BLOCK) ? BLOCK : outcnt; - ret = bsend(sock, buf, sent, dest, type); - if( ret < 0 ){ - Error("Ssend: bsend failed, type=%d, dest=%d, outcnt=%d\n", - type, dest, outcnt); - } - outcnt -= sent; - buf += sent; - } while (outcnt || sent == BLOCK); -} - -int -Srecv(void *inb, int size, int type, int *from) -{ - int sent, inbytes = 0; - char *buf = inb; - int timeout; - int verbose = 0; - - /* Only the first brecv is non-blocking. We wait for the rest. */ - sent = brecv(sock, buf+inbytes, size, from, type, 0); - if( sent < 0 ){ - if( sent == BRECV_TIMEDOUT ){ - return -1; /* nothing available, not an error! */ - } - Error("First brecv failed in Srecv, errno=%d\n", errno); - } - - inbytes += sent; - size -= sent; - timeout = TIMEOUT2; - while(sent == BLOCK){ - tryagain: - sent = brecv(sock, buf+inbytes, size, from, type, timeout); - if( sent < 0 ){ - if( sent == BRECV_TIMEDOUT ){ - Warning("Srecv: brecv timed out, will wait indefinitely now\n"); - verbose = 1; - timeout = -1; - goto tryagain; - } - Error("brecv failed in Srecv, inbytes=%d, errno=%d\n", - inbytes, errno); - } - inbytes += sent; - size -= sent; - } - if( verbose || Msg_test(__FILE__) ) - Msg_do("Srecv: (%d) from %d ret %d\n", type, *from, inbytes); - return(inbytes); -} - -/* last arg should not be a pointer */ - -int -Srecv_block(void *inb, int size, int type, int *from) -{ - int sent, inbytes = 0; - char *buf = inb; - int timeout = TIMEOUT1; - int verbose = 0; - - do { - tryagain: - sent = brecv(sock, buf+inbytes, size, from, type, timeout); - if( sent < 0 ){ - if( sent == BRECV_TIMEDOUT ){ - Warning("Srecv_block: brecv(size=%d, from=%d, type=%d, timeout=%d) timed out, inbytes=%d, errno=%d\n", - size, *from, type, timeout, - inbytes, errno); - timeout = -1; - verbose = 1; - goto tryagain; - } - return -1; - } - inbytes += sent; - size -= sent; - timeout = TIMEOUT2; - } while (sent == BLOCK); - if( verbose || Msg_test(__FILE__) ) - Msg_do("Srecv_block: (%d) from %d ret %d\n", type, *from, inbytes); - return(inbytes); -} - -void Sdiag(int (*printf_like)(const char *, ...)){ - int i; - int *buf; - printf_like("lsv.c: counters to and from various destinations\n[dest seqout[dest] seqin[dest] nretry[dest]]\n"); - for(i=-1; i ACK_NRETRY ){ - SeriousWarning("bsend timed out %d times waiting for ack\n", - retry); - return -1; - } - verbose = 1; - goto try_again; - } - if( verbose || Msg_test(__FILE__) ) - Msg_do("bsend ackrecv ready\n"); - - memset(&src_addr, 0, sizeof(struct sockaddr_in)); - incnt = recvfrom(s, (void *)inbuf, MAXLEN, 0, (struct sockaddr *)&src_addr, &len); -#else - memset(&src_addr, 0, sizeof(struct sockaddr_in)); - failed = 0; - alarm(1+retry); - errno = 0; - incnt = recvfrom(s, inbuf, MAXLEN, 0, (struct sockaddr *)&src_addr, &len); - if (failed) { - Msgf(("retry, errno=%d\n", errno)); - if (retry > ACK_NRETRY) { - SeriousWarning("bsend timed out on ack, errno=%d\n", errno); - return -1; - } - goto try_again; - } - alarm(0); -#endif - - if (incnt < 0) { - Warning("recvfrom(ack from %d) returns %d, errno=%d\n", dest, incnt, errno); - if(nfail++ > 5){ - SeriousWarning("recvfrom(ack from %d) returns %d, errno=%d\n", dest, incnt, errno); - return -1; - } - goto try_again; - } - if (Swap(inbuf[0]) != H_MAGIC) { - Warning("Bad header in bsend\n"); - goto ackrecv; - } - -#ifdef __DO_SWAP__ - inbuf[1] = Swap(inbuf[1]); - inbuf[2] = Swap(inbuf[2]); - inbuf[3] = Swap(inbuf[3]); - inbuf[4] = Swap(inbuf[4]); -#endif - - src = inbuf[1]; - seq = inbuf[2]; - intype = inbuf[3]; - inlen = inbuf[4]; - - if (intype != ACK_TYPE) { /* got a data packet */ - if (seq < seqin[src]) - Msgf(("aignore2 %d from %d ", seq, src)); - else if (chk_defer(src, intype, seq) > -1) - Msgf(("aignore %d from %d ", seq, src)); - else { - msgbuf[msgcnt] = Malloc((incnt+8)&~07); - memcpy(msgbuf[msgcnt], inbuf, incnt); - msgcnt++; - if (msgcnt >= MAXDEFER) Error("msgcnt too large\n"); - Msgf(("adefer seq:%d type:%d, len:%d from %d ", - seq, intype, inlen, src)); - } - send_ack(s, src, seq, &src_addr); - goto ackrecv; - } else { - if (incnt != HLEN) - Warning("Bad incnt, errno=%d", errno); - else if (dest != src || seq != seqout[dest]) - Msgf(("aduplicate ack %d from %d ", seq, src)); - else { - Msgf(("ack seq: %d, dest: %d\n", seq, dest)); - seqout[dest]++; - return (sent-HLEN); - } - goto ackrecv; - } -} - -/* Block is a timeout. We treat a negative value as meaning to block - forever*/ -static int -brecv(int s, void *inb, int sent, int *dest, int type, int block) -{ - int src, seq, incnt; - struct sockaddr_in src_addr; - int len = sizeof(struct sockaddr_in); - int inlen, i; - int intype; - int inbuf[(BLOCK+HLEN)/sizeof(int)]; - fd_set rdset; - struct timeval timeout, *timeoutp; - int selreturn; - - Msgf(("brecv(sent=%d, dest=%d, type=%d, block=%d)\n", - sent, *dest, type, block)); - if (*dest == LSV_ANY) - i = chk_deferw(type, &src); /* sets src */ - else - i = chk_defer(*dest, type, seqin[*dest]); - if (i != -1) { - if (*dest == LSV_ANY) *dest = src; - inlen = *(int *)(msgbuf[i]+4*sizeof(int)); - if (inlen > sent) Error("Too much data\n"); - memcpy(inb, msgbuf[i]+HLEN, inlen); - Free(msgbuf[i]); - msgbuf[i] = msgbuf[--msgcnt]; - Msgf(("brecv %d (%d) from %d.\n", seqin[*dest], type, *dest)); - seqin[*dest]++; - return(inlen); - } - - datrecv: - if( block >= 0 ){ - timeout.tv_sec = block; - timeout.tv_usec = 0; - timeoutp = &timeout; - }else{ - timeoutp = NULL; - } - FD_ZERO(&rdset); - FD_SET(s, &rdset); - selreturn = select(s+1, &rdset, NULL, NULL, timeoutp); - if( selreturn < 0 ){ - if (errno == EINTR) - goto datrecv; /* SIGPROF interrupts select */ - else { - SeriousWarning("select failed, errno=%d\n", errno); - return -1; - } - }else if(selreturn == 0){ - return BRECV_TIMEDOUT; - } - Msgf(("brecv any (%d)...", type)); - - memset(&src_addr, 0, sizeof(struct sockaddr_in)); - /* What's the best thing to do here if we timed out? - return? goto datrecv? something else?*/ - incnt = recvfrom(s, (void *)inbuf, MAXLEN, 0, (struct sockaddr *)&src_addr, &len); - - if (incnt < 0) { - Warning("brecv: recvfrom, errno=%d", errno); - goto datrecv; - } - if (Swap(inbuf[0]) != H_MAGIC) { - Warning("Bad header in brecv (%x,%x,%x,%x), incnt %d\n", - Swap(inbuf[0]), Swap(inbuf[1]), Swap(inbuf[2]), Swap(inbuf[3]), - incnt); - goto datrecv; - } - -#ifdef __DO_SWAP__ - inbuf[1] = Swap(inbuf[1]); - inbuf[2] = Swap(inbuf[2]); - inbuf[3] = Swap(inbuf[3]); - inbuf[4] = Swap(inbuf[4]); -#endif - - src = inbuf[1]; - seq = inbuf[2]; - intype = inbuf[3]; - inlen = inbuf[4]; - - Msgf((" [%d, %d, %d, %d] ", src, seq, intype, inlen)); - - if (intype == ACK_TYPE) { - Msgf(("duplicate ack %d from %d ", seq, src)); - goto datrecv; - } - else if (inlen != incnt-HLEN) { - Shout("Bad inlen in bsend, errno=%d", errno); - goto datrecv; - } - else if (type == intype && seq == seqin[src] && - (*dest == src || *dest == LSV_ANY)) { - if (*dest == LSV_ANY) { - *dest = src; - Msgf(("%d from %d ", seq, src)); - } - send_ack(s, src, seq, &src_addr); - if (inlen > sent) Error("Too much data\n"); - memcpy(inb, inbuf+HLEN/sizeof(int), inlen); - seqin[src]++; - return(inlen); - } else { - if (seq < seqin[src]) - Msgf(("ignore2 %d from %d ", seq, src)); - else if (chk_defer(src, intype, seq) > -1) - Msgf(("ignore3 %d from %d ", seq, src)); - else if (src != *dest || type != intype || seq != seqin[src]) { - msgbuf[msgcnt] = Malloc((incnt+8)&~07); - memcpy(msgbuf[msgcnt], inbuf, incnt); - msgcnt++; - if (msgcnt >= MAXDEFER) Error("msgcnt too large\n"); - Msgf(("defer %d (%d) seqin[%d]=%d ", seq, intype, src, seqin[src])); - } - send_ack(s, src, seq, &src_addr); - goto datrecv; - } -} - -static int -chk_defer(int src, int type, int seq) -{ - int i, insrc, inseq, intype; - - Msgf(("chk_defer(src=%d, type=%d, seq=%d)\n", src, type, seq)); - for (i = 0; i < msgcnt; i++) { - insrc = *(int *)(msgbuf[i]+sizeof(int)); - inseq = *(int *)(msgbuf[i]+2*sizeof(int)); - intype = *(int *)(msgbuf[i]+3*sizeof(int)); - if (src == insrc && type == intype && seq == inseq){ - Msgf(("deferred match: msgbuf[%d]\n", i)); - return(i); - } - } - Msgf(("no match\n")); - return(-1); -} - -static int -chk_deferw(int type, int *src) -{ - int i, insrc, inseq, intype; - - for (i = 0; i < msgcnt; i++) { - insrc = *(int *)(msgbuf[i]+sizeof(int)); - inseq = *(int *)(msgbuf[i]+2*sizeof(int)); - intype = *(int *)(msgbuf[i]+3*sizeof(int)); - if (type == intype && inseq == seqin[insrc]) { - *src = insrc; - return(i); - } - } - return(-1); -} - -static void -send_ack(int s, int dest, int seq, struct sockaddr_in *dest_addr) -{ - int ack[HLEN/sizeof(int)]; - - ack[0] = Swap(H_MAGIC); - ack[1] = Swap(LSV_procnum); - ack[2] = Swap(seq); - ack[3] = Swap(ACK_TYPE); - ack[4] = Swap(0); - if (sendto(s, (void *)ack, HLEN, 0, (struct sockaddr *)dest_addr, - sizeof(struct sockaddr_in)) != HLEN) - Warning("sendto, errno=%d", errno); - else - Msgf(("acked\n")); -} - -static void -sock_init(struct sockaddr_in *acc, int bind_flag) -{ - sock = socket(AF_INET, SOCK_DGRAM, 0); - if( sock < 0 ){ - Error("socket failed, errno=%d\n", errno); - } -#ifdef SOCKBUF - { - int sockbuf; - /* These appear not to be supported on the delta */ - sockbuf= SOCKBUF; - if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &sockbuf, sizeof(int))) { - SeriousWarning("sockopt sndbuf, errno=%d", errno); - exit(1); - } - if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &sockbuf, sizeof(int))) { - SeriousWarning("sockopt rcvbuf, errno=%d", errno); - exit(1); - } - } -#endif - - if (bind_flag) { - int ret; - int len = sizeof(struct sockaddr_in); - char hostname[256]; - struct hostent *hp; - char *p; - - /* If we're being asked to do a 'bind', then that implies that - we should fill in the sockaddr as well */ - memset(acc, 0, sizeof(struct sockaddr_in)); - acc->sin_family = AF_INET; - acc->sin_addr.s_addr = INADDR_ANY; - acc->sin_port = 0; /* INADDR_ANY? */ - ret = bind(sock,(struct sockaddr *)acc,sizeof(struct sockaddr_in)); - if (ret < 0 ) { - Error("LSV: Can't bind socket. errno=%d\n", - errno); - } - if( getsockname(sock, (struct sockaddr *)acc, &len) ){ - Error("LSV: Can't getsockname. errno=%d\n", errno); - } - - /* Unfortunately, getsockname doesn't replace INADDR_ANY - with a valid saddr_in. We should be able to overrule - gethostname with an env var or a cmd-line arg */ - if( (p = getenv("LSV_MYNAME")) ){ - strncpy(hostname, p, sizeof(hostname)); - }else{ - if( gethostname(hostname, sizeof(hostname)) ) - Error("gethostname failed, errno=%d\n", errno); - } - hostname[sizeof(hostname)-1] = '\0'; - if( (hp = gethostbyname(hostname)) == NULL ) - Error("gethostbyname(%s) failed\n", hostname); - memcpy(&(acc->sin_addr), hp->h_addr, hp->h_length); - - /* Now acc holds 'correct' info about the socket */ - Msgf(("Bound port %d\n", ntohs(acc->sin_port))); - errno = 0; /* clear errors */ - } -} diff --git a/external/libsdf/libsw/malloc.c b/external/libsdf/libsw/malloc.c deleted file mode 100644 index 8db5f9f..0000000 --- a/external/libsdf/libsw/malloc.c +++ /dev/null @@ -1,1067 +0,0 @@ -/* Combine malloc.c, prt_mem.c and _malloc.h into one file. */ -/* Then remove abort() in favor of Error(). - johns, 12/24/92*/ - -/* Throw out the whole thing if USE_SYSTEM_MALLOC is defined. */ -#ifdef USE_SYSTEM_MALLOC -#include -#include -#include -#include -#include "Msgs.h" -#ifndef __INSIGHT__ -int malloc_debug(int i){ return -1; } -int malloc_verify(void){return 0;} -void malloc_print(void){Msg_do("Can't print malloc structures for system malloc\n");} -#endif -size_t malloc_avail(void){return -1;} - -size_t -malloc_heapsz(void) -{ - char fname[128]; - char line[128]; - FILE *fp; - int ret; - size_t size = 0; - - sprintf(fname, "/proc/%d/status", getpid()); - if ((fp = fopen(fname, "r")) == NULL) return 0; - while (fgets(line, sizeof(line), fp)) { - ret = sscanf(line, "VmPeak: %ld kB", &size); - if (ret == 1) break; - } - fclose(fp); - return size*1024; -} - -size_t -malloc_used(void) -{ - char fname[128]; - char line[128]; - FILE *fp; - int ret; - size_t size = 0; - - sprintf(fname, "/proc/%d/status", getpid()); - if ((fp = fopen(fname, "r")) == NULL) return 0; - while (fgets(line, sizeof(line), fp)) { - ret = sscanf(line, "VmRSS: %ld kB", &size); - if (ret == 1) break; - } - fclose(fp); - return size*1024; -} - - - -/* Do not define malloc, calloc, realloc or free!!! */ - -#else /* USE_SYSTEM_MALLOC */ - -#include -#include -#include -#include -#include "malloc.h" -#include "protos.h" -#include "Msgs.h" -#include "error.h" - -#define ALIGN 8 - -/* Knuth's_c must be >= (sizeof(fheader_t) + sizeof(aheader_t)) */ -/* See p. 438 of Knuth, and the soln to exercise 12. */ -/* When equal to the above amount, */ -/* the control data in a free block created */ -/* at the end of a not-quite-filled block completely fills the block. */ -/* Since an aheader_t is smaller than an fheader_t, you can still */ -/* get it if you ask for <= (sizeof(fheader_t) - sizeof(aheader_t)) */ - -#define KNUTHS_C (sizeof(fheader_t) + sizeof(aheader_t)) -#define FREE '-' -#define INUSE '+' - -/* The CHUNKSIZE is the amount of memory allocated */ -/* by each call to sbrk. It should be reasonably large, */ -/* but not so large that it is likely to fail. */ -#ifdef __NCUBE1__ -#define CHUNKSIZE (16*1024) -#else -#define CHUNKSIZE (256*1024*1024) -#endif - -/* MAXCHUNKS is the maximum number of chunks */ -/* that may be obtained. The value is used */ -/* exclusively for the size of an array with */ -/* information describing each chunk. With a */ -/* little cleverness, we could chain the chunks */ -/* together, but it hardly seems worth it since */ -/* the only purpose of this information is to */ -/* allow debugging/printing of diagnostics. */ -/* Now that chunks get coallesced when sbrk has */ -/* not been called by the user, there is even less */ -/* reason for MAXCHUNKS to be large... */ -#define MAXCHUNKS 8 - -/* If any of these typedefs are changed, be sure that */ -/* sizeof(header_t) and sizeof(trailer_t) both are multiples */ -/* of ALIGN */ - -typedef int tag_t; - -/* An aheader is the header at the beginning of an */ -/* allocated block. It must be identical to an fheader, */ -/* except that allocated fields don't need linking info */ -/* WARNING: If this struct is changed, it must also be */ -/* changed in ../stdio/prt_mem.c!!!! */ -typedef struct aheader{ - tag_t tag; - size_t size; -} aheader_t ; - -typedef struct fheader{ - tag_t tag; /* The tag is a single bit */ - size_t size; /* it should be merged into size */ - struct fheader *link; - struct fheader *prev; -} fheader_t; - -typedef struct trailer{ - tag_t tag; - size_t size; -} trailer_t; - - -/* Each piece of memory is preceded by a header, and followed */ -/* by a trailer. If the piece is a free block, the tag fields */ -/* in the header and trailer are FREE, otherwise, they are INUSE */ -/* For free blocks, the size field in the trailer is valid, but it */ -/* is not necessarily valid for allocated blocks. */ -/* The point of all this is to make freeing an object take */ -/* constant time. One can examine the trailer that immediately */ -/* precedes the to-be-freed object, and determine whether the */ -/* block immediately below should be coalesced. Similarly for */ -/* the block immediately above. */ - -/* The avail fheader_t is special. Its link field */ -/* points to the front of the free list. Its prev field */ -/* points to the end of the free list, and its space field */ -/* contains the total available space in the free list, so */ -/* mall_avail runs quickly. Unfortunately, mall_avail can't*/ -/* give any info about fragmentation. It also doesn't */ -/* call getrlimit, although it might be useful to ask the */ -/* OS exactly how much farther we will be able to extend */ -/* memory. */ - -/* Export */ -/* In addition to malloc, calloc, realloc, free */ -char malloc_errstring[256]; -int malloc_verify(void); -void malloc_print(void); -int malloc_debug(int); - -/* The avail fheader_t is special. Its link field */ -/* points to the front of the free list. Its prev field */ -/* points to the end of the free list, and its space field */ -/* contains the total available space in the free list, so */ -/* mall_avail runs quickly. Unfortunately, mall_avail can't*/ -/* give any info about fragmentation. */ - -static fheader_t avail = { - FREE, /* tag */ - 0, /* size */ - &avail, /* link */ - &avail /* prev */ -}; - -/* The last entry in the chunk_tbl is special */ -struct _chunk_desc{ - size_t size; - void *begin; -}; - -static fheader_t *rover = &avail; -static size_t chunksize = CHUNKSIZE; -static int debug_lev = 1; -static int debug_verify; -static int debug_abort_nomem; -static int debug_test; -static fheader_t *top_of_mem, *bottom_of_mem; -static int n_free_blocks; -static struct _chunk_desc _chunk_tbl[MAXCHUNKS + 1]; -static int _nchunks; - -static int extend_mem(size_t n); -static int verify_blk(fheader_t *p); - -/* We use these system-dependent functions. */ -extern void *sbrk(int incr); -extern int brk(void *addr); -static void *getmaxbrk(void); - -void -*calloc(size_t nmemb, size_t size) -{ - void *p; - - /* What are we supposed to do here??? Should we round up the size */ - /* so all elements are aligned? I don't think so, but I'm not */ - /* confident. */ -/* - if(size > 1 && size % ALIGN) - size += ALIGN - size%ALIGN; -*/ - - p = malloc(size*nmemb); - if(p) - (void)memset(p, 0, size*nmemb); - return p; -} - -void -*malloc(size_t size) -/* Implement Knuth's Algorithm A, modified for doubly linked */ -/* lists, and using the A4' step to avoid small blocks. */ -/* It may be found on p. 598 in the soln. to problem 12. */ -{ - size_t N, k; - int looped; - fheader_t *p, *p1; - aheader_t *L; - trailer_t *trl; - size_t askfor; - int got; - - if(debug_verify && malloc_verify()){ - Error("bad malloc structures: %s\n", malloc_errstring); - } - - if(size == 0) - return (void *)0; - - if(size%ALIGN) - size += ALIGN - size%ALIGN; - - /* If we allocate a block that's too small, we will have */ - /* BIG problems when we try to free it!! */ - if(size + sizeof(aheader_t) < sizeof(fheader_t)) - N = sizeof(fheader_t) + sizeof(trailer_t); - else - N = size + sizeof(aheader_t) + sizeof(trailer_t); - p = rover; - looped = 0; - while(p->size < N || p == &avail){ - if(p == &avail){ - if(looped){ - askfor = (Nlink; - } - - if(debug_test && verify_blk(p)){ - Error("Bad block (%#lx) in malloc: %s\n", - (unsigned long)p, malloc_errstring); - return (void *)0; - } - rover = p->link; - k = p->size - N; -#if 0 - /* This code allocates the new block at the top of */ - /* the free block. This has very bad consequences */ - /* for fragmentation when sbrk is called many times */ - /* to get new chunks. Thus, the improved code below. */ - if(k < KNUTHS_C){ - avail.size -= p->size; - p->prev->link = rover; - rover->prev = p->prev; - L = (aheader_t *)p; - n_free_blocks--; - }else{ - /* Here, we split the large block */ - avail.size -= N; - p->size = k; - L = (aheader_t *)((char *)p + k); - trl = (trailer_t *)L - 1; - trl->size = k; - trl->tag = FREE; - L->size = N; - } - L->tag = INUSE; - trl = (trailer_t *)((char *)L + L->size) - 1; - trl->tag = INUSE; - trl->size = L->size; -#else - L = (aheader_t *)p; - if(k < KNUTHS_C){ - avail.size -= p->size; - p->prev->link = rover; - rover->prev = p->prev; - n_free_blocks--; - }else{ - /* Here, we split a large free block into an allocated block */ - /* and a smaller free block. */ - /* Knuth's method is considerably easier, since */ - /* it leaves the free block essentially alone. There */ - /* is no need to poke around in the free list and fix pointers */ - /* Undoubtedly, the correct thing is to make the linked lists */ - /* out of the trailers instead... Maybe in some other life */ - avail.size -= N; - L->size = N; - p1 = (fheader_t *)((char *)L + N); - p1->tag = FREE; - p1->size = k; - p1->link = p->link; - p1->prev = p->prev; - p->prev->link = p1; - p->link->prev = p1; - trl = (trailer_t *)((char *)p1 + k) - 1; - trl->size = k; - /* the tag is FREE already */ - } - L->tag = INUSE; - trl = (trailer_t *)((char *)L + L->size) - 1; - trl->tag = INUSE; - trl->size = L->size; -#endif - return (void *)(L+1); -} - -void -*realloc(void *ptr, size_t size) -{ - void *ret; - aheader_t *p0; - fheader_t *p, *p1, *p2; - trailer_t *trl, *trl0; - size_t N; - size_t ptrsz; - int k; - - if(debug_verify && malloc_verify()){ - Error("Bad structures in realloc: %s\n", malloc_errstring); - return (void *)0; - } - - if(size == 0){ - if(ptr) - free(ptr); - return (void *)0; - } - - if(ptr == (void *)0) - return malloc(size); - - if(size%ALIGN) - size += ALIGN - size%ALIGN; - - /* If we allocate a block that's too small, we will have */ - /* BIG problems when we try to free it!! */ - if(size + sizeof(aheader_t) < sizeof(fheader_t)) - N = sizeof(fheader_t) + sizeof(trailer_t); - else - N = size + sizeof(aheader_t) + sizeof(trailer_t); - - /* This code is very similar to that in free. */ - /* They should probably be combined in a common subroutine */ - - p0 = (aheader_t *) ((aheader_t *)ptr - 1); - /* How much data is actuall stored under ptr??? */ - /* I think this is correct even for 'small' N */ - ptrsz = p0->size - (sizeof(aheader_t) + sizeof(trailer_t)); - p = (fheader_t *)((char *)p0 + p0->size); - if(debug_test && verify_blk(p)){ - Error("Bad blk (%#lx) in realloc: %s\n", - (unsigned long)p, malloc_errstring); - return (void *)0; - } - if(p->tag == FREE){ - /* The next block is free. Combine them */ - p1 = p->link; - p2 = p->prev; - p1->prev = p2; - p2->link = p1; - p0->size += p->size; - avail.size -= p->size; - /* p just got removed from the free list. */ - /* Make sure it's not equal to rover */ - if(p == rover) - rover = &avail; - p = (fheader_t *)( (char *)p + p->size ); - trl = (trailer_t *)p - 1; - trl->tag = INUSE; - trl->size = p0->size; - n_free_blocks--; - } - - trl = (trailer_t *)p0 -1; -#ifdef UNFRAGMENT - /* Combine this block and the one before it whenever possible */ - if(trl->tag == FREE && (trl->size + p0->size) > N){ -#else - /* Only combine this block with the one before it if we don't have */ - /* enough space yet. */ - if(trl->tag == FREE && (p0->size < N) && (trl->size + p0->size) > N){ -#endif - /* In the event that the previous blk is free, and it doesn't meet */ - /* our needs, we will coalesce it when the current block */ - /* is freed, postponing any irreversible damage until after */ - /* new space has been successfully found */ - p = (fheader_t *)((char *)p0 - trl->size); - p1 = p->link; - p2 = p->prev; - p1->prev = p2; - p2->link = p1; - avail.size -= p->size; - p->size += p0->size; - /* p just got removed from the free list. */ - /* Make sure it's not equal to rover */ - if(p == rover) - rover = &avail; - /* Copy the data from p0 to p */ - if( (char *)((aheader_t*)p+1) < (char *)ptr - ptrsz ) - memcpy(((aheader_t *)p+1), ptr, ptrsz); - else - memmove(((aheader_t *)p+1), ptr, ptrsz); - p->tag = INUSE; - p0 = (aheader_t *)p; - trl0 = ((trailer_t *)((char *)p + p->size)) -1; - trl0->size = p->size; - n_free_blocks--; - } - - if(debug_test && verify_blk((fheader_t *)p0)){ - Error("Bad block (p0) (%#lx) in realloc: %s\n", - (unsigned long)p0, malloc_errstring); - return (void *)0; - } - k = p0->size - N; - if(k<0){ - ret = malloc(size); - if(ret){ - memcpy(ret, ptr, p0->size - sizeof(aheader_t)-sizeof(trailer_t)); - free(ptr); - }else if(debug_abort_nomem){ - Error("Out of mem in realloc\n"); - } - /* Fortunately, we didn't combine the preceding block */ - /* with the given block unless we were sure that would */ - /* result in enough space. Thus, we didn't molest the data */ - /* or the list structures in any way that would need to */ - /* be reversed. */ - return ret; - }else if(k >= KNUTHS_C){ - /* First, shrink this node. */ - p0->size = N; - p1 = (fheader_t *)((char *)p0 +N); - trl = (trailer_t *)p1 - 1; - trl->tag = INUSE; - trl->size = N; - /* then create a new free node at the top of this block */ - n_free_blocks++; - avail.size += k; - p1->size = k; - p1->tag = FREE; - p1->link = avail.link; - p1->prev = &avail; - avail.link->prev = p1; - avail.link = p1; - trl = (trailer_t *) ((char *)p1 + k) -1; - trl->tag = FREE; - trl->size = k; - }/* else there is nothing to do. The change is not significant */ - return (void *)((aheader_t *)p0 + 1); -} - -void -free(void *ptr) -/* Implement Knuth's Algorithm C, p. 442 */ -{ - fheader_t *p, *p0, *p1, *p2; - trailer_t *trl; - - if(debug_verify && malloc_verify()){ - Error("Bad structures in free: %s\n", malloc_errstring); - return; - } - - if(ptr == (void *)0) - return; - - p0 = (fheader_t *) ((aheader_t *)ptr - 1); - if(debug_test && verify_blk(p0)){ - Error("Bad block (%#lx) in free: %s\n", - (unsigned long)p0, malloc_errstring); - } - trl = (trailer_t *)p0 -1; - avail.size += p0->size; - if(trl->tag == FREE){ - /* The preceding block is free. Combine them */ - p = (fheader_t *)((char *)p0 - trl->size); - p1 = p->link; - p2 = p->prev; - p1->prev = p2; - p2->link = p1; - p->size += p0->size; - /* p just got removed from the free list. */ - /* Make sure it's not equal to rover */ - if(p == rover) - rover = &avail; - p0 = p; - n_free_blocks--; - } - - p = (fheader_t *)((char *)p0 + p0->size); - if(debug_test && verify_blk(p)){ - Error("Bad block (p) (%#lx) in free: %s\n", - (unsigned long)p, malloc_errstring); - } - if(p->tag == FREE){ - /* The anteceding block is free. Combine them */ - p1 = p->link; - p2 = p->prev; - p1->prev = p2; - p2->link = p1; - p0->size += p->size; - /* p just got removed from the free list. */ - /* Make sure it's not equal to rover */ - if(p == rover) - rover = &avail; - p = (fheader_t *)( (char *)p + p->size ); - n_free_blocks--; - } - - /* link the new block into the front of the avail list */ - trl = (trailer_t *)p - 1; - trl->size = p0->size; - trl->tag = FREE; - p0->link = avail.link; - p0->prev = &avail; - avail.link->prev = p0; - avail.link = p0; - p0->tag = FREE; - n_free_blocks++; -} - - -size_t -malloc_avail(void) -{ - /* The space unallocated in the blocks we have appropriated, */ - /* minus the space left that the OS will give us. */ - /* If the OS won't tell us, we have to return -1, which is */ - /* more likely to mean we don't know than that there is none! */ - void *memlim = getmaxbrk(); - void *curtop = sbrk(0); - - if((long)memlim == -1 || (long)curtop == -1) - return -1; - return avail.size + ((char *)memlim - (char *)curtop); -} - -size_t -malloc_heapsz(void) -{ - void *curtop = sbrk(0); - return((long)curtop - (long)_chunk_tbl[0].begin); -} - -size_t -malloc_used(void) -{ - return malloc_heapsz()-avail.size; -} - - -static int -extend_mem(size_t n) -/* Try to obtain a block of at least size n */ -/* from the OS using sbrk. Return the size */ -/* of the block actually obtained. */ -{ - trailer_t *trl0; - aheader_t *hdr0; - aheader_t *hdr1; - fheader_t *hdr; - trailer_t *trl; - char *old_top; - void *max_brk, *begin; - - Msgf(("extend_mem(%ld)\n", (long)n)); - /* Check structure sizes */ - if (sizeof(aheader_t) % ALIGN != 0) - Error("sizeof(aheader_t) (%d) not multiple of ALIGN (%d)\n", - (int)sizeof(aheader_t), ALIGN); - if (sizeof(aheader_t) != sizeof(trailer_t)) - Error("sizeof(aheader_t) (%d) != sizeof(trailer_t) (%d)\n", - (int)sizeof(aheader_t), (int)sizeof(trailer_t)); - /* First, try to get a chunk of memory */ - /* If the system won't give us one of the */ - /* size we ask for, then halve the size */ - /* until we get something */ - - /* Technically, sbrk returns a caddr_t, which */ - /* is typedef'ed to be a char *. It returns */ - /* an error condition, however, by returning the */ - /* integer -1, so the casts are necessary. */ - while (1) { - if(n < (sizeof(fheader_t) + sizeof(trailer_t))) { - Error("no more memory!\n"); - } - begin = sbrk(n + sizeof(aheader_t) +sizeof(trailer_t)); - if ((long int)begin != -1L) break; - Msgf(("sbrk(%ld) returns -1\n", - (long)(n+sizeof(aheader_t) + sizeof(trailer_t)))); - n = n/2; - } - old_top = (char *)top_of_mem; - if(bottom_of_mem == 0){ - /* The first time through here, remember the lowest possible */ - /* malloc'ed location */ - bottom_of_mem = (fheader_t *)(begin); - } - /* Assume sbrk is strictly increasing, so the end of memory */ - /* is represented by the end of the most recent sbrk call */ - top_of_mem = (fheader_t *)((char*)begin + n+sizeof(aheader_t)+sizeof(trailer_t)); - - if(begin == old_top){ - /* put a fake INUSE block at the top */ - Msgf(("Adding extended mem to previous chunk\n")); - hdr1 = ((aheader_t *)top_of_mem) - 1; - hdr1->size = sizeof(aheader_t); - hdr1->tag = INUSE; - /* Now change the hdr that used to be at the top of memory */ - hdr0 = ((aheader_t *)old_top) - 1; - hdr0->tag = INUSE; - hdr0->size = n + sizeof(aheader_t) + sizeof(trailer_t); - /* Now put a consistent trailer at the end of it */ - trl0 = ((trailer_t *)hdr1) - 1; - trl0->tag = INUSE; - trl0->size = hdr0->size; - /* And now free it to connect it with the free-list */ - /* This might change trl0->size */ - free((void *)(hdr0 + 1)); - /* Finally, record that the chunk has grown */ -#if 0 /* wrong? */ - _chunk_tbl[_nchunks-1].size += n + sizeof(trailer_t); -#else - _chunk_tbl[_nchunks-1].size += n+sizeof(aheader_t)+sizeof(trailer_t); -#endif - Msgf(("extend_mem returns %lu\n", (unsigned long)trl0->size)); - return trl0->size; - } - - /* Now we've got a big chunk of memory */ - /* Prepare it by placing INUSE markers at */ - /* both ends, and a header after the INUSE */ - /* marker at the beginning. */ - trl0 = (trailer_t *)begin; - trl0->tag = INUSE; - hdr0 = (aheader_t *)((char *)begin + n + sizeof(trailer_t)); - hdr0->tag = INUSE; - /* WARNING! These two lines will keep verify_blk happy */ - /* if it is asked to verify the markers at the beginning */ - /* and end of memory. They RELY ON THE FACT that: */ - /* sizeof(header_t) == sizeof(trailer_t) */ - hdr0->size = sizeof(aheader_t); - trl0->size = sizeof(trailer_t); - hdr = (fheader_t *)(trl0 + 1); /* the header of the new free block */ - trl = ((trailer_t *)hdr0) - 1; /* the trailer of the new free block */ - - /* Now link the header into the free chain */ - hdr->link = avail.link; - hdr->prev = &avail; - avail.link->prev = hdr; - avail.link = hdr; - hdr->tag = FREE; - hdr->size = n; - trl->tag = FREE; - trl->size = n; - avail.size += n; - n_free_blocks++; - - /* Now record info about this chunk in the table */ - if(_nchunks < MAXCHUNKS){ - _chunk_tbl[_nchunks].size = n; - _chunk_tbl[_nchunks].begin = (void *)hdr; - _nchunks++; - }else{ - /* There's no more room in the table! */ - /* Don't panic, though, just give up on */ - /* recording the sizes of individual chunks for */ - /* posterity. */ - _chunk_tbl[MAXCHUNKS].size += n; - } - - Msgf(("extend_mem returns %lu\n", (unsigned long)n)); - return n; -} - -/* These two are patterned after the diagnostic version of */ -/* malloc available on SUNs. Malloc_debug(lev) sets the debugging */ -/* level to its arg. Values are: */ -/* 0 : the default case */ -/* 1 : abort if any problem is detected in malloc's data structures */ -/* Level 1 does not actively seek out problems, but if it happens upon */ -/* one, it calls abort. This is the default level. It should */ -/* be only marginally slower than level 0. */ -/* 2 : Examine the entire data structure on every call of malloc/calloc/ */ -/* realloc/free. This may be VERY slow. */ -/* 3 : Same as 1, but also abort when malloc would return NULL. */ -/* 4 : Same as 2, but also abort when malloc would return NULL. */ -/* Neither of the last two abort if 0 bytes are requested */ -/* malloc_verify() performs a very thorough of the entire malloc */ -/* data structures. If all is well, it returns 0, otherwise it */ -/* returns 1 */ -/* Whenever an error is detected, the external (void *) malloc_bad_block */ -/* is set to point to the bad block. It points to the value that */ -/* would have been returned by malloc, i.e. sizeof(aheader_t) past */ -/* the address of the header. If the error is a global one that */ -/* cannot be blamed on a single block, e.g. sizes not adding up, */ -/* malloc_bad_block points to the static avail. */ -int -malloc_debug(int level) -{ - int ret; - - if(level > 4 || level < 0) - return -1; - - ret = debug_lev; - debug_lev = level; - switch(debug_lev){ - case 0: - debug_test = 0; - debug_verify = 0; - debug_abort_nomem = 0; - break; - case 1: - debug_test = 1; - debug_verify = 0; - debug_abort_nomem = 0; - break; - case 2: - debug_test = 1; - debug_verify = 1; - debug_abort_nomem = 0; - break; - case 3: - debug_test = 1; - debug_verify = 0; - debug_abort_nomem = 1; - break; - case 4: - debug_test = 1; - debug_verify = 1; - debug_abort_nomem = 1; - break; - } - return ret; -} - -int -malloc_verify(void) -{ - fheader_t *last; - fheader_t *hdr; - int i; - int n_free_blocks1 = 0; - int n_free_blocks2 = 0; - size_t sz_free = 0; - - /* This is very similar to the loop in prt_mem... */ - /* we loop over all chunks, and all blocks in the chunk, */ - /* calling verify_blk for each one. We also count the */ - /* number of free blocks, which we compare with a scan down the */ - /* linked list of free blocks starting at avail. */ - for(i=0; i<_nchunks; i++){ - hdr = (fheader_t *)_chunk_tbl[i].begin; - last = (fheader_t *)((char *)hdr + _chunk_tbl[i].size); - while(hdr < last){ - if(verify_blk(hdr)){ - return 1; - } - if(hdr->tag == FREE){ - n_free_blocks1++; - sz_free += hdr->size; - } - /* Avoid infinite loops by counting free blocks */ - if(n_free_blocks1 > n_free_blocks){ - sprintf(malloc_errstring, "nfree_blocks1(%d) > nfreeblocks(%d)\n", - n_free_blocks1, n_free_blocks); - return 1; - } - hdr = (fheader_t *)((char *)hdr + hdr->size); - } - if( hdr != last ){ - SeriousWarning("Possible too-long chunk: hdr=%#lx != last=%#lx\n", - (unsigned long)hdr, (unsigned long)last); - } - } - - /* Only make this test if the chunk_tbl contains all the relevant */ - /* information */ - if((_nchunks != MAXCHUNKS) && - (sz_free != avail.size || n_free_blocks != n_free_blocks1)){ - sprintf(malloc_errstring, "Sizes don't add up, sz_free=%ld, avail.size=%ld, n_free_blocks=%d, n_free_blocks1=%d!\n", - (long)sz_free, (long)avail.size, - n_free_blocks, n_free_blocks1); - SeriousWarning("%s", malloc_errstring); - /* return 1; */ - } - - /* Now scan the linked list of free blocks and make sure */ - /* it is the right length, and that its size adds up too */ - sz_free = 0; - for(hdr = avail.link; hdr != &avail; hdr = hdr->link){ - n_free_blocks2++; - sz_free += hdr->size; - /* avoid infinite loops this way */ - if(n_free_blocks2 > n_free_blocks1){ - sprintf(malloc_errstring, "Too many links in chain\n"); - return 1; - } - } - if(sz_free != avail.size || n_free_blocks2 != n_free_blocks){ - sprintf(malloc_errstring, "Sizes or counts don't add up!\n"); - return 1; - } - - return 0; -} - -static int -verify_blk(fheader_t *p) -{ - fheader_t *l; - trailer_t *tp; - /* rely on the two variables top_of_mem and bottom_of_mem */ - /* being set before entering here... */ - /* How slow is this????? Is it unreasonable to call it */ - /* every time through the linked list in malloc??? */ - if(p >= top_of_mem || p < bottom_of_mem){ - sprintf(malloc_errstring, "ptr (%#lx) outside of memory\n", - (unsigned long)p); - return 1; - } - - tp = ((trailer_t *)((char *)p + p->size)) - 1; - /* make sure the size isn't preposterous */ - if((fheader_t *)tp > top_of_mem){ - sprintf(malloc_errstring, "block goes past (%#lx) top of memory\n", - (unsigned long)tp); - return 1; - } - - /* Verify that the flag is ok */ - if((p->tag != FREE && p->tag != INUSE)){ - sprintf(malloc_errstring, - "Bad magic byte in hdr %#lx\n", (unsigned long)p); - return 1; - } - - /* Verify that the header and trailer match */ - if(p->tag != tp->tag){ - sprintf(malloc_errstring, - "Tags don't match %#lx, %#lx\n", (unsigned long)p, (unsigned long)tp); - return 1; - } - - /* Check that the sizes agree in header and trailer */ - if(p->size != tp->size){ - sprintf(malloc_errstring, "Sizes don't match %#lx, %#lx\n", - (unsigned long)p, (unsigned long)tp); - return 1; - } - - /* Check that the size is reasonable */ - /* Accepting sizes exactly equal to sizeof(trailer_t) */ - /* allows the "dummy" headers at both ends of each chunk */ - /* to pass. It hardly seems worth the effort of looking through */ - /* the chunk_tbl, to verify that we are actually looking at */ - /* such a block */ - if(p->size < sizeof(fheader_t) + sizeof(trailer_t) && - p->size != sizeof(trailer_t)){ - sprintf(malloc_errstring, "Size doesn't make sense p=%#lx\n", - (unsigned long)p); - return 1; - } - - /* Verify that the forward and backward pointers are reasonable */ - if(p->tag == FREE){ - l = p->link; - if(l != &avail && (l >= top_of_mem || l < bottom_of_mem)){ - sprintf(malloc_errstring, "Link ptr (%#lx) of %#lx out of range\n", - (unsigned long)l, (unsigned long)p); - return 1; - } - - l = p->prev; - if(l != &avail && (l >= top_of_mem || l < bottom_of_mem)){ - sprintf(malloc_errstring, "Prev ptr (%#lx) of %#lx out of range\n", - (unsigned long)l, (unsigned long)p); - return 1; - } - } - - /* Amazing, all is well. */ - return 0; -} - - -void -malloc_print(void) -/* Print the map of allocated memory. */ -/* Beware that printf might call malloc if */ -/* the buffer for the file, fp, is extensible */ -/* This will have dire consequences. */ -/* For the moment, a solution is to guarantee that */ -/* fprintf is linked with any paralib program via */ -/* the trick in stdio/data.c */ -{ - aheader_t *last; - aheader_t *hdr; - fheader_t *fhdr; - int ch, i; - int nfb; - - Msg_do("Malloc_print called. heapsz: %ld, avail: %ld, used: %ld\n", - (long)malloc_heapsz(), (long)malloc_avail(), (long)malloc_used()); - Msg_do( "Memory map:\n"); - for(i=0; i<_nchunks; i++){ - Msg_do( "Chunk %d of size %lu\n", - i, (unsigned long)_chunk_tbl[i].size); - Msg_do( "address size [allocated|free]\n"); - hdr = (aheader_t *)_chunk_tbl[i].begin; - last = (aheader_t *)((char *)hdr + _chunk_tbl[i].size); - while(hdr < last){ - if( verify_blk((fheader_t *)hdr) ){ - Msg_do( "Bad block (%#lx): %s\n", - (unsigned long)hdr, malloc_errstring); - break; - } - /* ch is 'f' for free, 'a' for allocated */ - /* We print out the address that would have been */ - /* returned by malloc, and the maximum possible */ - /* size of USER memory in the block. Due to */ - /* rounding, this may be more than he asked for, */ - /* but the size of any headers and/or trailers is */ - /* subtracted. Note the use of the %p conversion */ - /* specifier. */ - ch = (hdr->tag == INUSE)? 'a' : 'f'; - Msg_do( "%#lx %lu %c\n", (unsigned long)(hdr+1), - (unsigned long)(hdr->size - sizeof(aheader_t) - sizeof(trailer_t)), - ch); - hdr = (aheader_t *)((char *)hdr + hdr->size); - } - Msg_do( "\n"); - } - if(_nchunks == MAXCHUNKS){ - Msg_do( "There are more chunks with\n"); - Msg_do( "a total size of %lu. I don't\n", - (unsigned long)_chunk_tbl[MAXCHUNKS].size); - Msg_do( "have detailed info about them though.\n"); - } - Msg_do("Free list:\n"); - nfb = 0; - for(fhdr = avail.link; fhdr != &avail; fhdr = fhdr->link){ - nfb++; - ch = (fhdr->tag == INUSE)? 'a' : 'f'; - if( verify_blk(fhdr) ){ - Msg_do("Bad block (%#lx): %s\n", (unsigned long)fhdr, malloc_errstring); - } - Msg_do( "%#lx %lu %c\n", (unsigned long)((aheader_t *)fhdr+1), - (unsigned long)(fhdr->size - sizeof(aheader_t) - sizeof(trailer_t)), - ch); - /* avoid infinite loops this way */ - if(nfb > n_free_blocks){ - Msg_do("Too many free blocks. Possible loop\n"); - break; - } - } - -} - -/* This uses the same discredited idea that we abandoned */ -/* in the tree11/sysdep.c: define a GETMAXBRK_DEFINED symbol */ -/* as soon as we find a system-predicate we like. When we hit the */ -/* end, complain if we haven't yet defined GETMAXBRK_DEFINED. */ -#undef GETMAXBRK_DEFINED - -#if defined(__hpux) -#define GETMAXBRK_DEFINED -#include -static void *getmaxbrk(void){ - (void *)ulimit(UL_GETMAXBRK); -} -#endif - -#if defined(sun)||defined(__PARAGON__)||defined(linux) -/* is getrlimit a sunos'ism, a bsd'ism or what??? */ -#define GETMAXBRK_DEFINED -#include -#include - -extern char etext; - -static void * -getmaxbrk(void) -{ - struct rlimit rl; - - if(getrlimit(RLIMIT_DATA, &rl)) - return (void *)-1; - if(rl.rlim_max == RLIM_INFINITY){ - return (void *)-1; - }else{ - return &etext + 2750LL*1024LL*1024LL; - } -} - -#endif /* sun||PARAGON */ - -#ifdef __DELTA__ -#define GETMAXBRK_DEFINED -#define BEGIN 0x10000000 -static void * -getmaxbrk(void){ - return (void *)(BEGIN + 12*1024*1024); /* 12Meg */ -} -#endif - -#ifndef GETMAXBRK_DEFINED -static void * -getmaxbrk(void) -{ - return (void *)-1; -} -#endif /* GETMAXBRK_DEFINED */ - -#endif /* USE_SYSTEM_MALLOC */ - diff --git a/external/libsdf/libsw/memfile.c b/external/libsdf/libsw/memfile.c deleted file mode 100644 index 556c167..0000000 --- a/external/libsdf/libsw/memfile.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include "Malloc.h" -#include "Msgs.h" -#include "error.h" -#include "protos.h" -#include "mpmy.h" - -/* Here we try to implement a cicular memory buffer which we can use as */ -/* the vfprintf-like arg to Msg_init */ - -static char *memfile; -static int memfile_offset; -static int memfile_bufsz; - -void -memfile_init(int sz) -{ - memfile = Malloc(sz); - memfile_offset = 0; - memfile_bufsz = sz-1; - memfile[sz-1] = 0; /* final null to make wrapped output cleaner */ -} - -void -memfile_delete(void) -{ - Free(memfile); - memfile_offset = 0; - memfile_bufsz = 0; -} - -#define BUFSZ 1024 - -void -memfile_vfprintf(void *junk, const char *fmt, va_list args) -{ - char tbuf[BUFSZ]; /* This might overflow, but msgs should be small */ - int i, len; - - vsprintf(tbuf, fmt, args); - len = strlen(tbuf); - if (len >= BUFSZ) Error("Buffer overflowed in mem_vfprintf\n"); - for (i = 0; i <= len; i++) { - memfile[(memfile_offset+i)%memfile_bufsz] = tbuf[i]; - } - memfile_offset += len; -} - -void -PrintMemfile(void) -{ - if (memfile_offset == 0) return; - printf("----- Messages from procnum %d -----\n", MPMY_Procnum()); - if (memfile_offset < memfile_bufsz) { - printf("%s\n", memfile); - } else { - printf("Buffer has wrapped\n"); - printf("%s\n%s\n", memfile+(memfile_offset+1)%memfile_bufsz, - memfile); - } - fflush(stdout); -} diff --git a/external/libsdf/libsw/memmove.c b/external/libsdf/libsw/memmove.c deleted file mode 100644 index 517805c..0000000 --- a/external/libsdf/libsw/memmove.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -void -*memmove(void *s1, const void *s2, size_t n) -{ -#if 0 /* Assume the caller knew this when he decided to use memmove */ - if ((char *)s1 >= (char *)s2 + n || (char *)s1 + n <= (char *)s2){ - return memcpy(s1, s2, n); - } -#endif - if(((unsigned long)s1)%sizeof(int)==0 && - ((unsigned long)s2)%sizeof(int)==0 && - n%sizeof(int)==0){ - /* Everything is alligned. We can use int assignment. */ - int *ip1 = s1; - const int *ip2 = s2; - n /= sizeof(int); - if( ip1 < ip2 ){ - while(n--) - *ip1++ = *ip2++; - }else{ - ip2 += n; - ip1 += n; - while(n--) - *--ip1 = *--ip2; - } - }else{ - char *cp1 = s1; - const char *cp2 = s2; - if(cp1 < cp2) { - while(n--) - *cp1++ = *cp2++; - }else{ - cp2 += n; - cp1 += n; - while(n--) - *--cp1 = *--cp2; - } - } - return s1; -} diff --git a/external/libsdf/libsw/mpi_bcast.c b/external/libsdf/libsw/mpi_bcast.c deleted file mode 100644 index 796e958..0000000 --- a/external/libsdf/libsw/mpi_bcast.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "swampi.h" -#include "Msgs.h" -#include "gc.h" /* for ilog2 */ -#include "error.h" - -#define TAG 4 - -int -MPI_Bcast(void *buf, int count, MPI_Datatype type, int srcproc, MPI_Comm comm) -{ - int chan; - int doc; - int sendproc; - int ret; - MPI_Request rreq, sreq; - MPI_Status status; - int procnum = _MPI_Procnum; - int nproc = _MPI_Nproc; - int nbytes = _MPI_Datasize[type] * count; - - Msgf(("mpi: Bcast\n")); - if (srcproc != 0) { /* Is this stupid? */ - if (_MPI_Procnum == 0) { - MPI_Irecv(buf, nbytes, MPI_BYTE, srcproc, TAG, MPI_COMM_PRIVATE, - &rreq); - MPI_Wait(&rreq, &status); - MPI_Get_count(&status, MPI_BYTE, &ret); - if (ret != nbytes) Error("Bcast got wrong len\n"); - } else if (_MPI_Procnum == srcproc) { - MPI_Isend(buf, nbytes, MPI_BYTE, 0, TAG, MPI_COMM_PRIVATE, &sreq); - MPI_Wait(&sreq, 0); - } - } - - doc = ilog2(nproc); - if (nproc != 1 << doc) - doc++; /* for non power-of-two sizes */ - - for (chan = 0; chan < doc; chan++) { - sendproc = procnum ^ (1 << chan); - if (sendproc >= 0 && sendproc < nproc) { - if (procnum & (1 << chan)) { - MPI_Irecv(buf, nbytes, MPI_BYTE, sendproc, TAG, - MPI_COMM_PRIVATE, &rreq); - MPI_Wait(&rreq, &status); - MPI_Get_count(&status, MPI_BYTE, &ret); - if (ret != nbytes) Error("Bcast got wrong len\n"); - } else { - MPI_Isend(buf, nbytes, MPI_BYTE, sendproc, TAG, - MPI_COMM_PRIVATE, &sreq); - MPI_Wait(&sreq, 0); - } - } - } - return MPI_SUCCESS; -} diff --git a/external/libsdf/libsw/mpi_reduce.c b/external/libsdf/libsw/mpi_reduce.c deleted file mode 100644 index 050231d..0000000 --- a/external/libsdf/libsw/mpi_reduce.c +++ /dev/null @@ -1,378 +0,0 @@ -#include -#include "swampi.h" -#include "stk.h" -#include "gc.h" -#include "Msgs.h" -#include "error.h" - -static int setup; -static int mask; - -static Stk cstk, outdata; - -#define TAG 5 - -struct comb_st { - void *recvbuf; - int count; - MPI_Datatype datatype; - union{ - MPI_Op op; - MPI_user_comb_func user_func; - } u; -}; - -/* This currently only works with one request outstanding at a time */ - -static int -MPI_IreduceInit(MPI_Request *reqp) -{ - StkInitEz(&cstk); - StkInitEz(&outdata); - setup = 1; - mask = ~0; - *reqp = 0; - return MPI_SUCCESS; -} - -static int -MPI_Ireduce(void *sendbuf, void *recvbuf, int count, - MPI_Datatype datatype, MPI_Op op, - MPI_Request req, MPI_Comm comm) -{ - struct comb_st *combuf; - int total_size; - - if (setup == 0) - Error("MPI_Ireduce with no call to MPI_IreduceInit\n"); - total_size = count * _MPI_Datasize[datatype]; - - StkPushData(&outdata, (void *)sendbuf, total_size); - combuf = StkPush(&cstk, sizeof(struct comb_st)); - - combuf->recvbuf = recvbuf; - combuf->count = count; - combuf->datatype = datatype; - combuf->u.op = op; - - return MPI_SUCCESS; -} - -#if 0 -static int -MPI_IreduceFunc(void *sendbuf, void *recvbuf, int size, - void (*func)(void *, void *, void*), - MPI_Request req) -{ - struct comb_st *combuf; - int total_size; - - if (setup == 0) - Error("MPI_Ireduce_func with no call to MPI_IreduceInit\n"); - total_size = size; - - StkPushData(&outdata, (void *)sendbuf, total_size); - combuf = StkPush(&cstk, sizeof(struct comb_st)); - - combuf->recvbuf = recvbuf; - combuf->count = size; - combuf->datatype = MPI_USER_DATA; - combuf->u.user_func = func; - - return MPI_SUCCESS; -} - -static int -MPI_Setmask(unsigned int maskval) -{ - mask = maskval; - return MPI_SUCCESS; -} -#endif - -#define ALIGN(n) ((n + _STK_DEFAULT_ALIGNMENT)&~_STK_DEFAULT_ALIGNMENT) - -/* gcc with optimization will cause this to fail efence */ -#define Do_Op(outbuf, op, inbuf, type, cnt) \ -do{char *oend = (char *)outbuf + ALIGN(cnt*sizeof(type)); \ - char *iend = (char *)inbuf + ALIGN(cnt*sizeof(type)); \ - while (cnt--) { \ - *(type *)(outbuf) op *(type *)(inbuf); \ - (outbuf) = (char *)(outbuf) + sizeof(type); \ - (inbuf) = (char *)(inbuf) + sizeof(type); \ - } \ - outbuf = oend; \ - inbuf = iend; \ -}while(0) - - -static void -do_combine(void *inbuf, void *outbuf, int n, struct comb_st *manifest) -{ - int i; - int count; - - for (i = 0; i < n; i++, manifest++) { - count = manifest->count; - if (count < 0) Error("Bad count in reduce\n"); - - Msgf(("mpi: reduce Op %s Datatype %s\n", mpi_op_name[manifest->u.op], - mpi_datatype_name[manifest->datatype])); - switch(manifest->datatype) { - case MPI_FLOAT: -#define Type float -#include "mpi_template.c" -#undef Type - break; - case MPI_DOUBLE: -#define Type double -#include "mpi_template.c" -#undef Type - break; - case MPI_LONG_DOUBLE: -#define Type double -#include "mpi_template.c" -#undef Type - break; - -#define BIT_OPS /* Turns on bitwise ops in mpi_template.c */ - case MPI_BYTE: - case MPI_CHAR: -#define Type char -#include "mpi_template.c" -#undef Type - break; - case MPI_SHORT: -#define Type short -#include "mpi_template.c" -#undef Type - break; - case MPI_INT: -#define Type int -#include "mpi_template.c" -#undef Type - break; - case MPI_LONG: -#define Type long -#include "mpi_template.c" -#undef Type - break; - case MPI_LONG_LONG: -#define Type long -#include "mpi_template.c" -#undef Type - break; - case MPI_UNSIGNED: - case MPI_UNSIGNED_INT: -#define Type unsigned int -#include "mpi_template.c" -#undef Type - break; - case MPI_UNSIGNED_CHAR: -#define Type unsigned char -#include "mpi_template.c" -#undef Type - break; - case MPI_UNSIGNED_SHORT: -#define Type unsigned short -#include "mpi_template.c" -#undef Type - break; - case MPI_UNSIGNED_LONG: -#define Type unsigned long -#include "mpi_template.c" -#undef Type - break; - case MPI_UNSIGNED_LONG_LONG: -#define Type unsigned long -#include "mpi_template.c" -#undef Type - break; -#undef BIT_OPS - -#define LOC_OPS - case MPI_FLOAT_INT: -#define Type MPI_float_int -#include "mpi_template.c" -#undef Type - break; - case MPI_DOUBLE_INT: -#define Type MPI_double_int -#include "mpi_template.c" -#undef Type - break; - case MPI_LONG_INT: -#define Type MPI_long_int -#include "mpi_template.c" -#undef Type - break; - case MPI_2INT: -#define Type MPI_2int -#include "mpi_template.c" -#undef Type - break; - case MPI_SHORT_INT: -#define Type MPI_short_int -#include "mpi_template.c" -#undef Type - break; - case MPI_LONG_DOUBLE_INT: -#define Type MPI_long_double_int -#include "mpi_template.c" -#undef Type - break; -#undef LOC_OPS - case MPI_COMPLEX: -#define Type MPI_complex - { - Type *out = outbuf; - Type *in = inbuf; - outbuf = (char *)outbuf + ALIGN(count*sizeof(Type)); - inbuf = (char *)inbuf + ALIGN(count*sizeof(Type)); - switch(manifest->u.op) { - case MPI_SUM: - while (count--) { - out->real += in->real; - out->imag += in->imag; - out++; - in++; - } - break; - case MPI_PROD: - while (count--) { - out->real = out->real*in->real - out->imag*in->imag; - out->imag = out->real*in->imag + out->imag*in->real; - out++; - in++; - } - break; - default: - Error("Unknown op in MPI_reduce\n"); - } - } -#undef Type - break; - case MPI_DOUBLE_COMPLEX: -#define Type MPI_double_complex - { - Type *out = outbuf; - Type *in = inbuf; - outbuf = (char *)outbuf + ALIGN(count*sizeof(Type)); - inbuf = (char *)inbuf + ALIGN(count*sizeof(Type)); - switch(manifest->u.op) { - case MPI_SUM: - while (count--) { - out->real += in->real; - out->imag += in->imag; - out++; - in++; - } - break; - case MPI_PROD: - while (count--) { - out->real = out->real*in->real - out->imag*in->imag; - out->imag = out->real*in->imag + out->imag*in->real; - out++; - in++; - } - break; - default: - Error("Unknown op in MPI_reduce\n"); - } - } -#undef Type - break; - case MPI_USER_DATA: - /* This came from a MPI_ICombine_func */ - (*manifest->u.user_func)(inbuf, outbuf, outbuf); - (outbuf) = (char *)(outbuf) + ALIGN(manifest->count); - (inbuf) = (char *)(inbuf) + ALIGN(manifest->count); - break; - default: - Error("Unknown type in Combine\n"); - } - } -} - -int -MPI_IreduceWait(MPI_Request req, MPI_Comm comm) -{ - int chan; - int doc; - int i; - void *inbuf; - void *outbuf = StkBase(&outdata); - MPI_Status stat; - int ret; - int total_size; - int sendproc; - int procnum = _MPI_Procnum; - int nproc = _MPI_Nproc; - int bufsz = StkSz(&outdata); - struct comb_st *manifest = StkBase(&cstk); - int n = StkSz(&cstk)/sizeof(struct comb_st); - - doc = ilog2(nproc); - if (nproc != 1 << doc) - doc++; /* for non power-of-two sizes */ - if ((inbuf = malloc(bufsz)) == NULL) - Error("out of memory\n"); - - for (chan = 0; chan < doc; chan++) { - if (mask & (1 << chan)) { - sendproc = procnum^(1<= 0 && sendproc < nproc) { - MPI_Sendrecv(outbuf, bufsz, MPI_BYTE, sendproc, TAG, - inbuf, bufsz, MPI_BYTE, sendproc, TAG, - comm, &stat); - MPI_Get_count(&stat, MPI_BYTE, &ret); - if (ret != bufsz) - Error("Shift failed, expected %d got %d\n", bufsz, ret); - do_combine(inbuf, outbuf, n, manifest); - } - } - } - if (nproc != 1 << doc) { - MPI_Bcast(outbuf, bufsz, MPI_BYTE, 0, comm); - } - for (i = 0; i < n; i++) { - total_size = manifest->count * _MPI_Datasize[manifest->datatype]; - memcpy(manifest->recvbuf, outbuf, total_size); - outbuf = (char *)outbuf + ALIGN(total_size); - manifest = (struct comb_st *)((char *)manifest + ALIGN(sizeof(*manifest))); - } - free(inbuf); - StkTerminate(&outdata); - StkTerminate(&cstk); - setup = 0; - return MPI_SUCCESS; -} - -int -MPI_Allreduce(void *sendbuf, void *recvbuf, int count, - MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) -{ - MPI_Request req; - - Msgf(("mpi: Allreduce\n")); - if (op < 0 || op >= _MPI_NUMOPS) Error("Bad MPI_Op\n"); - MPI_IreduceInit(&req); - MPI_Ireduce(sendbuf, recvbuf, count, datatype, op, req, MPI_COMM_PRIVATE); - MPI_IreduceWait(req, MPI_COMM_PRIVATE); - return MPI_SUCCESS; -} - -int -MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, - MPI_Op op, int root, MPI_Comm comm) -{ - Msgf(("mpi: Reduce\n")); - if (op < 0 || op >= _MPI_NUMOPS) Error("Bad MPI_Op\n"); - if (_MPI_Procnum != root) - if ((recvbuf = malloc(count * _MPI_Datasize[datatype])) == NULL) - Error("out of memory\n"); - MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm); - if (_MPI_Procnum != root) free(recvbuf); - return MPI_SUCCESS; -} - diff --git a/external/libsdf/libsw/mpi_template.c b/external/libsdf/libsw/mpi_template.c deleted file mode 100644 index b2b7e57..0000000 --- a/external/libsdf/libsw/mpi_template.c +++ /dev/null @@ -1,66 +0,0 @@ - - /* This is a template that is included multiple times in MPI_reduce.c */ - - switch(manifest->u.op) { -#ifndef LOC_OPS - case MPI_SUM: - Do_Op(outbuf, +=, inbuf, Type, count); - break; - case MPI_PROD: - Do_Op(outbuf, *=, inbuf, Type, count); - break; - case MPI_MAX: - Do_Op(outbuf, - = (*(Type *)outbuf > *(Type *)inbuf) ? *(Type *)outbuf :, - inbuf, Type, count); - break; - case MPI_MIN: - Do_Op(outbuf, - = (*(Type *)outbuf < *(Type *)inbuf) ? *(Type *)outbuf :, - inbuf, Type, count); - break; -#ifdef BIT_OPS - case MPI_BAND: - Do_Op(outbuf, &=, inbuf, Type, count); - break; - case MPI_BOR: - Do_Op(outbuf, |=, inbuf, Type, count); - break; - case MPI_BXOR: - Do_Op(outbuf, ^=, inbuf, Type, count); - break; - case MPI_LAND: - Do_Op(outbuf, = *(Type *)outbuf && , inbuf, Type, count); - break; - case MPI_LOR: - Do_Op(outbuf, = *(Type *)outbuf || , inbuf, Type, count); - break; - case MPI_LXOR: /* cripes */ - Do_Op(outbuf, = (!*(Type *)outbuf == !*(Type *)inbuf) ? - 0 : 1 ||, inbuf, Type, count); - break; -#endif /*BIT_OPS */ -#else /* LOC_OPS */ - case MPI_MAXLOC: - Do_Op(outbuf, = (((Type *)outbuf)->x > ((Type *)inbuf)->x) ? - *(Type *)outbuf :, inbuf, Type, count); - break; - case MPI_MINLOC: - Do_Op(outbuf, = (((Type *)outbuf)->x < ((Type *)inbuf)->x) ? - *(Type *)outbuf :, inbuf, Type, count); - break; -#endif /* LOC_OPS */ - default: - Error("Unknown op in MPI_reduce\n"); - } - - - - - - - - - - - diff --git a/external/libsdf/libsw/mpmy_combine.c b/external/libsdf/libsw/mpmy_combine.c deleted file mode 100644 index 67f61d2..0000000 --- a/external/libsdf/libsw/mpmy_combine.c +++ /dev/null @@ -1,252 +0,0 @@ -#include -#include "Malloc.h" -#include "mpmy.h" -#include "stk.h" -#include "gc.h" -#include "Msgs.h" - -static int setup; -static int mask; - -static Stk cstk, outdata; - -struct comb_st { - void *recvbuf; - int count; - int datatype; - union{ - MPMY_Op op; - MPMY_user_comb_func user_func; - } u; -}; - -/* This currently only works with one request outstanding at a time */ - -int -MPMY_ICombine_Init(MPMY_Comm_request *reqp) -{ - StkInitEz(&cstk); - StkInitEz(&outdata); - setup = 1; - mask = ~0; - *reqp = 0; - return MPMY_SUCCESS; -} - -int -MPMY_ICombine(const void *sendbuf, void *recvbuf, int count, - MPMY_Datatype datatype, MPMY_Op op, - MPMY_Comm_request req) -{ - struct comb_st *combuf; - int total_size; - - if (setup == 0) - Error("MPMY_ICombine with no call to Init\n"); - total_size = count * MPMY_Datasize[datatype]; - - StkPushData(&outdata, (void *)sendbuf, total_size); - combuf = StkPush(&cstk, sizeof(struct comb_st)); - - combuf->recvbuf = recvbuf; - combuf->count = count; - combuf->datatype = datatype; - combuf->u.op = op; - - return MPMY_SUCCESS; -} - -int -MPMY_ICombine_func(const void *sendbuf, void *recvbuf, int size, - void (*func)(const void *, const void *, void*), - MPMY_Comm_request req) -{ - struct comb_st *combuf; - int total_size; - - Msgf(("MPMY_Icombine_func(): %p %p %d %p\n", - sendbuf, recvbuf, size, func)); - if (setup == 0) - Error("MPMY_ICombine with no call to Init\n"); - total_size = size; - - StkPushData(&outdata, (void *)sendbuf, total_size); - combuf = StkPush(&cstk, sizeof(struct comb_st)); - - combuf->recvbuf = recvbuf; - combuf->count = size; - combuf->datatype = MPMY_USER_DATA; - combuf->u.user_func = func; - - return MPMY_SUCCESS; -} - -void -MPMY_Combine_Mask(unsigned int maskval) -{ - mask = maskval; -} - - -/* gcc with optimization will cause this to fail efence */ -#define Do_Op(outbuf, op, inbuf, type, cnt) \ -do{char *oend = (char *)outbuf + StkAlign(&outdata, cnt*sizeof(type)); \ - char *iend = (char *)inbuf + StkAlign(&outdata, cnt*sizeof(type)); \ - while (cnt--) { \ - *(type *)(outbuf) op *(type *)(inbuf); \ - (outbuf) = (char *)(outbuf) + sizeof(type); \ - (inbuf) = (char *)(inbuf) + sizeof(type); \ - } \ - outbuf = oend; \ - inbuf = iend; \ -}while(0) - - -static void -do_combine(const void *inbuf, void *outbuf, const int n, - const struct comb_st *manifest) -{ - int i; - int count; - - for (i = 0; i < n; i++, manifest++) { - count = manifest->count; - if (count < 0) Error("Bad count in Combine\n"); - Msgf(("do_combine: %p %p %d %d\n", - inbuf, outbuf, manifest->datatype, manifest->u.op)); - switch(manifest->datatype) { - case MPMY_FLOAT: -#define Type float -#include "op_template.c" -#undef Type - break; - case MPMY_DOUBLE: -#define Type double -#include "op_template.c" -#undef Type - break; - case MPMY_INT: -#define BIT_OPS /* Turns on bitwise ops in op_template.c */ -#define Type int -#include "op_template.c" -#undef Type - break; - case MPMY_CHAR: -#define Type char -#include "op_template.c" -#undef Type - break; - case MPMY_SHORT: -#define Type short -#include "op_template.c" -#undef Type - break; - case MPMY_LONG: -#define Type long -#include "op_template.c" -#undef Type - case MPMY_OFFT: -#define Type off_t -#include "op_template.c" -#undef Type - break; - case MPMY_INT64: -#define Type int64_t -#include "op_template.c" -#undef Type - break; - case MPMY_UNSIGNED_INT: -#define Type unsigned int -#include "op_template.c" -#undef Type - break; - case MPMY_UNSIGNED_CHAR: -#define Type unsigned char -#include "op_template.c" -#undef Type - break; - case MPMY_UNSIGNED_SHORT: -#define Type unsigned short -#include "op_template.c" -#undef Type - break; - case MPMY_UNSIGNED_LONG: -#define Type unsigned long -#include "op_template.c" -#undef Type - break; -#undef BIT_OPS - case MPMY_USER_DATA: - /* This came from a MPMY_ICombine_func */ - (*manifest->u.user_func)(inbuf, outbuf, outbuf); - (outbuf) = (char *)(outbuf) + StkAlign(&outdata, manifest->count); - (inbuf) = (char *)(inbuf) + StkAlign(&outdata, manifest->count); - break; - default: - Error("Unknown type in Combine\n"); - } - } -} - -int -MPMY_ICombine_Wait(MPMY_Comm_request req) -{ - int chan; - int doc; - int i; - void *inbuf; - void *outbuf = StkBase(&outdata); - MPMY_Status stat; - int ret; - int total_size; - int sendproc; - int procnum = MPMY_Procnum(); - int nproc = MPMY_Nproc(); - int bufsz = StkSz(&outdata); - const struct comb_st *manifest = StkBase(&cstk); - int n = StkSz(&cstk)/sizeof(struct comb_st); - - Msgf(("MPMY_ICombine_Wait()\n")); - doc = ilog2(nproc); - if (nproc != 1 << doc) - doc++; /* for non power-of-two sizes */ - inbuf = Malloc(bufsz); - - for (chan = 0; chan < doc; chan++) { - if (mask & (1 << chan)) { - sendproc = procnum^(1<= 0 && sendproc < nproc) { - MPMY_Shift(sendproc, inbuf, bufsz, outbuf, bufsz, &stat); - ret = MPMY_Count(&stat); - if (ret != bufsz) - Error("Shift failed, expected %d got %d\n", bufsz, ret); - do_combine(inbuf, outbuf, n, manifest); - } - } - } - if (nproc != 1 << doc) { - MPMY_Bcast(outbuf, bufsz, MPMY_CHAR, 0); - } - for (i = 0; i < n; i++) { - total_size = manifest->count * MPMY_Datasize[manifest->datatype]; - memcpy(manifest->recvbuf, outbuf, total_size); - outbuf = (char *)outbuf + StkAlign(&outdata, total_size); - manifest = (const struct comb_st *)((char *)manifest + StkAlign(&outdata, sizeof(*manifest))); - } - Free(inbuf); - StkTerminate(&outdata); - StkTerminate(&cstk); - setup = 0; - return MPMY_SUCCESS; -} - -int -MPMY_Combine(const void *sendbuf, void *recvbuf, const int count, - const MPMY_Datatype datatype, const MPMY_Op op) -{ - MPMY_Comm_request req; - - MPMY_ICombine_Init(&req); - MPMY_ICombine(sendbuf, recvbuf, count, datatype, op, req); - return MPMY_ICombine_Wait(req); -} diff --git a/external/libsdf/libsw/mpmy_gather.c b/external/libsdf/libsw/mpmy_gather.c deleted file mode 100644 index f1ac585..0000000 --- a/external/libsdf/libsw/mpmy_gather.c +++ /dev/null @@ -1,556 +0,0 @@ -#include -#include -#include "mpmy.h" -#include "Msgs.h" -#include "Malloc.h" -#include "gc.h" /* for ilog2 */ -#include "verify.h" - -/* Could we implement gather using MPMY_Combine with MPMY_Op == MPMY_GATHER? */ - - -#define BCAST_DEFAULT_TAG 0x47 - -#define GATHER_BCAST_TAG 0x1145 -#define GATHER_TAG 0x2145 -#define NGATHER_TAG 0x3145 -#define ALLTOALL_TAG 0x4145 -#define ALLTOALL_RTAG 0x4146 -#define ALLTOALL_NTAG 0x4147 - -unsigned int MPMY_Datasize[] = -{ sizeof(float), sizeof(double), sizeof(int), sizeof(char), sizeof(short), - sizeof(long), sizeof(unsigned int), sizeof(unsigned char), - sizeof(unsigned short), sizeof(unsigned long), sizeof(off_t), sizeof(int64_t), 1/*user_data*/ -}; - -void -MPMY_send(const void *buf, int cnt, int dest, int tag) -{ - MPMY_Comm_request req; - - MPMY_Isend(buf, cnt, dest, tag, &req); - MPMY_Wait(req, 0); - if( Msg_test(__FILE__)){ - int i; - int sum = 0; - const char *cbuf = buf; - for(i=0; i= 0 && sendproc < nproc) { - nin = nout = (1 << chan); - if (procnum & (1 << chan)) { - if (nproc - procnum < nout) nout = nproc - procnum; - outbufsz = nout * nbytes; - outptr = (char *)recvbuf + (procnum & mask) * nbytes; - Msgf(("Gather: to %d, outidx %d, outsz %d\n", - sendproc, (procnum & mask), nout)); - MPMY_send(outptr, outbufsz, sendproc, GATHER_TAG+chan); - break; - } else { - if (nproc - sendproc < nin) nin = nproc - sendproc; - inbufsz = nin * nbytes; - inptr = (char *)recvbuf + (sendproc & mask) * nbytes; - Msgf(("Gather: from %d, inidx %d, insz %d\n", - sendproc, (sendproc & mask), nin)); - MPMY_recvn(inptr, inbufsz, sendproc, GATHER_TAG+chan); - } - } - mask <<= 1; - } - if (procnum != recvproc) - Free(recvbuf); - return MPMY_SUCCESS; -} - -/* "count" can vary for each processor in NGather */ - -int -MPMY_NGather(const void *sendbuf, int count, MPMY_Datatype type, - void **recvhndl, int recvproc) -{ - int chan; - int doc; - int sendproc; - int bufsz; - int inbytes; - unsigned int mask; - void *buf; - int procnum = MPMY_Procnum(); - int nproc = MPMY_Nproc(); - int nbytes = MPMY_Datasize[type] * count; - - if (recvproc != 0) Error("NGather to procnum != 0 not supported yet.\n"); - - doc = ilog2(nproc); - if (nproc != 1 << doc) - doc++; /* for non power-of-two sizes */ - - buf = Malloc(nbytes); - memcpy(buf, sendbuf, nbytes); - bufsz = nbytes; - - mask = ~0; - for (chan = 0; chan < doc; chan++) { - sendproc = procnum ^ (1 << chan); - if (sendproc >= 0 && sendproc < nproc) { - if (procnum & (1 << chan)) { - Msgf(("NGather: to %d, bufsz %d\n", sendproc, bufsz)); - MPMY_send(&bufsz, sizeof(int), sendproc, NGATHER_TAG+chan); - MPMY_send(buf, bufsz, sendproc, NGATHER_TAG+chan); - break; - } else { - MPMY_recvn(&inbytes, sizeof(int), sendproc, NGATHER_TAG+chan); - Msgf(("NGather: from %d, inbytes %d\n", sendproc, inbytes)); - buf = Realloc(buf, bufsz+inbytes); - MPMY_recvn(bufsz+(char*)buf, inbytes, sendproc, NGATHER_TAG+chan); - bufsz += inbytes; - } - } - mask <<= 1; - } - if (procnum != recvproc) { - Free(buf); - return 0; - } else { - Msgf(("NGather: Final bufsz %d\n", bufsz)); - *recvhndl = buf; - return bufsz/MPMY_Datasize[type]; - } -} - -int MPMY_Bcast(void *buf, int count, MPMY_Datatype type, int srcproc) -{ - return MPMY_BcastTag(buf, count, type, srcproc, BCAST_DEFAULT_TAG); -} - -int -MPMY_BcastTag(void *buf, int count, MPMY_Datatype type, int srcproc, int tag) -{ - int chan; - int doc; - int sendproc; - int procnum = MPMY_Procnum(); - int nproc = MPMY_Nproc(); - int nbytes = MPMY_Datasize[type] * count; - - if (srcproc != 0) Error("Bcast from procnum != 0 not supported yet.\n"); - - Msgf(("MPMYBcast(buf=%p, count=%d, type=%d, srcproc=%d\n", - buf, count, type, srcproc)); Msg_flush(); - doc = ilog2(nproc); - if (nproc != 1 << doc) - doc++; /* for non power-of-two sizes */ - - for (chan = 0; chan < doc; chan++) { - sendproc = procnum ^ (1 << chan); - if (sendproc >= 0 && sendproc < nproc) { - if (procnum & (1 << chan)) { - Msgf(("Bcast: recv from %d\n", sendproc)); - MPMY_recvn(buf, nbytes, sendproc, tag+chan); - } else { - Msgf(("Bcast: send to %d\n", sendproc)); - MPMY_send(buf, nbytes, sendproc, tag+chan); - } - } - } - return MPMY_SUCCESS; -} - - -int -MPMY_Alltoall(void *sendbuf, int sendcount, MPMY_Datatype sendtype, - void *recvbuf, int recvcount, MPMY_Datatype recvtype) -{ - MPMY_Status stat; - int i; - int ret; - int doc_procs, doc_nodes, relative, dest, proc; - int sendbytes = MPMY_Datasize[sendtype] * sendcount; - int recvbytes = MPMY_Datasize[recvtype] * recvcount; - int my_node = MPMY_Procnum() / PROCS_PER_NODE; - int my_leader = my_node * PROCS_PER_NODE; - int local_rank = MPMY_Procnum() % PROCS_PER_NODE; - int dest_leader; - char *tmpbuf_s = NULL; - char *tmpbuf_r = NULL; - MPMY_Comm_request req; - - doc_nodes = ilog2(MPMY_Nproc()/PROCS_PER_NODE-1) + 1; - doc_procs = ilog2(PROCS_PER_NODE-1) + 1; - Msgf(("Alltoall my_leader %d, local_rank %d, doc_nodes %d, doc_procs %d\n", - my_leader, local_rank, doc_nodes, doc_procs)); - /* Within a node */ - for (relative = 0; relative < 1 << doc_procs; relative++) { - dest = my_leader + (relative ^ local_rank); - if ((dest >= MPMY_Nproc()) || (dest >= my_leader + PROCS_PER_NODE)) - continue; - Msgf(("local Alltoall MPMY_Shift(dest=%d, instart=%p, incnt=%d, outstart=%p, outcnt=%d)\n", - dest, recvbuf + dest * recvbytes, recvbytes, - sendbuf + dest * sendbytes, sendbytes)); - MPMY_Shift(dest, recvbuf + dest * recvbytes, recvbytes, - sendbuf + dest * sendbytes, sendbytes, &stat); - ret = MPMY_Count(&stat); - if (ret != recvbytes) - Error("Shift failed, expected %d got %d\n", recvbytes, ret); - } - if (MPMY_Procnum() == my_leader) { - tmpbuf_s = Malloc(sendbytes*PROCS_PER_NODE); - tmpbuf_r = Malloc(recvbytes*PROCS_PER_NODE); - } - /* Across nodes */ - for (relative = 1; relative < 1 << doc_nodes; relative++) { - for (proc = 0; proc < PROCS_PER_NODE; proc++) { - dest_leader = (relative ^ my_node) * PROCS_PER_NODE; - dest = dest_leader + proc; - if (dest >= MPMY_Nproc()) - continue; - if (MPMY_Procnum() != my_leader) { - MPMY_Isend(sendbuf + dest * sendbytes, sendbytes, my_leader, ALLTOALL_RTAG, &req); - MPMY_Wait(req, 0); - if (MPMY_Procnum() == my_leader + proc) { - Msgf(("Alltoall relay recv from %d (source=%d, incnt=%d)\n", - my_leader, dest_leader, PROCS_PER_NODE * recvbytes)); - MPMY_Irecv(recvbuf + dest_leader * recvbytes, PROCS_PER_NODE * recvbytes, - my_leader, ALLTOALL_TAG, &req); - MPMY_Wait(req, &stat); - ret = MPMY_Count(&stat); - if (ret != PROCS_PER_NODE * recvbytes) { - Error("Irecv failed, expected %d got %d\n", PROCS_PER_NODE * recvbytes, ret); - } - } - } else { - memcpy(tmpbuf_s, sendbuf + dest * sendbytes, sendbytes); - for (i = 1; i < PROCS_PER_NODE; i++) { - if (my_leader + i >= MPMY_Nproc()) break; - MPMY_Irecv(tmpbuf_s + i * recvbytes, recvbytes, my_leader+i, ALLTOALL_RTAG, &req); - MPMY_Wait(req, &stat); - ret = MPMY_Count(&stat); - if (ret != recvbytes) { - Error("Irecv failed, expected %d got %d\n", recvbytes, ret); - } - } - Msgf(("Alltoall relay for %d MPMY_Shift(dest=%d, incnt=%d, outcnt=%d)\n", - dest, dest_leader, PROCS_PER_NODE * recvbytes, PROCS_PER_NODE * sendbytes)); - MPMY_Shift(dest_leader, tmpbuf_r, PROCS_PER_NODE * recvbytes, - tmpbuf_s, PROCS_PER_NODE * sendbytes, &stat); - ret = MPMY_Count(&stat); - if (ret != PROCS_PER_NODE * recvbytes) - Error("Shift failed, expected %d got %d\n", PROCS_PER_NODE * recvbytes, ret); - if (proc == 0) { - Msgf(("Alltoall local copy (source=%d, incnt=%d)\n", - dest_leader, PROCS_PER_NODE * recvbytes)); - memcpy(recvbuf + dest_leader * recvbytes, tmpbuf_r, PROCS_PER_NODE * recvbytes); - } else { - Msgf(("Alltoall relay send to %d (source=%d, incnt=%d)\n", - my_leader+proc, dest_leader, PROCS_PER_NODE * recvbytes)); - MPMY_Isend(tmpbuf_r, PROCS_PER_NODE * recvbytes, my_leader+proc, ALLTOALL_TAG, &req); - MPMY_Wait(req, 0); - } - } - } - } - if (MPMY_Procnum() == my_leader) { - Free(tmpbuf_r); - Free(tmpbuf_s); - } - return MPMY_SUCCESS; -} - -int -MPMY_Alltoallv(void *sendbuf, int *scount, int *soff, MPMY_Datatype sendtype, - void *recvbuf, int *rcount, int *roff, MPMY_Datatype recvtype) -{ - MPMY_Status stat; - int i; - int ret; - int doc_procs, doc_nodes, relative, dest, proc; - int ssize = MPMY_Datasize[sendtype]; - int rsize = MPMY_Datasize[recvtype]; - int my_node = MPMY_Procnum() / PROCS_PER_NODE; - int my_leader = my_node * PROCS_PER_NODE; - int local_rank = MPMY_Procnum() % PROCS_PER_NODE; - int dest_leader; - char *tmpbuf_s = NULL; - char *tmpbuf_r = NULL; - int *stcnt = NULL; - int *stoff = NULL; - MPMY_Comm_request req; - int sendbytes, recvbytes; - - doc_nodes = ilog2(MPMY_Nproc()/PROCS_PER_NODE-1) + 1; - doc_procs = ilog2(PROCS_PER_NODE-1) + 1; - if (MPMY_Procnum() == my_leader) { - stcnt = Calloc(PROCS_PER_NODE, sizeof(int)); - stoff = Calloc(PROCS_PER_NODE, sizeof(int)); - } - Msgf(("Alltoallv my_leader %d, local_rank %d, doc_nodes %d, doc_procs %d\n", - my_leader, local_rank, doc_nodes, doc_procs)); - /* Within a node */ - for (relative = 0; relative < 1 << doc_procs; relative++) { - dest = my_leader + (relative ^ local_rank); - if ((dest >= MPMY_Nproc()) || (dest >= my_leader + PROCS_PER_NODE)) - continue; - if ((rcount[dest] == 0) && (scount[dest] == 0)) - continue; - Msgf(("local Alltoallv MPMY_Shift(dest=%d, instart=%p, incnt=%d, outstart=%p, outcnt=%d)\n", - dest, recvbuf + roff[dest] * rsize, rcount[dest] * rsize, - sendbuf + soff[dest] * ssize, scount[dest] * ssize)); - MPMY_Shift(dest, recvbuf + roff[dest] * rsize, rcount[dest] * rsize, - sendbuf + soff[dest] * ssize, scount[dest] * ssize, &stat); - ret = MPMY_Count(&stat); - if (ret != rcount[dest] * rsize) - Error("Shift failed, expected %d got %d\n", rcount[dest] * rsize, ret); - } - /* Across nodes */ - for (relative = 1; relative < 1 << doc_nodes; relative++) { - for (proc = 0; proc < PROCS_PER_NODE; proc++) { - dest_leader = (relative ^ my_node) * PROCS_PER_NODE; - dest = dest_leader + proc; - if (dest >= MPMY_Nproc()) - continue; - if (MPMY_Procnum() != my_leader) { - MPMY_Isend(&scount[dest], sizeof(int), my_leader, ALLTOALL_NTAG, &req); - MPMY_Wait(req, 0); - if (MPMY_Procnum() == my_leader + proc) { - for (recvbytes = 0, i = dest_leader; i < dest_leader + PROCS_PER_NODE; i++) { - if (i >= MPMY_Nproc()) break; - recvbytes += rcount[i] * rsize; - } - MPMY_Isend(&recvbytes, sizeof(int), my_leader, ALLTOALL_NTAG, &req); - MPMY_Wait(req, 0); - } - if (scount[dest]) { - MPMY_Isend(sendbuf + soff[dest] * ssize, scount[dest] * ssize, my_leader, - ALLTOALL_RTAG, &req); - MPMY_Wait(req, 0); - } - if ((MPMY_Procnum() == my_leader + proc) && recvbytes) { - Msgf(("Alltoallv relay recv from %d (source=%d, incnt=%d)\n", - my_leader, dest_leader, recvbytes)); - MPMY_Irecv(recvbuf + roff[dest_leader] * rsize, recvbytes, - my_leader, ALLTOALL_TAG, &req); - MPMY_Wait(req, &stat); - ret = MPMY_Count(&stat); - if (ret != recvbytes) { - Error("Irecv failed, expected %d got %d\n", recvbytes, ret); - } - } - } else { - stcnt[0] = scount[dest]; - stoff[0] = 0; - sendbytes = stcnt[0] * ssize; - for (i = 1; i < PROCS_PER_NODE; i++) { - if (my_leader + i >= MPMY_Nproc()) break; - MPMY_Irecv(stcnt+i, sizeof(int), my_leader+i, ALLTOALL_NTAG, &req); - MPMY_Wait(req, &stat); - ret = MPMY_Count(&stat); - if (ret != sizeof(int)) { - Error("Irecv failed, expected %ld got %d\n", sizeof(int), ret); - } - stoff[i] = stoff[i-1] + stcnt[i-1]; - sendbytes += stcnt[i] * ssize; - } - if (proc == 0) { - for (recvbytes = 0, i = dest_leader; i < dest_leader + PROCS_PER_NODE; i++) { - if (i >= MPMY_Nproc()) break; - recvbytes += rcount[i] * rsize; - } - } else if (my_leader+proc < MPMY_Nproc()) { - MPMY_Irecv(&recvbytes, sizeof(int), my_leader+proc, ALLTOALL_NTAG, &req); - MPMY_Wait(req, &stat); - ret = MPMY_Count(&stat); - if (ret != sizeof(int)) { - Error("Irecv failed, expected %ld got %d\n", sizeof(int), ret); - } - } - if (sendbytes || recvbytes) { - Msgf(("allocating %d bytes for send\n", sendbytes)); - tmpbuf_s = Malloc(sendbytes); - memcpy(tmpbuf_s, sendbuf + soff[dest] * ssize, scount[dest] * ssize); - for (i = 1; i < PROCS_PER_NODE; i++) { - if (my_leader + i >= MPMY_Nproc()) break; - if (stcnt[i]) { - MPMY_Irecv(tmpbuf_s + stoff[i] * ssize, stcnt[i] * ssize, - my_leader+i, ALLTOALL_RTAG, &req); - MPMY_Wait(req, &stat); - ret = MPMY_Count(&stat); - if (ret != stcnt[i] * ssize) { - Error("Irecv failed, expected %d got %d\n", stcnt[i] * ssize, ret); - } - } - } - Msgf(("allocating %d bytes for recv\n", recvbytes)); - Msgf(("Alltoallv relay for %d MPMY_Shift(dest=%d, incnt=%d, outcnt=%d)\n", - dest, dest_leader, recvbytes, sendbytes)); - tmpbuf_r = Malloc(recvbytes); - if (sendbytes || recvbytes) { - MPMY_Shift(dest_leader, tmpbuf_r, recvbytes, tmpbuf_s, sendbytes, &stat); - ret = MPMY_Count(&stat); - if (ret != recvbytes) - Error("Shift failed, expected %d got %d\n", recvbytes, ret); - } - Free(tmpbuf_s); - if (recvbytes) { - if (proc == 0) { - Msgf(("Alltoallv local copy (source=%d, incnt=%d)\n", - dest_leader, recvbytes)); - memcpy(recvbuf + roff[dest_leader] * rsize, tmpbuf_r, recvbytes); - } else if (my_leader+proc < MPMY_Nproc()) { - Msgf(("Alltoallv relay send to %d (source=%d, incnt=%d)\n", - my_leader+proc, dest_leader, recvbytes)); - MPMY_Isend(tmpbuf_r, recvbytes, my_leader+proc, ALLTOALL_TAG, &req); - MPMY_Wait(req, 0); - } - } - Free(tmpbuf_r); - } - } - } - } - if (MPMY_Procnum() == my_leader) { - Free(stcnt); - Free(stoff); - } - return MPMY_SUCCESS; -} - -int -MPMY_Alltoallv_simple(void *sendbuf, int *scount, int *soff, MPMY_Datatype sendtype, - void *recvbuf, int *rcount, int *roff, MPMY_Datatype recvtype) -{ - MPMY_Status stat; - int ret; - int doc, relative, i; - int ssize = MPMY_Datasize[sendtype]; - int rsize = MPMY_Datasize[recvtype]; - - doc = ilog2(MPMY_Nproc()-1) + 1; - i = MPMY_Procnum(); - if (scount[i]) { - memcpy(recvbuf + roff[i] * rsize, sendbuf + soff[i] * ssize, scount[i] * ssize); - } - for (relative = 1; relative < 1<= MPMY_Nproc()) - continue; - if ((scount[i] == 0) && (rcount[i] == 0)) - continue; - Msgf(("Alltoallv MPMY_Shift(dest=%d, instart=%p, incnt=%d, outstart=%p, outcnt=%d)\n", - i, recvbuf + roff[i] * rsize, rcount[i] * rsize, - sendbuf + soff[i] * ssize, scount[i] * ssize)); - MPMY_Shift(i, recvbuf + roff[i] * rsize, rcount[i] * rsize, - sendbuf + soff[i] * ssize, scount[i] * ssize, &stat); - ret = MPMY_Count(&stat); - if (ret != rcount[i] * rsize) - Error("Shift failed, expected %d got %d\n", rcount[i] * rsize, ret); - } - return MPMY_SUCCESS; -} diff --git a/external/libsdf/libsw/msgdirinit.c b/external/libsdf/libsw/msgdirinit.c deleted file mode 100644 index bd92246..0000000 --- a/external/libsdf/libsw/msgdirinit.c +++ /dev/null @@ -1,83 +0,0 @@ -#define NO_MSGS -#include -#include -#include -#include -#include -#include -#include -#include -#include "Malloc.h" -#include "mpmy_abnormal.h" -#include "protos.h" -#include "error.h" -#include "Msgs.h" -#include "mpmy.h" -#include "files.h" -#include "mpmy_io.h" - -#ifdef __DELTA__ -void ivfprintf(FILE *stream, const char *fmt, va_list args); -void ifflush(FILE *stream); -#endif - -void MsgdirInit(const char *name) -{ - char *junk; - void *dbgfp; - char *lastslash; - char *dirname; - -#ifdef __PARAGON__ -#define PARAGON_MAX_OPEN 128 - if (MPMY_Nproc() > PARAGON_MAX_OPEN) { - SinglWarning("Can't open more than %d files on paragon because of NORMA-IPC\n", - PARAGON_MAX_OPEN); - return; - } -#endif - -#ifdef sun - if (MPMY_Nproc() > 32) { - SinglWarning("Can't open %d files on cm5 because of fd limit\n", - MPMY_Nproc()); - return; - } -#endif - - junk = Malloc(strlen(name)+1); /* enough? */ - lastslash = strrchr(name, '/'); - if( lastslash == NULL || lastslash == &name[0] ){ - /* Either it's in "." or in "/" */ - /* In either case we don't need to do a mkdir */ - dirname = NULL; - }else{ - strncpy(junk, name, lastslash-name); - junk[lastslash-name] = '\0'; - dirname = junk; - } - - /* We only try to create the lowest level of the name. No - recursion here... Nosiree. */ - if( dirname && !fexists(dirname) ){ - if( MPMY_Mkdir(dirname, 0777) ){ - SinglWarning("Mkdir(%s) failed\n", dirname); - goto outahere; - } - } - - /* Now the directory is sure to exist. */ - dbgfp = fopen(name, "w"); - if( dbgfp == NULL ){ - Error("Could not fopen %s, errno=%d\n", name, errno); - } - -#ifdef __DELTA__ - Msg_addfile(dbgfp, (Msgvfprintf_t)ivfprintf, (Msgfflush_t)ifflush); -#else - Msg_addfile(dbgfp, (Msgvfprintf_t)vfprintf, (Msgfflush_t)fflush); -#endif - outahere: - Free(junk); -} - diff --git a/external/libsdf/libsw/obstack.c b/external/libsdf/libsw/obstack.c deleted file mode 100644 index 75440d9..0000000 --- a/external/libsdf/libsw/obstack.c +++ /dev/null @@ -1,441 +0,0 @@ -/* obstack.c - subroutines used implicitly by object stack macros - Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ - - -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifdef _LIBC -# include -# include -#else -# include "obstack.h" -#endif - -/* NOTE BEFORE MODIFYING THIS FILE: This version number must be - incremented whenever callers compiled using an old obstack.h can no - longer properly call the functions in this obstack.c. */ -#define OBSTACK_INTERFACE_VERSION 1 - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself, and the installed library - supports the same library interface we do. This code is part of the GNU - C Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object - files, it is simpler to just do this in the source for each such file. */ - -#include /* Random thing to get __GNU_LIBRARY__. */ -#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1 -# include -# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION -# define ELIDE_CODE -# endif -#endif - -#include - -#ifndef ELIDE_CODE - - -# if HAVE_INTTYPES_H -# include -# endif -# if HAVE_STDINT_H || defined _LIBC -# include -# endif - -/* Determine default alignment. */ -union fooround -{ - uintmax_t i; - long double d; - void *p; -}; -struct fooalign -{ - char c; - union fooround u; -}; -/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT. - But in fact it might be less smart and round addresses to as much as - DEFAULT_ROUNDING. So we prepare for it to do that. */ -enum - { - DEFAULT_ALIGNMENT = offsetof (struct fooalign, u), - DEFAULT_ROUNDING = sizeof (union fooround) - }; - -/* When we copy a long block of data, this is the unit to do it with. - On some machines, copying successive ints does not work; - in such a case, redefine COPYING_UNIT to `long' (if that works) - or `char' as a last resort. */ -# ifndef COPYING_UNIT -# define COPYING_UNIT int -# endif - - -/* The functions allocating more room by calling `obstack_chunk_alloc' - jump to the handler pointed to by `obstack_alloc_failed_handler'. - This can be set to a user defined function which should either - abort gracefully or use longjump - but shouldn't return. This - variable by default points to the internal function - `print_and_abort'. */ -static void print_and_abort (void); -void (*obstack_alloc_failed_handler) (void) = print_and_abort; - -/* Exit value used when `print_and_abort' is used. */ -# include -# ifdef _LIBC -int obstack_exit_failure = EXIT_FAILURE; -# else -# include "exitfail.h" -# define obstack_exit_failure exit_failure -# endif - -# ifdef _LIBC -# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4) -/* A looong time ago (before 1994, anyway; we're not sure) this global variable - was used by non-GNU-C macros to avoid multiple evaluation. The GNU C - library still exports it because somebody might use it. */ -struct obstack *_obstack_compat; -compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0); -# endif -# endif - -/* Define a macro that either calls functions with the traditional malloc/free - calling interface, or calls functions with the mmalloc/mfree interface - (that adds an extra first argument), based on the state of use_extra_arg. - For free, do not use ?:, since some compilers, like the MIPS compilers, - do not allow (expr) ? void : void. */ - -# define CALL_CHUNKFUN(h, size) \ - (((h) -> use_extra_arg) \ - ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \ - : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size))) - -# define CALL_FREEFUN(h, old_chunk) \ - do { \ - if ((h) -> use_extra_arg) \ - (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \ - else \ - (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \ - } while (0) - - -/* Initialize an obstack H for use. Specify chunk size SIZE (0 means default). - Objects start on multiples of ALIGNMENT (0 means use default). - CHUNKFUN is the function to use to allocate chunks, - and FREEFUN the function to free them. - - Return nonzero if successful, calls obstack_alloc_failed_handler if - allocation fails. */ - -int -_obstack_begin (struct obstack *h, - int size, int alignment, - void *(*chunkfun) (long), - void (*freefun) (void *)) -{ - register struct _obstack_chunk *chunk; /* points to new chunk */ - - if (alignment == 0) - alignment = DEFAULT_ALIGNMENT; - if (size == 0) - /* Default size is what GNU malloc can fit in a 4096-byte block. */ - { - /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc. - Use the values for range checking, because if range checking is off, - the extra bytes won't be missed terribly, but if range checking is on - and we used a larger request, a whole extra 4096 bytes would be - allocated. - - These number are irrelevant to the new GNU malloc. I suspect it is - less sensitive to the size of the request. */ - int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1)) - + 4 + DEFAULT_ROUNDING - 1) - & ~(DEFAULT_ROUNDING - 1)); - size = 4096 - extra; - } - - h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun; - h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; - h->chunk_size = size; - h->alignment_mask = alignment - 1; - h->use_extra_arg = 0; - - chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size); - if (!chunk) - (*obstack_alloc_failed_handler) (); - h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents, - alignment - 1); - h->chunk_limit = chunk->limit - = (char *) chunk + h->chunk_size; - chunk->prev = 0; - /* The initial chunk now contains no empty object. */ - h->maybe_empty_object = 0; - h->alloc_failed = 0; - return 1; -} - -int -_obstack_begin_1 (struct obstack *h, int size, int alignment, - void *(*chunkfun) (void *, long), - void (*freefun) (void *, void *), - void *arg) -{ - register struct _obstack_chunk *chunk; /* points to new chunk */ - - if (alignment == 0) - alignment = DEFAULT_ALIGNMENT; - if (size == 0) - /* Default size is what GNU malloc can fit in a 4096-byte block. */ - { - /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc. - Use the values for range checking, because if range checking is off, - the extra bytes won't be missed terribly, but if range checking is on - and we used a larger request, a whole extra 4096 bytes would be - allocated. - - These number are irrelevant to the new GNU malloc. I suspect it is - less sensitive to the size of the request. */ - int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1)) - + 4 + DEFAULT_ROUNDING - 1) - & ~(DEFAULT_ROUNDING - 1)); - size = 4096 - extra; - } - - h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun; - h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; - h->chunk_size = size; - h->alignment_mask = alignment - 1; - h->extra_arg = arg; - h->use_extra_arg = 1; - - chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size); - if (!chunk) - (*obstack_alloc_failed_handler) (); - h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents, - alignment - 1); - h->chunk_limit = chunk->limit - = (char *) chunk + h->chunk_size; - chunk->prev = 0; - /* The initial chunk now contains no empty object. */ - h->maybe_empty_object = 0; - h->alloc_failed = 0; - return 1; -} - -/* Allocate a new current chunk for the obstack *H - on the assumption that LENGTH bytes need to be added - to the current object, or a new object of length LENGTH allocated. - Copies any partial object from the end of the old chunk - to the beginning of the new one. */ - -void -_obstack_newchunk (struct obstack *h, int length) -{ - register struct _obstack_chunk *old_chunk = h->chunk; - register struct _obstack_chunk *new_chunk; - register long new_size; - register long obj_size = h->next_free - h->object_base; - register long i; - long already; - char *object_base; - - /* Compute size for new chunk. */ - new_size = (obj_size + length) + (obj_size >> 3) + h->alignment_mask + 100; - if (new_size < h->chunk_size) - new_size = h->chunk_size; - - /* Allocate and initialize the new chunk. */ - new_chunk = CALL_CHUNKFUN (h, new_size); - if (!new_chunk) - (*obstack_alloc_failed_handler) (); - h->chunk = new_chunk; - new_chunk->prev = old_chunk; - new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size; - - /* Compute an aligned object_base in the new chunk */ - object_base = - __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask); - - /* Move the existing object to the new chunk. - Word at a time is fast and is safe if the object - is sufficiently aligned. */ - if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT) - { - for (i = obj_size / sizeof (COPYING_UNIT) - 1; - i >= 0; i--) - ((COPYING_UNIT *)object_base)[i] - = ((COPYING_UNIT *)h->object_base)[i]; - /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT, - but that can cross a page boundary on a machine - which does not do strict alignment for COPYING_UNITS. */ - already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT); - } - else - already = 0; - /* Copy remaining bytes one by one. */ - for (i = already; i < obj_size; i++) - object_base[i] = h->object_base[i]; - - /* If the object just copied was the only data in OLD_CHUNK, - free that chunk and remove it from the chain. - But not if that chunk might contain an empty object. */ - if (! h->maybe_empty_object - && (h->object_base - == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents, - h->alignment_mask))) - { - new_chunk->prev = old_chunk->prev; - CALL_FREEFUN (h, old_chunk); - } - - h->object_base = object_base; - h->next_free = h->object_base + obj_size; - /* The new chunk certainly contains no empty object yet. */ - h->maybe_empty_object = 0; -} -# ifdef _LIBC -libc_hidden_def (_obstack_newchunk) -# endif - -/* Return nonzero if object OBJ has been allocated from obstack H. - This is here for debugging. - If you use it in a program, you are probably losing. */ - -/* Suppress -Wmissing-prototypes warning. We don't want to declare this in - obstack.h because it is just for debugging. */ -int _obstack_allocated_p (struct obstack *h, void *obj); - -int -_obstack_allocated_p (struct obstack *h, void *obj) -{ - register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ - register struct _obstack_chunk *plp; /* point to previous chunk if any */ - - lp = (h)->chunk; - /* We use >= rather than > since the object cannot be exactly at - the beginning of the chunk but might be an empty object exactly - at the end of an adjacent chunk. */ - while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj)) - { - plp = lp->prev; - lp = plp; - } - return lp != 0; -} - -/* Free objects in obstack H, including OBJ and everything allocate - more recently than OBJ. If OBJ is zero, free everything in H. */ - -# undef obstack_free - -void -obstack_free (struct obstack *h, void *obj) -{ - register struct _obstack_chunk *lp; /* below addr of any objects in this chunk */ - register struct _obstack_chunk *plp; /* point to previous chunk if any */ - - lp = h->chunk; - /* We use >= because there cannot be an object at the beginning of a chunk. - But there can be an empty object at that address - at the end of another chunk. */ - while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj)) - { - plp = lp->prev; - CALL_FREEFUN (h, lp); - lp = plp; - /* If we switch chunks, we can't tell whether the new current - chunk contains an empty object, so assume that it may. */ - h->maybe_empty_object = 1; - } - if (lp) - { - h->object_base = h->next_free = (char *) (obj); - h->chunk_limit = lp->limit; - h->chunk = lp; - } - else if (obj != 0) - /* obj is not in any of the chunks! */ - abort (); -} - -# ifdef _LIBC -/* Older versions of libc used a function _obstack_free intended to be - called by non-GCC compilers. */ -strong_alias (obstack_free, _obstack_free) -# endif - -int -_obstack_memory_used (struct obstack *h) -{ - register struct _obstack_chunk* lp; - register int nbytes = 0; - - for (lp = h->chunk; lp != 0; lp = lp->prev) - { - nbytes += lp->limit - (char *) lp; - } - return nbytes; -} - -/* Define the error handler. */ -# ifdef _LIBC -# include -# else -# include "gettext.h" -# endif -# ifndef _ -# define _(msgid) gettext (msgid) -# endif - -# ifdef _LIBC -# include -# endif - -# ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) -# define __attribute__(Spec) /* empty */ -# endif -# endif - -static void -__attribute__ ((noreturn)) -print_and_abort (void) -{ - /* Don't change any of these strings. Yes, it would be possible to add - the newline to the string and use fputs or so. But this must not - happen because the "memory exhausted" message appears in other places - like this and the translation should be reused instead of creating - a very similar string which requires a separate translation. */ -# ifdef _LIBC - (void) __fxprintf (NULL, "%s\n", _("memory exhausted")); -# else - fprintf (stderr, "%s\n", _("memory exhausted")); -# endif - exit (obstack_exit_failure); -} - -#endif /* !ELIDE_CODE */ diff --git a/external/libsdf/libsw/op_template.c b/external/libsdf/libsw/op_template.c deleted file mode 100644 index afff00b..0000000 --- a/external/libsdf/libsw/op_template.c +++ /dev/null @@ -1,34 +0,0 @@ - - /* This is a template that is included multiple times in mpmy_combine.c */ - - switch(manifest->u.op) { - case MPMY_SUM: - Do_Op(outbuf, +=, inbuf, Type, count); - break; - case MPMY_PROD: - Do_Op(outbuf, *=, inbuf, Type, count); - break; - case MPMY_MAX: - Do_Op(outbuf, - = (*(Type *)outbuf > *(Type *)inbuf) ? *(Type *)outbuf :, - inbuf, Type, count); - break; - case MPMY_MIN: - Do_Op(outbuf, - = (*(Type *)outbuf < *(Type *)inbuf) ? *(Type *)outbuf :, - inbuf, Type, count); - break; -#ifdef BIT_OPS - case MPMY_BAND: - Do_Op(outbuf, &=, inbuf, Type, count); - break; - case MPMY_BOR: - Do_Op(outbuf, |=, inbuf, Type, count); - break; - case MPMY_BXOR: - Do_Op(outbuf, ^=, inbuf, Type, count); - break; -#endif - default: - Error("Unknown op in mpmy_combine\n"); - } diff --git a/external/libsdf/libsw/peano.c b/external/libsdf/libsw/peano.c deleted file mode 100644 index 72609e5..0000000 --- a/external/libsdf/libsw/peano.c +++ /dev/null @@ -1,363 +0,0 @@ -#ifndef NDIM -#define NDIM 3 -#endif - -#include "Msgs.h" -#include "Assert.h" -#include "key.h" -#include "vop.h" - - -/* The long-awaited peano-hilbert key. */ -/* "When the going gets wierd, the wierd turn pro." */ -/* Interestingly, it isn't particularly more complicated by virtue */ -/* of the arbitrary NDIM support. The NDIM=3 only code was essentially */ -/* the same except for some loop indices */ - -#if NDIM==3 -/* The possible places to start. */ -/* They can only have an even number of bits turned on. */ -#define S000 0 -#define S011 1 -#define S101 2 -#define S110 3 -/* one for each of the possible startindices */ -static int sindex_to_mask[1<<(NDIM-1)] = {0, 3, 5, 6}; -static int smask_to_index[1<>rshift)&1; -#if NDIM > 1 - bits |= ((ikey1>>rshift)&1) << 1; -#if NDIM > 2 - bits |= ((ikey2>>rshift)&1) << 2; -#endif -#endif - ret = KeyOrInt(KeyLshift(ret, NDIM), bitmap[start][type][bits]); - otype = type; - type = typmap[start][otype][bits]; - start = startmap[start][otype][bits]; - } - return ret; -} - -Key_t PHKeyFromInts(unsigned int ikey[NDIM], int ndim, unsigned int depth){ - assert(ndim == NDIM); - return _PHKeyFromInts(ikey, depth, 0, 0); -} - -/* Convert from a PH key to a NDIM-tuple of ints. */ -/* Return the "depth" of the key */ - -static unsigned int -_IntsFromPHKey(Key_t key, unsigned int ikey[NDIM], - int depth, int start, int type){ - unsigned int lobits, unscrambled; - unsigned int otype; - unsigned int rshift, ret; - Vxd(unsigned int out); - Key_t keymax; - Key_t key0; - - if( !setup_done ) - setup(); - keymax = KeyLshift(KeyInt(1), NDIM*depth); - key0 = KeyInt(0); - - VxS(out, = 0); - /* We need to start at the left, so we need to figure out where the */ - /* left of key is! */ - while( KeyEQ(KeyAnd(keymax, key), key0) ){ - keymax = KeyRshift(keymax, NDIM); - depth--; - } - ret = depth; - - rshift = depth*NDIM; - Msgf(("IntsFromPHKey(%s)\n", PrintKey(key))); - while( rshift > 0 ){ - Key_t kr; - rshift -= NDIM; - depth--; - kr = KeyRshift(key, rshift); - lobits = KeyAndInt(kr, (1< 1 - out1 |= ((unscrambled>>1)&1)< 2 - out2 |= ((unscrambled>>2)&1)<= NDIM ) - Error("bad type\n"); - if( start < 0 || start >= 1<<(NDIM-1) ) - Error("bad start"); - - /* Test each ikey in a 3-d grid. Make sure that - _IntsFromKey(KeyFromInts(ik)) == ik */ - for(ik[0]=0; ik[0]<(1< %s -> revk=(%x %x %x)\n", - ik[0], ik[1], ik[2], - PrintKey(key), - revk[0], revk[1], revk[2]); - } - } - } - - /* Test each key starting at 0. Make sure that - KeyFromInts(IntsFromKey(k))==k */ - base = KeyLshift(KeyInt(1), depth*NDIM); - for(ikey=0; ikey < (1<<(NDIM*depth)); ikey++){ - Key_t revkey; - unsigned int di[NDIM]; - unsigned int iklast[NDIM]; - int d2; - - revd = _IntsFromPHKey(base, ik, depth, start, type); - assert(revd == depth); - revkey = _PHKeyFromInts(ik, depth, start, type); - if( KeyNEQ(revkey, base)){ - char s[64]; - strcpy(s, PrintKey(revkey)); - Warning("key %s -> %x %x %x -> %s\n", - PrintKey(base), ik[0], ik[1], ik[2], s); - } - VVV(di, = ik, - iklast); - d2 = Dot(di, di); - if( d2 != 1 && ikey ){ - Warning("Move by more than 1 at ikey=%#0o\n", ikey); - } - - VV(iklast, = ik); - base = KeyAddInt(base, 1); - } - exit(0); -} - -#endif - -#if NDIM==2 - -#define SZ 6. /* inches */ -main(int argc, char **argv){ - int depth; - unsigned int i, ikey; - unsigned int ik[NDIM]; - int type, start; - unsigned int revk[NDIM], revd; - Key_t key, base; - - depth = atoi(argv[1]); - start = atoi(argv[2]); - type = atoi(argv[3]); - if( depth < 0 ) - Error("bad depth\n"); - if( type < 0 || type >= NDIM ) - Error("bad type\n"); - if( start < 0 || start >= 1<<(NDIM-1) ) - Error("bad start"); - - Warning("This is test of the emergency warning system\n"); - /* Test each ikey in a 3-d grid. Make sure that - _IntsFromKey(KeyFromInts(ik)) == ik */ - for(ik[0]=0; ik[0]<(1< %s -> revk=(%x %x)\n", - ik[0], ik[1], - PrintKey(key), - revk[0], revk[1]); - } - } - - /* Test each key starting at 0. Make sure that - KeyFromInts(IntsFromKey(k))==k */ - printf("%%!\n"); - printf("/L {2 copy lineto stroke moveto pop} def\n"); - printf("72 72 translate\n"); - printf("%%scale to 6 inches width, hgt\n"); - printf("%g %g scale\n", 72.*SZ/(1< %x %x -> %s\n", - PrintKey(base), ik[0], ik[1], s); - } - printf("%d %d %d L\n", i, ik[0], ik[1]); - VVV(di, = ik, - iklast); - d2 = Dot(di, di); - if( d2 != 1 && ikey ){ - Warning("Move by more than 1 at ikey=%#0o\n", ikey); - } - - VV(iklast, = ik); - base = KeyAddInt(base, 1); - } - printf("showpage\n"); - exit(0); -} - -#endif /* NDIM==2 */ -#endif /* STANDALONE */ diff --git a/external/libsdf/libsw/poll.1.c b/external/libsdf/libsw/poll.1.c deleted file mode 100644 index ac904ae..0000000 --- a/external/libsdf/libsw/poll.1.c +++ /dev/null @@ -1,225 +0,0 @@ -#include -#include "mpmy.h" -#include "Msgs.h" -#include "assert.h" -#include "gc.h" -#include "timers.h" -#include "error.h" -#include "Malloc.h" -#include "dll.h" -#include "chn.h" -#include "poll.h" - -#define INBUFSZ (16384*sizeof(int)) -#define MAXRELAY 4096 -#define MAXLOCAL 64 -#define MAXREMOTE 2048 -Timer_t PollWaitTm; - -static void (*func)(); -static int size; -static int polldone; -static int localdone; -static int remotedone; -static int localid; -static int nremote; -static int nrelay_active; -static int nrelay_highwater; -static MPMY_Comm_request inreq; -static char localpoll[MAXLOCAL]; -static char remotepoll[MAXREMOTE]; -static int *relaybuf[MAXRELAY]; -static int inbuf[INBUFSZ/sizeof(int)]; /* avoid using malloc */ - -static void -process(int count, int tag) -{ - int dest = inbuf[0]; - - if (dest < 0 || dest >= MPMY_Nproc()) { - Error("Bad dest in Poll()\n"); - } - if (dest != MPMY_Procnum()) { /* relay */ - MPMY_Comm_request req; - - Msgf(("PollRelay: %d to %d using buffer %d\n", count, dest, nrelay_active)); - if (nrelay_active > MAXRELAY) Error("Out of relay buffers\n"); - memcpy(relaybuf[nrelay_active], inbuf, count); - MPMY_Isend(relaybuf[nrelay_active++], count, dest, tag, &req); - if (nrelay_active > nrelay_highwater) nrelay_highwater = nrelay_active; - MPMY_Irecv(&inbuf, size, MPMY_SOURCE_ANY, tag, &inreq); - /* This should be something more like a select() to free intermediate buffers */ - PollWait(req, tag); - if (--nrelay_active < 0) Error("Bad value for nrelay_active\n"); - } else if (count == 2*sizeof(int)) { - int src = inbuf[1]; - if (src < 0 || src >= MAXLOCAL+MAXREMOTE) { - Error("Bad src in Poll()\n"); - } - Msgf(("PollDone msg from %d\n", src)); - if (localid) polldone = 1; - else if (src < MAXLOCAL) { - /* local done message */ - if (src >= MPMY_ProcsPerNode()) Error("Bad src in Poll()\n"); - if (localpoll[src]) - Error("localpoll[%d] already set!\n", src); - if (localdone >= MPMY_ProcsPerNode()) Error("localdone already acheived\n"); - localpoll[src] = 1; - localdone++; - Msgf(("Poll: localdone is %d\n", localdone)); - } else { - /* remote done message */ - src -= MAXLOCAL; - if (src >= nremote) Error("Bad src in Poll()\n"); - if (remotepoll[src]) - Error("remotepoll[%d] already set!\n", src); - if (remotedone >= nremote) Error("remotedone already acheived\n"); - remotepoll[src] = 1; - if (++remotedone >= nremote) polldone = 1; - Msgf(("Poll: remotedone is %d\n", remotedone)); - } - MPMY_Irecv(&inbuf, size, MPMY_SOURCE_ANY, tag, &inreq); - } else { - Msgf(("PollProcess: %d\n", count)); - func(inbuf+1, count-sizeof(int)); - MPMY_Irecv(&inbuf, size, MPMY_SOURCE_ANY, tag, &inreq); - } -} - - -void -PollSetup(void put(void *buf, int size), int max_size, int tag) -{ - int i; - int procs_per_node = MPMY_ProcsPerNode(); - - Msgf(("PollSetup\n")); - func = put; - if (max_size > INBUFSZ) SinglError("INBUFSZ too small\n"); - if (procs_per_node > MAXLOCAL) SinglError("MAXLOCAL too small\n"); - if ((MPMY_Nproc()-1)/procs_per_node >= MAXREMOTE) SinglError("MAXREMOTE too small\n"); - nrelay_active = nrelay_highwater = polldone = localdone = remotedone = 0; - localid = MPMY_Procnum() % procs_per_node; - nremote = (MPMY_Nproc() + procs_per_node - 1) / procs_per_node; - for (i = 0; i < procs_per_node; i++) localpoll[i] = 0; - for (i = 0; i < nremote; i++) remotepoll[i] = 0; - if (MPMY_Nproc() % procs_per_node) { - if (MPMY_Procnum() == MPMY_Nproc() - 1) { - for (i = MPMY_Nproc() % procs_per_node; i < procs_per_node; i++) { - localpoll[i] = 1; - ++localdone; - } - } - } - if (localid == 0) { - for (i = 0; i < MAXRELAY; i++) { - relaybuf[i] = Malloc(INBUFSZ); - } - } - - /* In fact, this test is insufficient if somebody decides to send - a short message anyway we'll still be confused! */ - if (max_size == sizeof(int) || max_size == 2*sizeof(int)) - SinglError("Poll uses size for message sorting. You can't use size=%ld or %ld without some new coding\n", (long)sizeof(int), (long)2*sizeof(int)); - - size = max_size; - MPMY_Irecv(&inbuf, size, MPMY_SOURCE_ANY, tag, &inreq); -} - -void -Poll(int tag) -{ - int flag; - MPMY_Status stat; - - Msgf(("P(tag=%d)\n", tag)); - MPMY_Flick(); - while (MPMY_Test(inreq, &flag, &stat), flag) { - process(stat.count, tag); - } -} - -/* If we use a plain MPMY_Wait() during a poll session, deadlock may */ -/* result from isends blocking */ -void -PollWait(MPMY_Comm_request req, int tag) -{ - int flag; - MPMY_Status stat; - - Msgf(("PW(tag=%d)\n", tag)); - while (1) { - if (MPMY_Test(req, &flag, 0), flag) return; - if (MPMY_Test(inreq, &flag, &stat), flag) process(stat.count, tag); - MPMY_Flick(); - } -} - -void -PollUntilDone(int tag) -{ - MPMY_Comm_request req; - MPMY_Status stat; - int buf[2]; - int i; - int procnum = MPMY_Procnum(); - int procs_per_node = MPMY_ProcsPerNode(); - - Msg("polldone", ("PUD(tag=%d)\n", tag)); - StartTimer(&PollWaitTm); - if (localid == 0) { - /* I'm a group master */ - if (localpoll[0]) Error("localpoll[0] already set!\n"); - localpoll[0] = 1; - ++localdone; - while (localdone != procs_per_node) { /* not right if Nproc() % procs_per_node */ - MPMY_Wait(inreq, &stat); - process(stat.count, tag); - } - Msg("polldone", ("PollDone local group finished\n")); - /* Tell masters our group is done */ - for (i = 0; i < nremote; i++) { - buf[0] = i*procs_per_node; - buf[1] = MAXLOCAL + MPMY_Procnum() / procs_per_node; - Msg("polldone", ("PollDone sent to remote master %d\n", i*procs_per_node)); - MPMY_Isend(buf, 2*sizeof(int), i*procs_per_node, tag, &req); - PollWait(req, tag); - } - while (!polldone) { - MPMY_Wait(inreq, &stat); - process(stat.count, tag); - } - /* Tell local group we are done */ - for (i = MPMY_Procnum()+1; i < MPMY_Procnum()+procs_per_node && i < MPMY_Nproc(); i++) { - buf[0] = i; - buf[1] = 0; - Msg("polldone", ("PollDone sent to %d\n", i)); - MPMY_Isend(buf, 2*sizeof(int), i, tag, &req); - PollWait(req, tag); - } - } else { - /* I'm a slave in the local group */ - int dest = (procnum / procs_per_node) * procs_per_node; - buf[0] = dest; - buf[1] = localid; - /* Tell local master we're done */ - Msg("polldone", ("PollDone sent to local master %d\n", dest)); - MPMY_Isend(buf, 2*sizeof(int), dest, tag, &req); - PollWait(req, tag); - while (!polldone) { - MPMY_Wait(inreq, &stat); - process(stat.count, tag); - } - } - /* self send to clean up inreq */ - MPMY_Isend(buf, sizeof(int), MPMY_Procnum(), tag, &req); - MPMY_Wait(req, 0); - MPMY_Wait(inreq, 0); - StopTimer(&PollWaitTm); - if (localid == 0) { - for (i = 0; i < MAXRELAY; i++) { - Free(relaybuf[i]); - } - } - Msgf(("PollDone, nrelay_highwater = %d\n", nrelay_highwater)); -} diff --git a/external/libsdf/libsw/poll.c b/external/libsdf/libsw/poll.c deleted file mode 100644 index 6e2cd9e..0000000 --- a/external/libsdf/libsw/poll.c +++ /dev/null @@ -1,244 +0,0 @@ -#include -#include "mpmy.h" -#include "Msgs.h" -#include "assert.h" -#include "gc.h" -#include "timers.h" -#include "error.h" -#include "dll.h" -#include "chn.h" -#include "poll.h" - -#define INBUFSZ (16384*sizeof(int)) -#define MAXRELAY 512 -#define MAXLOCAL 64 -#define MAXREMOTE 2048 -Timer_t PollWaitTm; - -static void (*func)(); -static int size; -static int polldone; -static int localdone; -static int remotedone; -static int localid; -static int nremote; -static MPMY_Comm_request inreq; -static char localpoll[MAXLOCAL]; -static char remotepoll[MAXREMOTE]; -static int bufused[MAXRELAY]; -MPMY_Comm_request Rreq[MAXRELAY]; -static int relaybuf[MAXRELAY][INBUFSZ/sizeof(int)]; -static int inbuf[INBUFSZ/sizeof(int)]; /* avoid using malloc */ - -static int -allocbuf(void) -{ - int i; - int flag; - int inuse; - - inuse = 0; - for (i = 0; i < MAXRELAY; i++) { - if (bufused[i] == 1) { - if (MPMY_Test(Rreq[i], &flag, 0), flag) { - bufused[i] = 0; - } else inuse++; - } - } - Msgf(("%d relay inuse\n", ++inuse)); - for (i = 0; i < MAXRELAY; i++) { - if (bufused[i] == 0) { - bufused[i] = 1; - return i; - } - } - Error("Out of relay buffers\n"); -} - - -static void -process(int count, int tag) -{ - int dest = inbuf[0]; - - if (dest < 0 || dest >= MPMY_Nproc()) { - Error("Bad dest in Poll()\n"); - } - if (dest != MPMY_Procnum()) { /* relay */ - int i; - i = allocbuf(); - Msgf(("PollRelay: %d to %d using buffer %d\n", count, dest, i)); - memcpy(relaybuf[i], inbuf, count); - MPMY_Isend(relaybuf[i], count, dest, tag, Rreq+i); - MPMY_Irecv(&inbuf, size, MPMY_SOURCE_ANY, tag, &inreq); - } else if (count == 2*sizeof(int)) { - int src = inbuf[1]; - if (src < 0 || src >= MAXLOCAL+MAXREMOTE) { - Error("Bad src in Poll()\n"); - } - Msgf(("PollDone msg from %d\n", src)); - if (localid) polldone = 1; - else if (src < MAXLOCAL) { - /* local done message */ - if (src >= MPMY_ProcsPerNode()) Error("Bad src in Poll()\n"); - if (localpoll[src]) - Error("localpoll[%d] already set!\n", src); - if (localdone >= MPMY_ProcsPerNode()) Error("localdone already acheived\n"); - localpoll[src] = 1; - localdone++; - Msgf(("Poll: localdone is %d\n", localdone)); - } else { - /* remote done message */ - src -= MAXLOCAL; - if (src >= nremote) Error("Bad src in Poll()\n"); - if (remotepoll[src]) - Error("remotepoll[%d] already set!\n", src); - if (remotedone >= nremote) Error("remotedone already acheived\n"); - remotepoll[src] = 1; - if (++remotedone >= nremote) polldone = 1; - Msgf(("Poll: remotedone is %d\n", remotedone)); - } - MPMY_Irecv(&inbuf, size, MPMY_SOURCE_ANY, tag, &inreq); - } else { - Msgf(("PollProcess: %d\n", count)); - func(inbuf+1, count-sizeof(int)); - MPMY_Irecv(&inbuf, size, MPMY_SOURCE_ANY, tag, &inreq); - } -} - - -void -PollSetup(void put(void *buf, int size), int max_size, int tag) -{ - int i; - int procs_per_node = MPMY_ProcsPerNode(); - - Msgf(("PollSetup\n")); - func = put; - if (max_size > INBUFSZ) SinglError("INBUFSZ too small\n"); - if (procs_per_node > MAXLOCAL) SinglError("MAXLOCAL too small\n"); - if ((MPMY_Nproc()-1)/procs_per_node >= MAXREMOTE) SinglError("MAXREMOTE too small\n"); - polldone = localdone = remotedone = 0; - localid = MPMY_Procnum() % procs_per_node; - nremote = (MPMY_Nproc() + procs_per_node - 1) / procs_per_node; - for (i = 0; i < procs_per_node; i++) localpoll[i] = 0; - for (i = 0; i < nremote; i++) remotepoll[i] = 0; - for (i = 0; i < MAXRELAY; i++) bufused[i] = 0; - if (MPMY_Nproc() % procs_per_node) { - if (MPMY_Procnum() == MPMY_Nproc() - 1) { - for (i = MPMY_Nproc() % procs_per_node; i < procs_per_node; i++) { - localpoll[i] = 1; - ++localdone; - } - } - } - - /* In fact, this test is insufficient if somebody decides to send - a short message anyway we'll still be confused! */ - if (max_size == sizeof(int) || max_size == 2*sizeof(int)) - SinglError("Poll uses size for message sorting. You can't use size=%ld or %ld without some new coding\n", (long)sizeof(int), (long)2*sizeof(int)); - - size = max_size; - MPMY_Irecv(&inbuf, size, MPMY_SOURCE_ANY, tag, &inreq); -} - -void -Poll(int tag) -{ - int flag; - MPMY_Status stat; - - Msgf(("P(tag=%d)\n", tag)); - while (MPMY_Test(inreq, &flag, &stat), flag) { - process(stat.count, tag); - MPMY_Flick(); - } -} - -/* If we use a plain MPMY_Wait() during a poll session, deadlock may */ -/* result from isends blocking */ -void -PollWait(MPMY_Comm_request req, int tag) -{ - int flag; - MPMY_Status stat; - - Msgf(("PW(tag=%d)\n", tag)); - while (1) { - if (MPMY_Test(req, &flag, 0), flag) return; - if (MPMY_Test(inreq, &flag, &stat), flag) process(stat.count, tag); - MPMY_Flick(); - } -} - -void -PollUntilDone(int tag) -{ - MPMY_Comm_request req; - MPMY_Status stat; - int buf[2]; - int i; - int procnum = MPMY_Procnum(); - int procs_per_node = MPMY_ProcsPerNode(); - - Msg("polldone", ("PUD(tag=%d)\n", tag)); - StartTimer(&PollWaitTm); - if (localid == 0) { - /* I'm a group master */ - if (localpoll[0]) Error("localpoll[0] already set!\n"); - localpoll[0] = 1; - ++localdone; - while (localdone != procs_per_node) { /* not right if Nproc() % procs_per_node */ - MPMY_Wait(inreq, &stat); - process(stat.count, tag); - } - Msg("polldone", ("PollDone local group finished\n")); - /* Tell masters our group is done */ - for (i = 0; i < nremote; i++) { - buf[0] = i*procs_per_node; - buf[1] = MAXLOCAL + MPMY_Procnum() / procs_per_node; - Msg("polldone", ("PollDone sent to remote master %d\n", i*procs_per_node)); - MPMY_Isend(buf, 2*sizeof(int), i*procs_per_node, tag, &req); - PollWait(req, tag); - } - while (!polldone) { - MPMY_Wait(inreq, &stat); - process(stat.count, tag); - for (i = 0; i < MAXRELAY; i++) { - int flag; - if (bufused[i] == 1) { - if (MPMY_Test(Rreq[i], &flag, 0), flag) { - bufused[i] = 0; - } - } - } - } - /* Tell local group we are done */ - for (i = MPMY_Procnum()+1; i < MPMY_Procnum()+procs_per_node && i < MPMY_Nproc(); i++) { - buf[0] = i; - buf[1] = 0; - Msg("polldone", ("PollDone sent to %d\n", i)); - MPMY_Isend(buf, 2*sizeof(int), i, tag, &req); - PollWait(req, tag); - } - } else { - /* I'm a slave in the local group */ - int dest = (procnum / procs_per_node) * procs_per_node; - buf[0] = dest; - buf[1] = localid; - /* Tell local master we're done */ - Msg("polldone", ("PollDone sent to local master %d\n", dest)); - MPMY_Isend(buf, 2*sizeof(int), dest, tag, &req); - PollWait(req, tag); - while (!polldone) { - MPMY_Wait(inreq, &stat); - process(stat.count, tag); - } - } - /* self send to clean up inreq */ - MPMY_Isend(buf, sizeof(int), MPMY_Procnum(), tag, &req); - MPMY_Wait(req, 0); - MPMY_Wait(inreq, 0); - StopTimer(&PollWaitTm); - Msgf(("PollDone\n")); -} diff --git a/external/libsdf/libsw/qromo.c b/external/libsdf/libsw/qromo.c deleted file mode 100644 index f781a00..0000000 --- a/external/libsdf/libsw/qromo.c +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include "Malloc.h" -#include "error.h" -#include "qromo.h" - -#define NR_END 1 - -static float *vector(long nl, long nh) -/* allocate a float vector with subscript range v[nl..nh] */ -{ - float *v; - - v = Malloc((nh-nl+1+NR_END)*sizeof(float)); - return v-nl+NR_END; -} - -static void free_vector(v,nl,nh) -float *v; -long nh,nl; -/* free a float vector allocated with vector() */ -{ - Free(v+nl-NR_END); -} - -void polint(float xa[], float ya[], int n, float x, float *y, float *dy) -{ - int i,m,ns=1; - float den,dif,dift,ho,hp,w; - float *c,*d; - - dif=fabs(x-xa[1]); - c=vector(1,n); - d=vector(1,n); - for (i=1;i<=n;i++) { - if ( (dift=fabs(x-xa[i])) < dif) { - ns=i; - dif=dift; - } - c[i]=ya[i]; - d[i]=ya[i]; - } - *y=ya[ns--]; - for (m=1;m= K) { - polint(&h[j-K],&s[j-K],K,0.0,&ss,&dss); - if (fabs(dss) < EPS*fabs(ss)) return ss; - } - s[j+1]=s[j]; - h[j+1]=h[j]/9.0; - } - Error("Too many steps in routing qromo"); - return 0.0; -} diff --git a/external/libsdf/libsw/qromod.c b/external/libsdf/libsw/qromod.c deleted file mode 100644 index d50fed9..0000000 --- a/external/libsdf/libsw/qromod.c +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include "Malloc.h" -#include "error.h" -#include "qromo.h" - -#define NR_END 1 - -static double *vector(long nl, long nh) -/* allocate a double vector with subscript range v[nl..nh] */ -{ - double *v; - - v = Malloc((nh-nl+1+NR_END)*sizeof(double)); - return v-nl+NR_END; -} - -static void free_vector(v,nl,nh) -double *v; -long nh,nl; -/* free a double vector allocated with vector() */ -{ - Free(v+nl-NR_END); -} - -void polintd(double xa[], double ya[], int n, double x, double *y, double *dy) -{ - int i,m,ns=1; - double den,dif,dift,ho,hp,w; - double *c,*d; - - dif=fabs(x-xa[1]); - c=vector(1,n); - d=vector(1,n); - for (i=1;i<=n;i++) { - if ( (dift=fabs(x-xa[i])) < dif) { - ns=i; - dif=dift; - } - c[i]=ya[i]; - d[i]=ya[i]; - } - *y=ya[ns--]; - for (m=1;m= K) { - polintd(&h[j-K],&s[j-K],K,0.0,&ss,&dss); - if (fabs(dss) < EPS*fabs(ss)) return ss; - } - s[j+1]=s[j]; - h[j+1]=h[j]/9.0; - } - Error("Too many steps in routine qromod\n"); - return 0.0; -} diff --git a/external/libsdf/libsw/raise.c b/external/libsdf/libsw/raise.c deleted file mode 100644 index 7bdb4d0..0000000 --- a/external/libsdf/libsw/raise.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include - -int raise(int sig){ - return kill(getpid(), sig); -} diff --git a/external/libsdf/libsw/randoms.c b/external/libsdf/libsw/randoms.c deleted file mode 100644 index 4e9513d..0000000 --- a/external/libsdf/libsw/randoms.c +++ /dev/null @@ -1,126 +0,0 @@ -#include "error.h" -#include "randoms.h" - -/* ran2 from Numerical Recipes 2nd ed. modified to conform to our interface */ -/* You win $1000 from Press et al. if it fails non-trivially */ - -#define IM1 2147483563 -#define IM2 2147483399 -#define AM (1.0/IM1) -#define IMM1 (IM1-1) -#define IA1 40014 -#define IA2 40692 -#define IQ1 53668 -#define IQ2 52774 -#define IR1 12211 -#define IR2 3791 -#define NDIV (1+IMM1/NTAB) -#define EPS 1.2e-7 -#define RNMX (1.0-EPS) - -void -ran_init(int seed, ran_state *s) -{ - int j; - long k; - - if (seed < 1) - Error("Bad seed in ran_init2 (%d)\n", seed); - s->idum = s->idum2 = seed; - s->next_norml_ok = 0; - for (j=NTAB+7;j>=0;j--) { - k=(s->idum)/IQ1; - s->idum=IA1*(s->idum-k*IQ1)-k*IR1; - if (s->idum < 0) s->idum += IM1; - if (j < NTAB) s->iv[j] = s->idum; - } - s->iy=s->iv[0]; - s->did_init = IQ1; -} - -float -uniform_rand(ran_state *s) -{ - int j; - long k; - float temp; - - if (s->did_init != IQ1) - Error("You forgot to call ran_init2\n"); - k=(s->idum)/IQ1; - s->idum=IA1*(s->idum-k*IQ1)-k*IR1; - if (s->idum < 0) s->idum += IM1; - k=s->idum2/IQ2; - s->idum2=IA2*(s->idum2-k*IQ2)-k*IR2; - if (s->idum2 < 0) s->idum2 += IM2; - j=s->iy/NDIV; - s->iy=s->iv[j]-s->idum2; - s->iv[j] = s->idum; - if (s->iy < 1) s->iy += IMM1; - if ((temp=AM*s->iy) > RNMX) return RNMX; - else return temp; -} - -float normal_rand(ran_state *st) -/* -This is the Polar method for normal distributions, as described on or near -page 104 of Knuth, Semi-numerical Algorithms. To quote Knuth, "The polar -method is quite slow, but it has essentially perfect accuracy, and it is very -easy to write a program for the polar method..." 'nuf said. Algorithm due -to Box, Muller and Marsaglia. -*/ -{ - float v1, v2; /* uniformly distributed on [-1, 1) */ - float s; /* radius of a point pulled from a uniform circle */ - float foo; /* A useful intermediate value. */ - double log(double), sqrt(double); - - if(st->next_norml_ok){ - st->next_norml_ok = 0; - return st->next_norml; - } - - do{ - v1 = 2.0F * uniform_rand(st) - 1.0F; - v2 = 2.0F * uniform_rand(st) - 1.0F; - s = v1*v1 + v2*v2; - } while(s >= 1.0F); - foo = sqrt( -2.0F * log(s)/s); - st->next_norml_ok = 1; - st->next_norml = v1*foo; - return v2*foo; -} - -/* Return a uniform point in a ndim-sphere by rejection. */ -/* If ndim is large (bigger than 4 or so), this becomes very inefficient */ -/* Return the radius-squard of the result. */ -float sphere_rand(ran_state *st, int ndim, float *x) -{ - int k; - float rsqx; - - do { - rsqx = (float)0.0; - for (k = 0; k < ndim; k++) { - x[k] = uniform_rand(st)*2.0F - 1.0F; /* a pt in (-1,1) */ - rsqx += x[k] * x[k]; - } - } while (rsqx > (float)1.0); - return rsqx; -} - -/* Return a uniform point in a ndim-cube */ -/* Return the radius-squard of the result. */ -float cube_rand(ran_state *st, int ndim, float *x) -{ - int k; - float rsqx; - - rsqx = (float)0.0; - for (k = 0; k < ndim; k++) { - x[k] = uniform_rand(st)*2.0F - 1.0F; /* a pt in (-1,1) */ - rsqx += x[k] * x[k]; - } - return rsqx; -} - diff --git a/external/libsdf/libsw/ring.c b/external/libsdf/libsw/ring.c deleted file mode 100644 index 82413f0..0000000 --- a/external/libsdf/libsw/ring.c +++ /dev/null @@ -1,153 +0,0 @@ -#include -#include "ring.h" -#include "Malloc.h" -#include "mpmy.h" -#include "gc.h" -#include "Msgs.h" -#include "singlio.h" - -#define MSGTYPE 142 - -void -Ring(void *bptr, int bsize, int bnobj, - void *optr, int osize, int onobj, int oused, - void initf(void *, void *), void interactf(void *, void *, int, int)) -{ - char *p; - void *travel_btab; - void *tmpbuf; - int travel_size; - int n, i; - int from_proc, to_proc; - int procnum = MPMY_Procnum(); - int nproc = MPMY_Nproc(); - int max_nobj = onobj; - - MPMY_Combine(&onobj, &max_nobj, 1, MPMY_INT, MPMY_MAX); - - travel_size = max_nobj * oused; - travel_btab = Malloc(travel_size); - tmpbuf = Malloc(travel_size); - for (i = 0; i < onobj; i++) { - p = (char *)optr+i*osize; - initf((char *)travel_btab+i*oused, p); - } - -#if GRAYDECOMP - /* There should be functions like Gcup() which are periodic */ - to_proc = Gcup(procnum, nproc); - from_proc = Gcdown(procnum, nproc); - if (to_proc == -1) to_proc = bin2gray(0); - if (from_proc == -1) from_proc = bin2gray(nproc-1); -#else - to_proc = (procnum+1)%nproc; - from_proc = (procnum+nproc-1)%nproc; -#endif - - /* local part */ - for (p = bptr; p < (char *)bptr + bnobj * bsize; p += bsize) { - interactf(p, travel_btab, oused, onobj); - } - - for(n = 1; n < nproc; n++) { - MPMY_Comm_request req, req2; - MPMY_Status stat; - - singlPrintf("cycle %d starting\n", n); - Msgf(("communicate, cycle %d\n", n)); - /* This uses a lot more memory than packets would */ - memcpy(tmpbuf, travel_btab, travel_size); - MPMY_Irecv(travel_btab, travel_size, from_proc, MSGTYPE, &req); - MPMY_Isend(tmpbuf, onobj * oused, to_proc, MSGTYPE, &req2); - MPMY_Wait2(req, &stat, req2, 0); - onobj = MPMY_Count(&stat)/oused; - - Msgf(("compute, cycle %d\n", n)); - for (p = bptr; p < (char *)bptr + bnobj * bsize; p += bsize) { - interactf(p, travel_btab, oused, onobj); - } - } - Free(tmpbuf); - Free(travel_btab); -} - -/* Swap source and sink, and provide finishf() */ -void -Ring2(void *bptr, int bsize, int bnobj, - void *optr, int osize, int onobj, int tsize, - void initf(void *, void *), void interactf(void *, void *, int, int), void finishf(void *, void *)) -{ - char *p; - void *travel_btab; - void *tmpbuf; - int travel_size; - int n, i; - int from_proc, to_proc; - int procnum = MPMY_Procnum(); - int nproc = MPMY_Nproc(); - int max_nobj = onobj; - int initial_onobj = onobj; - MPMY_Comm_request req, req2; - MPMY_Status stat; - - - MPMY_Combine(&onobj, &max_nobj, 1, MPMY_INT, MPMY_MAX); - - travel_size = max_nobj * tsize; - travel_btab = Malloc(travel_size); - tmpbuf = Malloc(travel_size); - for (i = 0; i < onobj; i++) { - p = (char *)optr+i*osize; - initf((char *)travel_btab+i*tsize, p); - } - -#if GRAYDECOMP - /* There should be functions like Gcup() which are periodic */ - to_proc = Gcup(procnum, nproc); - from_proc = Gcdown(procnum, nproc); - if (to_proc == -1) to_proc = bin2gray(0); - if (from_proc == -1) from_proc = bin2gray(nproc-1); -#else - to_proc = (procnum+1)%nproc; - from_proc = (procnum+nproc-1)%nproc; -#endif - - /* local part */ - for (p = travel_btab; p < (char *)travel_btab + onobj * tsize; p += tsize) { - interactf(p, bptr, bsize, bnobj); - } - - for(n = 1; n < nproc; n++) { - singlPrintf("ring2, cycle %d starting\n", n); - Msgf(("communicate, cycle %d\n", n)); - /* This uses a lot more memory than packets would */ - memcpy(tmpbuf, travel_btab, onobj * tsize); - MPMY_Irecv(travel_btab, travel_size, from_proc, MSGTYPE, &req); - MPMY_Isend(tmpbuf, onobj * tsize, to_proc, MSGTYPE, &req2); - MPMY_Wait2(req, &stat, req2, 0); - onobj = MPMY_Count(&stat)/tsize; - - Msgf(("compute, cycle %d\n", n)); - for (p = travel_btab; p < (char *)travel_btab + onobj * tsize; p += tsize) { - interactf(p, bptr, bsize, bnobj); - } - } - - memcpy(tmpbuf, travel_btab, onobj * tsize); - MPMY_Irecv(travel_btab, travel_size, from_proc, MSGTYPE, &req); - MPMY_Isend(tmpbuf, onobj * tsize, to_proc, MSGTYPE, &req2); - MPMY_Wait2(req, &stat, req2, 0); - onobj = MPMY_Count(&stat)/tsize; - Free(tmpbuf); - - if (onobj != initial_onobj) Error("onobj doesn't match after trip around ring\n"); - - Msgf(("finish ring\n")); - if (finishf) { - for (i = 0; i < onobj; i++) { - p = (char *)optr+i*osize; - finishf((char *)travel_btab+i*tsize, p); - } - } - Free(travel_btab); -} diff --git a/external/libsdf/libsw/rsort.c b/external/libsdf/libsw/rsort.c deleted file mode 100644 index de78638..0000000 --- a/external/libsdf/libsw/rsort.c +++ /dev/null @@ -1,93 +0,0 @@ -#include -#include -#include "Malloc.h" -#include "key.h" - -#define pswap(a, b, sz) do { \ - char _c[sz]; \ - memcpy((void *)&_c, (void *)a, sz); \ - memcpy((void *)a, (void *)b, sz); \ - memcpy((void *)b, (void *)&_c, sz); \ - } while (0) - -#define STACKSIZE 16384 - -/* Only need to continue if there is more than 1 element */ -#define push(_shift, _offset, _n) \ - if (_n > 1LL && _shift >= 0) { \ - sp->shift = _shift; \ - sp->offset = _offset; \ - (sp++)->n = _n; \ - if (sp >= stack+STACKSIZE) Error("Stack overflow\n"); \ - } - -#define pop(_shift, _offset, _n) do { \ - _shift = (--sp)->shift; \ - _offset = sp->offset; \ - _n = sp->n; \ - } while (0) - - -/* insertion sort for small lists */ -static void -isort(void *k, int n, int sz, Key_t (*getkey)(const void *)) -{ - void *p, *q; - - for (p = k+sz; --n >= 1; p += sz) { - for (q = p; q > k; q -= sz) { - if (KeyGT(getkey(q), getkey(q-sz))) - break; - pswap(q, q-sz, sz); - } - } -} - -/* American Flag radix sort using aux storage of O(1) and stack of O(logN) */ -void -rsort(void *tag, int64_t n, int sz, int radixBits, int sortBits, Key_t (*getkey)(const void *)) -{ - int i, shift, c; - int64_t offset, *keyden, *pile; - void *ak; - unsigned int radix = 1 << radixBits; - unsigned int mask = radix - 1; - struct { - int shift; - int64_t offset; - int64_t n; - } stack[STACKSIZE], *sp = stack; - - keyden = Malloc(radix * sizeof(int64_t)); - pile = Malloc(radix * sizeof(int64_t)); - - /* start so last mask cycle uses all radixBits */ - push((sortBits-1)/radixBits*radixBits, 0, n); - - while (sp > stack) { - pop(shift, offset, n); - if (n < 64) { - isort(tag+offset*sz, n, sz, getkey); - continue; - } - - for (i = 0; i < radix; i++) - keyden[i] = 0; - for (ak = tag+offset*sz; ak < tag+(offset+n)*sz; ak += sz) - ++keyden[KeyAndInt(KeyRshift(getkey(ak), shift), mask)]; - for (pile[0] = keyden[0], i = 1; i < radix; i++) - pile[i] = pile[i-1]+keyden[i]; - push(shift-radixBits, offset, keyden[0]); - for (i = 1; i < radix; i++) - push(shift-radixBits, offset+pile[i-1], keyden[i]); - for (ak = tag+offset*sz; ak < tag+(offset+n-keyden[mask])*sz; ak += keyden[c]*sz) { - char tag_aux[sz]; - memcpy(tag_aux, ak, sz); /* in-place permutation */ - while (--pile[c = KeyAndInt(KeyRshift(getkey(tag_aux), shift), mask)] > (ak-tag)/sz-offset) - pswap(tag_aux, tag+(pile[c]+offset)*sz, sz); - memcpy(ak, tag_aux, sz); - } - } - Free(pile); - Free(keyden); -} diff --git a/external/libsdf/libsw/sigio_dump.c b/external/libsdf/libsw/sigio_dump.c deleted file mode 100644 index 47ad93a..0000000 --- a/external/libsdf/libsw/sigio_dump.c +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "error.h" -#include "singlio.h" -#include "Msgs.h" -#include "protos.h" -#include "mpmy.h" -#include "byteswap.h" -#include "memfile.h" - -static void sock_init(char *hostname, int *port, - struct sockaddr_in *acc, int bind_flag); - -static void setup_handler(void); -static void io_ready(int); - -static int sock; /* file descriptor for my UDP socket */ - -void -sigio_setup(void) -{ - int port = 4000; - struct sockaddr_in my_addr; - - setup_handler(); - sock_init(NULL, &port, &my_addr, 1); /* get my sockaddr */ - - if (fcntl(sock, F_SETOWN, getpid()) < 0) - Error("F_SETOWN error\n"); - -#ifdef FASYNC - if (fcntl(sock, F_SETFL, FASYNC) < 0) - Error("F_SETFL FASYNC error\n"); -#endif - -} - - -static void -setup_handler(void) -{ - signal(SIGIO, io_ready); -} - -static void -io_ready(int sig) -{ - int node; - - PrintMemfile(); - signal(SIGIO, io_ready); - return; -} - -/* This is virtually identical to the lsv code */ - -static void -sock_init(char *hostname, int *port, struct sockaddr_in *acc, int bind_flag) -{ - struct hostent *hp; - char host_name[256]; - unsigned long inaddr; - int tries = 0; - - if (hostname == NULL) { - if( (hostname = getenv("LSV_HOSTNAME")) == NULL ){ - if (gethostname(host_name, 256)) - Error("sock_create: gethostname failed\n"); - hostname = host_name; - } - } - memset(acc, 0, sizeof(struct sockaddr_in)); - acc->sin_family = htons(AF_INET); - - if ((inaddr = inet_addr(hostname)) != -1) /* it is numeric */ - acc->sin_addr.s_addr = inaddr; - else if ((hp = gethostbyname(hostname)) != (struct hostent *)0) - memcpy(&(acc->sin_addr), hp->h_addr, hp->h_length); - else - Error("gethostbyname failed\n"); - - if (bind_flag) { - sock = socket(AF_INET, SOCK_DGRAM, 0); - } - try_again: - acc->sin_port = htons(*port); - if (bind_flag) { - int ret; - ret = bind(sock,(struct sockaddr *)acc,sizeof(struct sockaddr_in)); - if (ret < 0 ) { - if (tries < 100) { - /* printf("bind returns %d\n", ret); */ - (*port)++; - tries++; - goto try_again; - } else { - Error("Can't bind socket. Tried %d, up to port %d\n", - tries, *port); - exit(1); - } - } - Msg_do("sigio_dump at %s port %d\n", hostname, *port); - errno = 0; /* clear errors */ - } -} diff --git a/external/libsdf/libsw/singlio.c b/external/libsdf/libsw/singlio.c deleted file mode 100644 index 17523df..0000000 --- a/external/libsdf/libsw/singlio.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include "protos.h" -#include "mpmy.h" -#include "Msgs.h" -#include "singlio.h" - -static int singl_auto_flush = 1; - -int singlAutoflush(int new){ - int ret = singl_auto_flush; - singl_auto_flush = new; - return ret; -} - -int singlPrintf(const char *fmt, ...){ - va_list ap; - int ret; - - if(MPMY_Procnum() != 0 ) - return 0; - va_start(ap, fmt); - ret = vfprintf(stdout, fmt, ap); - va_end(ap); - if( singl_auto_flush ) - fflush(stdout); - return ret; -} - -void singlFflush(void) -{ - if( MPMY_Procnum() != 0 ) - return; - fflush(stdout); -} diff --git a/external/libsdf/libsw/stk.c b/external/libsdf/libsw/stk.c deleted file mode 100644 index 1800e6b..0000000 --- a/external/libsdf/libsw/stk.c +++ /dev/null @@ -1,67 +0,0 @@ -#define STKdotC -#include "Assert.h" -#include "stk.h" -#include "error.h" -/* Everything else is inlined in stk.h */ - -/* Any non-inlined definitions can go here. */ - -void StkInit(struct stk *s, size_t initial_sz, - void *(*realloc_like)(void *, size_t), unsigned int alignment){ - s->growby = initial_sz; - s->realloc_like = realloc_like; - s->ptr = s->bottom = realloc_like(NULL, initial_sz); - s->top = s->bottom + initial_sz; - if( alignment == 0 ) - alignment = _STK_DEFAULT_ALIGNMENT; - assert( (alignment & (alignment-1)) == 0 ); - s->align_mask = alignment - 1; -} - -void StkInitWithData(struct stk *s, size_t initial_sz, - void *(*realloc_like)(void *, size_t), void *data, - unsigned int alignment){ - s->growby = initial_sz; - s->realloc_like = realloc_like; - s->bottom = data; - s->top = s->ptr = s->bottom + initial_sz; - if( alignment == 0 ) - alignment = _STK_DEFAULT_ALIGNMENT; - assert( (alignment & (alignment-1)) == 0 ); - s->align_mask = alignment - 1; -} - -void StkCopy(struct stk *to, const struct stk *from){ - size_t initial_sz; - - to->growby = from->growby; - to->realloc_like = from->realloc_like; - initial_sz = StkSz(from); - to->bottom = to->realloc_like(NULL, initial_sz); - to->top = to->ptr = to->bottom + initial_sz; - memcpy(to->bottom, from->bottom, initial_sz); -} - -void StkTerminate(struct stk *s){ - (*s->realloc_like)(s->bottom, 0); /* free */ - s->ptr = s->bottom = s->top = NULL; -} - -void StkGrow(Stk *s, int nbytes){ - size_t newsz = (s->ptr - s->bottom) + nbytes + s->growby; - char *newbottom = (*s->realloc_like)(s->bottom, newsz); - if( newbottom == NULL ){ - Error("Can't realloc to sz=%ld in StkGrow\n", newsz); - } - s->ptr = (s->ptr - s->bottom) + newbottom; - s->top = newbottom + newsz; - s->bottom = newbottom; -} - -void *StkCrunch(struct stk *s){ - size_t newsz = s->ptr - s->bottom; - char *newbottom = (*s->realloc_like)(s->bottom, newsz); - s->ptr = s->top = newsz + newbottom; - s->bottom = newbottom; - return newbottom; -} diff --git a/external/libsdf/libsw/swampi.c b/external/libsdf/libsw/swampi.c deleted file mode 100644 index 6c6979a..0000000 --- a/external/libsdf/libsw/swampi.c +++ /dev/null @@ -1,1428 +0,0 @@ -/* - * Copyright 1997 Michael Warren & John Salmon. All Rights Reserved. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if defined(__SUN4__) || defined(__SUN5__) || defined(linux) -/* SunOS hides TCP_NODELAY and TCP_MAXSEG in netinet/tcp.h */ -#include -#endif -#ifdef __alpha -#include -#endif -#include "protos.h" -#include "swampi.h" -#include "mpmy.h" -#include "mpmy_io.h" -#include "mpmy_abnormal.h" -#include "error.h" -#include "Msgs.h" -#include "dll.h" -#include "hwclock.h" - -#ifndef INADDR_NONE -/* e.g., on SunOS */ -#define INADDR_NONE (-1) -#endif - -#ifndef MAX -#define MAX(a, b) ((a > b) ? a : b) -#define MIN(a, b) ((a < b) ? a : b) -#endif - -#define H_MAGIC (0x9f07) /* Magic number for headers */ - -#define HOST_NUM (-1) /* can't redefine this without mem adjust. */ - -/* message header */ -typedef struct { - int src : 20; - unsigned int comm : 6; - int len; - int tag; - int magic; -} msghdr_t; - -typedef struct { - int proc : 20; - unsigned int comm : 6; - unsigned int pending : 1; - unsigned int outgoing : 1; - unsigned int hdr_flag : 1; - unsigned int wild_src : 1; - unsigned int wild_tag : 1; - unsigned int buffered : 1; - int len; - int left; - int tag; - char *buf; /* This is where the message belongs */ - char *ptr; /* This might be a malloced temp buffer */ -} req_t; - -/* Must match MPI_Datatype enum */ -static unsigned int MPI_Datasize[] = -{ sizeof(float), sizeof(double), sizeof(long double), - sizeof(char), sizeof(char), sizeof(short), sizeof(int), - sizeof(long), sizeof(long long), - sizeof(unsigned), sizeof(unsigned int), sizeof(unsigned char), - sizeof(unsigned short), sizeof(unsigned long), sizeof(unsigned long long), - sizeof(MPI_float_int), sizeof(MPI_double_int), sizeof(MPI_long_int), - sizeof(MPI_2int), sizeof(MPI_short_int), sizeof(MPI_long_double_int), - 2*sizeof(float), 2*sizeof(double), - 1/*user_data*/ -}; - -char *mpi_datatype_name[_MPI_NUMDATATYPES] = { - "float", "double", "long double", - "byte", "char", "short", "int", - "long", "long long", - "unsigned", "unsigned int", "unsigned char", - "unsigned short", "unsigned long", "unsigned long long", - "float int", "double int", "long int", - "2int", "short int", "long double int", - "complex", "double complex", - "user data" -}; - -/* Must match MPI_Op enum */ -char *mpi_op_name[_MPI_NUMOPS] = { - "sum", "prod", "max", "min", "band", "bor", - "bxor", "land", "lor", "lxor", "maxloc", "minloc" -}; - -typedef enum { - ExecTm, WaitTm, TestTm, SelectTm, SendTm, RecvTm, SendBytes, RecvBytes, - NSends, NRecvs, - _MPI_NUMSTATS -} MPI_Statistics; - -char *mpi_stats_name[_MPI_NUMSTATS] = { - "Exec Time", "Wait Time", "Test Time", "Select Time", "Send Time", "Recv Time", - "Send MBytes", "Recv MBytes", "Num Sends", "Num Recvs" -}; - -static double mpi_statistics[_MPI_NUMSTATS]; - -unsigned int *_MPI_Datasize = MPI_Datasize; -int _MPI_Procnum, _MPI_Nproc; - -static int MPI_Procnum, MPI_Nproc; -static int Max_fd; /* for select */ - -/* these limits are arbitrary, and mostly to catch programming errors */ -#define MAX_NPOST 1000 /* This many req_t ptrs for each proc */ -#define MAX_NPOSTANY 1000 /* This many req ptrs for MPI_ANY_SOURCE */ - -#define CheckTypeOK(type) \ -if (type < 0 || type >= _MPI_NUMDATATYPES) Error("Invalid type (%d)\n", type) - -/* req_chn stores all send and recv request. It has a separate dll of send */ -/* and receive entries for each socket, and one wildcard receive entry */ -static Chn req_chn; -static Dll *recv_list, *send_list; /* we malloc Nproc of these */ -static Dll wild_dll, *wild_list; /* only need one of these */ - -/* For messages that arrive without the corresponding Irecv posted */ -static Dll bufr_dll, *bufr_list; /* only need one of these */ - -/* we malloc Nproc of these */ -static req_t **read_active, **write_active; - -static int my_pid; /* my process id */ -static struct sockaddr_in host_addr; -static struct sockaddr_in my_addr; -static int sock; /* file descriptor for listen socket */ -static int *s; /* array of file descriptor for all channels */ -static struct sockaddr_in *addr; /* sockaddrs for all listen sockets */ -static int sock_bind(struct sockaddr_in *acc); -static int sock_connect(struct sockaddr_in *acc); -static void sock_setopt(int fd); -static void req_done(Dll_elmt *req, MPI_Status *stat); -static int writemsg(int fd, const void *ptr, int nbytes); -static int readmsg(int fd, void *ptr, int nbytes); -static void writemsg_block(int fd, const void *ptr, int nbytes); -static void readmsg_block(int fd, void *ptr, int nbytes); -req_t *parse_hdr(msghdr_t *hdr, req_t *req, int proc); -static req_t *io_pending(Dll *d); -static void spin_io(Dll_elmt *req); -static int do_io(req_t *req, int proc); -static void do_io_local(req_t *ireq, int proc); -static void init_elt(void); -static void sock_getopt(int fd); -static void mpi_diagnostics(void); - -/* This controls the maximum amount read/written per system call */ -#define PKTSIZE (20*1460) -static void -init_elt(void) -{ - int suspend_proc; - int i, j; - int size = sizeof(struct sockaddr_in); - int hostport; - char *hostip; - unsigned long inaddr; - int addr_len = sizeof(struct sockaddr_in); - struct sockaddr_in tmp_addr; - int noblock = 1; - char msgfile[256]; - extern int singlAutoflush(int); - extern int _MPMY_procnum_, _MPMY_nproc_, _MPMY_initialized_; - - sock = sock_bind(&my_addr); /* establish port to listen */ - my_pid = getpid(); - - if (!(getenv("MPI_PROCNUM") && getenv("MPI_NPROC") - && getenv("MPI_HOSTPORT") && getenv("MPI_HOST"))) - Error("startup variables not in environment\n"); - - MPI_Procnum = atoi(getenv("MPI_PROCNUM")); - MPI_Nproc = atoi(getenv("MPI_NPROC")); - hostip = getenv("MPI_HOST"); - hostport = atoi(getenv("MPI_HOSTPORT")); - - if (listen(sock, MPI_Nproc+1) < 0) Error("listen failed, errno=%d\n", errno); - - if( getenv("MPI_SUSPEND") && strlen(getenv("MPI_SUSPEND")) > 0 ){ - suspend_proc = atoi(getenv("MPI_SUSPEND")); - if (suspend_proc == -1) /* suspend all */ - suspend_proc = MPI_Procnum; - if (MPI_Procnum == suspend_proc){ - Shout("suspending pid=%d, MPI_Procnum=%d\n", - my_pid, MPI_Procnum); -#ifdef linux - sleep(10); /* hack. How can we do it right? */ -#else - kill(my_pid, SIGSTOP); -#endif - } - } - - if (getenv("MPI_MESSAGE_TURNON") - && strlen(getenv("MPI_MESSAGE_TURNON")) > 0 ) { - sprintf(msgfile, "msgs/msg.%d", MPI_Procnum); - MsgdirInit(msgfile); - Msg_turnon(getenv("MPI_MESSAGE_TURNON")); - } - /* This allows us to be polite about hung processes */ - if (getenv("MPI_TIMEOUT") && strlen(getenv("MPI_TIMEOUT")) > 0 ) - MPMY_TimeoutSet(atoi(getenv("MPI_TIMEOUT"))); - - /* This lets us use the MPMY stuff like Error */ - _MPI_Procnum = MPI_Procnum; - _MPI_Nproc = MPI_Nproc; - _MPMY_procnum_ = MPI_Procnum; - _MPMY_nproc_ = MPI_Nproc; - _MPMY_initialized_ = 1; - _MPMY_setup_absigs(); - MPMY_OnAbnormal(MPMY_SystemAbort); -#if 1 /* should this be under argc/argv control? */ - sprintf(MPMY_Abchdir_arg, "mpi/%03d", MPI_Procnum); - MPMY_OnAbnormal(MPMY_Abchdir); -#endif - MPMY_OnAbnormal(mpi_diagnostics); - MPMY_OnAbnormal(MPMY_Abannounce); - singlAutoflush(1); - - /* fill in host_addr here */ - memset(&host_addr, sizeof(host_addr), 0); - host_addr.sin_family = AF_INET; - /* Now try to figure out the host's address from hostname */ - /* Don't bother with gethostbyname here. Assume that the host - has worked out its preferred numeric IP address and passed that - to us through the environment var MPI_HOST */ - if ((inaddr = inet_addr(hostip)) != INADDR_NONE) /* it is numeric */ - host_addr.sin_addr.s_addr = inaddr; - else - Error("inet_addr(%s) failed, errno=%d\n", hostip, errno); - host_addr.sin_port = htons(hostport); - Msgf(("mpi: host is %s, address is %s, port is %d\n", - hostip, inet_ntoa(host_addr.sin_addr), ntohs(host_addr.sin_port))); - - addr = (struct sockaddr_in *) calloc(MPI_Nproc+1, size); - s = calloc(MPI_Nproc+1, sizeof(int)); - if (addr == NULL || s == NULL) Error("out of memory\n"); - addr++; /* offset by one so host is at -1 */ - s++; - - read_active = malloc(MPI_Nproc * sizeof(req_t *)); - write_active = malloc(MPI_Nproc * sizeof(req_t *)); - recv_list = malloc(MPI_Nproc * sizeof(Dll)); - send_list = malloc(MPI_Nproc * sizeof(Dll)); - if (read_active == NULL || write_active == NULL || - recv_list == NULL || send_list == NULL) Error("out of memory\n"); - /* I want to use plain realloc here, and DllCreatChn won't let me */ - /* Thus, I use ChnInit explicitly */ - /* DllCreateChn(&req_chn, sizeof(req_t), 100); */ - ChnInit(&req_chn, sizeof(Dll_elmt)+sizeof(req_t)-sizeof(int), 100, - realloc); - for (i = 0; i < MPI_Nproc; i++) { - DllCreate(recv_list+i, &req_chn); - DllCreate(send_list+i, &req_chn); - read_active[i] = 0; - write_active[i] = 0; - } - wild_list = &wild_dll; - DllCreate(wild_list, &req_chn); - bufr_list = &bufr_dll; - DllCreate(bufr_list, &req_chn); - - s[HOST_NUM] = sock_connect(&host_addr); /* establish connection to host */ - - writemsg_block(s[HOST_NUM], &MPI_Procnum, sizeof(int)); - /* send port on which we listen for connections from other procs */ - writemsg_block(s[HOST_NUM], &my_addr, size); - - /* read array of listening ports */ - readmsg_block(s[HOST_NUM], addr, MPI_Nproc * size); - Msgf(("mpi: Got port list\n")); - - for (i = 0; i < MPI_Nproc; i++) { - if (i == MPI_Procnum) { - for (j = MPI_Procnum; j < MPI_Nproc-1; j++) { - int proc, ts; - memset(&tmp_addr, 0, sizeof(struct sockaddr_in)); - ts = accept(sock, (struct sockaddr *)&tmp_addr, &addr_len); - if (ts < 0) Error("accept failed, errno=%d\n", errno); - sock_setopt(ts); - readmsg_block(ts, &proc, sizeof(int)); - s[proc] = ts; -#ifdef FIONBIO - /* Isn't this the same as the TCP_NODELAY that we set in - sock_setopt() ? Solaris doesn't have FIONBIO at all. - Does it matter? */ - if(ioctl(s[proc], FIONBIO, &noblock)) { - Error("ioctl, errno=%d", errno); - } -#endif - Msgf(("mpi: Accepted %d on socket %d\n", proc, ts)); - } - } else if (MPI_Procnum > i) { - s[i] = sock_connect(addr+i); - writemsg_block(s[i], &MPI_Procnum, sizeof(int)); -#ifdef FIONBIO - /* Isn't this the same as the TCP_NODELAY that we set in - sock_setopt() ? Solaris doesn't have FIONBIO at all. - Does it matter? */ - if(ioctl(s[i], FIONBIO, &noblock)) { - Error("ioctl, errno=%d", errno); - } -#endif - Msgf(("mpi: Connected to %d on socket %d\n", i, s[i])); - } - } - Max_fd = 0; - for (i = 0; i < MPI_Nproc; i++) { - if (s[i] > Max_fd) Max_fd = s[i]; - } - s[MPI_Procnum] = -1; /* we should never connect to ourself */ - if (MPI_Nproc > 1 && MPI_Procnum == 0) sock_getopt(s[1]); - MPI_Barrier(MPI_COMM_PRIVATE); - zero_hwclock(); /* zero timer here */ - Msgf(("mpi: hwclock zeroed\n")); -} - -/* _MPI_init_host1 is called BEFORE the host forks off child processes. - It has to figure out its own port and hostname, so it can pass it - to the children in the environment. */ -void -_MPI_init_host1(int *portp, char **namep, int nproc){ - char *p; - - sock = sock_bind(&host_addr); - if (listen(sock, nproc+1) < 0) Error("listen failed, errno=%d\n", errno); - my_pid = getpid(); - MPI_Procnum = HOST_NUM; - *portp = ntohs(host_addr.sin_port); - p = inet_ntoa(host_addr.sin_addr); - *namep = malloc(strlen(p)+1); - strcpy(*namep, p); -} - -/* _MPI_init_host is called after the host forks the child processes. - Its job is to communicate all the port info with them so they - can talk to one another directly. */ -void -_MPI_init_host(int n) /* n is how many nodes we talk to */ -{ - int i; - int proc; - int addr_len = sizeof(struct sockaddr_in); - struct sockaddr_in tmp_addr; - int size = sizeof(struct sockaddr_in); - - addr = (struct sockaddr_in *) calloc(n+1, size); - s = calloc(n+1, sizeof(int)); - if (addr == NULL || s == NULL) Error("out of memory\n"); - addr++; /* offset by one so host is at -1 */ - s++; - - for (i = 0; i < n; i++) { - int ts; - memset(&tmp_addr, 0, sizeof(struct sockaddr_in)); - ts = accept(sock, (struct sockaddr *)&tmp_addr, &addr_len); - if (ts < 0) Error("accept failed, errno=%d\n", errno); - readmsg_block(ts, &proc, sizeof(int)); /* who did it come from */ - readmsg_block(ts, addr+proc, size); /* address that is listening */ - s[proc] = ts; - Msgf(("mpi: Received addr from %d\n", proc)); - } - s[HOST_NUM] = -1; - - for (i = 0; i < n; i++) { - writemsg_block(s[i], addr, n * size); - Msgf(("mpi: Sent addrs to %d\n", i)); - } -} - -static void -sock_setopt(int fd) -{ - int nodelay = 1; - int no_check = 0; /* not clear if this does anything */ - int sendbuf = 65535; - int recvbuf = 65535; - - - if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&nodelay, sizeof(int))) - Error("setsockopt tcp_nodelay, errno=%d", errno); - /* The idea is to turn off checksumming, since ethernet does it anyway */ -#ifdef SO_NO_CHECK - /* SunOS doesn't have SO_NO_CHECK */ - if (setsockopt(fd, SOL_SOCKET, SO_NO_CHECK, (const void *)&no_check, sizeof(int))) - Error("sockopt no_check, errno=%d", errno); -#endif - if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *)&sendbuf, sizeof(int))) - Error("sockopt sndbuf, errno=%d", errno); - if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const void *)&recvbuf, sizeof(int))) - Error("sockopt rcvbuf, errno=%d", errno); -} - -static void -sock_getopt(int fd) -{ - int val, len; - - len = sizeof(int); - if (getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void *)&val, &len)) - Error("getsockopt, errno=%d", errno); - Msgf(("mpi: tcp_nodelay %d\n", val)); - len = sizeof(int); - if (getsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, (void *)&val, &len)) - Error("getsockopt, errno=%d", errno); - Msgf(("mpi: tcp_maxseg %d\n", val)); - len = sizeof(int); -#ifdef SO_NO_CHECK - if (getsockopt(fd, SOL_SOCKET, SO_NO_CHECK, (void *)&val, &len)) - Error("getsockopt, errno=%d", errno); - Msgf(("mpi: so_no_check %d\n", val)); -#endif - len = sizeof(int); - if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *)&val, &len)) - Error("getsockopt, errno=%d", errno); - Msgf(("mpi: so_sndbuf %d\n", val)); - len = sizeof(int); - if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *)&val, &len)) - Error("getsockopt, errno=%d", errno); - Msgf(("mpi: so_rcvbuf %d\n", val)); - len = sizeof(int); -} - -static char * -printSockaddr(const struct sockaddr_in *sa){ - static char ans[512]; - sprintf(ans, "sockaddr_in: family: %d, sin_addr: %s, sin_port is %d\n", - sa->sin_family, inet_ntoa(sa->sin_addr), ntohs(sa->sin_port)); - return ans; -} - -/* Connect with listening socket described by acc, return a descriptor */ -static int -sock_connect(struct sockaddr_in *acc) -{ - int ret, fd; - - if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) - Error("socket failed, errno=%d\n", errno); - sock_setopt(fd); -#if 0 - do { - /* we should use a select here */ - ret = connect(fd, (struct sockaddr *)acc, sizeof(struct sockaddr_in)); - if (ret && errno != ECONNREFUSED) - Error("connect failed, errno=%d\n", errno); - else Msgf(("mpi: connection refused\n")); - if (max_retries < 10) sleep(1); /* try not to beat on the other side */ - } while (ret && max_retries--); -#else - /* We want to make this non-blocking, so we can select on it. */ - fcntl(fd, F_SETFL, O_NONBLOCK); - ret = connect(fd, (struct sockaddr *)acc, sizeof(struct sockaddr_in)); - if( ret ){ - if( errno == EINPROGRESS ){ - fd_set wtfds; - struct timeval timeout; - int intlen; - FD_ZERO(&wtfds); - FD_SET(fd, &wtfds); - timeout.tv_sec = 20; - timeout.tv_usec = 0; - ret = select(fd+1, NULL, &wtfds, NULL, &timeout); - if( ret < 0 ) - Error("initial select on socket fails, errno=%d\n", errno); - if( ret == 0 ) - Error("Socket never became ready, timing out\n"); - if( ret != 1 ) - Error("Select returns unexpected value: %d. Giving up\n", ret); - /* Ok, there's one fd ready, we can look at it to see whether - it had a genuine error, or it's hunky dory (c.f., man connect) */ - intlen = sizeof(ret); - getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&ret, &intlen); - if( ret ){ - Error("getsockopt says SO_ERROR=%d trying to connect to %s, Dazed and confused\n", ret, printSockaddr(acc)); - } - }else{ - Error("connect failed with errno=%d\n", errno); - } - } -#endif - return fd; -} - -/* Bind a port to listen on, fill acc with info, return a descriptor */ -static int -sock_bind(struct sockaddr_in *acc) -{ - int fd, ret; - int len = sizeof(struct sockaddr_in); - char hostname[256]; - struct hostent *hp; - - fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (fd < 0 ) Error("socket failed, errno=%d\n", errno); - sock_setopt(fd); - memset(acc, 0, sizeof(struct sockaddr_in)); - acc->sin_family = AF_INET; - acc->sin_addr.s_addr = INADDR_ANY; - acc->sin_port = 0; /* INADDR_ANY? */ - ret = bind(fd, (struct sockaddr *) acc, sizeof(struct sockaddr_in)); - if (ret < 0 ) Error(" Can't bind socket. errno=%d\n", errno); - if (getsockname(fd, (struct sockaddr *)acc, &len)) - Error(" Can't getsockname. errno=%d\n", errno); - - /* Unfortunately, getsockname doesn't replace INADDR_ANY with - a valid saddr_in */ - /* We should be able to overrule gethostname with an env var - or a cmd-line arg */ - if (gethostname(hostname, sizeof(hostname))) - Error("gethostname failed, errno=%d\n", errno); - hostname[sizeof(hostname)-1] = '\0'; - if ((hp = gethostbyname(hostname)) == NULL) - Error("gethostbyname(%s) failed\n", hostname); - memcpy(&(acc->sin_addr), hp->h_addr, hp->h_length); - - /* Now acc holds 'correct' info about the socket */ - Msgf(("mpi: Bound port %d\n", ntohs(acc->sin_port))); - errno = 0; /* clear errors */ - return fd; -} - -static void -req_done(Dll_elmt *elmt, MPI_Status *status) -{ - req_t *req = DllData(elmt); - Dll *remove; - int len; - - if (req->left || req->pending) - Error("req_done called before all data was delivered\n"); - - if (status) { - status->MPI_SOURCE = req->proc; - status->MPI_TAG = req->tag; - status->count = req->len; - } - if (req->outgoing) { - Msgf(("mpi: %9f delivered (%d.%d) to %d len %d\n", hwclock(), - req->tag, req->comm, req->proc, req->len)); - remove = send_list+req->proc; - } else { - Msgf(("mpi: %9f %s (%d.%d) from %d len %d\n", hwclock(), - (req->buffered) ? "unbuffered" : "received", - req->tag, req->comm, req->proc, req->len)); - if (req->buffered) remove = bufr_list; - else if (req->wild_src) remove = wild_list; - else remove = recv_list+req->proc; - } - DllDelete(remove, elmt); - len = DllLength(remove); - if (len < 0 || len > MAX_NPOSTANY) Error("bad dll length (%d)\n", len); -} - -static req_t * -io_pending(Dll *d) -{ - Dll_elmt *p; - - for (p = DllBottom(d); p != DllSup(d); p = DllUp(p)) { - req_t *r = DllData(p); - if (r->pending) return r; - } - return NULL; -} - - -/* if req is set, block until req is clear */ -static void -spin_io(Dll_elmt *elmt) -{ - int i, j, ret; - fd_set rdset, wtset; - struct timeval timeout, *tv; - req_t *req = NULL; - req_t *r; - req_t *wild_pending; - double t1, t2; - - if (elmt) { - int npoll = 100; - req = DllData(elmt); - Msgf(("mpi: %9f spin_io %s (%d.%d) %d \n", hwclock(), (req->outgoing) - ? "sending" : "receiving", req->tag, req->comm, req->proc)); - - /* Fast path to avoid select overhead */ - - if (req->proc != MPI_ANY_SOURCE && req->proc != MPI_Procnum) { - i = req->proc; - t1 = hwclock(); - while (req->pending && npoll-- > 0) { - if (req->outgoing) { - if (write_active[i]) - do_io(write_active[i], i); - else if ((r = io_pending(send_list+i)) != NULL) - do_io(r, i); - } else { - if (read_active[i]) - do_io(read_active[i], i); - else if ((r = io_pending(recv_list+i)) != NULL) - do_io(r, i); - } - } -#if 0 - t2 = hwclock(); - if (req->pending) - Msgf(("mpi: %9f polled %6.3f msec without success\n", t1, - (t2-t1)*1e3)); - else - Msgf(("mpi: %9f polled %6.3f msec (%d times)\n", t1, - (t2-t1)*1e3, 30-npoll)); -#endif - } - if (req->pending == 0) return; - } - - do { - FD_ZERO(&rdset); - FD_ZERO(&wtset); - - wild_pending = io_pending(wild_list); - for (i = 0; i < MPI_Nproc; i++) { - if (i == MPI_Procnum) continue; - /* We need to check all read ports if there is a wildcard recv */ - if (read_active[i] || wild_pending != NULL - || io_pending(recv_list+i) != NULL) - FD_SET(s[i], &rdset); - if (write_active[i] || io_pending(send_list+i) != NULL) - FD_SET(s[i], &wtset); - } - timeout.tv_sec = 0; - timeout.tv_usec = 0; - if (req && MPI_Nproc > 1 && req->proc != MPI_Procnum) { - tv = NULL; /* Don't let select block if there is only 1 proc */ - } else { - tv = &timeout; - } - - again: - t1 = hwclock(); - ret = select(Max_fd+1, &rdset, &wtset, NULL, tv); - t2 = hwclock(); - if (ret == -1) { - if (errno == EINTR) goto again; /* SIGPROF interrupts select */ - else Error("select, errno=%d\n", errno); - } - mpi_statistics[SelectTm] += t2-t1; - Msgf(("mpi: %9f select %6.3f msec\n", t1, (t2-t1)*1e3)); - - /* We use read_active and write_active to make sure we finish */ - /* reading an entire message before starting on a new one */ - - /* This might work better if one did hypercube channels first */ - /* or, flipped reads and writes based on procnum parity, etc. */ - - for (j = 0; j < MPI_Nproc; j++) { - i = (j + MPI_Procnum) % MPI_Nproc; - if (i == MPI_Procnum) continue; - if (FD_ISSET(s[i], &rdset)) { - if (read_active[i]) - do_io(read_active[i], i); - else if ((r = io_pending(recv_list+i)) != NULL) - do_io(r, i); - else if ((r = io_pending(wild_list)) != NULL) - if (!r->hdr_flag || r->proc == i) - do_io(r, i); - } - } - - for (j = 0; j < MPI_Nproc; j++) { - i = (j + MPI_Procnum) % MPI_Nproc; - if (i == MPI_Procnum) continue; - if (FD_ISSET(s[i], &wtset)) { - if (write_active[i]) - do_io(write_active[i], i); - else if ((r = io_pending(send_list+i)) != NULL) - do_io(r, i); - } - } - - /* Take care of messages to ourself */ - if (read_active[MPI_Procnum]) - do_io_local(read_active[MPI_Procnum], MPI_Procnum); - else if (io_pending(send_list+MPI_Procnum) != NULL) { - if ((r = io_pending(recv_list+MPI_Procnum)) != NULL) - do_io_local(r, MPI_Procnum); - else if ((r = io_pending(wild_list))) - if (!r->hdr_flag || r->proc == MPI_Procnum) - do_io_local(r, MPI_Procnum); - } - } while (req && req->pending); -} - -/* Return number of bytes if we got any, to help out spin_io */ -static int -do_io(req_t *req, int proc) -{ - int n = 0; - int left; - double t1, t2; - msghdr_t hdr; - int fd = s[proc]; - - if (!req->hdr_flag) { - - /* In order to reduce latency, we package the header together */ - /* with some data. One would think writev would work, but it */ - /* does not. tcpdump indicates we get multiple packets from writev */ - /* Doing this gets latency from 350 usec down to 220 (with polling) */ - - if (req->outgoing) { - char pktbuf[1024+sizeof(msghdr_t)]; - msghdr_t *hdrp; - hdrp = (msghdr_t *)pktbuf; - hdrp->src = MPI_Procnum; - hdrp->comm = req->comm; - hdrp->tag = req->tag; - hdrp->len = req->len; - hdrp->magic = H_MAGIC; - n = MIN(req->left, 1024); - memcpy(pktbuf + sizeof(msghdr_t), req->ptr, n); - t1 = hwclock(); - if (writemsg(fd, pktbuf, n+sizeof(msghdr_t)) == -1) return 0; - t2 = hwclock(); - Msgf(("mpi: %9f %s %6.3f msec %2d %5d - %5.2f Mb/s\n", - t1, "wrote ", (t2-t1)*1000.0, proc, n, n/(1e6*(t2-t1)))); - write_active[proc] = req; - req->left -= n; - req->ptr += n; - mpi_statistics[SendBytes] += n; - mpi_statistics[SendTm] += t2-t1; - } else { - if (readmsg(fd, &hdr, sizeof(msghdr_t)) == -1) return 0; - /* We may decide we match a different request */ - req = parse_hdr(&hdr, req, proc); - read_active[proc] = req; - } - req->hdr_flag = 1; /* mark header done */ - } - - if (req->pending == 0) Error("req already completed\n"); - if (req->proc != proc) Error("req is inconsistent with proc\n"); - left = MIN(req->left, PKTSIZE); - /* Small messages get sent with the header */ - if (left) { - t1 = hwclock(); -#if 1 - n = (req->outgoing) ? write(fd, req->ptr, left) - : read(fd, req->ptr, left); -#else - n = (req->outgoing) ? send(fd, req->ptr, left, 0) - : recv(fd, req->ptr, left, 0); -#endif - t2 = hwclock(); - if (n < 0) { - if (errno == EAGAIN) n = 0; - else Error("%s failed, errno=%d\n", - (req->outgoing) ? "write" : "read", errno); - } - if (req->outgoing) { - mpi_statistics[SendBytes] += n; - mpi_statistics[SendTm] += t2-t1; - } else { - mpi_statistics[RecvBytes] += n; - mpi_statistics[RecvTm] += t2-t1; - } - Msgf(("mpi: %9f %s %6.3f msec %2d %5d - %5.2f Mb/s\n", - t1, (req->outgoing) ? "wrote " : "read ", - (t2-t1)*1000.0, proc, n, n/(1e6*(t2-t1)))); - req->left -= n; - req->ptr += n; - } - if (req->left == 0) { - req->pending = 0; - if (req->outgoing) write_active[proc] = NULL; - else read_active[proc] = NULL; - } - return n; -} - -static int -writemsg(int fd, const void *p, int n) -{ - int nwrote; - int left = n; - const char *ptr = p; - while (left > 0) { - if ((nwrote = send(fd, ptr, left, 0)) < 0) { - if (errno == EAGAIN) { - if (left == n) return -1; - else continue; - } - else Error("write failed, errno=%d\n", errno); - } - left -= nwrote; - ptr += nwrote; - } - return 0; -} - -static int -readmsg(int fd, void *p, int n) -{ - int nread; - int left = n; - char *ptr = p; - while (left > 0) { - if ((nread = recv(fd, ptr, left, 0)) < 0) { - if (errno == EAGAIN) { - if (left == n) return -1; - else continue; - } - else Error("read failed, errno=%d\n", errno); - } - left -= nread; - ptr += nread; - } - return 0; -} - -/* Blocking write. Don't return until all data is sent */ -static void -writemsg_block(int fd, const void *p, int n) -{ - int nwrote; - int left = n; - const char *ptr = p; - while (left > 0) { - if ((nwrote = write(fd, ptr, left)) < 0) { - if (errno == EAGAIN) continue; - else Error("write failed, errno=%d\n", errno); - } - left -= nwrote; - ptr += nwrote; - } -} - -/* Blocking read. Don't return until all data is read */ -static void -readmsg_block(int fd, void *p, int n) -{ - int nread; - int left = n; - char *ptr = p; - while (left > 0) { - if ((nread = read(fd, ptr, left)) < 0) { - if (errno == EAGAIN) continue; - else Error("read failed, errno=%d\n", errno); - } - left -= nread; - ptr += nread; - } -} - -static req_t * -match_tag(msghdr_t *hdr, Dll *wildp, Dll *recvp) -{ - Dll_elmt *p; - req_t *req; - - for (p = DllBottom(wildp); p != DllSup(wildp); p = DllUp(p)) { - req_t *r = DllData(p); - if (r->pending && hdr->tag == r->tag && hdr->comm == r->comm) - return r; - } - for (p = DllBottom(recvp); p != DllSup(recvp); p = DllUp(p)) { - req_t *r = DllData(p); - if (r->pending && hdr->tag == r->tag && hdr->comm == r->comm) - return r; - } - /* No matches, so make a new entry which points to a malloced buffer */ - /* When Irecv is called with a matching tag, it will find this */ - p = DllInsertAtTop(bufr_list); - if (DllLength(bufr_list) > MAX_NPOSTANY) - Error("Too many recvs buffered\n"); - if (p == NULL) Error("dll is NULL\n"); - req = DllData(p); - req->proc = hdr->src; - req->pending = 1; - req->wild_src = 0; - req->outgoing = req->hdr_flag = req->wild_tag = 0; - req->buffered = 1; - req->len = req->left = hdr->len; - req->comm = hdr->comm; - req->tag = hdr->tag; - req->buf = req->ptr = malloc(hdr->len); - if (req->ptr == NULL) Error("out of memory\n"); - Msgf(("mpi: %9f buffering (%d.%d) from %d len %d\n", - hwclock(), req->tag, req->comm, req->proc, req->len)); - return req; -} - -/* return a req_t which matches the header we just read, or else buffer */ -req_t * -parse_hdr(msghdr_t *hdr, req_t *req, int proc) -{ - if (hdr->magic != H_MAGIC) - Error("bad magic number %d\n", hdr->magic); - if (hdr->tag != req->tag || hdr->comm != req->comm) { - if (req->wild_tag && hdr->comm == req->comm) - req->tag = hdr->tag; - else - req = match_tag(hdr, wild_list, recv_list+proc); - } - if (hdr->src != req->proc) { - if (req->wild_src) req->proc = hdr->src; - else Error("bad src, got %d expected %d\n", hdr->src, req->proc); - } - if (hdr->len != req->len) { - if (hdr->len >= 0 && hdr->len < req->len) - req->len = req->left = hdr->len; - else Error("bad len, got %d expected %d\n", hdr->len, req->len); - } - Msgf(("mpi: %9f receiving (%d.%d)\n", hwclock(), req->tag, req->comm)); - return req; -} - -static void -do_io_local(req_t *ireq, int proc) -{ - msghdr_t hdr; - int left; - double t1, t2; - req_t *oreq = io_pending(send_list + proc); - - hdr.src = MPI_Procnum; - hdr.tag = oreq->tag; - hdr.comm = oreq->comm; - hdr.len = oreq->len; - hdr.magic = H_MAGIC; - ireq = parse_hdr(&hdr, ireq, proc); - ireq->hdr_flag = oreq->hdr_flag = 1; - - left = MIN(ireq->left, PKTSIZE); - t1 = hwclock(); - memcpy(ireq->ptr, oreq->ptr, left); - t2 = hwclock()-t1; - Msgf(("mpi: %9f %s %2d %5d - %5.2f Mb/s\n", hwclock(), "copy ", - MPI_Procnum, left, left/(1e6*t2))); - ireq->left -= left; - ireq->ptr += left; - oreq->ptr += left; - if (ireq->left == 0) { - ireq->pending = 0; - oreq->pending = 0; - oreq->left = 0; /* input may be smaller than output */ - } -} - -static void -dump_req(Dll *d) -{ - Dll_elmt *p; - - for (p = DllBottom(d); p != DllSup(d); p = DllUp(p)) { - req_t *r = DllData(p); - Msg_do("\tproc %3d tag %6d flags %d%d%d%d%d len %6d left %6d\n", - r->proc, r->tag, r->pending, r->hdr_flag, r->wild_src, - r->wild_tag, r->buffered, r->len, r->left); - } -} - -static void -mpi_diagnostics(void) -{ - int i, sum; - - sum = 0; - for (i = 0; i < MPI_Nproc; i++) - sum += DllLength(send_list+i); - if (sum) { - Msg_do("mpi: %d writes active:\n", sum); - for (i = 0; i < MPI_Nproc; i++) - dump_req(send_list+i); - } - sum = 0; - for (i = 0; i < MPI_Nproc; i++) - sum += DllLength(recv_list+i); - if (sum) { - Msg_do("mpi: %d reads active:\n", sum); - for (i = 0; i < MPI_Nproc; i++) - dump_req(recv_list+i); - } - if (DllLength(bufr_list)) { - Msg_do("mpi: %d buffered reads active:\n", DllLength(bufr_list)); - dump_req(bufr_list); - } - if (DllLength(wild_list)) { - Msg_do("mpi: %d ANY_SOURCE reads active:\n", DllLength(wild_list)); - dump_req(wild_list); - } -} - - -int -MPI_Init(int *argcp, char ***argvp) -{ - int i; - init_elt(); - for (i = 0; i < _MPI_NUMSTATS; i++) mpi_statistics[i] = 0.0; - mpi_statistics[ExecTm] = hwclock(); - return MPI_SUCCESS; -} - -int -MPI_Finalize(void) -{ - int i; - Msgf(("mpi: Finalize\n")); - MPI_Barrier(MPI_COMM_PRIVATE); - mpi_statistics[ExecTm] = hwclock() - mpi_statistics[ExecTm]; - mpi_statistics[SendBytes] /= 1e6; - mpi_statistics[RecvBytes] /= 1e6; - for (i = 0; i < _MPI_NUMSTATS; i++) { - Msg_do("%14s %12.2f\n", mpi_stats_name[i], mpi_statistics[i]); - } - MPMY_Abchdir(); /* puts gmon.out in different dirs */ - /* Should we free some of the arrays??? */ - return MPI_SUCCESS; -} - -int -MPI_Abort(MPI_Comm comm, int errorcode) -{ - Error("MPI_Abort, errorcode=%d\n", errorcode); -} - -double -MPI_Wtime(void) -{ - return hwclock(); -} - -double -MPI_Wtick(void) -{ - return hwtick(); -} - -int -MPI_Comm_rank(MPI_Comm comm, int *rank) -{ - *rank = MPI_Procnum; - return MPI_SUCCESS; -} - -int -MPI_Comm_size(MPI_Comm comm, int *size) -{ - *size = MPI_Nproc; - return MPI_SUCCESS; -} - -int -MPI_Get_count(MPI_Status *status, MPI_Datatype type, int *cnt) -{ - if (type < 0 || type >= _MPI_NUMDATATYPES) - Error("Datatype invalid in Get_count (%d)\n", type); - *cnt = status->count/MPI_Datasize[type]; - return MPI_SUCCESS; -} - -int -MPI_Isend(void *buf, int cnt, MPI_Datatype type, int dest, int tag, - MPI_Comm comm, MPI_Request *req) -{ - Dll_elmt *dll; - req_t *request; - - Msgf(("mpi: %9f Isend: (%d.%d) to %d len %d\n", - hwclock(), tag, comm, dest, cnt * MPI_Datasize[type])); - if ((long)buf % MPI_Datasize[type]) - Msg_do("mpi: Unaligned send of %s at %p\n", - mpi_datatype_name[type], buf); - mpi_statistics[NSends] += 1.0; - - CheckTypeOK(type); - if (dest < 0 || dest > MPI_Nproc) - Error("dest invalid in Isend (%d)\n", dest); - - dll = DllInsertAtTop(send_list+dest); - if (dll == 0) Error("dll is NULL\n"); - if (DllLength(send_list+dest) > MAX_NPOST) - Error("Too many Isends pending\n"); - request = DllData(dll); - request->proc = dest; - request->pending = 1; - request->outgoing = 1; - request->hdr_flag = request->wild_src = request->wild_tag = 0; - request->buffered = 0; - request->len = request->left = cnt * MPI_Datasize[type]; - request->comm = comm; - request->tag = tag; - request->buf = request->ptr = (void *)buf; - *(MPI_Request *)req = dll; - return MPI_SUCCESS; -} - -int -MPI_Irecv(void *buf, int cnt, MPI_Datatype type, int src, int tag, - MPI_Comm comm, MPI_Request *req) -{ - Dll_elmt *elmt; - req_t *request; - - Msgf(("mpi: %9f Irecv: (%d.%d) from %d len %d\n", - hwclock(), tag, comm, src, cnt * MPI_Datasize[type])); - if ((long)buf % MPI_Datasize[type]) - Msg_do("mpi: Unaligned recv of %s at %p\n", - mpi_datatype_name[type], buf); - mpi_statistics[NRecvs] += 1.0; - - CheckTypeOK(type); - if (src != MPI_ANY_SOURCE && (src < 0 || src > MPI_Nproc)) - Error("source invalid in Irecv (%d)\n", src); - - /* Check if we already have the message */ - for (elmt = DllBottom(bufr_list); elmt != DllSup(bufr_list); - elmt = DllUp(elmt)) { - request = DllData(elmt); - if ((tag == request->tag || tag == MPI_ANY_TAG) - && (src == request->proc || src == MPI_ANY_SOURCE) - && comm == request->comm) { - Msgf(("mpi: %9f matched (%d.%d) len %d\n", hwclock(), tag, comm, - request->len-request->left)); - /* We might not have buffered the entire message yet */ - memcpy(buf, request->buf, request->len-request->left); - free(request->buf); - request->buf = buf; - request->ptr = request->buf + (request->len-request->left); - if (request->pending && read_active[request->proc] != request) - Error("Irecv request was buffered+pending but not active\n"); - *(MPI_Request *)req = elmt; - return MPI_SUCCESS; - } - } - if (src == MPI_ANY_SOURCE) { - elmt = DllInsertAtTop(wild_list); - if (DllLength(wild_list) > MAX_NPOSTANY) - Error("Too many wildcard Irecvs pending\n"); - } else { - elmt = DllInsertAtTop(recv_list+src); - if (DllLength(recv_list+src) > MAX_NPOST) - Error("Too many Irecvs pending\n"); - } - if (elmt == 0) Error("elmt is NULL\n"); - request = DllData(elmt); - if (request == 0) Error("dlldata is NULL\n"); - request->proc = src; - request->pending = 1; - request->wild_src = (src == MPI_ANY_SOURCE) ? 1 : 0; - request->outgoing = request->hdr_flag = request->wild_tag = 0; - request->buffered = 0; - request->len = request->left = cnt * MPI_Datasize[type]; - request->comm = comm; - request->tag = tag; - request->buf = request->ptr = buf; - *(MPI_Request *)req = elmt; - return MPI_SUCCESS; -} - -int -MPI_Test(MPI_Request *rptr, int *flag, MPI_Status *status) -{ - Dll_elmt *elmt = *rptr; - req_t *req; - double t1; - - if (elmt == NULL) Error("NULL message request\n"); - req = DllData(elmt); - -/* req->pending is the same as left being non-zero */ -/* except for zero length messages */ - - t1 = hwclock(); - if (req->pending) - spin_io(NULL); - t1 = hwclock() - t1; - - mpi_statistics[TestTm] += t1; - if (req->pending) { - *flag = 0; - } else { - req_done(elmt, status); - *flag = 1; - } - return MPI_SUCCESS; -} - -int -MPI_Wait(MPI_Request *rptr, MPI_Status *status) -{ - Dll_elmt *elmt = *rptr; - req_t *req; - double t1; - - if (elmt == NULL) Error("NULL message request\n"); - req = DllData(elmt); - - t1 = hwclock(); - while (req->pending) - spin_io(elmt); - t1 = hwclock() - t1; - - mpi_statistics[WaitTm] += t1; - req_done(elmt, status); - - return MPI_SUCCESS; -} - -int -MPI_Waitall(int count, MPI_Request *reqv, MPI_Status *statusv) -{ - int i; - for (i = 0; i < count; i++) - if (statusv == NULL) MPI_Wait(reqv+i, NULL); - else MPI_Wait(reqv+i, statusv+i); - return MPI_SUCCESS; -} - -int -MPI_Send(void *buf, int cnt, MPI_Datatype type, int dest, int tag, - MPI_Comm comm) -{ - MPI_Request req; - - MPI_Isend(buf, cnt, type, dest, tag, comm, &req); - MPI_Wait(&req, 0); - return MPI_SUCCESS; -} - -int -MPI_Recv(void *buf, int cnt, MPI_Datatype type, int src, int tag, - MPI_Comm comm, MPI_Status *status) -{ - MPI_Request req; - MPI_Irecv(buf, cnt, type, src, tag, comm, &req); - MPI_Wait(&req, status); - return MPI_SUCCESS; -} - - -int -MPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, - int dest, int sendtag, void *recvbuf, int recvcount, - MPI_Datatype recvtype, int source, int recvtag, - MPI_Comm comm, MPI_Status *status) -{ - MPI_Request rreq, sreq; - MPI_Status sstatus; - - Msgf(("mpi: Sendrecv\n")); - MPI_Irecv(recvbuf, recvcount, recvtype, source, recvtag, comm, &rreq); - MPI_Isend(sendbuf, sendcount, sendtype, dest, sendtag, comm, &sreq); - MPI_Wait(&sreq, &sstatus); - MPI_Wait(&rreq, status); - return MPI_SUCCESS; -} - -int -MPI_Barrier(MPI_Comm comm) -{ - int i, junk; - - Msgf(("mpi: Barrier\n")); - if (MPI_Nproc == 1) return MPI_SUCCESS; - if (MPI_Procnum != 0) { - MPI_Send(&junk, 1, MPI_INT, 0, 1, MPI_COMM_PRIVATE); - MPI_Recv(&junk, 1, MPI_INT, 0, 2, MPI_COMM_PRIVATE, NULL); - } else { - MPI_Request *req = malloc(MPI_Nproc * sizeof(MPI_Request)); - for (i = 1; i < MPI_Nproc; i++) - MPI_Irecv(&junk, 1, MPI_INT, i, 1, MPI_COMM_PRIVATE, req+i-1); - MPI_Waitall(MPI_Nproc-1, req, NULL); - for (i = 1; i < MPI_Nproc; i++) - MPI_Send(&junk, 1, MPI_INT, i, 2, MPI_COMM_PRIVATE); - free(req); - } - return MPI_SUCCESS; -} - -#define TAG 3 - -int -MPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype, - void *recvbuf, int recvcount, MPI_Datatype recvtype, - MPI_Comm comm) -{ - int i; - char *sbuf = sendbuf; - char *rbuf = recvbuf; - MPI_Request *rreq, *sreq; - MPI_Status *status; - - Msgf(("mpi: Alltoall\n")); - CheckTypeOK(sendtype); - CheckTypeOK(recvtype); - rreq = malloc(MPI_Nproc * sizeof(MPI_Request)); - sreq = malloc(MPI_Nproc * sizeof(MPI_Request)); - status = malloc(MPI_Nproc * sizeof(MPI_Status)); - if (rreq == NULL || sreq == NULL || status == NULL) - Error("out of memory\n"); - for (i = 0; i < MPI_Nproc; i++) { - MPI_Irecv(rbuf+i*recvcount*MPI_Datasize[recvtype], recvcount, - recvtype, i, TAG, MPI_COMM_PRIVATE, &rreq[i]); - } - for (i = 0; i < MPI_Nproc; i++) { - MPI_Isend(sbuf+i*sendcount*MPI_Datasize[sendtype], sendcount, - sendtype, i, TAG, MPI_COMM_PRIVATE, &sreq[i]); - } - for (i = 0; i < MPI_Nproc; i++) { - MPI_Wait(&rreq[i], &status[i]); - } - for (i = 0; i < MPI_Nproc; i++) { - MPI_Wait(&sreq[i], NULL); - } - free(status); - free(sreq); - free(rreq); - return MPI_SUCCESS; -} - -int -MPI_Alltoallv(void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype stype, - void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype rtype, - MPI_Comm comm) -{ - int i; - char *sbuf = sendbuf; - char *rbuf = recvbuf; - MPI_Request *rreq, *sreq; - MPI_Status *status; - - Msgf(("mpi: Alltoallv\n")); - CheckTypeOK(stype); - CheckTypeOK(rtype); - rreq = malloc(MPI_Nproc * sizeof(MPI_Request)); - sreq = malloc(MPI_Nproc * sizeof(MPI_Request)); - status = malloc(MPI_Nproc * sizeof(MPI_Status)); - if (rreq == NULL || sreq == NULL || status == NULL) - Error("out of memory\n"); - for (i = 0; i < MPI_Nproc; i++) { - MPI_Irecv(rbuf+rdispls[i]*MPI_Datasize[rtype], recvcnts[i], - rtype, i, TAG, MPI_COMM_PRIVATE, &rreq[i]); - } - for (i = 0; i < MPI_Nproc; i++) { - MPI_Isend(sbuf+sdispls[i]*MPI_Datasize[stype], sendcnts[i], - stype, i, TAG, MPI_COMM_PRIVATE, &sreq[i]); - } - for (i = 0; i < MPI_Nproc; i++) { - MPI_Wait(&rreq[i], &status[i]); - } - for (i = 0; i < MPI_Nproc; i++) { - MPI_Wait(&sreq[i], NULL); - } - free(status); - free(sreq); - free(rreq); - return MPI_SUCCESS; -} - -/* These Comm functions are not really implemented */ - -int -MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm) -{ - *newcomm = comm; - return MPI_SUCCESS; -} - -int -MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm) -{ - *newcomm = comm; - return MPI_SUCCESS; -} - -int -MPI_Comm_free(MPI_Comm *commp) -{ - return MPI_SUCCESS; -} - - - -/* These Type functions are not really implemented */ - -int -MPI_Type_contiguous(int len, MPI_Datatype type, MPI_Datatype *ptr) -{ - return MPI_SUCCESS; -} - -int -MPI_Type_commit(MPI_Datatype *ptr) -{ - return MPI_SUCCESS; -} - -/* g77 */ -#define _F77(sym) sym##__ -#include "swampif.c" -#undef _F77 - -/* pgf77 */ -#define _F77(sym) sym##_ -#include "swampif.c" -#undef _F77 - diff --git a/external/libsdf/libsw/swampif.c b/external/libsdf/libsw/swampif.c deleted file mode 100644 index 3c67db8..0000000 --- a/external/libsdf/libsw/swampif.c +++ /dev/null @@ -1,140 +0,0 @@ -void _F77(mpi_init)(int *ierr) -{ - *ierr = MPI_Init(0, 0); -} - -void _F77(mpi_finalize)(int *ierr) -{ - *ierr = MPI_Finalize(); -} - -void _F77(mpi_abort)(int *comm, int *err, int *ierr) -{ - *ierr = MPI_Abort(*comm, *err); -} - -void _F77(mpi_comm_rank)(int *comm, int *rank, int *ierr) -{ - *ierr = MPI_Comm_rank(*comm, rank); -} - -void _F77(mpi_comm_size)(int *comm, int *size, int *ierr) -{ - *ierr = MPI_Comm_size(*comm, size); -} - -void _F77(mpi_get_count)(MPI_Status *status, int *type, int *cnt, int *ierr) -{ - *ierr = MPI_Get_count(status, *type, cnt); -} - -void _F77(mpi_isend)(void *buf, int *cnt, int *type, int *dest, int *tag, - int *comm, MPI_Request req, int *ierr) -{ - *ierr = MPI_Isend(buf, *cnt, *type, *dest, *tag, *comm, req); -} - -void _F77(mpi_irecv)(void *buf, int *cnt, int *type, int *src, int *tag, - int *comm, MPI_Request req, int *ierr) -{ - *ierr = MPI_Irecv(buf, *cnt, *type, *src, *tag, *comm, req); -} - -void _F77(mpi_test)(MPI_Request req, int *flag, MPI_Status *stat, int *ierr) -{ - *ierr = MPI_Test(req, flag, stat); -} - -void _F77(mpi_wait)(MPI_Request req, MPI_Status *status, int *ierr) -{ - *ierr = MPI_Wait(req, status); -} - -void _F77(mpi_waitall)(int *count, MPI_Request *reqv, - MPI_Status *statusv, int *ierr) -{ - *ierr = MPI_Waitall(*count, reqv, statusv); -} - -void _F77(mpi_send)(void *buf, int *cnt, int *type, int *dest, int *tag, - int *comm, int *ierr) -{ - *ierr = MPI_Send(buf, *cnt, *type, *dest, *tag, *comm); -} - -void _F77(mpi_recv)(void *buf, int *cnt, int *type, int *src, int *tag, - int *comm, MPI_Status *status, int *ierr) -{ - *ierr = MPI_Recv(buf, *cnt, *type, *src, *tag, *comm, status); -} - -void _F77(mpi_sendrecv)(void *sendbuf, int *sendcnt, int *sendtype, - int *dest, int *sendtag, void *recvbuf, int *recvcnt, - int *recvtype, int *source, int *recvtag, - int *comm, MPI_Status *status, int *ierr) -{ - *ierr = MPI_Sendrecv(sendbuf, *sendcnt, *sendtype, *dest, *sendtag, - recvbuf, *recvcnt, *recvtype, *source, *recvtag, - *comm, status); -} - -void _F77(mpi_bcast)(void *buf, int *cnt, int *type, int *src, int *comm, - int *ierr) -{ - *ierr = MPI_Bcast(buf, *cnt, *type, *src, *comm); -} - -void _F77(mpi_reduce)(void *sendbuf, void *recvbuf, int *count, int *datatype, - int *op, int *root, int *comm, int *ierr) -{ - *ierr = MPI_Reduce(sendbuf, recvbuf, *count, *datatype, *op, *root, *comm); -} - -void _F77(mpi_allreduce)(void *sendbuf, void *recvbuf, int *count, - int *datatype, int *op, int *comm, int *ierr) -{ - *ierr = MPI_Allreduce(sendbuf, recvbuf, *count, *datatype, *op, *comm); -} - -void _F77(mpi_barrier)(int *comm, int *ierr) -{ - *ierr = MPI_Barrier(*comm); -} - -void _F77(mpi_alltoallv)(void *sbuf, int *sendcnts, int *sdispls, int *stype, - void *rbuf, int *recvcnts, int *rdispls, int *rtype, - int *comm, int *ierr) -{ - *ierr = MPI_Alltoallv(sbuf, sendcnts, sdispls, *stype, - rbuf, recvcnts, rdispls, *rtype, *comm); -} - -void _F77(mpi_alltoall)(void *sendbuf, int *sendcount, int *sendtype, - void *recvbuf, int *recvcount, int *recvtype, - int *comm, int *ierr) -{ - *ierr = MPI_Alltoall(sendbuf, *sendcount, *sendtype, - recvbuf, *recvcount, *recvtype, *comm); -} - -void _F77(mpi_comm_dup)(MPI_Comm *comm, MPI_Comm *newcomm, int *ierr) -{ - *ierr = MPI_Comm_dup(*comm, newcomm); -} - -void _F77(mpi_comm_split)(MPI_Comm *comm, int *color, int *key, - MPI_Comm *newcomm, int *ierr) -{ - *ierr = MPI_Comm_split(*comm, *color, *key, newcomm); -} - - -double _F77(mpi_wtime)(void) -{ - return MPI_Wtime(); -} - -double _F77(mpi_wtick)(void) -{ - return MPI_Wtick(); -} diff --git a/external/libsdf/libsw/timers.c b/external/libsdf/libsw/timers.c deleted file mode 100644 index 88322a7..0000000 --- a/external/libsdf/libsw/timers.c +++ /dev/null @@ -1,159 +0,0 @@ -#include -#include -#include -#include "Malloc.h" -#include "timers.h" -#include "mpmy.h" -#include "mpmy_time.h" -#include "Assert.h" - -/* Make sure any #defines in timers.h don't interfere... */ -#undef StartTimer -#undef StopTimer -#undef StartWCTimer -#undef StopWCTimer - -#define MAXENABLED 100 - -static Timer_t *enabled_timers[MAXENABLED]; -static int nenabled_timers; - -void ClearTimer(Timer_t *t) -{ - MPMY_ClearTimer(t->mpmy_tm); - return; -} - -double ReadTimer(Timer_t *t) -{ - return MPMY_ReadTimer(t->mpmy_tm); -} - -void StartTimer(Timer_t *t) -{ - if (t->enabled) - MPMY_StartTimer(t->mpmy_tm); - return; -} - -void CopyTimer(Timer_t *src, Timer_t *dest) -{ - MPMY_CopyTimer(src->mpmy_tm, dest->mpmy_tm); -} - -void StopTimer(Timer_t *t) -{ - if (t->enabled) - MPMY_StopTimer(t->mpmy_tm); - return; -} - -void ClearEnabledTimers(void){ - int i; - for(i=0; iname = Malloc(strlen(name)+1); - strcpy(t->name, name); - t->enabled = 1; - t->mpmy_tm = MPMY_CreateTimer(MPMY_WC_TIME); - ClearTimer(t); -} - -void EnableCPUTimer(Timer_t *t, char *name){ - assert(nenabled_timers < MAXENABLED); - enabled_timers[nenabled_timers++] = t; - t->name = Malloc(strlen(name)+1); - strcpy(t->name, name); - t->enabled = 1; - t->mpmy_tm = MPMY_CreateTimer(MPMY_CPU_TIME); - ClearTimer(t); -} - -void DisableTimer(Timer_t *t){ - int i; - - for(i=0; ienabled = 0; - Free(t->name); - t->name = NULL; - enabled_timers[i] = enabled_timers[--nenabled_timers]; - MPMY_DestroyTimer(t->mpmy_tm); -} - -void SumTimers(void){ - double nprocinv; - Timer_t *t; - int i; - MPMY_Comm_request req; - - MPMY_ICombine_Init(&req); - for(i=0; imean = t->min = t->max = MPMY_ReadTimer(t->mpmy_tm); - MPMY_ICombine(&t->min, &t->min, 1, MPMY_DOUBLE, MPMY_MIN, req); - MPMY_ICombine(&t->max, &t->max, 1, MPMY_DOUBLE, MPMY_MAX, req); - MPMY_ICombine(&t->mean, &t->mean, 1, MPMY_DOUBLE, MPMY_SUM, req); - } - MPMY_ICombine_Wait(req); - - /* Now loop a second time and divide the mean by Nproc */ - nprocinv = 1./MPMY_Nproc(); - for(i=0; imean *= nprocinv; - } -} - -void OutputTimers(int (*Printf_Like)(const char *, ...)){ - int i; - Timer_t *t; - - SumTimers(); - Printf_Like("%12s %10s %10s %10s\n", "Timers", "Min", "Max", "Mean"); - for (i = 0; i < nenabled_timers; i++) { - t = enabled_timers[i]; - if( t->enabled && t->name ) - Printf_Like("%12s %10.2f %10.2f %10.2f\n", t->name, - t->min, t->max, t->mean); - } -} - -void OutputTimer(Timer_t *t, int (*Printf_Like)(const char *, ...)){ - MPMY_Comm_request req; - - if( t->enabled && t->name ) { - MPMY_ICombine_Init(&req); - t->mean = t->min = t->max = MPMY_ReadTimer(t->mpmy_tm); - MPMY_ICombine(&t->min, &t->min, 1, MPMY_DOUBLE, MPMY_MIN, req); - MPMY_ICombine(&t->max, &t->max, 1, MPMY_DOUBLE, MPMY_MAX, req); - MPMY_ICombine(&t->mean, &t->mean, 1, MPMY_DOUBLE, MPMY_SUM, req); - MPMY_ICombine_Wait(req); - t->mean /= MPMY_Nproc(); - Printf_Like("%12s %10.2f %10.2f %10.2f\n", t->name, - t->min, t->max, t->mean); - } -} - -void OutputIndividualTimers(int (*Printf_Like)(const char *, ...)){ - int i; - Timer_t *t; - - Printf_Like("%12s %10s\n", "Timers", "(sec)"); - for (i = 0; i < nenabled_timers; i++) { - t = enabled_timers[i]; - if( t->enabled && t->name ){ - Printf_Like("%12s %10.2f\n", t->name, MPMY_ReadTimer(t->mpmy_tm)); - } - } -} - diff --git a/external/patch_sdf b/external/patch_sdf new file mode 100644 index 0000000..b41345c --- /dev/null +++ b/external/patch_sdf @@ -0,0 +1,64 @@ +--- SDF.h 2014-06-04 07:22:26.000000000 +0200 ++++ SDF.h.new 2014-06-04 10:06:18.521116967 +0200 +@@ -85,7 +85,7 @@ + int SDFswap(SDF *hdr); + int SDFnoswap(SDF *hdr); + int SDFisswapping(SDF *hdr); +-int SDFsetmaxbufsz(int new); ++int SDFsetmaxbufsz(int); + int SDFrdvecs(SDF *hdr, ... + /* char *name, int n, void *address, int stride, + ... , +@@ -113,10 +113,10 @@ + + /* These four are harder to write than one might guess. */ + /* They're in the library to avoid duplicating code. */ +-int SDFgetint(SDF *sdfp, char *name, int *value); +-int SDFgetint64(SDF *sdfp, char *name, int64_t *value); +-int SDFgetfloat(SDF *sdfp, char *name, float *value); +-int SDFgetdouble(SDF *sdfp, char *name, double *value); ++int SDFgetint(SDF *sdfp, const char *name, int *value); ++int SDFgetint64(SDF *sdfp, const char *name, int64_t *value); ++int SDFgetfloat(SDF *sdfp, const char *name, float *value); ++int SDFgetdouble(SDF *sdfp, const char *name, double *value); + int SDFgetstring(SDF *sdfp, const char *name, char *string, int size); + + void SDFwrite(const char *filename, int64_t gnobj, int64_t nobj, +--- SDFget.c.old 2014-06-04 10:17:16.380531163 +0200 ++++ SDFget.c 2014-06-04 10:17:40.991953383 +0200 +@@ -22,7 +22,7 @@ + /* I'll resist the temptation to make one macro to cover all these cases */ + /* Should we check for loss of precision in float too? */ + int +-SDFgetfloat(SDF *sdfp, char *name, float *value) ++SDFgetfloat(SDF *sdfp, const char *name, float *value) + { + double double_value; + int int_value; +@@ -62,7 +62,7 @@ + } + + int +-SDFgetdouble(SDF *sdfp, char *name, double *value) ++SDFgetdouble(SDF *sdfp, const char *name, double *value) + { + double double_value; + float float_value; +@@ -102,7 +102,7 @@ + } + + int +-SDFgetint(SDF *sdfp, char *name, int *value) ++SDFgetint(SDF *sdfp, const char *name, int *value) + { + int int_value; + float float_value; +@@ -198,7 +198,7 @@ + } + + int +-SDFgetint64(SDF *sdfp, char *name, int64_t *value) ++SDFgetint64(SDF *sdfp, const char *name, int64_t *value) + { + int int_value; + float float_value;