summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Fmpio.c88
-rw-r--r--src/H5Fprivate.h22
2 files changed, 70 insertions, 40 deletions
diff --git a/src/H5Fmpio.c b/src/H5Fmpio.c
index b9f2238..4c24621 100644
--- a/src/H5Fmpio.c
+++ b/src/H5Fmpio.c
@@ -38,9 +38,6 @@
* that the number of bytes read is always equal to the number
* requested. This kluge is activated by #ifdef MPI_KLUGE0202.
*
- * H5F_MPIOff_to_haddr and H5F_haddr_to_MPIOff
- * - For now, we assume that MPI_Offset and haddr_t
- * are the same size. Needs to be generalized.
*/
#include <mpi.h>
#include <mpio.h>
@@ -70,8 +67,8 @@ static herr_t H5F_mpio_read(H5F_low_t *lf, const haddr_t *addr,
static herr_t H5F_mpio_write(H5F_low_t *lf, const haddr_t *addr,
size_t size, const uint8 *buf);
static herr_t H5F_mpio_flush(H5F_low_t *lf);
-static haddr_t H5F_MPIOff_to_haddr( MPI_Offset mpi_off );
-static MPI_Offset H5F_haddr_to_MPIOff( haddr_t addr );
+static herr_t H5F_MPIOff_to_haddr( MPI_Offset mpi_off, haddr_t *addr);
+static herr_t H5F_haddr_to_MPIOff( haddr_t addr, MPI_Offset *mpi_off);
const H5F_low_class_t H5F_LOW_MPIO[1] =
{
@@ -261,7 +258,12 @@ H5F_mpio_open(const char *name, uintn flags, H5F_search_t *key /*out */ )
MPI_Error_string( mpierr, mpierrmsg, &msglen );
HRETURN_ERROR(H5E_IO, H5E_CANTOPENFILE, NULL, mpierrmsg );
} else {
- haddr_t new_eof = H5F_MPIOff_to_haddr( size );
+ haddr_t new_eof;
+ if (SUCCEED != H5F_MPIOff_to_haddr( size, &new_eof )) {
+ MPI_File_close( &(lf->u.mpio.f) );
+ HRETURN_ERROR(H5E_IO, H5E_CANTOPENFILE, NULL,
+ "couldn't convert size to haddr_t" );
+ }
H5F_low_seteof( lf, &new_eof );
}
@@ -370,9 +372,18 @@ H5F_mpio_read(H5F_low_t *lf, const haddr_t *addr, size_t size, uint8 *buf)
if (0 == size)
HRETURN(SUCCEED);
- /* Read the data. */
- mpi_off = H5F_haddr_to_MPIOff( *addr );
+ /* numeric conversion of offset and size */
+ if (SUCCEED != H5F_haddr_to_MPIOff( *addr, &mpi_off )) {
+ HRETURN_ERROR(H5E_IO, H5E_READERROR, FAIL,
+ "couldn't convert addr to MPIOffset" );
+ }
size_i = (int)size;
+ if (size_i != size) { /* check type conversion */
+ HRETURN_ERROR(H5E_IO, H5E_READERROR, FAIL,
+ "couldn't convert size to int" );
+ }
+
+ /* Read the data. */
mpierr = MPI_File_read_at( lf->u.mpio.f, mpi_off, (void*) buf,
size_i, MPI_BYTE, &mpi_stat );
if (mpierr != MPI_SUCCESS) {
@@ -446,9 +457,8 @@ H5F_mpio_write(H5F_low_t *lf, const haddr_t *addr, size_t size,
{
MPI_Offset mpi_off;
MPI_Status mpi_stat;
- int mpierr;
+ int mpierr, msglen, size_i;
char mpierrmsg[MPI_MAX_ERROR_STRING];
- int msglen;
FUNC_ENTER(H5F_mpio_write, FAIL);
#ifdef H5F_MPIO_DEBUG
@@ -459,10 +469,20 @@ H5F_mpio_write(H5F_low_t *lf, const haddr_t *addr, size_t size,
if (0 == size)
HRETURN(SUCCEED);
+ /* numeric conversion of offset and size */
+ if (SUCCEED != H5F_haddr_to_MPIOff( *addr, &mpi_off )) {
+ HRETURN_ERROR(H5E_IO, H5E_READERROR, FAIL,
+ "couldn't convert addr to MPIOffset" );
+ }
+ size_i = (int)size;
+ if (size_i != size) { /* check type conversion */
+ HRETURN_ERROR(H5E_IO, H5E_READERROR, FAIL,
+ "couldn't convert size to int" );
+ }
+
/* Write the data. */
- mpi_off = H5F_haddr_to_MPIOff( *addr );
mpierr = MPI_File_write_at( lf->u.mpio.f, mpi_off, (void*) buf,
- (int) size, MPI_BYTE, &mpi_stat );
+ size_i, MPI_BYTE, &mpi_stat );
if (mpierr != MPI_SUCCESS) {
MPI_Error_string( mpierr, mpierrmsg, &msglen );
HRETURN_ERROR(H5E_IO, H5E_READERROR, FAIL, mpierrmsg );
@@ -517,17 +537,16 @@ H5F_mpio_flush(H5F_low_t *lf)
}
/*-------------------------------------------------------------------------
- * Function: H5F_MPIOff_to_haddr(size) );
+ * Function: H5F_MPIOff_to_haddr
*
* Purpose: Convert an MPI_Offset value to haddr_t.
*
* Problems and limitations:
- * For now, we assume that MPI_Offset and haddr_t
- * are the same size. Needs to be generalized.
*
- * Return: Success: the offset value, as an hddr_t.
+ * Return: Success: return value is SUCCEED
+ * and the haddr_t contains the converted value
*
- * Failure: 0
+ * Failure: return value is FAIL, the haddr_t is undefined
*
* Programmer:
* January 30, 1998
@@ -536,28 +555,29 @@ H5F_mpio_flush(H5F_low_t *lf)
*
*-------------------------------------------------------------------------
*/
-static haddr_t
-H5F_MPIOff_to_haddr( MPI_Offset mpi_off )
+static herr_t
+H5F_MPIOff_to_haddr( MPI_Offset mpi_off, haddr_t *addr )
{
- haddr_t addr;
+ herr_t ret_val = FAIL;
- addr.offset = (uint64) mpi_off;
+ addr->offset = (uint64) mpi_off;
+ if (addr->offset == mpi_off)
+ ret_val = SUCCEED;
- return(addr);
+ return (ret_val);
}
/*-------------------------------------------------------------------------
- * Function: H5F_haddr_to_MPIOff(size) );
+ * Function: H5F_haddr_to_MPIOff
*
* Purpose: Convert an haddr_t value to MPI_Offset.
*
* Problems and limitations:
- * For now, we assume that MPI_Offset and haddr_t
- * are the same size. Needs to be generalized.
*
- * Return: Success: the offset value, as an MPI_Offset.
+ * Return: Success: return value is SUCCEED
+ * and the MPIOffset contains the converted value
*
- * Failure: 0
+ * Failure: return value is FAIL, the MPIOffset is undefined
*
* Programmer:
* January 30, 1998
@@ -566,14 +586,14 @@ H5F_MPIOff_to_haddr( MPI_Offset mpi_off )
*
*-------------------------------------------------------------------------
*/
-static MPI_Offset
-H5F_haddr_to_MPIOff( haddr_t addr )
+static herr_t
+H5F_haddr_to_MPIOff( haddr_t addr, MPI_Offset *mpi_off )
{
- MPI_Offset mpi_off;
-
- FUNC_ENTER(H5F_haddr_to_MPIOff, (MPI_Offset)0);
+ herr_t ret_val = FAIL;
- mpi_off = (MPI_Offset) addr.offset;
+ *mpi_off = (MPI_Offset) addr.offset;
+ if (*mpi_off == addr.offset)
+ ret_val = SUCCEED;
- FUNC_LEAVE(mpi_off);
+ return (ret_val);
}
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h
index 7550165..dc3147e 100644
--- a/src/H5Fprivate.h
+++ b/src/H5Fprivate.h
@@ -100,10 +100,10 @@
# define INT64ENCODE(p, n) { \
int64 _n = (n); \
- size_t _i; \
+ intn _i; \
uint8 *_p = (uint8*)(p); \
for (_i=0; _i<sizeof(int64); _i++, _n>>=8) { \
- *_p++ = (uint8)(_n & 0xff); \
+ *_p++ = _n & 0xff; \
} \
for (/*void*/; _i<8; _i++) { \
*_p++ = (n)<0 ? 0xff : 0; \
@@ -113,10 +113,10 @@
# define UINT64ENCODE(p, n) { \
uint64 _n = (n); \
- size_t _i; \
+ intn _i; \
uint8 *_p = (uint8*)(p); \
for (_i=0; _i<sizeof(uint64); _i++, _n>>=8) { \
- *_p++ = (uint8)(_n & 0xff); \
+ *_p++ = _n & 0xff; \
} \
for (/*void*/; _i<8; _i++) { \
*_p++ = 0; \
@@ -150,7 +150,7 @@
# define INT64DECODE(p, n) { \
/* WE DON'T CHECK FOR OVERFLOW! */ \
- size_t _i; \
+ intn _i; \
n = 0; \
(p) += 8; \
for (_i=0; _i<sizeof(int64); _i++, n<<=8) { \
@@ -161,7 +161,7 @@
# define UINT64DECODE(p, n) { \
/* WE DON'T CHECK FOR OVERFLOW! */ \
- size_t _i; \
+ intn _i; \
n = 0; \
(p) += 8; \
for (_i=0; _i<sizeof(uint64); _i++, n<<=8) { \
@@ -327,7 +327,11 @@ typedef struct H5F_low_t {
/* What types of low-level files are there? */
#ifndef H5F_LOW_DFLT
+# ifdef HAVE_PARALLEL
+# define H5F_LOW_DFLT H5F_LOW_MPIO /* when parallel, MPI-IO is default */
+# else
# define H5F_LOW_DFLT H5F_LOW_STDIO /* The default type */
+# endif
#endif
extern const H5F_low_class_t H5F_LOW_SEC2[]; /* Posix section 2 */
extern const H5F_low_class_t H5F_LOW_STDIO[]; /* Posix stdio */
@@ -399,12 +403,18 @@ typedef struct H5F_t {
break; \
}
+#ifdef NOT_YET
+#define H5F_encode_length(f,p,l) (H5F_SIZEOF_SIZE(f)==4 ? UINT32ENCODE(p,l) \
+ : H5F_SIZEOF_SIZE(f)==8 ? UINT64ENCODE(p,l) \
+ : H5F_SIZEOF_SIZE(f)==2 ? UINT16ENCODE(p,l) : H5FPencode_unusual_length(f,&(p),(uint8 *)&(l)))
+#else
#define H5F_encode_length(f,p,l) \
switch(H5F_SIZEOF_SIZE(f)) { \
case 4: UINT32ENCODE(p,l); break; \
case 8: UINT64ENCODE(p,l); break; \
case 2: UINT16ENCODE(p,l); break; \
}
+#endif
#define H5F_decode_length(f,p,l) \
switch(H5F_SIZEOF_SIZE(f)) { \