From 28aec9e333045fa109b912166767e8da434f74b9 Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Sat, 11 Nov 2017 13:44:44 -0600 Subject: [PATCH 1/2] use off_t as type long is 4bytes on 32bit machines, and include unistd.h to call lseek() to get file size --- libdispatch/dfile.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libdispatch/dfile.c b/libdispatch/dfile.c index 27112f9d4..99d08986e 100644 --- a/libdispatch/dfile.c +++ b/libdispatch/dfile.c @@ -20,6 +20,8 @@ Research/Unidata. See COPYRIGHT file for more info. #ifdef HAVE_SYS_STAT_H #include #endif +#include /* lseek() */ + #include "ncdispatch.h" #include "netcdf_mem.h" #include "ncwinpath.h" @@ -2092,17 +2094,17 @@ fprintf(stderr,"XXX: openmagic: memory=0x%llx size=%ld\n",meminfo->memory,meminf {status = errno; goto done;} /* Get its length */ { -#ifdef _MSC_VER int fd = fileno(file->fp); +#ifdef _MSC_VER __int64 len64 = _filelengthi64(fd); if(len64 < 0) {status = errno; goto done;} file->filelen = (long long)len64; #else - long size; - if((status = fseek(file->fp, 0L, SEEK_END)) < 0) + off_t size; + size = lseek(fd, 0, SEEK_END); + if(size == -1) {status = errno; goto done;} - size = ftell(file->fp); file->filelen = (long long)size; #endif rewind(file->fp); From e9d222c5d36a91e3b0089cf145270876b3831bca Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Sat, 11 Nov 2017 18:33:39 -0600 Subject: [PATCH 2/2] replace MPI_File_seek and MPI_File_read with MPI_File_read_at_all --- libdispatch/dfile.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/libdispatch/dfile.c b/libdispatch/dfile.c index 99d08986e..9e8b6831a 100644 --- a/libdispatch/dfile.c +++ b/libdispatch/dfile.c @@ -2063,7 +2063,6 @@ fprintf(stderr,"XXX: openmagic: memory=0x%llx size=%ld\n",meminfo->memory,meminf } #ifdef USE_PARALLEL if (file->use_parallel) { - MPI_Status mstatus; int retval; MPI_Offset size; MPI_Comm comm = MPI_COMM_WORLD; @@ -2137,12 +2136,8 @@ printmagic("XXX: readmagic",magic,file); if (file->use_parallel) { MPI_Status mstatus; int retval; - MPI_Offset offset; - offset = pos; - if((retval = MPI_File_seek(file->fh, offset, MPI_SEEK_SET)) != MPI_SUCCESS) - {status = NC_EPARINIT; goto done;} - if((retval = MPI_File_read(file->fh, magic, MAGIC_NUMBER_LEN, MPI_CHAR, - &mstatus)) != MPI_SUCCESS) + if((retval = MPI_File_read_at_all(file->fh, pos, magic, + MAGIC_NUMBER_LEN, MPI_CHAR, &mstatus)) != MPI_SUCCESS) {status = NC_EPARINIT; goto done;} goto done; } @@ -2172,7 +2167,6 @@ closemagic(struct MagicFile* file) if(file->inmemory) goto done; /* noop*/ #ifdef USE_PARALLEL if (file->use_parallel) { - MPI_Status mstatus; int retval; if((retval = MPI_File_close(&file->fh)) != MPI_SUCCESS) {status = NC_EPARINIT; goto done;}