romio314: update NFS read/write routines for large xfers
When we updated UFS and others we left NFS alone. HDF group would like a fix, so here we go. Signed-off-by: Ken Raffenetti <raffenet@mcs.anl.gov> (back-ported from upstream commit pmodels/mpich@684df9f4c9) Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>
Этот коммит содержится в:
родитель
7185567d50
Коммит
02af10ce6e
@ -7,79 +7,68 @@
|
||||
|
||||
#include "ad_nfs.h"
|
||||
#include "adio_extern.h"
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void ADIOI_NFS_ReadContig(ADIO_File fd, void *buf, int count,
|
||||
MPI_Datatype datatype, int file_ptr_type,
|
||||
ADIO_Offset offset, ADIO_Status *status, int *error_code)
|
||||
{
|
||||
int err=-1;
|
||||
ssize_t err=-1;
|
||||
MPI_Count datatype_size, len;
|
||||
ADIO_Offset bytes_xfered=0;
|
||||
size_t rd_count;
|
||||
static char myname[] = "ADIOI_NFS_READCONTIG";
|
||||
char *p;
|
||||
|
||||
MPI_Type_size_x(datatype, &datatype_size);
|
||||
len = datatype_size * count;
|
||||
|
||||
if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
|
||||
if (fd->fp_sys_posn != offset) {
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
|
||||
#endif
|
||||
lseek(fd->fd_sys, offset, SEEK_SET);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
|
||||
#endif
|
||||
}
|
||||
if (fd->atomicity)
|
||||
ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
|
||||
else ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
|
||||
#endif
|
||||
err = read(fd->fd_sys, buf, len);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
|
||||
#endif
|
||||
ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
|
||||
fd->fp_sys_posn = offset + err;
|
||||
/* individual file pointer not updated */
|
||||
}
|
||||
else { /* read from curr. location of ind. file pointer */
|
||||
if (file_ptr_type == ADIO_INDIVIDUAL) {
|
||||
offset = fd->fp_ind;
|
||||
if (fd->fp_sys_posn != fd->fp_ind) {
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
|
||||
#endif
|
||||
lseek(fd->fd_sys, fd->fp_ind, SEEK_SET);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
|
||||
#endif
|
||||
}
|
||||
if (fd->atomicity)
|
||||
ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
|
||||
else ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
|
||||
#endif
|
||||
err = read(fd->fd_sys, buf, len);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
|
||||
#endif
|
||||
ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
|
||||
fd->fp_ind += err;
|
||||
fd->fp_sys_posn = fd->fp_ind;
|
||||
}
|
||||
|
||||
/* --BEGIN ERROR HANDLING-- */
|
||||
if (err == -1) {
|
||||
*error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
|
||||
myname, __LINE__, MPI_ERR_IO,
|
||||
"**io", "**io %s", strerror(errno));
|
||||
return;
|
||||
p = buf;
|
||||
while (bytes_xfered < len ) {
|
||||
rd_count = len - bytes_xfered;
|
||||
/* FreeBSD and Darwin workaround: bigger than INT_MAX is an error */
|
||||
if (rd_count > INT_MAX)
|
||||
rd_count = INT_MAX;
|
||||
if (fd->atomicity)
|
||||
ADIOI_WRITE_LOCK(fd, offset+bytes_xfered, SEEK_SET, rd_count);
|
||||
else ADIOI_READ_LOCK(fd, offset+bytes_xfered, SEEK_SET, rd_count);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
|
||||
#endif
|
||||
err = pread(fd->fd_sys, p, rd_count, offset+bytes_xfered);
|
||||
/* --BEGIN ERROR HANDLING-- */
|
||||
if (err == -1) {
|
||||
*error_code = MPIO_Err_create_code(MPI_SUCCESS,
|
||||
MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO,
|
||||
"**io", "**io %s", strerror(errno));
|
||||
}
|
||||
/* --END ERROR HANDLING-- */
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
|
||||
#endif
|
||||
ADIOI_UNLOCK(fd, offset+bytes_xfered, SEEK_SET, rd_count);
|
||||
if (err == 0) {
|
||||
/* end of file */
|
||||
break;
|
||||
}
|
||||
bytes_xfered += err;
|
||||
p += err;
|
||||
}
|
||||
|
||||
fd->fp_sys_posn = offset + bytes_xfered;
|
||||
if (file_ptr_type == ADIO_INDIVIDUAL) {
|
||||
fd->fp_ind += bytes_xfered;
|
||||
}
|
||||
/* --END ERROR HANDLING-- */
|
||||
|
||||
#ifdef HAVE_STATUS_SET_BYTES
|
||||
MPIR_Status_set_bytes(status, datatype, err);
|
||||
if (err != -1) MPIR_Status_set_bytes(status, datatype, bytes_xfered);
|
||||
#endif
|
||||
|
||||
*error_code = MPI_SUCCESS;
|
||||
|
@ -7,76 +7,64 @@
|
||||
|
||||
#include "ad_nfs.h"
|
||||
#include "adio_extern.h"
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void ADIOI_NFS_WriteContig(ADIO_File fd, const void *buf, int count,
|
||||
MPI_Datatype datatype, int file_ptr_type,
|
||||
ADIO_Offset offset, ADIO_Status *status, int *error_code)
|
||||
{
|
||||
int err=-1;
|
||||
ssize_t err=-1;
|
||||
MPI_Count datatype_size, len;
|
||||
ADIO_Offset bytes_xfered=0;
|
||||
size_t wr_count;
|
||||
static char myname[] = "ADIOI_NFS_WRITECONTIG";
|
||||
char *p;
|
||||
|
||||
MPI_Type_size_x(datatype, &datatype_size);
|
||||
len = datatype_size * count;
|
||||
len = datatype_size * (ADIO_Offset)count;
|
||||
|
||||
if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
|
||||
if (fd->fp_sys_posn != offset) {
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
|
||||
#endif
|
||||
lseek(fd->fd_sys, offset, SEEK_SET);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
|
||||
#endif
|
||||
}
|
||||
ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
|
||||
#endif
|
||||
err = write(fd->fd_sys, buf, len);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
|
||||
#endif
|
||||
ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
|
||||
fd->fp_sys_posn = offset + err;
|
||||
/* individual file pointer not updated */
|
||||
}
|
||||
else { /* write from curr. location of ind. file pointer */
|
||||
if (file_ptr_type == ADIO_INDIVIDUAL) {
|
||||
offset = fd->fp_ind;
|
||||
if (fd->fp_sys_posn != fd->fp_ind) {
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
|
||||
#endif
|
||||
lseek(fd->fd_sys, fd->fp_ind, SEEK_SET);
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
|
||||
#endif
|
||||
}
|
||||
ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
|
||||
}
|
||||
|
||||
p = (char *)buf;
|
||||
while (bytes_xfered < len) {
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
|
||||
#endif
|
||||
err = write(fd->fd_sys, buf, len);
|
||||
wr_count = len - bytes_xfered;
|
||||
/* work around FreeBSD and OS X defects*/
|
||||
if (wr_count > INT_MAX)
|
||||
wr_count = INT_MAX;
|
||||
|
||||
ADIOI_WRITE_LOCK(fd, offset+bytes_xfered, SEEK_SET, wr_count);
|
||||
err = pwrite(fd->fd_sys, p, wr_count, offset+bytes_xfered);
|
||||
/* --BEGIN ERROR HANDLING-- */
|
||||
if (err == -1) {
|
||||
*error_code = MPIO_Err_create_code(MPI_SUCCESS,
|
||||
MPIR_ERR_RECOVERABLE,
|
||||
myname, __LINE__, MPI_ERR_IO, "**io",
|
||||
"**io %s", strerror(errno));
|
||||
fd->fp_sys_posn = -1;
|
||||
return;
|
||||
}
|
||||
/* --END ERROR HANDLING-- */
|
||||
#ifdef ADIOI_MPE_LOGGING
|
||||
MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
|
||||
#endif
|
||||
ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
|
||||
fd->fp_ind += err;
|
||||
fd->fp_sys_posn = fd->fp_ind;
|
||||
ADIOI_UNLOCK(fd, offset+bytes_xfered, SEEK_SET, wr_count);
|
||||
bytes_xfered += err;
|
||||
p += err;
|
||||
}
|
||||
|
||||
/* --BEGIN ERROR HANDLING-- */
|
||||
if (err == -1) {
|
||||
*error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
|
||||
myname, __LINE__, MPI_ERR_IO,
|
||||
"**io",
|
||||
"**io %s", strerror(errno));
|
||||
return;
|
||||
if (file_ptr_type == ADIO_INDIVIDUAL) {
|
||||
fd->fp_ind += bytes_xfered;
|
||||
}
|
||||
/* --END ERROR HANDLING-- */
|
||||
|
||||
#ifdef HAVE_STATUS_SET_BYTES
|
||||
MPIR_Status_set_bytes(status, datatype, err);
|
||||
MPIR_Status_set_bytes(status, datatype, bytes_xfered);
|
||||
#endif
|
||||
|
||||
*error_code = MPI_SUCCESS;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user