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