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_shared = PMPI_File_seek_shared
00015 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
00016 #pragma _HP_SECONDARY_DEF PMPI_File_seek_shared MPI_File_seek_shared
00017 #elif defined(HAVE_PRAGMA_CRI_DUP)
00018 #pragma _CRI duplicate MPI_File_seek_shared as PMPI_File_seek_shared
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_shared(MPI_File fh, MPI_Offset offset, int whence)
00038 {
00039 int error_code=MPI_SUCCESS, tmp_whence, myrank;
00040 #ifndef PRINT_ERR_MSG
00041 static char myname[] = "MPI_FILE_SEEK_SHARED";
00042 #endif
00043 MPI_Offset curr_offset, eof_offset, tmp_offset;
00044
00045 #ifdef PRINT_ERR_MSG
00046 if ((fh <= (MPI_File) 0) || (fh->cookie != ADIOI_FILE_COOKIE)) {
00047 FPRINTF(stderr, "MPI_File_seek_shared: Invalid file handle\n");
00048 MPI_Abort(MPI_COMM_WORLD, 1);
00049 }
00050 #else
00051 ADIOI_TEST_FILE_HANDLE(fh, myname);
00052 #endif
00053
00054 if (fh->access_mode & MPI_MODE_SEQUENTIAL) {
00055 #ifdef PRINT_ERR_MSG
00056 FPRINTF(stderr, "MPI_File_seek_shared: Can't use this function because file was opened with MPI_MODE_SEQUENTIAL\n");
00057 MPI_Abort(MPI_COMM_WORLD, 1);
00058 #else
00059 error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION,
00060 MPIR_ERR_AMODE_SEQ, myname, (char *) 0, (char *) 0);
00061 return ADIOI_Error(fh, error_code, myname);
00062 #endif
00063 }
00064
00065 if ((fh->file_system == ADIO_PIOFS) || (fh->file_system == ADIO_PVFS)) {
00066 #ifdef PRINT_ERR_MSG
00067 FPRINTF(stderr, "MPI_File_seek_shared: Shared file pointer not supported on PIOFS and PVFS\n");
00068 MPI_Abort(MPI_COMM_WORLD, 1);
00069 #else
00070 error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION,
00071 MPIR_ERR_NO_SHARED_FP, myname, (char *) 0, (char *) 0);
00072 return ADIOI_Error(fh, error_code, myname);
00073 #endif
00074 }
00075
00076 tmp_offset = offset;
00077 MPI_Bcast(&tmp_offset, 1, ADIO_OFFSET, 0, fh->comm);
00078 if (tmp_offset != offset) {
00079 #ifdef PRINT_ERR_MSG
00080 FPRINTF(stderr, "MPI_File_seek_shared: offset must be the same on all processes\n");
00081 MPI_Abort(MPI_COMM_WORLD, 1);
00082 #else
00083 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_OFFSET_ARG_NOT_SAME,
00084 myname, (char *) 0, (char *) 0);
00085 return ADIOI_Error(fh, error_code, myname);
00086 #endif
00087 }
00088
00089 tmp_whence = whence;
00090 MPI_Bcast(&tmp_whence, 1, MPI_INT, 0, fh->comm);
00091 if (tmp_whence != whence) {
00092 #ifdef PRINT_ERR_MSG
00093 FPRINTF(stderr, "MPI_File_seek_shared: whence argument must be the same on all processes\n");
00094 MPI_Abort(MPI_COMM_WORLD, 1);
00095 #else
00096 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_WHENCE_ARG_NOT_SAME,
00097 myname, (char *) 0, (char *) 0);
00098 return ADIOI_Error(fh, error_code, myname);
00099 #endif
00100 }
00101
00102 MPI_Comm_rank(fh->comm, &myrank);
00103
00104 if (!myrank) {
00105 switch(whence) {
00106 case MPI_SEEK_SET:
00107 if (offset < 0) {
00108 #ifdef PRINT_ERR_MSG
00109 FPRINTF(stderr, "MPI_File_seek_shared: Invalid offset argument\n");
00110 MPI_Abort(MPI_COMM_WORLD, 1);
00111 #else
00112 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_OFFSET_ARG,
00113 myname, (char *) 0, (char *) 0);
00114 return ADIOI_Error(fh, error_code, myname);
00115 #endif
00116 }
00117 break;
00118 case MPI_SEEK_CUR:
00119
00120 ADIO_Get_shared_fp(fh, 0, &curr_offset, &error_code);
00121 if (error_code != MPI_SUCCESS) {
00122 FPRINTF(stderr, "MPI_File_seek_shared: Error! Could not access shared file pointer.\n");
00123 MPI_Abort(MPI_COMM_WORLD, 1);
00124 }
00125 offset += curr_offset;
00126 if (offset < 0) {
00127 #ifdef PRINT_ERR_MSG
00128 FPRINTF(stderr, "MPI_File_seek_shared: offset points to a negative location in the file\n");
00129 MPI_Abort(MPI_COMM_WORLD, 1);
00130 #else
00131 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_OFFSET_ARG_NEG,
00132 myname, (char *) 0, (char *) 0);
00133 return ADIOI_Error(fh, error_code, myname);
00134 #endif
00135 }
00136 break;
00137 case MPI_SEEK_END:
00138
00139 ADIOI_Get_eof_offset(fh, &eof_offset);
00140 offset += eof_offset;
00141 if (offset < 0) {
00142 #ifdef PRINT_ERR_MSG
00143 FPRINTF(stderr, "MPI_File_seek_shared: offset points to a negative location in the file\n");
00144 MPI_Abort(MPI_COMM_WORLD, 1);
00145 #else
00146 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_OFFSET_ARG_NEG,
00147 myname, (char *) 0, (char *) 0);
00148 return ADIOI_Error(fh, error_code, myname);
00149 #endif
00150 }
00151 break;
00152 default:
00153 #ifdef PRINT_ERR_MSG
00154 FPRINTF(stderr, "MPI_File_seek_shared: Invalid whence argument\n");
00155 MPI_Abort(MPI_COMM_WORLD, 1);
00156 #else
00157 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_WHENCE_ARG,
00158 myname, (char *) 0, (char *) 0);
00159 return ADIOI_Error(fh, error_code, myname);
00160 #endif
00161 }
00162
00163 ADIO_Set_shared_fp(fh, offset, &error_code);
00164 }
00165
00166 MPI_Barrier(fh->comm);
00167
00168 return error_code;
00169 }