00001
00002
00003
00004
00005
00006
00007
00008 #include "mpioimpl.h"
00009
00010 #ifdef HAVE_WEAK_SYMBOLS
00011
00012 #if defined(HAVE_PRAGMA_WEAK)
00013 #pragma weak MPI_File_open = PMPI_File_open
00014 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
00015 #pragma _HP_SECONDARY_DEF PMPI_File_open MPI_File_open
00016 #elif defined(HAVE_PRAGMA_CRI_DUP)
00017 #pragma _CRI duplicate MPI_File_open as PMPI_File_open
00018
00019 #endif
00020
00021
00022 #define MPIO_BUILD_PROFILING
00023 #include "mpioprof.h"
00024 #endif
00025
00026
00027 #include "adio_extern.h"
00028
00029
00030 CtvExtern(int, ADIO_Init_keyval);
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 int MPI_File_open(MPI_Comm comm, char *filename, int amode,
00047 MPI_Info info, MPI_File *fh)
00048 {
00049 int error_code, file_system, flag, tmp_amode=0, rank;
00050 char *tmp;
00051 MPI_Comm dupcomm;
00052 ADIOI_Fns *fsops;
00053 static char myname[] = "MPI_FILE_OPEN";
00054 #ifdef MPI_hpux
00055 int fl_xmpi;
00056
00057 HPMP_IO_OPEN_START(fl_xmpi, comm);
00058 #endif
00059
00060 MPIU_THREAD_CS_ENTER(ALLFUNC,);
00061
00062
00063 if (comm == MPI_COMM_NULL)
00064 {
00065 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00066 myname, __LINE__, MPI_ERR_COMM,
00067 "**comm", 0);
00068 goto fn_fail;
00069 }
00070
00071
00072 MPI_Comm_test_inter(comm, &flag);
00073
00074 if (flag)
00075 {
00076 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00077 myname, __LINE__, MPI_ERR_COMM,
00078 "**commnotintra", 0);
00079 goto fn_fail;
00080 }
00081
00082 if ( ((amode&MPI_MODE_RDONLY)?1:0) + ((amode&MPI_MODE_RDWR)?1:0) +
00083 ((amode&MPI_MODE_WRONLY)?1:0) != 1 )
00084 {
00085 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00086 myname, __LINE__, MPI_ERR_AMODE,
00087 "**fileamodeone", 0);
00088 goto fn_fail;
00089 }
00090
00091 if ((amode & MPI_MODE_RDONLY) &&
00092 ((amode & MPI_MODE_CREATE) || (amode & MPI_MODE_EXCL)))
00093 {
00094 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00095 myname, __LINE__, MPI_ERR_AMODE,
00096 "**fileamoderead", 0);
00097 goto fn_fail;
00098 }
00099
00100 if ((amode & MPI_MODE_RDWR) && (amode & MPI_MODE_SEQUENTIAL))
00101 {
00102 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00103 myname, __LINE__, MPI_ERR_AMODE,
00104 "**fileamodeseq", 0);
00105 goto fn_fail;
00106 }
00107
00108 MPI_Comm_dup(comm, &dupcomm);
00109
00110
00111 MPIR_MPIOInit(&error_code);
00112 if (error_code != MPI_SUCCESS) goto fn_fail;
00113
00114
00115 MPI_Allreduce(&amode, &tmp_amode, 1, MPI_INT, CtvAccess(ADIO_same_amode), dupcomm);
00116
00117 if (tmp_amode == ADIO_AMODE_NOMATCH) {
00118 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00119 myname, __LINE__, MPI_ERR_AMODE,
00120 "**fileamodediff", 0);
00121 goto fn_fail;
00122 }
00123
00124
00125 file_system = -1;
00126
00127
00128 ADIO_ResolveFileType(dupcomm, filename, &file_system, &fsops, &error_code);
00129
00130 if (error_code != MPI_SUCCESS)
00131 {
00132
00133
00134
00135
00136 goto fn_fail;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145 tmp = strchr(filename, ':');
00146 if (tmp > filename + 1) {
00147 filename = tmp + 1;
00148 }
00149
00150
00151
00152 *fh = ADIO_Open(comm, dupcomm, filename, file_system, fsops, amode, 0,
00153 MPI_BYTE, MPI_BYTE, info, ADIO_PERM_NULL, &error_code);
00154
00155
00156 if (error_code != MPI_SUCCESS) {
00157 MPI_Comm_free(&dupcomm);
00158 goto fn_fail;
00159 }
00160
00161
00162
00163
00164
00165 if ( !ADIO_Feature((*fh), ADIO_SHARED_FP) && (amode & MPI_MODE_SEQUENTIAL))
00166 {
00167 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00168 myname, __LINE__,
00169 MPI_ERR_UNSUPPORTED_OPERATION,
00170 "**iosequnsupported", 0);
00171 ADIO_Close(*fh, &error_code);
00172 goto fn_fail;
00173 }
00174
00175
00176
00177
00178 if ((error_code == MPI_SUCCESS) &&
00179 ADIO_Feature((*fh), ADIO_SHARED_FP)) {
00180 MPI_Comm_rank(dupcomm, &rank);
00181 ADIOI_Shfp_fname(*fh, rank);
00182
00183
00184
00185
00186 if ((*fh)->access_mode & MPI_MODE_APPEND) {
00187 if (rank == (*fh)->hints->ranklist[0])
00188 ADIO_Set_shared_fp(*fh, (*fh)->fp_ind, &error_code);
00189 MPI_Barrier(dupcomm);
00190 }
00191 }
00192
00193 #ifdef MPI_hpux
00194 HPMP_IO_OPEN_END(fl_xmpi, *fh, comm);
00195 #endif
00196
00197 fn_exit:
00198 MPIU_THREAD_CS_EXIT(ALLFUNC,);
00199 return error_code;
00200 fn_fail:
00201
00202 error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code);
00203 goto fn_exit;
00204
00205 }