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

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_File_seek_shared

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *   Copyright (C) 1997 University of Chicago. 
   4  *   See COPYRIGHT notice in top-level directory.
   5  */
   6 
   7 #include "mpioimpl.h"
   8 
   9 #ifdef HAVE_WEAK_SYMBOLS
  10 
  11 #if defined(HAVE_PRAGMA_WEAK)
  12 #pragma weak MPI_File_seek_shared = PMPI_File_seek_shared
  13 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
  14 #pragma _HP_SECONDARY_DEF PMPI_File_seek_shared MPI_File_seek_shared
  15 #elif defined(HAVE_PRAGMA_CRI_DUP)
  16 #pragma _CRI duplicate MPI_File_seek_shared as PMPI_File_seek_shared
  17 /* end of weak pragmas */
  18 #elif defined(HAVE_WEAK_ATTRIBUTE)
  19 int MPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence) __attribute__((weak,alias("PMPI_File_seek_shared")));
  20 #endif
  21 
  22 /* Include mapping from MPI->PMPI */
  23 #define MPIO_BUILD_PROFILING
  24 #include "mpioprof.h"
  25 #endif
  26 
  27 /*@
  28     MPI_File_seek_shared - Updates the shared file pointer
  29 
  30 Input Parameters:
  31 . fh - file handle (handle)
  32 . offset - file offset (integer)
  33 . whence - update mode (state)
  34 
  35 .N fortran
  36 @*/
  37 int MPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence)
  38 {
  39     int error_code=MPI_SUCCESS, tmp_whence, myrank;
  40     static char myname[] = "MPI_FILE_SEEK_SHARED";
  41     MPI_Offset curr_offset, eof_offset, tmp_offset;
  42     ADIO_File adio_fh;
  43 
  44     ROMIO_THREAD_CS_ENTER();
  45 
  46     adio_fh = MPIO_File_resolve(fh);
  47 
  48     /* --BEGIN ERROR HANDLING-- */
  49     MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code);
  50     MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code);
  51     MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code);
  52     /* --END ERROR HANDLING-- */
  53 
  54     tmp_offset = offset;
  55     MPI_Bcast(&tmp_offset, 1, ADIO_OFFSET, 0, adio_fh->comm);
  56     /* --BEGIN ERROR HANDLING-- */
  57     if (tmp_offset != offset)
  58     {
  59         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
  60                                           myname, __LINE__, MPI_ERR_ARG,
  61                                           "**notsame", 0);
  62         error_code = MPIO_Err_return_file(adio_fh, error_code);
  63         goto fn_exit;
  64     }
  65     /* --END ERROR HANDLING-- */
  66 
  67     tmp_whence = whence;
  68     MPI_Bcast(&tmp_whence, 1, MPI_INT, 0, adio_fh->comm);
  69     /* --BEGIN ERROR HANDLING-- */
  70     if (tmp_whence != whence)
  71     {
  72         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
  73                                           myname, __LINE__, MPI_ERR_ARG,
  74                                           "**iobadwhence", 0);
  75         error_code = MPIO_Err_return_file(adio_fh, error_code);
  76         goto fn_exit;
  77     }
  78     /* --END ERROR HANDLING-- */
  79 
  80     ADIOI_TEST_DEFERRED(adio_fh, "MPI_File_seek_shared", &error_code);
  81 
  82     MPI_Comm_rank(adio_fh->comm, &myrank);
  83 
  84     if (!myrank)
  85     {
  86         switch(whence)
  87         {
  88         case MPI_SEEK_SET:
  89             /* --BEGIN ERROR HANDLING-- */
  90             if (offset < 0)
  91             {
  92                 error_code = MPIO_Err_create_code(MPI_SUCCESS,
  93                                                   MPIR_ERR_RECOVERABLE,
  94                                                   myname, __LINE__,
  95                                                   MPI_ERR_ARG,
  96                                                   "**iobadoffset", 0);
  97                 error_code = MPIO_Err_return_file(adio_fh, error_code);
  98                 goto fn_exit;
  99             }
 100             /* --END ERROR HANDLING-- */
 101             break;
 102         case MPI_SEEK_CUR:
 103             /* get current location of shared file pointer */
 104             ADIO_Get_shared_fp(adio_fh, 0, &curr_offset, &error_code);
 105             /* --BEGIN ERROR HANDLING-- */
 106             if (error_code != MPI_SUCCESS)
 107             {
 108                 error_code = MPIO_Err_create_code(MPI_SUCCESS,
 109                                                   MPIR_ERR_FATAL,
 110                                                   myname, __LINE__,
 111                                                   MPI_ERR_INTERN, 
 112                                                   "**iosharedfailed", 0);
 113                 error_code = MPIO_Err_return_file(adio_fh, error_code);
 114                 goto fn_exit;
 115             }
 116             /* --END ERROR HANDLING-- */
 117             offset += curr_offset;
 118             /* --BEGIN ERROR HANDLING-- */
 119             if (offset < 0)
 120             {
 121                 error_code = MPIO_Err_create_code(MPI_SUCCESS,
 122                                                   MPIR_ERR_RECOVERABLE,
 123                                                   myname, __LINE__,
 124                                                   MPI_ERR_ARG,
 125                                                   "**ionegoffset", 0);
 126                 error_code = MPIO_Err_return_file(adio_fh, error_code);
 127                 goto fn_exit;
 128             }
 129             /* --END ERROR HANDLING-- */
 130             break;
 131         case MPI_SEEK_END:
 132             /* find offset corr. to end of file */
 133             ADIOI_Get_eof_offset(adio_fh, &eof_offset);
 134             offset += eof_offset;
 135             /* --BEGIN ERROR HANDLING-- */
 136             if (offset < 0)
 137             {
 138                 error_code = MPIO_Err_create_code(MPI_SUCCESS,
 139                                                   MPIR_ERR_RECOVERABLE,
 140                                                   myname, __LINE__,
 141                                                   MPI_ERR_ARG,
 142                                                   "**ionegoffset", 0);
 143                 error_code = MPIO_Err_return_file(adio_fh, error_code);
 144                 goto fn_exit;
 145             }
 146             /* --END ERROR HANDLING-- */
 147             break;
 148         default:
 149             /* --BEGIN ERROR HANDLING-- */
 150             error_code = MPIO_Err_create_code(MPI_SUCCESS,
 151                                               MPIR_ERR_RECOVERABLE,
 152                                               myname, __LINE__, MPI_ERR_ARG,
 153                                               "**iobadwhence", 0);
 154             error_code = MPIO_Err_return_file(adio_fh, error_code);
 155             goto fn_exit;
 156             /* --END ERROR HANDLING-- */
 157         }
 158 
 159         ADIO_Set_shared_fp(adio_fh, offset, &error_code);
 160         /* --BEGIN ERROR HANDLING-- */
 161         if (error_code != MPI_SUCCESS)
 162         {
 163             error_code = MPIO_Err_create_code(MPI_SUCCESS,
 164                                               MPIR_ERR_FATAL,
 165                                               myname, __LINE__,
 166                                               MPI_ERR_INTERN, 
 167                                               "**iosharedfailed", 0);
 168             error_code = MPIO_Err_return_file(adio_fh, error_code);
 169             goto fn_exit;
 170         }
 171         /* --END ERROR HANDLING-- */
 172 
 173     }
 174 
 175     /* FIXME: explain why the barrier is necessary */
 176     MPI_Barrier(adio_fh->comm);
 177 
 178     error_code = MPI_SUCCESS;
 179 
 180 fn_exit:
 181     ROMIO_THREAD_CS_EXIT();
 182 
 183     return error_code;
 184 }

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