00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "mpioimpl.h"
00010
00011 #ifdef HAVE_WEAK_SYMBOLS
00012
00013 #if defined(HAVE_PRAGMA_WEAK)
00014 #pragma weak MPI_File_read = PMPI_File_read
00015 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
00016 #pragma _HP_SECONDARY_DEF PMPI_File_read MPI_File_read
00017 #elif defined(HAVE_PRAGMA_CRI_DUP)
00018 #pragma _CRI duplicate MPI_File_read as PMPI_File_read
00019
00020 #endif
00021
00022
00023 #define MPIO_BUILD_PROFILING
00024 #include "mpioprof.h"
00025 #endif
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 int MPI_File_read(MPI_File fh, void *buf, int count,
00045 MPI_Datatype datatype, MPI_Status *status)
00046 {
00047 int error_code, bufsize, buftype_is_contig, filetype_is_contig;
00048 #ifndef PRINT_ERR_MSG
00049 static char myname[] = "MPI_FILE_READ";
00050 #endif
00051 int datatype_size;
00052 ADIO_Offset off;
00053 #ifdef MPI_hpux
00054 int fl_xmpi;
00055
00056 HPMP_IO_START(fl_xmpi, BLKMPIFILEREAD, TRDTBLOCK, fh, datatype, count);
00057 #endif
00058
00059 #ifdef PRINT_ERR_MSG
00060 if ((fh <= (MPI_File) 0) || (fh->cookie != ADIOI_FILE_COOKIE)) {
00061 FPRINTF(stderr, "MPI_File_read: Invalid file handle\n");
00062 MPI_Abort(MPI_COMM_WORLD, 1);
00063 }
00064 #else
00065 ADIOI_TEST_FILE_HANDLE(fh, myname);
00066 #endif
00067
00068 if (count < 0) {
00069 #ifdef PRINT_ERR_MSG
00070 FPRINTF(stderr, "MPI_File_read: Invalid count argument\n");
00071 MPI_Abort(MPI_COMM_WORLD, 1);
00072 #else
00073 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_COUNT_ARG,
00074 myname, (char *) 0, (char *) 0);
00075 return ADIOI_Error(fh, error_code, myname);
00076 #endif
00077 }
00078
00079 if (datatype == MPI_DATATYPE_NULL) {
00080 #ifdef PRINT_ERR_MSG
00081 FPRINTF(stderr, "MPI_File_read: Invalid datatype\n");
00082 MPI_Abort(MPI_COMM_WORLD, 1);
00083 #else
00084 error_code = MPIR_Err_setmsg(MPI_ERR_TYPE, MPIR_ERR_TYPE_NULL,
00085 myname, (char *) 0, (char *) 0);
00086 return ADIOI_Error(fh, error_code, myname);
00087 #endif
00088 }
00089
00090 MPI_Type_size(datatype, &datatype_size);
00091 if (count*datatype_size == 0) {
00092 #ifdef MPI_hpux
00093 HPMP_IO_END(fl_xmpi, fh, datatype, count);
00094 #endif
00095 return MPI_SUCCESS;
00096 }
00097
00098 if ((count*datatype_size) % fh->etype_size != 0) {
00099 #ifdef PRINT_ERR_MSG
00100 FPRINTF(stderr, "MPI_File_read: Only an integral number of etypes can be accessed\n");
00101 MPI_Abort(MPI_COMM_WORLD, 1);
00102 #else
00103 error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_ETYPE_FRACTIONAL,
00104 myname, (char *) 0, (char *) 0);
00105 return ADIOI_Error(fh, error_code, myname);
00106 #endif
00107 }
00108
00109 if (fh->access_mode & MPI_MODE_WRONLY) {
00110 #ifdef PRINT_ERR_MSG
00111 FPRINTF(stderr, "MPI_File_read: Can't read from a file opened with MPI_MODE_WRONLY\n");
00112 MPI_Abort(MPI_COMM_WORLD, 1);
00113 #else
00114 error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION,
00115 MPIR_ERR_MODE_WRONLY, myname, (char *) 0, (char *) 0);
00116 return ADIOI_Error(fh, error_code, myname);
00117 #endif
00118 }
00119
00120 if (fh->access_mode & MPI_MODE_SEQUENTIAL) {
00121 #ifdef PRINT_ERR_MSG
00122 FPRINTF(stderr, "MPI_File_read: Can't use this function because file was opened with MPI_MODE_SEQUENTIAL\n");
00123 MPI_Abort(MPI_COMM_WORLD, 1);
00124 #else
00125 error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION,
00126 MPIR_ERR_AMODE_SEQ, myname, (char *) 0, (char *) 0);
00127 return ADIOI_Error(fh, error_code, myname);
00128 #endif
00129 }
00130
00131 ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
00132 ADIOI_Datatype_iscontig(fh->filetype, &filetype_is_contig);
00133
00134
00135
00136 if (buftype_is_contig && filetype_is_contig) {
00137 bufsize = datatype_size * count;
00138
00139
00140
00141 off = fh->fp_ind;
00142 if ((fh->atomicity) && (fh->file_system != ADIO_PIOFS) &&
00143 (fh->file_system != ADIO_NFS) && (fh->file_system != ADIO_PVFS))
00144 ADIOI_WRITE_LOCK(fh, off, SEEK_SET, bufsize);
00145
00146 ADIO_ReadContig(fh, buf, count, datatype, ADIO_INDIVIDUAL, 0,
00147 status, &error_code);
00148
00149 if ((fh->atomicity) && (fh->file_system != ADIO_PIOFS) &&
00150 (fh->file_system != ADIO_NFS) && (fh->file_system != ADIO_PVFS))
00151 ADIOI_UNLOCK(fh, off, SEEK_SET, bufsize);
00152 }
00153 else ADIO_ReadStrided(fh, buf, count, datatype, ADIO_INDIVIDUAL,
00154 0, status, &error_code);
00155
00156
00157 #ifdef MPI_hpux
00158 HPMP_IO_END(fl_xmpi, fh, datatype, count);
00159 #endif
00160 return error_code;
00161 }