root/ompi/mca/io/romio321/romio/mpi-io/seek.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. MPI_File_seek

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 1997 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "mpioimpl.h"
   9 #include "adioi.h"
  10 
  11 #ifdef HAVE_WEAK_SYMBOLS
  12 
  13 #if defined(HAVE_PRAGMA_WEAK)
  14 #pragma weak MPI_File_seek = PMPI_File_seek
  15 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
  16 #pragma _HP_SECONDARY_DEF PMPI_File_seek MPI_File_seek
  17 #elif defined(HAVE_PRAGMA_CRI_DUP)
  18 #pragma _CRI duplicate MPI_File_seek as PMPI_File_seek
  19 /* end of weak pragmas */
  20 #elif defined(HAVE_WEAK_ATTRIBUTE)
  21 int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence) __attribute__((weak,alias("PMPI_File_seek")));
  22 #endif
  23 
  24 /* Include mapping from MPI->PMPI */
  25 #define MPIO_BUILD_PROFILING
  26 #include "mpioprof.h"
  27 #endif
  28 
  29 /*@
  30     MPI_File_seek - Updates the individual file pointer
  31 
  32 Input Parameters:
  33 . fh - file handle (handle)
  34 . offset - file offset (integer)
  35 . whence - update mode (state)
  36 
  37 .N fortran
  38 @*/
  39 int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence)
  40 {
  41     int error_code;
  42     ADIO_File adio_fh;
  43     static char myname[] = "MPI_FILE_SEEK";
  44     MPI_Offset curr_offset, eof_offset;
  45 
  46 #ifdef MPI_hpux
  47     int fl_xmpi;
  48 
  49     HPMP_IO_START(fl_xmpi, BLKMPIFILESEEK, TRDTBLOCK, adio_fh, MPI_DATATYPE_NULL, -1);
  50 #endif /* MPI_hpux */
  51 
  52     ROMIO_THREAD_CS_ENTER();
  53 
  54     adio_fh = MPIO_File_resolve(fh);
  55 
  56     /* --BEGIN ERROR HANDLING-- */
  57     MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code);
  58     MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code);
  59     /* --END ERROR HANDLING-- */
  60 
  61     switch(whence) {
  62     case MPI_SEEK_SET:
  63         /* --BEGIN ERROR HANDLING-- */
  64         if (offset < 0) {
  65             error_code = MPIO_Err_create_code(MPI_SUCCESS,
  66                                               MPIR_ERR_RECOVERABLE, myname,
  67                                               __LINE__, MPI_ERR_ARG,
  68                                               "**iobadoffset", 0);
  69             error_code = MPIO_Err_return_file(adio_fh, error_code);
  70             goto fn_exit;
  71         }
  72         /* --END ERROR HANDLING-- */
  73         break;
  74     case MPI_SEEK_CUR:
  75         /* find offset corr. to current location of file pointer */
  76         ADIOI_Get_position(adio_fh, &curr_offset);
  77         offset += curr_offset;
  78 
  79         /* --BEGIN ERROR HANDLING-- */
  80         if (offset < 0) {
  81             error_code = MPIO_Err_create_code(MPI_SUCCESS,
  82                                               MPIR_ERR_RECOVERABLE, myname,
  83                                               __LINE__, MPI_ERR_ARG,
  84                                               "**ionegoffset", 0);
  85             error_code = MPIO_Err_return_file(adio_fh, error_code);
  86             goto fn_exit;
  87         }
  88         /* --END ERROR HANDLING-- */
  89 
  90         break;
  91     case MPI_SEEK_END:
  92         /* we can in many cases do seeks w/o a file actually opened, but not in
  93          * the MPI_SEEK_END case */
  94         ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_seek", &error_code);
  95 
  96         /* find offset corr. to end of file */
  97         ADIOI_Get_eof_offset(adio_fh, &eof_offset);
  98         offset += eof_offset;
  99 
 100         /* --BEGIN ERROR HANDLING-- */
 101         if (offset < 0) {
 102             error_code = MPIO_Err_create_code(MPI_SUCCESS,
 103                                               MPIR_ERR_RECOVERABLE, myname,
 104                                               __LINE__, MPI_ERR_ARG,
 105                                               "**ionegoffset", 0);
 106             error_code = MPIO_Err_return_file(adio_fh, error_code);
 107             goto fn_exit;
 108         }
 109         /* --END ERROR HANDLING-- */
 110 
 111         break;
 112     default:
 113         /* --BEGIN ERROR HANDLING-- */
 114         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
 115                                           myname, __LINE__, MPI_ERR_ARG,
 116                                           "**iobadwhence", 0);
 117         error_code = MPIO_Err_return_file(adio_fh, error_code);
 118         goto fn_exit;
 119         /* --END ERROR HANDLING-- */
 120     }
 121 
 122     ADIO_SeekIndividual(adio_fh, offset, ADIO_SEEK_SET, &error_code);
 123     /* TODO: what do we do with this error? */
 124 
 125     /* --BEGIN ERROR HANDLING-- */
 126     if (error_code != MPI_SUCCESS)
 127         error_code = MPIO_Err_return_file(adio_fh, error_code);
 128     /* --END ERROR HANDLING-- */
 129 
 130 #ifdef MPI_hpux
 131     HPMP_IO_END(fl_xmpi, adio_fh, MPI_DATATYPE_NULL, -1);
 132 #endif /* MPI_hpux */
 133 
 134     error_code = MPI_SUCCESS;
 135 
 136 fn_exit:
 137     ROMIO_THREAD_CS_EXIT();
 138     return error_code;
 139 }

/* [<][>][^][v][top][bottom][index][help] */