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_WriteContig(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_WRITECONTIG";
00025
00026 #ifdef AGGREGATION_PROFILE
00027 MPE_Log_event (5036, 0, NULL);
00028 #endif
00029
00030 MPI_Type_size(datatype, &datatype_size);
00031 len = (ADIO_Offset)datatype_size * (ADIO_Offset)count;
00032 ADIOI_Assert(len == (unsigned int) len);
00033
00034 if (file_ptr_type == ADIO_INDIVIDUAL) {
00035 offset = fd->fp_ind;
00036 }
00037
00038 if (fd->fp_sys_posn != offset) {
00039 #ifdef ADIOI_MPE_LOGGING
00040 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
00041 #endif
00042 err = lseek(fd->fd_sys, offset, SEEK_SET);
00043 #ifdef ADIOI_MPE_LOGGING
00044 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
00045 #endif
00046
00047 if (err == -1) {
00048 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00049 MPIR_ERR_RECOVERABLE,
00050 myname, __LINE__,
00051 MPI_ERR_IO, "**io",
00052 "**io %s", strerror(errno));
00053 fd->fp_sys_posn = -1;
00054 return;
00055 }
00056
00057 }
00058
00059 #ifdef ADIOI_MPE_LOGGING
00060 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
00061 #endif
00062 err = write(fd->fd_sys, buf, (unsigned int)len);
00063 #ifdef ADIOI_MPE_LOGGING
00064 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
00065 #endif
00066
00067 if (err == -1) {
00068 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00069 MPIR_ERR_RECOVERABLE,
00070 myname, __LINE__,
00071 MPI_ERR_IO, "**io",
00072 "**io %s", strerror(errno));
00073 fd->fp_sys_posn = -1;
00074 return;
00075 }
00076
00077
00078 fd->fp_sys_posn = offset + err;
00079
00080 if (file_ptr_type == ADIO_INDIVIDUAL) {
00081 fd->fp_ind += err;
00082 }
00083
00084 #ifdef HAVE_STATUS_SET_BYTES
00085 if (err != -1 && status) MPIR_Status_set_bytes(status, datatype, err);
00086 #endif
00087
00088 *error_code = MPI_SUCCESS;
00089 #ifdef AGGREGATION_PROFILE
00090 MPE_Log_event (5037, 0, NULL);
00091 #endif
00092 }