00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_pvfs.h"
00010 #include "adio_extern.h"
00011 #ifdef PROFILE
00012 #include "mpe.h"
00013 #endif
00014
00015 ADIO_Offset ADIOI_PVFS_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
00016 int whence, int *error_code)
00017 {
00018
00019
00020
00021
00022
00023 #ifndef PRINT_ERR_MSG
00024 static char myname[] = "ADIOI_PVFS_SEEKINDIVIDUAL";
00025 #endif
00026 ADIO_Offset off, err;
00027 ADIOI_Flatlist_node *flat_file;
00028
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 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00036 etype_size = fd->etype_size;
00037
00038 if (filetype_is_contig) off = fd->disp + etype_size * offset;
00039 else {
00040 flat_file = 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, &filetype_size);
00045 if ( ! filetype_size ) {
00046 *error_code = MPI_SUCCESS;
00047 return 0;
00048 }
00049
00050 n_etypes_in_filetype = filetype_size/etype_size;
00051 n_filetypes = (int) (offset / n_etypes_in_filetype);
00052 etype_in_filetype = (int) (offset % n_etypes_in_filetype);
00053 size_in_filetype = etype_in_filetype * etype_size;
00054
00055 sum = 0;
00056 for (i=0; i<flat_file->count; i++) {
00057 sum += flat_file->blocklens[i];
00058 if (sum > size_in_filetype) {
00059 abs_off_in_filetype = flat_file->indices[i] +
00060 size_in_filetype - (sum - flat_file->blocklens[i]);
00061 break;
00062 }
00063 }
00064
00065
00066 off = fd->disp + (ADIO_Offset) n_filetypes * filetype_extent +
00067 abs_off_in_filetype;
00068 }
00069
00070 #ifdef PROFILE
00071 MPE_Log_event(11, 0, "start seek");
00072 #endif
00073 err = pvfs_lseek64(fd->fd_sys, off, SEEK_SET);
00074 #ifdef PROFILE
00075 MPE_Log_event(12, 0, "end seek");
00076 #endif
00077 fd->fp_ind = off;
00078 fd->fp_sys_posn = off;
00079
00080 #ifdef PRINT_ERR_MSG
00081 *error_code = (err == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00082 #else
00083 if (err == -1) {
00084 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00085 myname, "I/O Error", "%s", strerror(errno));
00086 ADIOI_Error(fd, *error_code, myname);
00087 }
00088 else *error_code = MPI_SUCCESS;
00089 #endif
00090 return off;
00091 }