00001
00002
00003
00004
00005
00006
00007 #include "adio.h"
00008 #include "adio_extern.h"
00009
00010 #ifdef HAVE_UNISTD_H
00011 #include <unistd.h>
00012 #endif
00013
00014 ADIO_Offset ADIOI_GEN_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
00015 int whence, int *error_code)
00016 {
00017
00018
00019
00020
00021
00022 ADIO_Offset off;
00023 ADIOI_Flatlist_node *flat_file;
00024
00025 int i;
00026 ADIO_Offset n_etypes_in_filetype, n_filetypes, etype_in_filetype;
00027 ADIO_Offset abs_off_in_filetype=0;
00028 ADIO_Offset size_in_filetype, sum;
00029 unsigned filetype_size;
00030 int etype_size, filetype_is_contig;
00031 MPI_Aint filetype_extent;
00032
00033 ADIOI_UNREFERENCED_ARG(whence);
00034
00035 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00036 etype_size = fd->etype_size;
00037
00038 if (filetype_is_contig) off = fd->disp + (ADIO_Offset)etype_size * offset;
00039 else {
00040 flat_file = CtvAccess(ADIOI_Flatlist);
00041 while (flat_file->type != fd->filetype) flat_file = flat_file->next;
00042
00043 MPI_Type_extent(fd->filetype, &filetype_extent);
00044 MPI_Type_size(fd->filetype, (int*)&filetype_size);
00045 if ( ! filetype_size ) {
00046
00047
00048
00049 *error_code = MPI_SUCCESS;
00050 return 0;
00051 }
00052
00053 n_etypes_in_filetype = filetype_size/etype_size;
00054 n_filetypes = offset / n_etypes_in_filetype;
00055 etype_in_filetype = offset % n_etypes_in_filetype;
00056 size_in_filetype = etype_in_filetype * etype_size;
00057
00058 sum = 0;
00059 for (i=0; i<flat_file->count; i++) {
00060 sum += flat_file->blocklens[i];
00061 if (sum > size_in_filetype) {
00062 abs_off_in_filetype = flat_file->indices[i] +
00063 size_in_filetype - (sum - flat_file->blocklens[i]);
00064 break;
00065 }
00066 }
00067
00068
00069 off = fd->disp + n_filetypes * filetype_extent +
00070 abs_off_in_filetype;
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 fd->fp_ind = off;
00082
00083 *error_code = MPI_SUCCESS;
00084
00085 return off;
00086 }