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 = PMPI_File_write
00015 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
00016 #pragma _HP_SECONDARY_DEF PMPI_File_write MPI_File_write
00017 #elif defined(HAVE_PRAGMA_CRI_DUP)
00018 #pragma _CRI duplicate MPI_File_write as PMPI_File_write
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(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_WRITE";
00049 #endif
00050 int datatype_size;
00051 ADIO_Offset off;
00052 #ifdef MPI_hpux
00053 int fl_xmpi;
00054
00055 HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITE, TRDTBLOCK, fh, datatype, count);
00056 #endif
00057
00058 #ifdef PRINT_ERR_MSG
00059 if ((fh <= (MPI_File) 0) || (fh->cookie != ADIOI_FILE_COOKIE)) {
00060 FPRINTF(stderr, "MPI_File_write: Invalid file handle\n");
00061 MPI_Abort(MPI_COMM_WORLD, 1);
00062 }
00063 #else
00064 ADIOI_TEST_FILE_HANDLE(fh, myname);
00065 #endif
00066
00067 if (count < 0) {
00068 #ifdef PRINT_ERR_MSG
00069 FPRINTF(stderr, "MPI_File_write: Invalid count argument\n");
00070 MPI_Abort(MPI_COMM_WORLD, 1);
00071 #else
00072 error_code = MPIR_Err_setmsg(MPI_ERR_ARG, MPIR_ERR_COUNT_ARG,
00073 myname, (char *) 0, (char *) 0);
00074 return ADIOI_Error(fh, error_code, myname);
00075 #endif
00076 }
00077
00078 if (datatype == MPI_DATATYPE_NULL) {
00079 #ifdef PRINT_ERR_MSG
00080 FPRINTF(stderr, "MPI_File_write: Invalid datatype\n");
00081 MPI_Abort(MPI_COMM_WORLD, 1);
00082 #else
00083 error_code = MPIR_Err_setmsg(MPI_ERR_TYPE, MPIR_ERR_TYPE_NULL,
00084 myname, (char *) 0, (char *) 0);
00085 return ADIOI_Error(fh, error_code, myname);
00086 #endif
00087 }
00088
00089 MPI_Type_size(datatype, &datatype_size);
00090 if (count*datatype_size == 0) {
00091 #ifdef MPI_hpux
00092 HPMP_IO_END(fl_xmpi, fh, datatype, count);
00093 #endif
00094 return MPI_SUCCESS;
00095 }
00096
00097 if ((count*datatype_size) % fh->etype_size != 0) {
00098 #ifdef PRINT_ERR_MSG
00099 FPRINTF(stderr, "MPI_File_write: Only an integral number of etypes can be accessed\n");
00100 MPI_Abort(MPI_COMM_WORLD, 1);
00101 #else
00102 error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_ETYPE_FRACTIONAL,
00103 myname, (char *) 0, (char *) 0);
00104 return ADIOI_Error(fh, error_code, myname);
00105 #endif
00106 }
00107
00108 if (fh->access_mode & MPI_MODE_SEQUENTIAL) {
00109 #ifdef PRINT_ERR_MSG
00110 FPRINTF(stderr, "MPI_File_write: Can't use this function because file was opened with MPI_MODE_SEQUENTIAL\n");
00111 MPI_Abort(MPI_COMM_WORLD, 1);
00112 #else
00113 error_code = MPIR_Err_setmsg(MPI_ERR_UNSUPPORTED_OPERATION,
00114 MPIR_ERR_AMODE_SEQ, myname, (char *) 0, (char *) 0);
00115 return ADIOI_Error(fh, error_code, myname);
00116 #endif
00117 }
00118
00119 ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
00120 ADIOI_Datatype_iscontig(fh->filetype, &filetype_is_contig);
00121
00122
00123
00124 if (buftype_is_contig && filetype_is_contig) {
00125 bufsize = datatype_size * count;
00126
00127
00128
00129 off = fh->fp_ind;
00130 if ((fh->atomicity) && (fh->file_system != ADIO_PIOFS) &&
00131 (fh->file_system != ADIO_PVFS) && (fh->file_system != ADIO_NFS))
00132 ADIOI_WRITE_LOCK(fh, off, SEEK_SET, bufsize);
00133
00134 ADIO_WriteContig(fh, buf, count, datatype, ADIO_INDIVIDUAL,
00135 0, status, &error_code);
00136
00137 if ((fh->atomicity) && (fh->file_system != ADIO_PIOFS) &&
00138 (fh->file_system != ADIO_PVFS) && (fh->file_system != ADIO_NFS))
00139 ADIOI_UNLOCK(fh, off, SEEK_SET, bufsize);
00140 }
00141 else
00142 ADIO_WriteStrided(fh, buf, count, datatype, ADIO_INDIVIDUAL,
00143 0, status, &error_code);
00144
00145
00146 #ifdef MPI_hpux
00147 HPMP_IO_END(fl_xmpi, fh, datatype, count);
00148 #endif
00149 return error_code;
00150 }