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