00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009 #include "adio_extern.h"
00010
00011 void ADIOI_GEN_ReadStrided_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 ADIO_Offset size, brd_size, frd_size=0, req_len, sum;
00020 int b_index;
00021 int n_etypes_in_filetype;
00022 ADIO_Offset n_filetypes, etype_in_filetype;
00023 ADIO_Offset abs_off_in_filetype=0;
00024 unsigned bufsize, filetype_size, buftype_size, size_in_filetype;
00025 int etype_size;
00026 MPI_Aint filetype_extent, buftype_extent;
00027 int buf_count, buftype_is_contig, filetype_is_contig;
00028 ADIO_Offset userbuf_off;
00029 ADIO_Offset off, req_off, disp, end_offset=0, start_off;
00030 ADIO_Status status1;
00031
00032 *error_code = MPI_SUCCESS;
00033
00034 ADIOI_Datatype_iscontig(buftype, &buftype_is_contig);
00035 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00036
00037 MPI_Type_size(fd->filetype, (int*)&filetype_size);
00038 if ( ! filetype_size ) {
00039 *error_code = MPI_SUCCESS;
00040 return;
00041 }
00042
00043 MPI_Type_extent(fd->filetype, &filetype_extent);
00044 MPI_Type_size(buftype,(int*) &buftype_size);
00045 MPI_Type_extent(buftype, &buftype_extent);
00046 etype_size = fd->etype_size;
00047
00048 ADIOI_Assert((buftype_size * count) == ((ADIO_Offset)buftype_size * (ADIO_Offset)count));
00049 bufsize = buftype_size * count;
00050
00051
00052
00053 if (!buftype_is_contig && filetype_is_contig) {
00054 int b_count;
00055
00056
00057 ADIOI_Flatten_datatype(buftype);
00058 flat_buf = CtvAccess(ADIOI_Flatlist);
00059 while (flat_buf->type != buftype) flat_buf = flat_buf->next;
00060
00061 off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind :
00062 fd->disp + etype_size * offset;
00063
00064 start_off = off;
00065 end_offset = off + bufsize - 1;
00066
00067
00068 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
00069 {
00070 ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
00071 }
00072
00073
00074
00075
00076 for (b_count=0; b_count < count; b_count++) {
00077 for (b_index=0; b_index < flat_buf->count; b_index++) {
00078 userbuf_off = (ADIO_Offset)b_count*(ADIO_Offset)buftype_extent +
00079 flat_buf->indices[b_index];
00080 req_off = off;
00081 req_len = flat_buf->blocklens[b_index];
00082
00083 ADIOI_Assert((((ADIO_Offset)(MPIR_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIR_Upint)((MPIR_Upint)buf + userbuf_off));
00084 ADIOI_Assert(req_len == (int) req_len);
00085 ADIO_ReadContig(fd,
00086 (char *) buf + userbuf_off,
00087 req_len,
00088 MPI_BYTE,
00089 ADIO_EXPLICIT_OFFSET,
00090 req_off,
00091 &status1,
00092 error_code);
00093 if (*error_code != MPI_SUCCESS) return;
00094
00095
00096 off += flat_buf->blocklens[b_index];
00097 }
00098 }
00099
00100 if ((fd->atomicity) && ADIO_Feature(fd, ADIO_LOCKS))
00101 {
00102 ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
00103 }
00104
00105 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
00106
00107 }
00108
00109 else {
00110 int f_index, st_index = 0;
00111 ADIO_Offset st_n_filetypes;
00112 ADIO_Offset st_frd_size;
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 frd_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 = (int) (offset % n_etypes_in_filetype);
00161 size_in_filetype = (unsigned)etype_in_filetype * (unsigned)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 frd_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_frd_size = frd_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 frd_size = ADIOI_MIN(st_frd_size, bufsize);
00195 while (userbuf_off < bufsize) {
00196 userbuf_off += frd_size;
00197 end_offset = off + frd_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 frd_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 frd_size = ADIOI_MIN(st_frd_size, bufsize);
00236
00237
00238 while (userbuf_off < bufsize) {
00239 if (frd_size) {
00240
00241
00242 req_off = off;
00243 req_len = frd_size;
00244
00245 ADIOI_Assert((((ADIO_Offset)(MPIR_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIR_Upint)((MPIR_Upint)buf + userbuf_off));
00246 ADIOI_Assert(req_len == (int) req_len);
00247 ADIO_ReadContig(fd,
00248 (char *) buf + userbuf_off,
00249 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 += frd_size;
00258
00259 if (off + frd_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 += frd_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 frd_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 frd_size = st_frd_size;
00299 brd_size = flat_buf->blocklens[0];
00300
00301
00302 while (tmp_bufsize < bufsize) {
00303 ADIO_Offset new_brd_size = brd_size, new_frd_size = frd_size;
00304
00305 size = ADIOI_MIN(frd_size, brd_size);
00306 if (size) {
00307 req_off = off;
00308 req_len = size;
00309 userbuf_off = i_offset;
00310
00311 ADIOI_Assert((((ADIO_Offset)(MPIR_Upint)buf) + userbuf_off) == (ADIO_Offset)(MPIR_Upint)((MPIR_Upint)buf + userbuf_off));
00312 ADIOI_Assert(req_len == (int) req_len);
00313 ADIO_ReadContig(fd,
00314 (char *) buf + userbuf_off,
00315 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 == frd_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_frd_size = flat_file->blocklens[f_index];
00336 if (size != brd_size) {
00337 i_offset += size;
00338 new_brd_size -= size;
00339 }
00340 }
00341
00342 if (size == brd_size) {
00343
00344
00345 b_index = (b_index + 1)%flat_buf->count;
00346 buf_count++;
00347 i_offset = buftype_extent*(buf_count/flat_buf->count) +
00348 flat_buf->indices[b_index];
00349 new_brd_size = flat_buf->blocklens[b_index];
00350 if (size != frd_size) {
00351 off += size;
00352 new_frd_size -= size;
00353 }
00354 }
00355 tmp_bufsize += size;
00356 frd_size = new_frd_size;
00357 brd_size = new_brd_size;
00358 }
00359 }
00360
00361
00362 if ((fd->atomicity) && (fd->file_system != ADIO_PIOFS) &&
00363 (fd->file_system != ADIO_PVFS) && (fd->file_system != ADIO_PVFS2))
00364 {
00365 ADIOI_UNLOCK(fd, start_off, SEEK_SET, end_offset-start_off+1);
00366 }
00367
00368 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
00369 }
00370
00371 fd->fp_sys_posn = -1;
00372
00373 #ifdef HAVE_STATUS_SET_BYTES
00374 MPIR_Status_set_bytes(status, buftype, bufsize);
00375
00376
00377
00378 #endif
00379
00380 if (!buftype_is_contig) ADIOI_Delete_flattened(buftype);
00381 }