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