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