00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009
00010 #ifdef HAVE_UNISTD_H
00011 #include <unistd.h>
00012 #endif
00013 #ifdef AGGREGATION_PROFILE
00014 #include "mpe.h"
00015 #endif
00016
00017 void ADIOI_GEN_ReadContig(ADIO_File fd, void *buf, int count,
00018 MPI_Datatype datatype, int file_ptr_type,
00019 ADIO_Offset offset, ADIO_Status *status,
00020 int *error_code)
00021 {
00022 int err = -1, datatype_size;
00023 ADIO_Offset len;
00024 static char myname[] = "ADIOI_GEN_READCONTIG";
00025
00026 #ifdef AGGREGATION_PROFILE
00027 MPE_Log_event (5034, 0, NULL);
00028 #endif
00029 MPI_Type_size(datatype, &datatype_size);
00030 len = (ADIO_Offset)datatype_size * (ADIO_Offset)count;
00031 ADIOI_Assert(len == (unsigned int) len);
00032
00033 if (file_ptr_type == ADIO_INDIVIDUAL) {
00034 offset = fd->fp_ind;
00035 }
00036
00037 if (fd->fp_sys_posn != offset) {
00038 #ifdef ADIOI_MPE_LOGGING
00039 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
00040 #endif
00041 err = lseek(fd->fd_sys, offset, SEEK_SET);
00042 #ifdef ADIOI_MPE_LOGGING
00043 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
00044 #endif
00045
00046 if (err == -1) {
00047 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00048 MPIR_ERR_RECOVERABLE,
00049 myname, __LINE__,
00050 MPI_ERR_IO, "**io",
00051 "**io %s", strerror(errno));
00052 fd->fp_sys_posn = -1;
00053 return;
00054 }
00055
00056 }
00057
00058 #ifdef ADIOI_MPE_LOGGING
00059 MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
00060 #endif
00061 err = read(fd->fd_sys, buf, (unsigned int)len);
00062 #ifdef ADIOI_MPE_LOGGING
00063 MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
00064 #endif
00065
00066 if (err == -1) {
00067 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00068 MPIR_ERR_RECOVERABLE,
00069 myname, __LINE__,
00070 MPI_ERR_IO, "**io",
00071 "**io %s", strerror(errno));
00072 fd->fp_sys_posn = -1;
00073 return;
00074 }
00075
00076
00077 fd->fp_sys_posn = offset + err;
00078
00079 if (file_ptr_type == ADIO_INDIVIDUAL) {
00080 fd->fp_ind += err;
00081 }
00082
00083 #ifdef HAVE_STATUS_SET_BYTES
00084 if (err != -1) MPIR_Status_set_bytes(status, datatype, err);
00085 #endif
00086
00087 *error_code = MPI_SUCCESS;
00088 #ifdef AGGREGATION_PROFILE
00089 MPE_Log_event (5035, 0, NULL);
00090 #endif
00091 }