00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009 #include "adio_extern.h"
00010
00011 void ADIOI_GEN_WriteStrided_naive(ADIO_File fd, void *buf, int count,
00012 MPI_Datatype buftype, int file_ptr_type,
00013 ADIO_Offset offset, ADIO_Status *status, int
00014 *error_code)
00015 {
00016
00017
00018 ADIOI_Flatlist_node *flat_buf, *flat_file;
00019
00020 ADIO_Offset bwr_size, fwr_size=0, sum, size_in_filetype;
00021 int b_index;
00022 unsigned bufsize;
00023 int n_etypes_in_filetype;
00024 ADIO_Offset size, n_filetypes, etype_in_filetype;
00025 ADIO_Offset abs_off_in_filetype=0, req_len;
00026 int filetype_size, etype_size, buftype_size;
00027 MPI_Aint filetype_extent, buftype_extent;
00028 int buf_count, buftype_is_contig, filetype_is_contig;
00029 ADIO_Offset userbuf_off;
00030 ADIO_Offset off, req_off, disp, end_offset=0, start_off;
00031 ADIO_Status status1;
00032
00033 *error_code = MPI_SUCCESS;
00034
00035 ADIOI_Datatype_iscontig(buftype, &buftype_is_contig);
00036 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00037
00038 MPI_Type_size(fd->filetype, &filetype_size);
00039 if ( ! filetype_size ) {
00040 *error_code = MPI_SUCCESS;
00041 return;
00042 }
00043
00044 MPI_Type_extent(fd->filetype, &filetype_extent);
00045 MPI_Type_size(buftype, &buftype_size);
00046 MPI_Type_extent(buftype, &buftype_extent);
00047 etype_size = fd->etype_size;
00048
00049 ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)(unsigned)buftype_size * (ADIO_Offset)count));
00050 bufsize = buftype_size * count;
00051
00052
00053
00054 if (!buftype_is_contig && filetype_is_contig) {
00055 int b_count;
00056
00057
00058 ADIOI_Flatten_datatype(buftype);
00059 flat_buf = CtvAccess(ADIOI_Flatlist);
00060 while (flat_buf->type != buftype) flat_buf = flat_buf->next;
00061
00062 off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind :
00063 fd->disp + (ADIO_Offset)etype_size * offset;
00064
00065 start_off = off;
00066 end_offset = off + bufsize - 1;
00067
00068
00069 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
00070 {
00071 ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
00072 }
00073
00074
00075
00076
00077 for (b_count=0; b_count < count; b_count++) {
00078 for (b_index=0; b_index < flat_buf->count; b_index++) {
00079 userbuf_off = (ADIO_Offset)b_count*(ADIO_Offset)buftype_extent +
00080 flat_buf->indices[b_index];
00081 req_off = off;
00082 req_len = flat_buf->blocklens[b_index];
00083
00084 ADIOI_Assert(req_len == (int) req_len);
00085 ADIOI_Assert((((ADIO_Offset)(MPIR_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIR_Upint)((MPIR_Upint)buf + userbuf_off));
00086 ADIO_WriteContig(fd,
00087 (char *) buf + userbuf_off,
00088 (int)req_len,
00089 MPI_BYTE,
00090 ADIO_EXPLICIT_OFFSET,
00091 req_off,
00092 &status1,
00093 error_code);
00094 if (*error_code != MPI_SUCCESS) return;
00095
00096
00097 off += flat_buf->blocklens[b_index];
00098 }
00099 }
00100
00101 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
00102 {
00103 ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
00104 }
00105
00106 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
00107
00108 }
00109
00110 else {
00111 int f_index, st_index = 0;
00112 ADIO_Offset st_fwr_size, st_n_filetypes;
00113 int flag;
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 flat_file = CtvAccess(ADIOI_Flatlist);
00131 while (flat_file->type != fd->filetype) flat_file = flat_file->next;
00132 disp = fd->disp;
00133
00134 if (file_ptr_type == ADIO_INDIVIDUAL) {
00135 start_off = fd->fp_ind;
00136 n_filetypes = -1;
00137 flag = 0;
00138 while (!flag) {
00139 n_filetypes++;
00140 for (f_index=0; f_index < flat_file->count; f_index++) {
00141 if (disp + flat_file->indices[f_index] +
00142 n_filetypes*(ADIO_Offset)filetype_extent +
00143 flat_file->blocklens[f_index] >= start_off)
00144 {
00145
00146
00147 st_index = f_index;
00148 fwr_size = disp + flat_file->indices[f_index] +
00149 n_filetypes*(ADIO_Offset)filetype_extent +
00150 flat_file->blocklens[f_index] - start_off;
00151 flag = 1;
00152 break;
00153 }
00154 }
00155 }
00156 }
00157 else {
00158 n_etypes_in_filetype = filetype_size/etype_size;
00159 n_filetypes = offset / n_etypes_in_filetype;
00160 etype_in_filetype = offset % n_etypes_in_filetype;
00161 size_in_filetype = etype_in_filetype * etype_size;
00162
00163 sum = 0;
00164 for (f_index=0; f_index < flat_file->count; f_index++) {
00165 sum += flat_file->blocklens[f_index];
00166 if (sum > size_in_filetype) {
00167 st_index = f_index;
00168 fwr_size = sum - size_in_filetype;
00169 abs_off_in_filetype = flat_file->indices[f_index] +
00170 size_in_filetype -
00171 (sum - flat_file->blocklens[f_index]);
00172 break;
00173 }
00174 }
00175
00176
00177 start_off = disp + n_filetypes*(ADIO_Offset)filetype_extent +
00178 abs_off_in_filetype;
00179 }
00180
00181 st_fwr_size = fwr_size;
00182 st_n_filetypes = n_filetypes;
00183
00184
00185
00186
00187
00188
00189
00190
00191 userbuf_off = 0;
00192 f_index = st_index;
00193 off = start_off;
00194 fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
00195 while (userbuf_off < bufsize) {
00196 userbuf_off += fwr_size;
00197 end_offset = off + fwr_size - 1;
00198
00199 if (f_index < (flat_file->count - 1)) f_index++;
00200 else {
00201 f_index = 0;
00202 n_filetypes++;
00203 }
00204
00205 off = disp + flat_file->indices[f_index] +
00206 n_filetypes*(ADIO_Offset)filetype_extent;
00207 fwr_size = ADIOI_MIN(flat_file->blocklens[f_index],
00208 bufsize-(unsigned)userbuf_off);
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
00222 {
00223 ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
00224 }
00225
00226 if (buftype_is_contig && !filetype_is_contig) {
00227
00228
00229
00230
00231 userbuf_off = 0;
00232 f_index = st_index;
00233 off = start_off;
00234 n_filetypes = st_n_filetypes;
00235 fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
00236
00237
00238 while (userbuf_off < bufsize) {
00239 if (fwr_size) {
00240
00241
00242 req_off = off;
00243 req_len = fwr_size;
00244
00245 ADIOI_Assert(req_len == (int) req_len);
00246 ADIOI_Assert((((ADIO_Offset)(MPIR_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIR_Upint)((MPIR_Upint)buf + userbuf_off));
00247 ADIO_WriteContig(fd,
00248 (char *) buf + userbuf_off,
00249 (int)req_len,
00250 MPI_BYTE,
00251 ADIO_EXPLICIT_OFFSET,
00252 req_off,
00253 &status1,
00254 error_code);
00255 if (*error_code != MPI_SUCCESS) return;
00256 }
00257 userbuf_off += fwr_size;
00258
00259 if (off + fwr_size < disp + flat_file->indices[f_index] +
00260 flat_file->blocklens[f_index] +
00261 n_filetypes*(ADIO_Offset)filetype_extent)
00262 {
00263
00264
00265
00266
00267 off += fwr_size;
00268 }
00269
00270
00271
00272 else {
00273 if (f_index < (flat_file->count - 1)) f_index++;
00274 else {
00275 f_index = 0;
00276 n_filetypes++;
00277 }
00278 off = disp + flat_file->indices[f_index] +
00279 n_filetypes*(ADIO_Offset)filetype_extent;
00280 fwr_size = ADIOI_MIN(flat_file->blocklens[f_index],
00281 bufsize-(unsigned)userbuf_off);
00282 }
00283 }
00284 }
00285 else {
00286 ADIO_Offset i_offset, tmp_bufsize = 0;
00287
00288
00289 ADIOI_Flatten_datatype(buftype);
00290 flat_buf = CtvAccess(ADIOI_Flatlist);
00291 while (flat_buf->type != buftype) flat_buf = flat_buf->next;
00292
00293 b_index = buf_count = 0;
00294 i_offset = flat_buf->indices[0];
00295 f_index = st_index;
00296 off = start_off;
00297 n_filetypes = st_n_filetypes;
00298 fwr_size = st_fwr_size;
00299 bwr_size = flat_buf->blocklens[0];
00300
00301
00302 while (tmp_bufsize < bufsize) {
00303 ADIO_Offset new_bwr_size = bwr_size, new_fwr_size = fwr_size;
00304
00305 size = ADIOI_MIN(fwr_size, bwr_size);
00306 if (size) {
00307 req_off = off;
00308 req_len = size;
00309 userbuf_off = i_offset;
00310
00311 ADIOI_Assert(req_len == (int) req_len);
00312 ADIOI_Assert((((ADIO_Offset)(MPIR_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIR_Upint)((MPIR_Upint)buf + userbuf_off));
00313 ADIO_WriteContig(fd,
00314 (char *) buf + userbuf_off,
00315 (int)req_len,
00316 MPI_BYTE,
00317 ADIO_EXPLICIT_OFFSET,
00318 req_off,
00319 &status1,
00320 error_code);
00321 if (*error_code != MPI_SUCCESS) return;
00322 }
00323
00324 if (size == fwr_size) {
00325
00326 if (f_index < (flat_file->count - 1)) f_index++;
00327 else {
00328 f_index = 0;
00329 n_filetypes++;
00330 }
00331
00332 off = disp + flat_file->indices[f_index] +
00333 n_filetypes*(ADIO_Offset)filetype_extent;
00334
00335 new_fwr_size = flat_file->blocklens[f_index];
00336 if (size != bwr_size) {
00337 i_offset += size;
00338 new_bwr_size -= size;
00339 }
00340 }
00341
00342 if (size == bwr_size) {
00343
00344
00345 b_index = (b_index + 1)%flat_buf->count;
00346 buf_count++;
00347 i_offset = (ADIO_Offset)buftype_extent*(ADIO_Offset)(buf_count/flat_buf->count) +
00348 flat_buf->indices[b_index];
00349 new_bwr_size = flat_buf->blocklens[b_index];
00350 if (size != fwr_size) {
00351 off += size;
00352 new_fwr_size -= size;
00353 }
00354 }
00355 tmp_bufsize += size;
00356 fwr_size = new_fwr_size;
00357 bwr_size = new_bwr_size;
00358 }
00359 }
00360
00361
00362 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
00363 {
00364 ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
00365 }
00366
00367 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
00368 }
00369
00370 fd->fp_sys_posn = -1;
00371
00372 #ifdef HAVE_STATUS_SET_BYTES
00373 MPIR_Status_set_bytes(status, buftype, bufsize);
00374
00375
00376
00377 #endif
00378
00379 if (!buftype_is_contig) ADIOI_Delete_flattened(buftype);
00380 }