root/ompi/mca/io/romio321/romio/adio/ad_testfs/ad_testfs_seek.c

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

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_TESTFS_SeekIndividual

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 2001 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "ad_testfs.h"
   9 #include "adioi.h"
  10 #include "adio_extern.h"
  11 
  12 /* ADIOI_TESTFS_SeekIndividual()
  13  *
  14  * Implements SEEK_SET only (and doesn't test for whence type); all
  15  * other types of whence must be converted before calling this.
  16  *
  17  * Returns an absolute offset in bytes.  The offset passed into the call is in
  18  * terms of the etype relative to the filetype, so some calculations are
  19  * necessary.  
  20  */
  21 ADIO_Offset ADIOI_TESTFS_SeekIndividual(ADIO_File fd, ADIO_Offset offset, 
  22                                         int whence, int *error_code)
  23 {
  24     int myrank, nprocs;
  25 
  26     ADIO_Offset off;
  27     ADIOI_Flatlist_node *flat_file;
  28     int i, n_etypes_in_filetype, n_filetypes, etype_in_filetype;
  29     ADIO_Offset abs_off_in_filetype=0, sum;
  30     int size_in_filetype;
  31     int filetype_is_contig;
  32     MPI_Count filetype_size;
  33     MPI_Aint etype_size, filetype_extent, lb;
  34 
  35     *error_code = MPI_SUCCESS;
  36 
  37     MPI_Comm_size(fd->comm, &nprocs);
  38     MPI_Comm_rank(fd->comm, &myrank);
  39     FPRINTF(stdout, "[%d/%d] ADIOI_TESTFS_SeekIndividual called on %s\n", 
  40             myrank, nprocs, fd->filename);
  41 
  42     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
  43     etype_size = fd->etype_size;
  44 
  45     if (filetype_is_contig) off = fd->disp + etype_size * offset;
  46     else {
  47         flat_file = ADIOI_Flatlist;
  48         while (flat_file->type != fd->filetype) flat_file = flat_file->next;
  49 
  50         MPI_Type_get_extent(fd->filetype, &lb, &filetype_extent);
  51         MPI_Type_size_x(fd->filetype, &filetype_size);
  52         if ( ! filetype_size ) {
  53             *error_code = MPI_SUCCESS; 
  54             return 0;
  55         }
  56 
  57         n_etypes_in_filetype = filetype_size/etype_size;
  58   ADIOI_Assert((offset / n_etypes_in_filetype) == (int) (offset / n_etypes_in_filetype));
  59         n_filetypes = (int) (offset / n_etypes_in_filetype);
  60         etype_in_filetype = (int) (offset % n_etypes_in_filetype);
  61         size_in_filetype = etype_in_filetype * etype_size;
  62  
  63         sum = 0;
  64         for (i=0; i<flat_file->count; i++) {
  65             sum += flat_file->blocklens[i];
  66 
  67             if (sum > size_in_filetype) {
  68                 abs_off_in_filetype = flat_file->indices[i] +
  69                     size_in_filetype - (sum - flat_file->blocklens[i]);
  70                 break;
  71             }
  72         }
  73 
  74         /* abs. offset in bytes in the file */
  75         off = fd->disp + (ADIO_Offset)n_filetypes * (ADIO_Offset)filetype_extent +
  76                 abs_off_in_filetype;
  77     }
  78 
  79     fd->fp_ind = off;
  80 
  81     return off;
  82 }

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