root/ompi/mca/io/romio321/romio/adio/ad_pvfs/ad_pvfs_read.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_PVFS_ReadContig
  2. ADIOI_PVFS_ReadStrided
  3. ADIOI_PVFS_ReadStridedListIO

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 1997 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   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         /* individual file pointer not updated */        
  49     }
  50     else {  /* read from curr. location of ind. file pointer */
  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 /* If hint set to DISABLE or AUTOMATIC, don't use listio */
  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 /* offset is in units of etype relative to the filetype. */
 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;  /* changed below if error */
 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 /* noncontiguous in memory, contiguous in file. */
 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         /* allocate arrays according to max usage */
 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         /* step through each block in memory, filling memory arrays */
 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                     /* in the case of the last read list call,
 206                        adjust mem_list_count */
 207                     if (b_blks_read == total_blks_to_read) {
 208                         mem_list_count = total_blks_to_read % MAX_ARRAY_SIZE;
 209                         /* in case last read list call fills max arrays */
 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                     /* in the case of the last read list call, leave here */
 218                     if (b_blks_read == total_blks_to_read) break;
 219 
 220                     file_offsets += file_lengths;
 221                     file_lengths = 0;
 222                 } 
 223             } /* for (i=0; i<flat_buf->count; i++) */
 224             j++;
 225         } /* while (b_blks_read < total_blks_to_read) */
 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;  /* set it to null. */
 232 
 233 #ifdef HAVE_STATUS_SET_BYTES
 234         MPIR_Status_set_bytes(status, datatype, bufsize);
 235         /* This isa temporary way of filling in status.  The right way is to
 236            keep tracke of how much data was actually read adn placed in buf
 237            by ADIOI_BUFFERED_READ. */
 238 #endif
 239         ADIOI_Delete_flattened(datatype);
 240 
 241         return;
 242     } /* if (!buftype_is_contig && filetype_is_contig) */
 243 
 244     /* know file is noncontiguous from above */
 245     /* noncontiguous in file */
 246 
 247     /* filetype already flattened in ADIO_Open */
 248     flat_file = ADIOI_Flatlist;
 249     while (flat_file->type != fd->filetype) flat_file = flat_file->next;
 250 
 251     disp = fd->disp;
 252 
 253     /* for each case - ADIO_Individual pointer or explicit, find the file
 254        offset in bytes (offset), n_filetypes (how many filetypes into
 255        file to start), frd_size (remaining amount of data in present
 256        file block), and st_index (start point in terms of blocks in
 257        starting filetype) */
 258     if (file_ptr_type == ADIO_INDIVIDUAL) {
 259         offset = fd->fp_ind; /* in bytes */
 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         } /* while (!flag) */
 277     } /* if (file_ptr_type == ADIO_INDIVIDUAL) */
 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         /* abs. offset in bytes in the file */
 297         offset = disp + (ADIO_Offset) n_filetypes*filetype_extent + 
 298             abs_off_in_filetype;
 299     } /* else [file_ptr_type != ADIO_INDIVIDUAL] */
 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 /* contiguous in memory, noncontiguous in file. should be the most
 308    common case. */
 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         /* determine how many blocks in file to read */
 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         /* if at least one full readlist, allocate file arrays
 339            at max array size and don't free until very end */
 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         /* if there's no full readlist allocate file arrays according
 347            to needed size (extra_blks) */
 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         /* for file arrays that are of MAX_ARRAY_SIZE, build arrays */
 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             } /* for (k=0; k<MAX_ARRAY_SIZE; k++) */
 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         } /* for (i=0; i<n_read_lists; i++) */
 383 
 384         /* for file arrays smaller than MAX_ARRAY_SIZE (last read_list call) */
 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                 } /* if(i || k) */
 401                 mem_lengths += file_lengths[k];
 402                 if (j<(flat_file->count - 1)) j++;
 403                 else {
 404                     j = 0;
 405                     n_filetypes++;
 406                 }
 407             } /* for (k=0; k<extra_blks; k++) */
 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 /* noncontiguous in memory as well as in file */
 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         /* run through and file max_file_list and max_mem_list so that you 
 430            can allocate the file and memory arrays less than MAX_ARRAY_SIZE
 431            if possible */
 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                 /* find mem_list_count and file_list_count such that both are
 440                    less than MAX_ARRAY_SIZE, the sum of their lengths are
 441                    equal, and the sum of all the data read and data to be
 442                    read in the next immediate read list is less than
 443                    bufsize */
 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              } /* while ((mem_list_count < MAX_ARRAY_SIZE) && 
 466                (new_buffer_read < bufsize-size_read)) */
 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                     } /* while (new_buffer_read < new_file_read) */
 523                 } /* if ((new_file_read < new_buffer_read) && (file_list_count
 524                      == MAX_ARRAY_SIZE)) */
 525             } /* while ((mem_list_count < MAX_ARRAY_SIZE) && 
 526                  (new_buffer_read < bufsize-size_read)) */
 527 
 528             /*  fakes filling the readlist arrays of lengths found above  */
 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             } /* for (i=0; i<mem_list_count; i++) */
 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             } /* for (i=0; i<file_list_count; i++) */
 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         } /* while (size_read < bufsize) */
 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         /*  this section calculates mem_list_count and file_list_count
 589             and also finds the possibly odd sized last array elements
 590             in new_frd_size and new_brd_size  */
 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                 /* find mem_list_count and file_list_count such that both are
 599                    less than MAX_ARRAY_SIZE, the sum of their lengths are
 600                    equal, and the sum of all the data read and data to be
 601                    read in the next immediate read list is less than
 602                    bufsize */
 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              } /* while ((mem_list_count < MAX_ARRAY_SIZE) && 
 625                (new_buffer_read < bufsize-size_read)) */
 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                     } /* while (new_buffer_read < new_file_read) */
 682                 } /* if ((new_file_read < new_buffer_read) && (file_list_count
 683                      == MAX_ARRAY_SIZE)) */
 684             } /* while ((mem_list_count < MAX_ARRAY_SIZE) && 
 685                  (new_buffer_read < bufsize-size_read)) */
 686 
 687             /*  fills the allocated readlist arrays  */
 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             } /* for (i=0; i<mem_list_count; i++) */
 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             } /* for (i=0; i<file_list_count; i++) */
 743 
 744             /* 
 745             printf("about to call read_list in noncontig/noncontig\n");
 746             printf("offsets and lengths in terms of integers\n");
 747             printf("\nmem_list_count = %d\n", mem_list_count);
 748             for (i=0; i<mem_list_count; i++) {
 749               printf("mem_offsets[%2d] = %2d   ", i, (int)(mem_offsets[i] - (int)buf)/4);
 750               printf("mem_lengths[%2d] = %2d\n", i, mem_lengths[i]/4);
 751             }
 752             printf("\nfile_list_count = %d\n", file_list_count);
 753             for (i=0; i<file_list_count; i++) {
 754               printf("file_offsets[%2d] = %2d   ", i, (int)file_offsets[i]/4);
 755               printf("file_lengths[%2d] = %2d\n", i, file_lengths[i]/4);
 756             }
 757             printf("\n\n");
 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         } /* while (size_read < bufsize) */
 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;   /* set it to null. */
 774     
 775 #ifdef HAVE_STATUS_SET_BYTES
 776     MPIR_Status_set_bytes(status, datatype, bufsize);
 777     /* This is a temporary way of filling in status. The right way is to 
 778        keep track of how much data was actually read and placed in buf 
 779        by ADIOI_BUFFERED_READ. */
 780 #endif
 781     
 782     if (!buftype_is_contig) ADIOI_Delete_flattened(datatype);
 783 }
 784 #endif /* HAVE_PVFS_LISTIO */

/* [<][>][^][v][top][bottom][index][help] */