00001
00002
00003
00004
00005
00006
00007 #include "mpioimpl.h"
00008
00009 #ifdef HAVE_WEAK_SYMBOLS
00010
00011 #if defined(HAVE_PRAGMA_WEAK)
00012 #pragma weak MPI_File_write = PMPI_File_write
00013 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
00014 #pragma _HP_SECONDARY_DEF PMPI_File_write MPI_File_write
00015 #elif defined(HAVE_PRAGMA_CRI_DUP)
00016 #pragma _CRI duplicate MPI_File_write as PMPI_File_write
00017
00018 #endif
00019
00020
00021 #define MPIO_BUILD_PROFILING
00022 #include "mpioprof.h"
00023 #endif
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 int MPI_File_write(MPI_File mpi_fh, void *buf, int count,
00042 MPI_Datatype datatype, MPI_Status *status)
00043 {
00044 int error_code;
00045 static char myname[] = "MPI_FILE_WRITE";
00046 #ifdef MPI_hpux
00047 int fl_xmpi;
00048
00049 HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITE, TRDTBLOCK, fh, datatype, count);
00050 #endif
00051
00052 error_code = MPIOI_File_write(mpi_fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf,
00053 count, datatype, myname, status);
00054
00055 #ifdef MPI_hpux
00056 HPMP_IO_END(fl_xmpi, fh, datatype, count);
00057 #endif
00058
00059 return error_code;
00060 }
00061
00062
00063
00064 int MPIOI_File_write(MPI_File mpi_fh,
00065 MPI_Offset offset,
00066 int file_ptr_type,
00067 void *buf,
00068 int count,
00069 MPI_Datatype datatype,
00070 char *myname,
00071 MPI_Status *status)
00072 {
00073 int error_code, bufsize, buftype_is_contig, filetype_is_contig;
00074 int datatype_size;
00075 ADIO_Offset off;
00076 ADIO_File fh;
00077
00078 MPIU_THREAD_CS_ENTER(ALLFUNC,);
00079
00080 fh = MPIO_File_resolve(mpi_fh);
00081
00082
00083 MPIO_CHECK_FILE_HANDLE(fh, myname, error_code);
00084 MPIO_CHECK_COUNT(fh, count, myname, error_code);
00085 MPIO_CHECK_DATATYPE(fh, datatype, myname, error_code);
00086
00087 if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0)
00088 {
00089 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00090 myname, __LINE__, MPI_ERR_ARG,
00091 "**iobadoffset", 0);
00092 error_code = MPIO_Err_return_file(fh, error_code);
00093 goto fn_exit;
00094 }
00095
00096
00097 MPI_Type_size(datatype, &datatype_size);
00098
00099
00100 MPIO_CHECK_COUNT_SIZE(fh, count, datatype_size, myname, error_code);
00101
00102
00103 if (count*datatype_size == 0)
00104 {
00105 #ifdef HAVE_STATUS_SET_BYTES
00106 MPIR_Status_set_bytes(status, datatype, 0);
00107 #endif
00108 error_code = MPI_SUCCESS;
00109 goto fn_exit;
00110 }
00111
00112
00113 MPIO_CHECK_INTEGRAL_ETYPE(fh, count, datatype_size, myname, error_code);
00114 MPIO_CHECK_WRITABLE(fh, myname, error_code);
00115 MPIO_CHECK_NOT_SEQUENTIAL_MODE(fh, myname, error_code);
00116
00117
00118 ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
00119 ADIOI_Datatype_iscontig(fh->filetype, &filetype_is_contig);
00120
00121 ADIOI_TEST_DEFERRED(fh, myname, &error_code);
00122
00123 if (buftype_is_contig && filetype_is_contig)
00124 {
00125
00126 bufsize = datatype_size * count;
00127 if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
00128 off = fh->disp + fh->etype_size * offset;
00129 }
00130 else {
00131 off = fh->fp_ind;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 if ((fh->atomicity) && ADIO_Feature(fh, ADIO_LOCKS))
00141 {
00142 ADIOI_WRITE_LOCK(fh, off, SEEK_SET, bufsize);
00143 }
00144
00145 ADIO_WriteContig(fh, buf, count, datatype, file_ptr_type,
00146 off, status, &error_code);
00147
00148 if ((fh->atomicity) && ADIO_Feature(fh, ADIO_LOCKS))
00149 {
00150 ADIOI_UNLOCK(fh, off, SEEK_SET, bufsize);
00151 }
00152 }
00153 else
00154 {
00155
00156 ADIO_WriteStrided(fh, buf, count, datatype, file_ptr_type,
00157 offset, status, &error_code);
00158 }
00159
00160
00161 if (error_code != MPI_SUCCESS)
00162 error_code = MPIO_Err_return_file(fh, error_code);
00163
00164
00165 fn_exit:
00166 MPIU_THREAD_CS_EXIT(ALLFUNC,);
00167
00168 return error_code;
00169 }
00170