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