00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009 #include "adio_extern.h"
00010
00011
00012
00013
00014 void ADIOI_Get_byte_offset(ADIO_File fd, ADIO_Offset offset, ADIO_Offset *disp)
00015 {
00016 ADIOI_Flatlist_node *flat_file;
00017 int i;
00018 ADIO_Offset n_filetypes, etype_in_filetype, sum, abs_off_in_filetype=0, size_in_filetype;
00019 unsigned n_etypes_in_filetype, filetype_size, etype_size;
00020 int filetype_is_contig;
00021 MPI_Aint filetype_extent;
00022
00023 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00024 etype_size = fd->etype_size;
00025
00026 if (filetype_is_contig) *disp = fd->disp + etype_size * offset;
00027 else {
00028
00029 flat_file = CtvAccess(ADIOI_Flatlist);
00030 while (flat_file->type != fd->filetype) flat_file = flat_file->next;
00031
00032 MPI_Type_size(fd->filetype, (int*)&filetype_size);
00033 n_etypes_in_filetype = filetype_size/etype_size;
00034 n_filetypes = offset / n_etypes_in_filetype;
00035 etype_in_filetype = offset % n_etypes_in_filetype;
00036 size_in_filetype = etype_in_filetype * etype_size;
00037
00038 sum = 0;
00039 for (i=0; i<flat_file->count; i++) {
00040 sum += flat_file->blocklens[i];
00041 if (sum > size_in_filetype) {
00042 abs_off_in_filetype = flat_file->indices[i] +
00043 size_in_filetype - (sum - flat_file->blocklens[i]);
00044 break;
00045 }
00046 }
00047
00048
00049 MPI_Type_extent(fd->filetype, &filetype_extent);
00050 *disp = fd->disp + n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent + abs_off_in_filetype;
00051 }
00052 }