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_write_shared = PMPI_File_write_shared
00015 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
00016 #pragma _HP_SECONDARY_DEF PMPI_File_write_shared MPI_File_write_shared
00017 #elif defined(HAVE_PRAGMA_CRI_DUP)
00018 #pragma _CRI duplicate MPI_File_write_shared as PMPI_File_write_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
00038
00039
00040
00041
00042
00043 int MPI_File_write_shared(MPI_File fh, void *buf, int count,
00044 MPI_Datatype datatype, MPI_Status *status)
00045 {
00046 int error_code, bufsize, buftype_is_contig, filetype_is_contig;
00047 #ifndef PRINT_ERR_MSG
00048 static char myname[] = "MPI_FILE_READ_SHARED";
00049 #endif
00050 int datatype_size, incr;
00051 ADIO_Offset off, shared_fp;
00052
00053 #ifdef PRINT_ERR_MSG
00054 if ((fh <= (MPI_File) 0) || (fh->cookie != ADIOI_FILE_COOKIE)) {
00055 FPRINTF(stderr, "MPI_File_write_shared: Invalid file handle\n");
00056 MPI_Abort(MPI_COMM_WORLD, 1);
00057 }
00058 #else
00059 ADIOI_TEST_FILE_HANDLE(fh, myname);
00060 #endif
00061
00062 if (count < 0) {
00063 #ifdef PRINT_ERR_MSG
00064 FPRINTF(stderr, "MPI_File_write_shared: Invalid count argument\n");
00065 MPI_Abort(MPI_COMM_WORLD, 1);
00066 #else
00067 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_COUNT_ARG,
00068 myname, (char *) 0, (char *) 0);
00069 return ADIOI_Error(fh, error_code, myname);
00070 #endif
00071 }
00072
00073 if (datatype == MPI_DATATYPE_NULL) {
00074 #ifdef PRINT_ERR_MSG
00075 FPRINTF(stderr, "MPI_File_write_shared: Invalid datatype\n");
00076 MPI_Abort(MPI_COMM_WORLD, 1);
00077 #else
00078 error_code = MPIR_Err_setmsg(MPI_ERR_TYPE, MPIR_ERR_TYPE_NULL,
00079 myname, (char *) 0, (char *) 0);
00080 return ADIOI_Error(fh, error_code, myname);
00081 #endif
00082 }
00083
00084 MPI_Type_size(datatype, &datatype_size);
00085 if (count*datatype_size == 0) return MPI_SUCCESS;
00086
00087 if ((count*datatype_size) % fh->etype_size != 0) {
00088 #ifdef PRINT_ERR_MSG
00089 FPRINTF(stderr, "MPI_File_write_shared: Only an integral number of etypes can be accessed\n");
00090 MPI_Abort(MPI_COMM_WORLD, 1);
00091 #else
00092 error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_ETYPE_FRACTIONAL,
00093 myname, (char *) 0, (char *) 0);
00094 return ADIOI_Error(fh, error_code, myname);
00095 #endif
00096 }
00097
00098 if ((fh->file_system == ADIO_PIOFS) || (fh->file_system == ADIO_PVFS)) {
00099 #ifdef PRINT_ERR_MSG
00100 FPRINTF(stderr, "MPI_File_write_shared: Shared file pointer not supported on PIOFS and PVFS\n");
00101 MPI_Abort(MPI_COMM_WORLD, 1);
00102 #else
00103 error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION,
00104 MPIR_ERR_NO_SHARED_FP, myname, (char *) 0, (char *) 0);
00105 return ADIOI_Error(fh, error_code, myname);
00106 #endif
00107 }
00108
00109 ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
00110 ADIOI_Datatype_iscontig(fh->filetype, &filetype_is_contig);
00111
00112 incr = (count*datatype_size)/fh->etype_size;
00113 ADIO_Get_shared_fp(fh, incr, &shared_fp, &error_code);
00114 if (error_code != MPI_SUCCESS) {
00115 FPRINTF(stderr, "MPI_File_write_shared: Error! Could not access shared file pointer.\n");
00116 MPI_Abort(MPI_COMM_WORLD, 1);
00117 }
00118
00119
00120 if (buftype_is_contig && filetype_is_contig) {
00121
00122 bufsize = datatype_size * count;
00123 off = fh->disp + fh->etype_size * shared_fp;
00124
00125
00126
00127
00128
00129 if ((fh->atomicity) && (fh->file_system != ADIO_NFS))
00130 ADIOI_WRITE_LOCK(fh, off, SEEK_SET, bufsize);
00131
00132 ADIO_WriteContig(fh, buf, count, datatype, ADIO_EXPLICIT_OFFSET,
00133 off, status, &error_code);
00134
00135 if ((fh->atomicity) && (fh->file_system != ADIO_NFS))
00136 ADIOI_UNLOCK(fh, off, SEEK_SET, bufsize);
00137 }
00138 else
00139 ADIO_WriteStrided(fh, buf, count, datatype, ADIO_EXPLICIT_OFFSET,
00140 shared_fp, status, &error_code);
00141
00142
00143 return error_code;
00144 }