This source file includes following definitions.
- ADIOI_PVFS_ReadContig
- ADIOI_PVFS_ReadStrided
- ADIOI_PVFS_ReadStridedListIO
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 #include "adio.h"
   9 #include "adio_extern.h"
  10 #include "ad_pvfs.h"
  11 
  12 #ifdef HAVE_PVFS_LISTIO
  13 void ADIOI_PVFS_ReadStridedListIO(ADIO_File fd, void *buf, int count,
  14                        MPI_Datatype datatype, int file_ptr_type,
  15                        ADIO_Offset offset, ADIO_Status *status, int
  16                        *error_code);
  17 #endif
  18 
  19 void ADIOI_PVFS_ReadContig(ADIO_File fd, void *buf, int count, 
  20                      MPI_Datatype datatype, int file_ptr_type,
  21                      ADIO_Offset offset, ADIO_Status *status, int *error_code)
  22 {
  23     MPI_Count err=-1, datatype_size, len;
  24     static char myname[] = "ADIOI_PVFS_READCONTIG";
  25 
  26     MPI_Type_size_x(datatype, &datatype_size);
  27     len = datatype_size * count;
  28 
  29     if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
  30         if (fd->fp_sys_posn != offset) {
  31 #ifdef ADIOI_MPE_LOGGING
  32             MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
  33 #endif
  34             pvfs_lseek64(fd->fd_sys, offset, SEEK_SET);
  35 #ifdef ADIOI_MPE_LOGGING
  36             MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
  37 #endif
  38         }
  39 #ifdef ADIOI_MPE_LOGGING
  40         MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
  41 #endif
  42         err = pvfs_read(fd->fd_sys, buf, len);
  43 #ifdef ADIOI_MPE_LOGGING
  44         MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
  45 #endif
  46         if (err>0)
  47                 fd->fp_sys_posn = offset + err;
  48                 
  49     }
  50     else {  
  51         if (fd->fp_sys_posn != fd->fp_ind) {
  52 #ifdef ADIOI_MPE_LOGGING
  53             MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
  54 #endif
  55             pvfs_lseek64(fd->fd_sys, fd->fp_ind, SEEK_SET);
  56 #ifdef ADIOI_MPE_LOGGING
  57             MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
  58 #endif
  59         }
  60 #ifdef ADIOI_MPE_LOGGING
  61         MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
  62 #endif
  63         err = pvfs_read(fd->fd_sys, buf, len);
  64 #ifdef ADIOI_MPE_LOGGING
  65         MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
  66 #endif
  67         if (err > 0)
  68                 fd->fp_ind += err; 
  69         fd->fp_sys_posn = fd->fp_ind;
  70     }         
  71 
  72 #ifdef HAVE_STATUS_SET_BYTES
  73     if (err != -1) MPIR_Status_set_bytes(status, datatype, err);
  74 #endif
  75 
  76     if (err == -1) {
  77         *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
  78                                            myname, __LINE__, MPI_ERR_IO,
  79                                            "**io",
  80                                            "**io %s", strerror(errno));
  81     }
  82     else *error_code = MPI_SUCCESS;
  83 }
  84 
  85 
  86 void ADIOI_PVFS_ReadStrided(ADIO_File fd, void *buf, int count,
  87                             MPI_Datatype datatype, int file_ptr_type,
  88                             ADIO_Offset offset, ADIO_Status *status, int
  89                             *error_code)
  90 {
  91 #ifdef HAVE_PVFS_LISTIO
  92     if ( fd->hints->fs_hints.pvfs.listio_read == ADIOI_HINT_ENABLE) {
  93             ADIOI_PVFS_ReadStridedListIO(fd, buf, count, datatype, file_ptr_type,
  94                             offset, status, error_code);
  95             return;
  96     }
  97 #endif
  98 
  99     ADIOI_GEN_ReadStrided(fd, buf, count, datatype, file_ptr_type,
 100                     offset, status, error_code);
 101 }
 102 
 103 #ifdef HAVE_PVFS_LISTIO
 104 void ADIOI_PVFS_ReadStridedListIO(ADIO_File fd, void *buf, int count,
 105                        MPI_Datatype datatype, int file_ptr_type,
 106                        ADIO_Offset offset, ADIO_Status *status, int
 107                        *error_code)
 108 {
 109 
 110 
 111     ADIOI_Flatlist_node *flat_buf, *flat_file;
 112     int i, j, k, l, brd_size, frd_size=0, st_index=0;
 113     int sum, n_etypes_in_filetype, size_in_filetype;
 114     MPI_Count bufsize;
 115     int n_filetypes, etype_in_filetype;
 116     ADIO_Offset abs_off_in_filetype=0;
 117     MPI_Count filetype_size, etype_size, buftype_size;
 118     MPI_Aint filetype_extent, buftype_extent; 
 119     int buf_count, buftype_is_contig, filetype_is_contig;
 120     ADIO_Offset userbuf_off;
 121     ADIO_Offset off, disp, start_off;
 122     int flag, st_frd_size, st_n_filetypes;
 123     int new_brd_size, new_frd_size;
 124 
 125     int mem_list_count, file_list_count;
 126     char **mem_offsets;
 127     int64_t *file_offsets;
 128     int *mem_lengths;
 129     int32_t *file_lengths;
 130     int total_blks_to_read;
 131 
 132     int max_mem_list, max_file_list;
 133 
 134     int b_blks_read;
 135     int f_data_read;
 136     int size_read=0, n_read_lists, extra_blks;
 137 
 138     int end_brd_size, end_frd_size;
 139     int start_k, start_j, new_file_read, new_buffer_read;
 140     int start_mem_offset;
 141 
 142 #define MAX_ARRAY_SIZE 1024
 143 
 144 #ifndef PRINT_ERR_MESG
 145   static char myname[] = "ADIOI_PVFS_ReadStrided";
 146 #endif
 147 
 148     *error_code = MPI_SUCCESS;  
 149 
 150     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
 151     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
 152     MPI_Type_size_x(fd->filetype, &filetype_size);
 153     if ( ! filetype_size ) {
 154 #ifdef HAVE_STATUS_SET_BYTES
 155         MPIR_Status_set_bytes(status, datatype, 0);
 156 #endif
 157         *error_code = MPI_SUCCESS; 
 158         return;
 159     }
 160 
 161     MPI_Type_get_extent(fd->filetype, &filetype_lb, &filetype_extent);
 162     MPI_Type_size_x(datatype, &buftype_size);
 163     MPI_Type_get_extent(datatype, &buftype_lb, &buftype_extent);
 164     etype_size = fd->etype_size;
 165 
 166     bufsize = buftype_size * count;
 167 
 168     if (!buftype_is_contig && filetype_is_contig) {
 169 
 170 
 171         int64_t file_offsets;
 172         int32_t file_lengths;
 173 
 174         flat_buf = ADIOI_Flatten_and_find(datatype);
 175 
 176         off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : 
 177             fd->disp + etype_size * offset;
 178 
 179         file_list_count = 1;
 180         file_offsets = off;
 181         file_lengths = 0;
 182         total_blks_to_read = count*flat_buf->count;
 183         b_blks_read = 0;
 184 
 185         
 186         if (total_blks_to_read > MAX_ARRAY_SIZE)
 187             mem_list_count = MAX_ARRAY_SIZE;
 188         else mem_list_count = total_blks_to_read;
 189         mem_offsets = (char**)ADIOI_Malloc(mem_list_count*sizeof(char*));
 190         mem_lengths = (int*)ADIOI_Malloc(mem_list_count*sizeof(int));
 191 
 192         j = 0;
 193         
 194         while (b_blks_read < total_blks_to_read) {
 195             for (i=0; i<flat_buf->count; i++) {
 196                 mem_offsets[b_blks_read % MAX_ARRAY_SIZE] = 
 197                     (char*)((char *)buf + j*buftype_extent + flat_buf->indices[i]);
 198                 mem_lengths[b_blks_read % MAX_ARRAY_SIZE] = 
 199                     flat_buf->blocklens[i];
 200                 file_lengths += flat_buf->blocklens[i];
 201                 b_blks_read++;
 202                 if (!(b_blks_read % MAX_ARRAY_SIZE) ||
 203                     (b_blks_read == total_blks_to_read)) {
 204 
 205                     
 206 
 207                     if (b_blks_read == total_blks_to_read) {
 208                         mem_list_count = total_blks_to_read % MAX_ARRAY_SIZE;
 209                         
 210                         if (!mem_list_count) mem_list_count = MAX_ARRAY_SIZE;
 211                     }
 212 
 213                     pvfs_read_list(fd->fd_sys ,mem_list_count, mem_offsets,
 214                                    mem_lengths, file_list_count,
 215                                    &file_offsets, &file_lengths);
 216                   
 217                     
 218                     if (b_blks_read == total_blks_to_read) break;
 219 
 220                     file_offsets += file_lengths;
 221                     file_lengths = 0;
 222                 } 
 223             } 
 224             j++;
 225         } 
 226         ADIOI_Free(mem_offsets);
 227         ADIOI_Free(mem_lengths);
 228 
 229         if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
 230 
 231         fd->fp_sys_posn = -1;  
 232 
 233 #ifdef HAVE_STATUS_SET_BYTES
 234         MPIR_Status_set_bytes(status, datatype, bufsize);
 235         
 236 
 237 
 238 #endif
 239         ADIOI_Delete_flattened(datatype);
 240 
 241         return;
 242     } 
 243 
 244     
 245     
 246 
 247     
 248     flat_file = ADIOI_Flatlist;
 249     while (flat_file->type != fd->filetype) flat_file = flat_file->next;
 250 
 251     disp = fd->disp;
 252 
 253     
 254 
 255 
 256 
 257 
 258     if (file_ptr_type == ADIO_INDIVIDUAL) {
 259         offset = fd->fp_ind; 
 260         n_filetypes = -1;
 261         flag = 0;
 262         while (!flag) {
 263             n_filetypes++;
 264             for (i=0; i<flat_file->count; i++) {
 265                 if (disp + flat_file->indices[i] + 
 266                     (ADIO_Offset) n_filetypes*filetype_extent +
 267                     flat_file->blocklens[i]  >= offset) {
 268                     st_index = i;
 269                     frd_size = (int) (disp + flat_file->indices[i] + 
 270                                       (ADIO_Offset) n_filetypes*filetype_extent
 271                                       + flat_file->blocklens[i] - offset);
 272                     flag = 1;
 273                     break;
 274                 }
 275             }
 276         } 
 277     } 
 278     else {
 279         n_etypes_in_filetype = filetype_size/etype_size;
 280         n_filetypes = (int) (offset / n_etypes_in_filetype);
 281         etype_in_filetype = (int) (offset % n_etypes_in_filetype);
 282         size_in_filetype = etype_in_filetype * etype_size;
 283         
 284         sum = 0;
 285         for (i=0; i<flat_file->count; i++) {
 286             sum += flat_file->blocklens[i];
 287             if (sum > size_in_filetype) {
 288                 st_index = i;
 289                 frd_size = sum - size_in_filetype;
 290                 abs_off_in_filetype = flat_file->indices[i] +
 291                     size_in_filetype - (sum - flat_file->blocklens[i]);
 292                 break;
 293             }
 294         }
 295         
 296         
 297         offset = disp + (ADIO_Offset) n_filetypes*filetype_extent + 
 298             abs_off_in_filetype;
 299     } 
 300 
 301     start_off = offset;
 302     st_frd_size = frd_size;
 303     st_n_filetypes = n_filetypes;
 304     
 305     if (buftype_is_contig && !filetype_is_contig) {
 306 
 307 
 308 
 309 
 310         int mem_lengths;
 311         char *mem_offsets;
 312         
 313         i = 0;
 314         j = st_index;
 315         n_filetypes = st_n_filetypes;
 316         
 317         mem_list_count = 1;
 318         
 319         
 320         f_data_read = ADIOI_MIN(st_frd_size, bufsize);
 321         total_blks_to_read = 1;
 322         j++;
 323         while (f_data_read < bufsize) {
 324             f_data_read += flat_file->blocklens[j];
 325             total_blks_to_read++;
 326             if (j<(flat_file->count-1)) j++;
 327             else j = 0; 
 328         }
 329       
 330         j = st_index;
 331         n_filetypes = st_n_filetypes;
 332         n_read_lists = total_blks_to_read/MAX_ARRAY_SIZE;
 333         extra_blks = total_blks_to_read%MAX_ARRAY_SIZE;
 334         
 335         mem_offsets = buf;
 336         mem_lengths = 0;
 337         
 338         
 339 
 340         if (n_read_lists) {
 341             file_offsets = (int64_t*)ADIOI_Malloc(MAX_ARRAY_SIZE*
 342                                                   sizeof(int64_t));
 343             file_lengths = (int32_t*)ADIOI_Malloc(MAX_ARRAY_SIZE*
 344                                                   sizeof(int32_t));
 345         }
 346         
 347 
 348         else {
 349             file_offsets = (int64_t*)ADIOI_Malloc(extra_blks*
 350                                                   sizeof(int64_t));
 351             file_lengths = (int32_t*)ADIOI_Malloc(extra_blks*
 352                                                   sizeof(int32_t));
 353         }
 354         
 355         
 356         for (i=0; i<n_read_lists; i++) {
 357             file_list_count = MAX_ARRAY_SIZE;
 358             if(!i) {
 359                 file_offsets[0] = offset;
 360                 file_lengths[0] = st_frd_size;
 361                 mem_lengths = st_frd_size;
 362             }
 363             for (k=0; k<MAX_ARRAY_SIZE; k++) {
 364                 if (i || k) {
 365                     file_offsets[k] = disp + n_filetypes*filetype_extent
 366                       + flat_file->indices[j];
 367                     file_lengths[k] = flat_file->blocklens[j];
 368                     mem_lengths += file_lengths[k];
 369                 }
 370                 if (j<(flat_file->count - 1)) j++;
 371                 else {
 372                     j = 0;
 373                     n_filetypes++;
 374                 }
 375             } 
 376             pvfs_read_list(fd->fd_sys, mem_list_count,
 377                            &mem_offsets, &mem_lengths,
 378                            file_list_count, file_offsets,
 379                            file_lengths);
 380             mem_offsets += mem_lengths;
 381             mem_lengths = 0;
 382         } 
 383 
 384         
 385         if (extra_blks) {
 386             file_list_count = extra_blks;
 387             if(!i) {
 388                 file_offsets[0] = offset;
 389                 file_lengths[0] = st_frd_size;
 390             }
 391             for (k=0; k<extra_blks; k++) {
 392                 if(i || k) {
 393                     file_offsets[k] = disp + n_filetypes*filetype_extent +
 394                       flat_file->indices[j];
 395                     if (k == (extra_blks - 1)) {
 396                         file_lengths[k] = bufsize - (int32_t) mem_lengths
 397                           - (int32_t) mem_offsets + (int32_t)  buf;
 398                     }
 399                     else file_lengths[k] = flat_file->blocklens[j];
 400                 } 
 401                 mem_lengths += file_lengths[k];
 402                 if (j<(flat_file->count - 1)) j++;
 403                 else {
 404                     j = 0;
 405                     n_filetypes++;
 406                 }
 407             } 
 408             pvfs_read_list(fd->fd_sys, mem_list_count, &mem_offsets,
 409                            &mem_lengths, file_list_count, file_offsets,
 410                            file_lengths);
 411         }
 412     }
 413     else {
 414 
 415       
 416         flat_buf = ADIOI_Flatten_and_find(datatype);
 417 
 418         size_read = 0;
 419         n_filetypes = st_n_filetypes;
 420         frd_size = st_frd_size;
 421         brd_size = flat_buf->blocklens[0];
 422         buf_count = 0;
 423         start_mem_offset = 0;
 424         start_k = k = 0;
 425         start_j = st_index;
 426         max_mem_list = 0;
 427         max_file_list = 0;
 428 
 429         
 430 
 431 
 432 
 433         while (size_read < bufsize) {
 434             k = start_k;
 435             new_buffer_read = 0;
 436             mem_list_count = 0;
 437             while ((mem_list_count < MAX_ARRAY_SIZE) && 
 438                    (new_buffer_read < bufsize-size_read)) {
 439                 
 440 
 441 
 442 
 443 
 444                 if(mem_list_count) {
 445                     if((new_buffer_read + flat_buf->blocklens[k] + 
 446                         size_read) > bufsize) {
 447                         end_brd_size = new_buffer_read + 
 448                             flat_buf->blocklens[k] - (bufsize - size_read);
 449                         new_buffer_read = bufsize - size_read;
 450                     }
 451                     else {
 452                         new_buffer_read += flat_buf->blocklens[k];
 453                         end_brd_size = flat_buf->blocklens[k];
 454                     }
 455                 }
 456                 else {
 457                     if (brd_size > (bufsize - size_read)) {
 458                         new_buffer_read = bufsize - size_read;
 459                         brd_size = new_buffer_read;
 460                     }
 461                     else new_buffer_read = brd_size;
 462                 }
 463                 mem_list_count++;
 464                 k = (k + 1)%flat_buf->count;
 465              } 
 466 
 467             j = start_j;
 468             new_file_read = 0;
 469             file_list_count = 0;
 470             while ((file_list_count < MAX_ARRAY_SIZE) && 
 471                    (new_file_read < new_buffer_read)) {
 472                 if(file_list_count) {
 473                     if((new_file_read + flat_file->blocklens[j]) > 
 474                        new_buffer_read) {
 475                         end_frd_size = new_buffer_read - new_file_read;
 476                         new_file_read = new_buffer_read;
 477                         j--;
 478                     }
 479                     else {
 480                         new_file_read += flat_file->blocklens[j];
 481                         end_frd_size = flat_file->blocklens[j];
 482                     }
 483                 }
 484                 else {
 485                     if (frd_size > new_buffer_read) {
 486                         new_file_read = new_buffer_read;
 487                         frd_size = new_file_read;
 488                     }
 489                     else new_file_read = frd_size;
 490                 }
 491                 file_list_count++;
 492                 if (j < (flat_file->count - 1)) j++;
 493                 else j = 0;
 494                 
 495                 k = start_k;
 496                 if ((new_file_read < new_buffer_read) && 
 497                     (file_list_count == MAX_ARRAY_SIZE)) {
 498                     new_buffer_read = 0;
 499                     mem_list_count = 0;
 500                     while (new_buffer_read < new_file_read) {
 501                         if(mem_list_count) {
 502                             if((new_buffer_read + flat_buf->blocklens[k]) >
 503                                new_file_read) {
 504                                 end_brd_size = new_file_read - new_buffer_read;
 505                                 new_buffer_read = new_file_read;
 506                                 k--;
 507                             }
 508                             else {
 509                                 new_buffer_read += flat_buf->blocklens[k];
 510                                 end_brd_size = flat_buf->blocklens[k];
 511                             }
 512                         }
 513                         else {
 514                             new_buffer_read = brd_size;
 515                             if (brd_size > (bufsize - size_read)) {
 516                                 new_buffer_read = bufsize - size_read;
 517                                 brd_size = new_buffer_read;
 518                             }
 519                         }
 520                         mem_list_count++;
 521                         k = (k + 1)%flat_buf->count;
 522                     } 
 523                 } 
 524 
 525             } 
 526 
 527 
 528             
 529             k = start_k;
 530             j = start_j;
 531             for (i=0; i<mem_list_count; i++) {       
 532                 if(i) {
 533                     if (i == (mem_list_count - 1)) {
 534                         if (flat_buf->blocklens[k] == end_brd_size)
 535                             brd_size = flat_buf->blocklens[(k+1)%
 536                                                           flat_buf->count];
 537                         else {
 538                             brd_size = flat_buf->blocklens[k] - end_brd_size;
 539                             k--;
 540                             buf_count--;
 541                         }
 542                     }
 543                 }
 544                 buf_count++;
 545                 k = (k + 1)%flat_buf->count;
 546             } 
 547             for (i=0; i<file_list_count; i++) {
 548                 if (i) {
 549                     if (i == (file_list_count - 1)) {
 550                         if (flat_file->blocklens[j] == end_frd_size)
 551                             frd_size = flat_file->blocklens[(j+1)%
 552                                                           flat_file->count];   
 553                         else {
 554                             frd_size = flat_file->blocklens[j] - end_frd_size;
 555                             j--;
 556                         }
 557                     }
 558                 }
 559                 if (j < flat_file->count - 1) j++;
 560                 else {
 561                     j = 0;
 562                     n_filetypes++;
 563                 }
 564             } 
 565             size_read += new_buffer_read;
 566             start_k = k;
 567             start_j = j;
 568             if (max_mem_list < mem_list_count)
 569                 max_mem_list = mem_list_count;
 570             if (max_file_list < file_list_count)
 571                 max_file_list = file_list_count;
 572         } 
 573 
 574         mem_offsets = (char **)ADIOI_Malloc(max_mem_list*sizeof(char *));
 575         mem_lengths = (int *)ADIOI_Malloc(max_mem_list*sizeof(int));
 576         file_offsets = (int64_t *)ADIOI_Malloc(max_file_list*sizeof(int64_t));
 577         file_lengths = (int32_t *)ADIOI_Malloc(max_file_list*sizeof(int32_t));
 578             
 579         size_read = 0;
 580         n_filetypes = st_n_filetypes;
 581         frd_size = st_frd_size;
 582         brd_size = flat_buf->blocklens[0];
 583         buf_count = 0;
 584         start_mem_offset = 0;
 585         start_k = k = 0;
 586         start_j = st_index;
 587 
 588         
 589 
 590 
 591         
 592         while (size_read < bufsize) {
 593             k = start_k;
 594             new_buffer_read = 0;
 595             mem_list_count = 0;
 596             while ((mem_list_count < MAX_ARRAY_SIZE) && 
 597                    (new_buffer_read < bufsize-size_read)) {
 598                 
 599 
 600 
 601 
 602 
 603                 if(mem_list_count) {
 604                     if((new_buffer_read + flat_buf->blocklens[k] + 
 605                         size_read) > bufsize) {
 606                         end_brd_size = new_buffer_read + 
 607                             flat_buf->blocklens[k] - (bufsize - size_read);
 608                         new_buffer_read = bufsize - size_read;
 609                     }
 610                     else {
 611                         new_buffer_read += flat_buf->blocklens[k];
 612                         end_brd_size = flat_buf->blocklens[k];
 613                     }
 614                 }
 615                 else {
 616                     if (brd_size > (bufsize - size_read)) {
 617                         new_buffer_read = bufsize - size_read;
 618                         brd_size = new_buffer_read;
 619                     }
 620                     else new_buffer_read = brd_size;
 621                 }
 622                 mem_list_count++;
 623                 k = (k + 1)%flat_buf->count;
 624              } 
 625 
 626             j = start_j;
 627             new_file_read = 0;
 628             file_list_count = 0;
 629             while ((file_list_count < MAX_ARRAY_SIZE) && 
 630                    (new_file_read < new_buffer_read)) {
 631                 if(file_list_count) {
 632                     if((new_file_read + flat_file->blocklens[j]) > 
 633                        new_buffer_read) {
 634                         end_frd_size = new_buffer_read - new_file_read;
 635                         new_file_read = new_buffer_read;
 636                         j--;
 637                     }
 638                     else {
 639                         new_file_read += flat_file->blocklens[j];
 640                         end_frd_size = flat_file->blocklens[j];
 641                     }
 642                 }
 643                 else {
 644                     if (frd_size > new_buffer_read) {
 645                         new_file_read = new_buffer_read;
 646                         frd_size = new_file_read;
 647                     }
 648                     else new_file_read = frd_size;
 649                 }
 650                 file_list_count++;
 651                 if (j < (flat_file->count - 1)) j++;
 652                 else j = 0;
 653                 
 654                 k = start_k;
 655                 if ((new_file_read < new_buffer_read) && 
 656                     (file_list_count == MAX_ARRAY_SIZE)) {
 657                     new_buffer_read = 0;
 658                     mem_list_count = 0;
 659                     while (new_buffer_read < new_file_read) {
 660                         if(mem_list_count) {
 661                             if((new_buffer_read + flat_buf->blocklens[k]) >
 662                                new_file_read) {
 663                                 end_brd_size = new_file_read - new_buffer_read;
 664                                 new_buffer_read = new_file_read;
 665                                 k--;
 666                             }
 667                             else {
 668                                 new_buffer_read += flat_buf->blocklens[k];
 669                                 end_brd_size = flat_buf->blocklens[k];
 670                             }
 671                         }
 672                         else {
 673                             new_buffer_read = brd_size;
 674                             if (brd_size > (bufsize - size_read)) {
 675                                 new_buffer_read = bufsize - size_read;
 676                                 brd_size = new_buffer_read;
 677                             }
 678                         }
 679                         mem_list_count++;
 680                         k = (k + 1)%flat_buf->count;
 681                     } 
 682                 } 
 683 
 684             } 
 685 
 686 
 687             
 688             k = start_k;
 689             j = start_j;
 690             for (i=0; i<mem_list_count; i++) {       
 691                 mem_offsets[i] = (char*)((char *)buf + buftype_extent*
 692                                          (buf_count/flat_buf->count) +
 693                                          (int)flat_buf->indices[k]);
 694                 if(!i) {
 695                     mem_lengths[0] = brd_size;
 696                     mem_offsets[0] += flat_buf->blocklens[k] - brd_size;
 697                 }
 698                 else {
 699                     if (i == (mem_list_count - 1)) {
 700                         mem_lengths[i] = end_brd_size;
 701                         if (flat_buf->blocklens[k] == end_brd_size)
 702                             brd_size = flat_buf->blocklens[(k+1)%
 703                                                           flat_buf->count];
 704                         else {
 705                             brd_size = flat_buf->blocklens[k] - end_brd_size;
 706                             k--;
 707                             buf_count--;
 708                         }
 709                     }
 710                     else {
 711                         mem_lengths[i] = flat_buf->blocklens[k];
 712                     }
 713                 }
 714                 buf_count++;
 715                 k = (k + 1)%flat_buf->count;
 716             } 
 717             for (i=0; i<file_list_count; i++) {
 718                 file_offsets[i] = disp + flat_file->indices[j] + n_filetypes *
 719                     filetype_extent;
 720                 if (!i) {
 721                     file_lengths[0] = frd_size;
 722                     file_offsets[0] += flat_file->blocklens[j] - frd_size;
 723                 }
 724                 else {
 725                     if (i == (file_list_count - 1)) {
 726                         file_lengths[i] = end_frd_size;
 727                         if (flat_file->blocklens[j] == end_frd_size)
 728                             frd_size = flat_file->blocklens[(j+1)%
 729                                                           flat_file->count];   
 730                         else {
 731                             frd_size = flat_file->blocklens[j] - end_frd_size;
 732                             j--;
 733                         }
 734                     }
 735                     else file_lengths[i] = flat_file->blocklens[j];
 736                 }
 737                 if (j < flat_file->count - 1) j++;
 738                 else {
 739                     j = 0;
 740                     n_filetypes++;
 741                 }
 742             } 
 743 
 744             
 745 
 746 
 747 
 748 
 749 
 750 
 751 
 752 
 753 
 754 
 755 
 756 
 757 
 758 
 759             pvfs_read_list(fd->fd_sys,mem_list_count, mem_offsets,
 760                            mem_lengths, file_list_count, file_offsets,
 761                            file_lengths);
 762             size_read += new_buffer_read;
 763             start_k = k;
 764             start_j = j;
 765         } 
 766         ADIOI_Free(mem_offsets);
 767         ADIOI_Free(mem_lengths);
 768     }
 769     ADIOI_Free(file_offsets);
 770     ADIOI_Free(file_lengths);
 771     
 772     if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind = off;
 773     fd->fp_sys_posn = -1;   
 774     
 775 #ifdef HAVE_STATUS_SET_BYTES
 776     MPIR_Status_set_bytes(status, datatype, bufsize);
 777     
 778 
 779 
 780 #endif
 781     
 782     if (!buftype_is_contig) ADIOI_Delete_flattened(datatype);
 783 }
 784 #endif