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_seek = PMPI_File_seek
00015 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
00016 #pragma _HP_SECONDARY_DEF PMPI_File_seek MPI_File_seek
00017 #elif defined(HAVE_PRAGMA_CRI_DUP)
00018 #pragma _CRI duplicate MPI_File_seek as PMPI_File_seek
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 int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence)
00038 {
00039 int error_code;
00040 #ifndef PRINT_ERR_MSG
00041 static char myname[] = "MPI_FILE_SEEK";
00042 #endif
00043 MPI_Offset curr_offset, eof_offset;
00044 #ifdef MPI_hpux
00045 int fl_xmpi;
00046
00047 HPMP_IO_START(fl_xmpi, BLKMPIFILESEEK, TRDTBLOCK, fh, MPI_DATATYPE_NULL, -1);
00048 #endif
00049
00050 #ifdef PRINT_ERR_MSG
00051 if ((fh <= (MPI_File) 0) || (fh->cookie != ADIOI_FILE_COOKIE)) {
00052 FPRINTF(stderr, "MPI_File_seek: Invalid file handle\n");
00053 MPI_Abort(MPI_COMM_WORLD, 1);
00054 }
00055 #else
00056 ADIOI_TEST_FILE_HANDLE(fh, myname);
00057 #endif
00058
00059 if (fh->access_mode & MPI_MODE_SEQUENTIAL) {
00060 #ifdef PRINT_ERR_MSG
00061 FPRINTF(stderr, "MPI_File_seek: Can't use this function because file was opened with MPI_MODE_SEQUENTIAL\n");
00062 MPI_Abort(MPI_COMM_WORLD, 1);
00063 #else
00064 error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION,
00065 MPIR_ERR_AMODE_SEQ, myname, (char *) 0, (char *) 0);
00066 return ADIOI_Error(fh, error_code, myname);
00067 #endif
00068 }
00069
00070 switch(whence) {
00071 case MPI_SEEK_SET:
00072 if (offset < 0) {
00073 #ifdef PRINT_ERR_MSG
00074 FPRINTF(stderr, "MPI_File_seek: Invalid offset argument\n");
00075 MPI_Abort(MPI_COMM_WORLD, 1);
00076 #else
00077 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_OFFSET_ARG,
00078 myname, (char *) 0, (char *) 0);
00079 return ADIOI_Error(fh, error_code, myname);
00080 #endif
00081 }
00082 break;
00083 case MPI_SEEK_CUR:
00084
00085 ADIOI_Get_position(fh, &curr_offset);
00086 offset += curr_offset;
00087 if (offset < 0) {
00088 #ifdef PRINT_ERR_MSG
00089 FPRINTF(stderr, "MPI_File_seek: offset points to a negative location in the file\n");
00090 MPI_Abort(MPI_COMM_WORLD, 1);
00091 #else
00092 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_OFFSET_ARG_NEG,
00093 myname, (char *) 0, (char *) 0);
00094 return ADIOI_Error(fh, error_code, myname);
00095 #endif
00096 }
00097 break;
00098 case MPI_SEEK_END:
00099
00100 ADIOI_Get_eof_offset(fh, &eof_offset);
00101 offset += eof_offset;
00102 if (offset < 0) {
00103 #ifdef PRINT_ERR_MSG
00104 FPRINTF(stderr, "MPI_File_seek: offset points to a negative location in the file\n");
00105 MPI_Abort(MPI_COMM_WORLD, 1);
00106 #else
00107 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_OFFSET_ARG_NEG,
00108 myname, (char *) 0, (char *) 0);
00109 return ADIOI_Error(fh, error_code, myname);
00110 #endif
00111 }
00112 break;
00113 default:
00114 #ifdef PRINT_ERR_MSG
00115 FPRINTF(stderr, "MPI_File_seek: Invalid whence argument\n");
00116 MPI_Abort(MPI_COMM_WORLD, 1);
00117 #else
00118 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_WHENCE_ARG,
00119 myname, (char *) 0, (char *) 0);
00120 return ADIOI_Error(fh, error_code, myname);
00121 #endif
00122 }
00123
00124 ADIO_SeekIndividual(fh, offset, ADIO_SEEK_SET, &error_code);
00125
00126 #ifdef MPI_hpux
00127 HPMP_IO_END(fl_xmpi, fh, MPI_DATATYPE_NULL, -1);
00128 #endif
00129 return error_code;
00130 }