|
From: <kin...@us...> - 2025-08-15 18:02:01
|
Revision: 7273
http://sourceforge.net/p/teem/code/7273
Author: kindlmann
Date: 2025-08-15 18:01:56 +0000 (Fri, 15 Aug 2025)
Log Message:
-----------
Removing all code for SGI IRIX Direct I/O. There are more modern ways of doing fast data IO that bypasses kernel buffers, but they have different APIs than what SGI used, so there is nothing lost in removing code that will never be used to good effect again.
Modified Paths:
--------------
teem/trunk/CMakeLists.txt
teem/trunk/src/GNUmakefile
teem/trunk/src/air/CMakeLists.txt
teem/trunk/src/air/GNUmakefile
teem/trunk/src/air/air.h
teem/trunk/src/air/sane.c
teem/trunk/src/nrrd/encodingRaw.c
teem/trunk/src/nrrd/formatNRRD.c
teem/trunk/src/nrrd/formatPNM.c
teem/trunk/src/nrrd/formatVTK.c
teem/trunk/src/nrrd/privateNrrd.h
teem/trunk/src/nrrd/read.c
Removed Paths:
-------------
teem/trunk/src/air/dio.c
teem/trunk/src/air/test/tdio.c
Modified: teem/trunk/CMakeLists.txt
===================================================================
--- teem/trunk/CMakeLists.txt 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/CMakeLists.txt 2025-08-15 18:01:56 UTC (rev 7273)
@@ -247,22 +247,23 @@
endif()
# Option 8
# DirectIO is the fast way to do multi-gigabyte I/O and currently only available for SGI platforms.
-if(USE_DIRECTIO)
- add_definitions(-DTEEM_DIO=1)
-else()
- add_definitions(-DTEEM_DIO=0)
-endif()
-# Option 9
+# (and given the fate of SGI, this has been removed from Teem v2)
+#if(USE_DIRECTIO)
+# add_definitions(-DTEEM_DIO=1)
+#else()
+# add_definitions(-DTEEM_DIO=0)
+#endif()
+# Option 9->8
if(Teem_USE_LIB_INSTALL_SUBDIR)
set(EXTRA_INSTALL_PATH /Teem-${Teem_VERSION_STRING})
else()
set(EXTRA_INSTALL_PATH "")
endif()
-# Option 10 - Stand-alone programs to process hex encoding of data
+# Option 10->9 - Stand-alone programs to process hex encoding of data
if(BUILD_HEX)
add_subdirectory(src/hex)
endif()
-# Option 11 - For testing
+# Option 11->10 - For testing
if(BUILD_TESTING)
include(CTest)
enable_testing()
Modified: teem/trunk/src/GNUmakefile
===================================================================
--- teem/trunk/src/GNUmakefile 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/GNUmakefile 2025-08-15 18:01:56 UTC (rev 7273)
@@ -261,7 +261,7 @@
##
link = $(foreach LIB,$(call linkorder,$(1)),-l$(LIB))
-## For XXX in: "ENDIAN", "QNANHIBIT", "DIO"
+## For XXX in: "ENDIAN", "QNANHIBIT"
##
## TEEM_XXX is set in the architecture-specific makefile, and
## $(L).NEED_XXX is set in the Makefile for the library which needs
@@ -271,8 +271,7 @@
## reasonable. more.cflags(L) is the list of -D flags for all required
## XXX.
##
-more.cflags = $(if $($(1).NEED_DIO),-DTEEM_DIO=$(TEEM_DIO))\
- $(if $($(1).NEED_QNANHIBIT),-DTEEM_QNANHIBIT=$(TEEM_QNANHIBIT)) \
+more.cflags = $(if $($(1).NEED_QNANHIBIT),-DTEEM_QNANHIBIT=$(TEEM_QNANHIBIT))
## banner(L) is progress indication for compiling library L; see
## template.mk. The double colon rules previously used to print this
Modified: teem/trunk/src/air/CMakeLists.txt
===================================================================
--- teem/trunk/src/air/CMakeLists.txt 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/air/CMakeLists.txt 2025-08-15 18:01:56 UTC (rev 7273)
@@ -4,7 +4,6 @@
754.c
air.h
array.c
- dio.c
endianAir.c
enum.c
heap.c
Modified: teem/trunk/src/air/GNUmakefile
===================================================================
--- teem/trunk/src/air/GNUmakefile 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/air/GNUmakefile 2025-08-15 18:01:56 UTC (rev 7273)
@@ -48,13 +48,12 @@
$(L).PUBLIC_HEADERS = air.h
$(L).PRIVATE_HEADERS = privateAir.h
$(L).OBJS = 754.o randMT.o randJSF.o array.o miscAir.o parseAir.o math.o \
- endianAir.o dio.o mop.o enum.o sane.o string.o threadAir.o heap.o
+ endianAir.o mop.o enum.o sane.o string.o threadAir.o heap.o
$(L).TESTS = test/floatprint test/doubleprint test/tok \
- test/tmop test/tline test/fp test/trand test/trandJSF test/tmisc test/tdio \
+ test/tmop test/tline test/fp test/trand test/trandJSF test/tmisc \
test/bessy test/tarr test/texp test/logrice test/tprint
$(L).NEED_QNANHIBIT = true
-$(L).NEED_DIO = true
####
####
####
Modified: teem/trunk/src/air/air.h
===================================================================
--- teem/trunk/src/air/air.h 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/air/air.h 2025-08-15 18:01:56 UTC (rev 7273)
@@ -555,13 +555,12 @@
airInsane_QNaNHiBit, /* 7: airMyQNaNHiBit is wrong */
airInsane_AIR_NAN, /* 8: airFPClass_f(AIR_QNAN) wrong
(no longer checking on problematic SNAN) */
- airInsane_dio, /* 9: airMyDio set to something invalid */
- airInsane_UCSize, /* 10: unsigned char isn't 8 bits */
- airInsane_FISize, /* 11: sizeof(float), sizeof(int) not 4 */
- airInsane_DLSize, /* 12: sizeof(double), sizeof(airLLong) not 8 */
+ airInsane_UCSize, /* 9: unsigned char isn't 8 bits */
+ airInsane_FISize, /* 10: sizeof(float), sizeof(int) not 4 */
+ airInsane_DLSize, /* 11: sizeof(double), sizeof(airLLong) not 8 */
airInsane_last
};
-#define AIR_INSANE_MAX 12
+#define AIR_INSANE_MAX 11
AIR_EXPORT const char *airInsaneErr(int insane);
AIR_EXPORT int airSanity(void);
@@ -643,39 +642,6 @@
int swap);
/* ---- END non-NrrdIO */
-/* dio.c */
-/*
-******** airNoDio enum
-**
-** reasons for why direct I/O won't be used with a particular
-** file/pointer combination
-*/
-enum {
- airNoDio_okay, /* 0: actually, you CAN do direct I/O */
- airNoDio_arch, /* 1: Teem thinks this architecture can't do it */
- airNoDio_format, /* 2: Teem thinks given data file format can't use it */
- airNoDio_std, /* 3: DIO isn't possible for std{in|out|err} */
- airNoDio_fd, /* 4: couldn't get underlying file descriptor */
- airNoDio_dioinfo, /* 5: calling fcntl() to get direct I/O info failed */
- airNoDio_small, /* 6: requested size is too small */
- airNoDio_size, /* 7: requested size not a multiple of d_miniosz */
- airNoDio_ptr, /* 8: pointer not multiple of d_mem */
- airNoDio_fpos, /* 9: current file position not multiple of d_miniosz */
- airNoDio_setfl, /* 10: fcntl(fd, SETFL, FDIRECT) failed */
- airNoDio_test, /* 11: couldn't memalign() even a small bit of memory */
- airNoDio_disable, /* 12: someone disabled it with airDisableDio */
- airNoDio_last
-};
-#define AIR_NODIO_MAX 12
-AIR_EXPORT const char *airNoDioErr(int noDio);
-AIR_EXPORT const int airMyDio;
-AIR_EXPORT int airDisableDio;
-AIR_EXPORT void airDioInfo(int *align, int *min, int *max, int fd);
-AIR_EXPORT int airDioTest(int fd, const void *ptr, size_t size);
-AIR_EXPORT void *airDioMalloc(size_t size, int fd);
-AIR_EXPORT size_t airDioRead(int fd, void *ptr, size_t size);
-AIR_EXPORT size_t airDioWrite(int fd, const void *ptr, size_t size);
-
/* mop.c: clean-up utilities */
enum {
airMopNever,
@@ -757,7 +723,7 @@
#define AIR_CALLOC(N, T) (T *)(calloc((N), sizeof(T)))
/*
-******** AIR_ENDIAN, AIR_QNANHIBIT, AIR_DIO
+******** AIR_ENDIAN, AIR_QNANHIBIT
**
** These reflect particulars of hardware which we're running on. The
** difference from the things starting with TEEM_ is that the TEEM_
@@ -767,7 +733,6 @@
*/
#define AIR_ENDIAN (airMyEndian())
#define AIR_QNANHIBIT (airMyQNaNHiBit)
-#define AIR_DIO (airMyDio)
/*
******** AIR_NAN, AIR_QNAN, AIR_SNAN, AIR_POS_INF, AIR_NEG_INF
Deleted: teem/trunk/src/air/dio.c
===================================================================
--- teem/trunk/src/air/dio.c 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/air/dio.c 2025-08-15 18:01:56 UTC (rev 7273)
@@ -1,343 +0,0 @@
-/*
- Teem: Tools to process and visualize scientific data and images
- Copyright (C) 2009--2023 University of Chicago
- Copyright (C) 2005--2008 Gordon Kindlmann
- Copyright (C) 1998--2004 University of Utah
-
- This library is free software; you can redistribute it and/or modify it under the terms
- of the GNU Lesser General Public License (LGPL) as published by the Free Software
- Foundation; either version 2.1 of the License, or (at your option) any later version.
- The terms of redistributing and/or modifying this software also include exceptions to
- the LGPL that facilitate static linking.
-
- This 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
- this library; if not, write to Free Software Foundation, Inc., 51 Franklin Street,
- Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include "air.h"
-#include <teemDio.h>
-
-#if TEEM_DIO == 0
-#else
-/* HEY: these may be SGI-specific */
-# include <sys/types.h>
-# include <unistd.h>
-# include <fcntl.h>
-#endif
-
-#if TEEM_DIO == 0
-const int airMyDio = 0;
-#else
-const int airMyDio = 1;
-#endif
-
-int airDisableDio = AIR_FALSE;
-
-static const char _airNoDioErr[AIR_NODIO_MAX + 2][AIR_STRLEN_SMALL + 1]
- = {"(invalid noDio value)",
- "CAN TOO do direct I/O!",
- "direct I/O apparently not available on this architecture",
- "direct I/O apparently not suitable for given file format",
- "won't do direct I/O on std{in|out|err}",
- "got -1 as file descriptor",
- "fcntl(F_DIOINFO) to learn direct I/O specifics failed",
- "requested transfer size is too small",
- "requested transfer size not a multiple of d_miniosz",
- "data memory address not multiple of d_mem",
- "current file position not multiple of d_miniosz",
- "fcntl(F_SETFL, FDIRECT) to turn on direct I/O failed",
- "memalign() test (on a small chuck of memory) failed",
- "direct I/O (in air library) has been disabled with airDisableDio"};
-
-const char *
-airNoDioErr(int noDio) {
-
- if (AIR_IN_CL(0, noDio, AIR_NODIO_MAX)) {
- return _airNoDioErr[noDio + 1];
- } else {
- return _airNoDioErr[0];
- }
-}
-
-/*
-******** airDioTest
-**
-** does everything necessary to assess whether direct IO can be used
-** to read a data segment of a given size, from a given file
-** descriptor, into a given pointer. The given pointer ptr can be
-** NULL, and/or the size can be 0, in order to test the other aspects
-** of direct IO. The return value of this is from the airNoDio_* enum.
-** Note that airNoDio_okay means, "actually, direct IO *does* seem to
-** be possible here".
-*/
-#if TEEM_DIO == 0
-int
-airDioTest(int fd, const void *ptr, size_t size) {
- AIR_UNUSED(fd);
- AIR_UNUSED(ptr);
- AIR_UNUSED(size);
-
- /* Teem makefiles think no direct IO is possible on this architecture */
- return airNoDio_arch;
-}
-#else
-int
-airDioTest(int fd, const void *ptr, size_t size) {
- struct dioattr dioinfo;
- void *tmp;
- int flags;
-
- if (airDisableDio) {
- /* user turned direct I/O off */
- return airNoDio_disable;
- }
- if (0 == fd || 1 == fd || 2 == fd) {
- /* This was added because I was noticing a problem with piping
- between unrrdu programs- sometimes the fread() of the receiving
- data through a unix pipe ("|") failed to read all the data. If
- the body of this function was bypassed (with "return
- airNoDio_disable;", for instance), then the problem went away.
- The problematic call seemed to be the fflush() below (Tue Feb 1
- 06:47:33 EST 2005: which has since been removed with the change
- of this function's argument from a FILE * to an integral file
- descriptor). I don't think direct I/O is possible on stdin,
- stdout, or stdout, since the fcntl() call below fails on stdin
- and stdout. However, something about making that fcntl() call
- changes something which means that about half the time, the
- read() on a piped stdin fails (on an irix6.n32 O2, at
- least). So, seems to be safest to just explicitly say that
- direct I/O is unavailable, based solely on the file descriptor
- number (0, 1, 2). */
- return airNoDio_std;
- }
- if (-1 == fd) {
- /* caller probably couldn't get the underlying file descriptor */
- return airNoDio_fd;
- }
- if (0 != fcntl(fd, F_DIOINFO, &dioinfo)) {
- /* couldn't learn direct I/O specifics */
- return airNoDio_dioinfo;
- }
-
- if (size) {
- /*
- ** direct I/O requirements:
- ** 1) xfer size between d_miniosz and d_maxiosz
- ** 2) xfer size a multiple of d_miniosz
- ** 3) memory buffer on d_mem-byte boundary
- ** 4) file position on d_miniosz-byte boundary
- **
- ** As long as xfer size is >= d_miniosz and meets req. #2, then
- ** we can break the xfer into d_maxiosz-size pieces of need be.
- ** We can test #3 here if we're given non-NULL ptr
- ** We can always test #4
- */
- if (size < dioinfo.d_miniosz) {
- /* fails req. #1 above */
- return airNoDio_small;
- }
- /* we don't actually check for being too large, since we can always
- do IO on d_maxiosz-sized pieces */
- if (size % dioinfo.d_miniosz) {
- /* fails req. #2 above */
- return airNoDio_size;
- }
- }
- if (ptr) {
- if ((unsigned long)(ptr) % dioinfo.d_mem) {
- /* fails req. #3 above */
- return airNoDio_ptr;
- }
- } else {
- tmp = memalign(dioinfo.d_mem, dioinfo.d_miniosz);
- if (!tmp) {
- /* couldn't even alloc (via memalign) the minimum size */
- return airNoDio_test;
- }
- free(tmp);
- }
- if (lseek(fd, 0, SEEK_CUR) % dioinfo.d_miniosz) {
- /* fails req. #4 above */
- return airNoDio_fpos;
- }
- flags = fcntl(fd, F_GETFL);
- if (-1 == fcntl(fd, F_SETFL, flags | FDIRECT)) {
- /* couln't turn on direct I/O */
- return airNoDio_setfl;
- }
- /* put things back the way they were */
- fcntl(fd, F_SETFL, flags);
-
- /* as far as we know, direct I/O seems workable */
- return airNoDio_okay;
-}
-#endif
-
-/*
-******** airDioInfo
-**
-** does the fcntl stuff to learn the direct IO parameters:
-** align: required alignment of memory (pointer must be multiple of this)
-** min: minimum size of dio transfer
-** max: maximum size of dio transfer
-**
-** NOTE: this does not try to do any error checking, because it assumes
-** that you've already called airDioTest without incident.
-*/
-#if TEEM_DIO == 0
-void
-airDioInfo(int *align, int *min, int *max, int fd) {
- AIR_UNUSED(align);
- AIR_UNUSED(min);
- AIR_UNUSED(max);
- AIR_UNUSED(fd);
- return;
-}
-#else
-void
-airDioInfo(int *align, int *min, int *max, int fd) {
- struct dioattr dioinfo;
-
- if (align && min && max && !fcntl(fd, F_DIOINFO, &dioinfo)) {
- *align = dioinfo.d_mem;
- *min = dioinfo.d_miniosz;
- *max = dioinfo.d_maxiosz;
- }
- return;
-}
-#endif
-
-/*
-******** airDioMalloc
-**
-** does direct IO compatible memory allocation.
-**
-** NOTE: like airDioInfo, this assumes that you've called airDioTest
-** without incident
-*/
-#if TEEM_DIO == 0
-void *
-airDioMalloc(size_t size, int fd) {
- AIR_UNUSED(size);
- AIR_UNUSED(fd);
-
- return NULL;
-}
-#else
-void *
-airDioMalloc(size_t size, int fd) {
- int align, min, max;
-
- airDioInfo(&align, &min, &max, fd);
- return memalign(align, size);
-}
-#endif
-
-/*
-******** airDioRead
-**
-** like read(), but for direct IO. The idea is that you call this on as
-** big a chunk of memory as possible.
-**
-** NOTE: like airDioInfo, this assumes that you've called airDioTest
-** without incident
-*/
-#if TEEM_DIO == 0
-size_t
-airDioRead(int fd, void *_ptr, size_t size) {
- AIR_UNUSED(fd);
- AIR_UNUSED(_ptr);
- AIR_UNUSED(size);
-
- return 0;
-}
-#else
-size_t
-airDioRead(int fd, void *_ptr, size_t size) {
- size_t red, totalred;
- int align, min, max, flags;
- size_t remain, part;
- char *ptr;
-
- if (!(_ptr && airNoDio_okay == airDioTest(fd, _ptr, size))) {
- return 0;
- }
-
- flags = fcntl(fd, F_GETFL);
- fcntl(fd, F_SETFL, flags | FDIRECT);
- airDioInfo(&align, &min, &max, fd);
- remain = size;
- totalred = 0;
- ptr = (char *)_ptr;
- do {
- part = AIR_MIN(remain, max);
- red = read(fd, ptr, part);
- totalred += red;
- if (red != part) {
- break;
- }
- ptr += red;
- remain -= red;
- } while (remain);
- fcntl(fd, F_SETFL, flags);
-
- return totalred;
-}
-#endif
-
-/*
-******** airDioWrite
-**
-** like write(), but for direct IO. The idea is that you call this on as
-** big a chunk of memory as possible.
-**
-** NOTE: like airDioInfo, this assumes that you've called airDioTest
-** without incident
-*/
-#if TEEM_DIO == 0
-size_t
-airDioWrite(int fd, const void *_ptr, size_t size) {
- AIR_UNUSED(fd);
- AIR_UNUSED(_ptr);
- AIR_UNUSED(size);
-
- return 0;
-}
-#else
-size_t
-airDioWrite(int fd, const void *_ptr, size_t size) {
- size_t rit, totalrit;
- int align, min, max, flags;
- size_t remain, part;
- char *ptr;
-
- if (!(_ptr && (airNoDio_okay == airDioTest(fd, _ptr, size)))) {
- return 0;
- }
-
- flags = fcntl(fd, F_GETFL);
- fcntl(fd, F_SETFL, flags | FDIRECT);
- airDioInfo(&align, &min, &max, fd);
- remain = size;
- totalrit = 0;
- ptr = (char *)_ptr;
- do {
- part = AIR_MIN(remain, max);
- rit = write(fd, ptr, part);
- totalrit += rit;
- if (rit != part) {
- break;
- }
- ptr += rit;
- remain -= rit;
- } while (remain);
- fcntl(fd, F_SETFL, flags);
-
- return totalrit;
-}
-#endif
Modified: teem/trunk/src/air/sane.c
===================================================================
--- teem/trunk/src/air/sane.c 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/air/sane.c 2025-08-15 18:01:56 UTC (rev 7273)
@@ -183,17 +183,6 @@
return airInsane_FltDblFPClass;
}
- /* just make sure AIR_DIO is reasonably set
- (actually, this should be done by include/teemDio.h) */
- switch (AIR_DIO) {
- case 0:
- break;
- case 1:
- break;
- default:
- return airInsane_dio;
- }
-
/* _airSanity = 1; (see above) */
return airInsane_not;
}
@@ -208,10 +197,9 @@
"air_FPClass_f() wrong after double->float assign", /* 6: airInsane_FltDblFPClass */
"TEEM_QNANHIBIT is wrong", /* 7: airInsane_QNaNHiBit */
"airFPClass(AIR_QNAN) wrong", /* 8: airInsane_AIR_NAN */
- "TEEM_DIO has invalid value", /* 9: airInsane_dio */
- "unsigned char isn't 8 bits", /* 10: airInsane_UCSize */
- "sizeof(float), sizeof(int) not both == 4", /* 11: airInsane_FISize */
- "sizeof(double), sizeof(airLLong) not both == 8", /* 12: airInsane_DLSize */
+ "unsigned char isn't 8 bits", /* 9: airInsane_UCSize */
+ "sizeof(float), sizeof(int) not both == 4", /* 10: airInsane_FISize */
+ "sizeof(double), sizeof(airLLong) not both == 8", /* 11: airInsane_DLSize */
};
static const char _airBadInsane[] = "(invalid insane value)";
Deleted: teem/trunk/src/air/test/tdio.c
===================================================================
--- teem/trunk/src/air/test/tdio.c 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/air/test/tdio.c 2025-08-15 18:01:56 UTC (rev 7273)
@@ -1,209 +0,0 @@
-/*
- Teem: Tools to process and visualize scientific data and images
- Copyright (C) 2009--2023 University of Chicago
- Copyright (C) 2005--2008 Gordon Kindlmann
- Copyright (C) 1998--2004 University of Utah
-
- This library is free software; you can redistribute it and/or modify it under the terms
- of the GNU Lesser General Public License (LGPL) as published by the Free Software
- Foundation; either version 2.1 of the License, or (at your option) any later version.
- The terms of redistributing and/or modifying this software also include exceptions to
- the LGPL that facilitate static linking.
-
- This 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
- this library; if not, write to Free Software Foundation, Inc., 51 Franklin Street,
- Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include "../air.h"
-
-#if TEEM_DIO == 0
-#else
-/* HEY: these may be SGI-specific */
-# include <sys/types.h>
-# include <unistd.h>
-# include <fcntl.h>
-#endif
-
-int
-main(int argc, char *argv[]) {
-#if TEEM_DIO == 0
-
- AIR_UNUSED(argc);
- fprintf(stderr, "%s: no direct-io testing for you\n", argv[0]);
- return 1;
-#else
- char *me, *fname, *multS, *data;
- FILE *file;
- double time0, time1, time2;
- int fd, align, mult, min, max, ret;
- size_t size;
- airArray *mop;
-
- me = argv[0];
- if (3 != argc) {
- /* 0 1 2 (3) */
- fprintf(stderr, "usage: %s <filename> <mult>\n", me);
- return 1;
- }
- fname = argv[1];
- multS = argv[2];
- if (1 != sscanf(multS, "%d", &mult)) {
- fprintf(stderr, "%s: couln't parse mult %s as int\n", me, multS);
- return 1;
- }
-
- mop = airMopNew();
- if (!(file = fopen(fname, "w"))) {
- fprintf(stderr, "%s: couldn't open %s for writing\n", me, fname);
- airMopError(mop);
- return 1;
- }
- airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);
- fd = fileno(file);
- if (-1 == fd) {
- fprintf(stderr, "%s: couldn't get underlying descriptor\n", me);
- airMopError(mop);
- return 1;
- }
- fprintf(stderr, "%s: fd(%s) = %d\n", me, fname, fd);
-
- ret = airDioTest(fd, NULL, 0);
- if (airNoDio_okay != ret) {
- fprintf(stderr, "%s: no good: \"%s\"\n", me, airNoDioErr(ret));
- airMopError(mop);
- return 1;
- }
-
- airDioInfo(&align, &min, &max, fd);
- fprintf(stderr, "%s: --> align=%d, min=%d, max=%d\n", me, align, min, max);
- size = (size_t)max * mult;
- data = airDioMalloc(size, fd);
- if (!data) {
- char stmp[AIR_STRLEN_SMALL + 1];
- fprintf(stderr, "%s: airDioMalloc(%s) failed\n", me, airSprintSize_t(stmp, size));
- airMopError(mop);
- return 1;
- }
- airMopAdd(mop, data, airFree, airMopAlways);
- fprintf(stderr, "\ndata size = %g MB\n", (double)size / (1024 * 1024));
-
- /* -------------------------------------------------------------- */
- fprintf(stderr, "(1) non-aligned memory, regular write:\n");
- time0 = airTime();
- if (size - 1 != write(fd, data + 1, size - 1)) {
- fprintf(stderr, "%s: write failed\n", me);
- airMopError(mop);
- return 1;
- }
- time1 = airTime();
- fsync(fd);
- time2 = airTime();
- fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n", time1 - time0, time2 - time1,
- time2 - time0, (size / (1024 * 1024)) / (time2 - time0));
- airMopSub(mop, file, (airMopper)airFclose);
- fclose(file);
- /* -------------------------------------------------------------- */
- /* -------------------------------------------------------------- */
- fprintf(stderr, "(2) aligned memory, regular write:\n");
- file = fopen(fname, "w");
- airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);
- fd = fileno(file);
-
- time0 = airTime();
- if (size != write(fd, data, size)) {
- fprintf(stderr, "%s: write failed\n", me);
- airMopError(mop);
- return 1;
- }
- time1 = airTime();
- fsync(fd);
- time2 = airTime();
- fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n", time1 - time0, time2 - time1,
- time2 - time0, (size / (1024 * 1024)) / (time2 - time0));
- airMopSub(mop, file, (airMopper)airFclose);
- fclose(file);
- /* -------------------------------------------------------------- */
- /* -------------------------------------------------------------- */
- fprintf(stderr, "(3) aligned memory, air's direct IO:\n");
- file = fopen(fname, "w");
- airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);
- fd = fileno(file);
-
- time0 = airTime();
- if (size != airDioWrite(fd, data, size)) {
- fprintf(stderr, "%s: write failed\n", me);
- airMopError(mop);
- return 1;
- }
- time1 = airTime();
- fsync(fd);
- time2 = airTime();
- fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n", time1 - time0, time2 - time1,
- time2 - time0, (size / (1024 * 1024)) / (time2 - time0));
- airMopSub(mop, file, (airMopper)airFclose);
- fclose(file);
- /* -------------------------------------------------------------- */
- /* -------------------------------------------------------------- */
- fprintf(stderr, "(4) aligned memory, direct IO by hand:\n");
- {
- /* "input": fname, size, data */
- int flags;
- struct dioattr dio;
- char *ptr;
- size_t remain, totalrit, rit, part;
-
- file = fopen(fname, "w");
- if (-1 == (fd = fileno(file))) {
- fprintf(stderr, "%s: couldn't get underlying descriptor\n", me);
- airMopError(mop);
- return 1;
- }
- airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);
-
- flags = fcntl(fd, F_GETFL);
- if (-1 == fcntl(fd, F_SETFL, flags | FDIRECT)) {
- fprintf(stderr, "%s: couldn't turn on direct IO\n", me);
- airMopError(mop);
- return 1;
- }
- if (0 != fcntl(fd, F_DIOINFO, &dio)) {
- fprintf(stderr, "%s: couldn't learn direct IO specifics", me);
- airMopError(mop);
- return 1;
- }
-
- remain = size;
- totalrit = 0;
- ptr = data;
- time0 = airTime();
- do {
- part = remain > dio.d_maxiosz ? dio.d_maxiosz : remain;
- rit = write(fd, ptr, part);
- if (rit != part) {
- fprintf(stderr, "%s: write failed\n", me);
- airMopError(mop);
- return 1;
- }
- totalrit += rit;
- ptr += rit;
- remain -= rit;
- } while (remain);
- time1 = airTime();
- fsync(fd);
- time2 = airTime();
- fprintf(stderr, " time = %g + %g = %g (%g MB/sec)\n", time1 - time0, time2 - time1,
- time2 - time0, (size / (1024 * 1024)) / (time2 - time0));
- airMopSub(mop, file, (airMopper)airFclose);
- fclose(file);
- }
- /* -------------------------------------------------------------- */
-
- airMopError(mop);
- exit(0);
-#endif
-}
Modified: teem/trunk/src/nrrd/encodingRaw.c
===================================================================
--- teem/trunk/src/nrrd/encodingRaw.c 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/nrrd/encodingRaw.c 2025-08-15 18:01:56 UTC (rev 7273)
@@ -33,7 +33,7 @@
NrrdIoState *nio) {
static const char me[] = "_nrrdEncodingRaw_read";
size_t ret, bsize;
- int fd, dio, car;
+ int car;
long savePos;
char *data_c;
size_t elementSize, maxChunkSize, remainderValue, chunkSize;
@@ -40,82 +40,56 @@
size_t retTmp;
char stmp[3][AIR_STRLEN_SMALL + 1];
+ AIR_UNUSED(nio);
bsize = nrrdElementSize(nrrd) * elementNum;
- if (nio->format->usesDIO) {
- fd = fileno(file);
- dio = airDioTest(fd, data, bsize);
- } else {
- fd = -1;
- dio = airNoDio_format;
- }
- if (airNoDio_okay == dio) {
- if (2 <= nrrdStateVerboseIO) {
- fprintf(stderr, "with direct I/O ... ");
+
+ /* HEY: There's a bug in fread/fwrite in gcc 4.2.1 (with SnowLeopard).
+ When it reads/writes a >=2GB data array, it pretends to succeed
+ (i.e. the return value is the right number) but it hasn't
+ actually read/written the data. The work-around is to loop
+ over the data, reading/writing 1GB (or smaller) chunks. */
+ ret = 0;
+ data_c = (char *)data;
+ elementSize = nrrdElementSize(nrrd);
+ maxChunkSize = 1024 * 1024 * 1024 / elementSize;
+ while (ret < elementNum) {
+ remainderValue = elementNum - ret;
+ if (remainderValue < maxChunkSize) {
+ chunkSize = remainderValue;
+ } else {
+ chunkSize = maxChunkSize;
}
- ret = airDioRead(fd, data, bsize);
- if (ret != bsize) {
+ retTmp = fread(&(data_c[ret * elementSize]), elementSize, chunkSize, file);
+ ret += retTmp;
+ if (retTmp != chunkSize) {
biffAddf(NRRD,
- "%s: airDioRead got read only %s of %sbytes "
+ "%s: fread got only %s %s-sized things, not %s "
"(%g%% of expected)",
- me, airSprintSize_t(stmp[0], ret), airSprintSize_t(stmp[1], bsize),
- 100.0 * AIR_CAST(double, ret) / AIR_CAST(double, bsize));
+ me, airSprintSize_t(stmp[0], ret),
+ airSprintSize_t(stmp[1], nrrdElementSize(nrrd)),
+ airSprintSize_t(stmp[2], elementNum),
+ 100.0 * AIR_CAST(double, ret) / AIR_CAST(double, elementNum));
return 1;
}
- } else {
- if (2 <= nrrdStateVerboseIO) {
- if (AIR_DIO && nio->format->usesDIO) {
- fprintf(stderr, "with fread(), not DIO: %s ...", airNoDioErr(dio));
- }
- }
+ }
- /* HEY: There's a bug in fread/fwrite in gcc 4.2.1 (with SnowLeopard).
- When it reads/writes a >=2GB data array, it pretends to succeed
- (i.e. the return value is the right number) but it hasn't
- actually read/written the data. The work-around is to loop
- over the data, reading/writing 1GB (or smaller) chunks. */
- ret = 0;
- data_c = (char *)data;
- elementSize = nrrdElementSize(nrrd);
- maxChunkSize = 1024 * 1024 * 1024 / elementSize;
- while (ret < elementNum) {
- remainderValue = elementNum - ret;
- if (remainderValue < maxChunkSize) {
- chunkSize = remainderValue;
- } else {
- chunkSize = maxChunkSize;
- }
- retTmp = fread(&(data_c[ret * elementSize]), elementSize, chunkSize, file);
- ret += retTmp;
- if (retTmp != chunkSize) {
- biffAddf(NRRD,
- "%s: fread got only %s %s-sized things, not %s "
- "(%g%% of expected)",
- me, airSprintSize_t(stmp[0], ret),
- airSprintSize_t(stmp[1], nrrdElementSize(nrrd)),
- airSprintSize_t(stmp[2], elementNum),
- 100.0 * AIR_CAST(double, ret) / AIR_CAST(double, elementNum));
- return 1;
- }
+ car = fgetc(file);
+ if (EOF != car) {
+ if (1 <= nrrdStateVerboseIO) {
+ fprintf(stderr,
+ "%s: WARNING: finished reading raw data, "
+ "but file not at EOF\n",
+ me);
}
-
- car = fgetc(file);
- if (EOF != car) {
- if (1 <= nrrdStateVerboseIO) {
- fprintf(stderr,
- "%s: WARNING: finished reading raw data, "
- "but file not at EOF\n",
- me);
- }
- ungetc(car, file);
+ ungetc(car, file);
+ }
+ if (2 <= nrrdStateVerboseIO && nio->byteSkip && stdin != file) {
+ savePos = ftell(file);
+ if (!fseek(file, 0, SEEK_END)) {
+ double frac = (AIR_CAST(double, bsize) / AIR_CAST(double, ftell(file) + 1));
+ fprintf(stderr, "(%s: used %g%% of file for nrrd data)\n", me, 100.0 * frac);
+ fseek(file, savePos, SEEK_SET);
}
- if (2 <= nrrdStateVerboseIO && nio->byteSkip && stdin != file) {
- savePos = ftell(file);
- if (!fseek(file, 0, SEEK_END)) {
- double frac = (AIR_CAST(double, bsize) / AIR_CAST(double, ftell(file) + 1));
- fprintf(stderr, "(%s: used %g%% of file for nrrd data)\n", me, 100.0 * frac);
- fseek(file, savePos, SEEK_SET);
- }
- }
}
return 0;
@@ -125,79 +99,52 @@
_nrrdEncodingRaw_write(FILE *file, const void *data, size_t elementNum, const Nrrd *nrrd,
NrrdIoState *nio) {
static const char me[] = "_nrrdEncodingRaw_write";
- int fd, dio;
- size_t ret, bsize;
+ size_t ret;
const char *data_c;
size_t elementSize, maxChunkSize, remainderValue, chunkSize;
size_t retTmp;
char stmp[3][AIR_STRLEN_SMALL + 1];
- bsize = nrrdElementSize(nrrd) * elementNum;
- if (nio->format->usesDIO) {
- fd = fileno(file);
- dio = airDioTest(fd, data, bsize);
- } else {
- fd = -1;
- dio = airNoDio_format;
- }
- if (airNoDio_okay == dio) {
- if (2 <= nrrdStateVerboseIO) {
- fprintf(stderr, "with direct I/O ... ");
+ AIR_UNUSED(nio);
+
+ /* HEY: There's a bug in fread/fwrite in gcc 4.2.1 (with SnowLeopard).
+ When it reads/writes a >=2GB data array, it pretends to succeed
+ (i.e. the return value is the right number) but it hasn't
+ actually read/written the data. The work-around is to loop
+ over the data, reading/writing 1GB (or smaller) chunks. */
+ ret = 0;
+ data_c = AIR_CAST(const char *, data);
+ elementSize = nrrdElementSize(nrrd);
+ maxChunkSize = 1024 * 1024 * 1024 / elementSize;
+ while (ret < elementNum) {
+ remainderValue = elementNum - ret;
+ if (remainderValue < maxChunkSize) {
+ chunkSize = remainderValue;
+ } else {
+ chunkSize = maxChunkSize;
}
- ret = airDioWrite(fd, data, bsize);
- if (ret != bsize) {
+ retTmp = fwrite(&(data_c[ret * elementSize]), elementSize, chunkSize, file);
+ ret += retTmp;
+ if (retTmp != chunkSize) {
biffAddf(NRRD,
- "%s: airDioWrite wrote only %s of %s bytes "
+ "%s: fwrite wrote only %s %s-sized things, not %s "
"(%g%% of expected)",
- me, airSprintSize_t(stmp[0], ret), airSprintSize_t(stmp[1], bsize),
- 100.0 * AIR_CAST(double, ret) / AIR_CAST(double, bsize));
+ me, airSprintSize_t(stmp[0], ret),
+ airSprintSize_t(stmp[1], nrrdElementSize(nrrd)),
+ airSprintSize_t(stmp[2], elementNum),
+ 100.0 * AIR_CAST(double, ret) / AIR_CAST(double, elementNum));
return 1;
}
- } else {
- if (2 <= nrrdStateVerboseIO) {
- if (AIR_DIO && nio->format->usesDIO) {
- fprintf(stderr, "with fread(), not DIO: %s ...", airNoDioErr(dio));
- }
- }
+ }
- /* HEY: There's a bug in fread/fwrite in gcc 4.2.1 (with SnowLeopard).
- When it reads/writes a >=2GB data array, it pretends to succeed
- (i.e. the return value is the right number) but it hasn't
- actually read/written the data. The work-around is to loop
- over the data, reading/writing 1GB (or smaller) chunks. */
- ret = 0;
- data_c = AIR_CAST(const char *, data);
- elementSize = nrrdElementSize(nrrd);
- maxChunkSize = 1024 * 1024 * 1024 / elementSize;
- while (ret < elementNum) {
- remainderValue = elementNum - ret;
- if (remainderValue < maxChunkSize) {
- chunkSize = remainderValue;
- } else {
- chunkSize = maxChunkSize;
- }
- retTmp = fwrite(&(data_c[ret * elementSize]), elementSize, chunkSize, file);
- ret += retTmp;
- if (retTmp != chunkSize) {
- biffAddf(NRRD,
- "%s: fwrite wrote only %s %s-sized things, not %s "
- "(%g%% of expected)",
- me, airSprintSize_t(stmp[0], ret),
- airSprintSize_t(stmp[1], nrrdElementSize(nrrd)),
- airSprintSize_t(stmp[2], elementNum),
- 100.0 * AIR_CAST(double, ret) / AIR_CAST(double, elementNum));
- return 1;
- }
- }
+ fflush(file);
+ /*
+ if (ferror(file)) {
+ biffAddf(NRRD, "%s: ferror returned non-zero", me);
+ return 1;
+ }
+ */
- fflush(file);
- /*
- if (ferror(file)) {
- biffAddf(NRRD, "%s: ferror returned non-zero", me);
- return 1;
- }
- */
- }
return 0;
}
Modified: teem/trunk/src/nrrd/formatNRRD.c
===================================================================
--- teem/trunk/src/nrrd/formatNRRD.c 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/nrrd/formatNRRD.c 2025-08-15 18:01:56 UTC (rev 7273)
@@ -499,7 +499,7 @@
nrrd->data = NULL;
data = NULL;
} else {
- if (_nrrdCalloc(nrrd, nio, dataFile)) {
+ if (_nrrdCalloc(nrrd, nio)) {
biffAddf(NRRD, "%s: couldn't allocate memory for data", me);
return 1;
}
Modified: teem/trunk/src/nrrd/formatPNM.c
===================================================================
--- teem/trunk/src/nrrd/formatPNM.c 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/nrrd/formatPNM.c 2025-08-15 18:01:56 UTC (rev 7273)
@@ -255,7 +255,7 @@
nrrdAxisInfoSet_va(nrrd, nrrdAxisInfoSize, AIR_SIZE_T(sx), AIR_SIZE_T(sy));
}
if (!nio->skipData) {
- if (_nrrdCalloc(nrrd, nio, file)) {
+ if (_nrrdCalloc(nrrd, nio)) {
biffAddf(NRRD, "%s: couldn't allocate memory for data", me);
return 1;
}
Modified: teem/trunk/src/nrrd/formatVTK.c
===================================================================
--- teem/trunk/src/nrrd/formatVTK.c 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/nrrd/formatVTK.c 2025-08-15 18:01:56 UTC (rev 7273)
@@ -247,7 +247,7 @@
return 1;
}
if (!nio->skipData) {
- if (_nrrdCalloc(nrrd, nio, file)) {
+ if (_nrrdCalloc(nrrd, nio)) {
biffAddf(NRRD, "%s: couldn't allocate memory for data", me);
return 1;
}
Modified: teem/trunk/src/nrrd/privateNrrd.h
===================================================================
--- teem/trunk/src/nrrd/privateNrrd.h 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/nrrd/privateNrrd.h 2025-08-15 18:01:56 UTC (rev 7273)
@@ -148,7 +148,7 @@
extern const char *const _nrrdNoSpaceVector;
extern int _nrrdByteSkipSkip(FILE *dataFile, Nrrd *nrrd, NrrdIoState *nio,
long int byteSkip);
-extern int _nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio, FILE *file);
+extern int _nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio);
extern void _nrrdSplitName(char **dirP, char **baseP, const char *name);
/* write.c */
Modified: teem/trunk/src/nrrd/read.c
===================================================================
--- teem/trunk/src/nrrd/read.c 2025-08-15 16:43:53 UTC (rev 7272)
+++ teem/trunk/src/nrrd/read.c 2025-08-15 18:01:56 UTC (rev 7273)
@@ -185,20 +185,12 @@
** allocates the data for the array, but only if necessary (as informed by
** nio->oldData and nio->oldDataSize).
**
-** as a recent feature, this will handle the extra work of allocating
-** memory in the special way required for direct IO, if possible. For
-** this to work, though, the FILE *file has to be passed. Since file
-** is not otherwise needed, it can be passed as NULL for non-direct-IO
-** situations. In any case, if the directIO-compatible allocation fails
-** its not error, and we revert to regular allocation.
-**
** NOTE: this assumes the checking that is done by _nrrdHeaderCheck
*/
int /* Biff: (private) 1 */
-_nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio, FILE *file) {
+_nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio) {
static const char me[] = "_nrrdCalloc";
size_t needDataSize;
- int fd;
needDataSize = nrrdElementNumber(nrrd) * nrrdElementSize(nrrd);
if (nio->oldData && needDataSize == nio->oldDataSize) {
@@ -208,13 +200,8 @@
there's no other error checking to do here */
} else {
nrrd->data = airFree(nrrd->data);
- fd = file ? fileno(file) : -1;
- if (nrrdEncodingRaw == nio->encoding && -1 != fd
- && airNoDio_okay == airDioTest(fd, NULL, needDataSize)) {
- nrrd->data = airDioMalloc(needDataSize, fd);
- }
if (!nrrd->data) {
- /* directIO-compatible allocation wasn't tried, or it failed */
+ /* allocate data if needed */
nrrd->data = malloc(needDataSize);
}
if (!nrrd->data) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|