root/ompi/mca/io/romio321/romio/adio/common/ad_get_sh_fp.c

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

DEFINITIONS

This source file includes following definitions.
  1. ADIO_Get_shared_fp

   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 "adio.h"
   8 
   9 /* returns the current location of the shared_fp in terms of the
  10    no. of etypes relative to the current view, and also increments the
  11    shared_fp by the number of etypes to be accessed (incr) in the read
  12    or write following this function. */
  13 
  14 void ADIOI_NFS_Get_shared_fp(ADIO_File fd, ADIO_Offset incr, ADIO_Offset *shared_fp,
  15                              int *error_code);
  16 
  17 void ADIO_Get_shared_fp(ADIO_File fd, ADIO_Offset incr, ADIO_Offset *shared_fp,
  18                          int *error_code)
  19 {
  20     ADIO_Status status;
  21     ADIO_Offset new_fp;
  22     MPI_Comm dupcommself;
  23 
  24     /* Set the shared_fp in case this comes from an uninitialized stack variable
  25        The read routines will not read into the address of this variable if the file
  26        size of a shared pointer is 0, and if incr is always zero, this value will remain
  27        uninitialized.  Initialize it here to prevent incorrect values
  28     */
  29     *shared_fp = 0;
  30 
  31 #ifdef ROMIO_NFS
  32     if (fd->file_system == ADIO_NFS) {
  33         ADIOI_NFS_Get_shared_fp(fd, incr, shared_fp, error_code);
  34         return;
  35     }
  36 #endif
  37 
  38     if (fd->shared_fp_fd == ADIO_FILE_NULL) {
  39         MPI_Comm_dup(MPI_COMM_SELF, &dupcommself);
  40         fd->shared_fp_fd = ADIO_Open(MPI_COMM_SELF, dupcommself, 
  41                                      fd->shared_fp_fname, 
  42                                      fd->file_system,
  43                                      fd->fns,
  44                                      ADIO_CREATE | ADIO_RDWR | ADIO_DELETE_ON_CLOSE, 
  45                                      0, MPI_BYTE, MPI_BYTE,
  46                                      MPI_INFO_NULL, 
  47                                      ADIO_PERM_NULL, error_code);
  48         if (*error_code != MPI_SUCCESS) return;
  49         ADIOI_WRITE_LOCK(fd->shared_fp_fd, 0, SEEK_SET, sizeof(ADIO_Offset));
  50         ADIO_ReadContig(fd->shared_fp_fd, shared_fp, sizeof(ADIO_Offset), 
  51                        MPI_BYTE, ADIO_EXPLICIT_OFFSET, 0, &status, error_code);
  52         /* if the file is empty, the above function may return error
  53            (reading beyond end of file). In that case, shared_fp = 0, 
  54            set above, is the correct value. */
  55     }
  56     else {
  57         ADIOI_WRITE_LOCK(fd->shared_fp_fd, 0, SEEK_SET, sizeof(ADIO_Offset));
  58         ADIO_ReadContig(fd->shared_fp_fd, shared_fp, sizeof(ADIO_Offset), 
  59                        MPI_BYTE, ADIO_EXPLICIT_OFFSET, 0, &status, error_code);
  60         if (*error_code != MPI_SUCCESS) {
  61             ADIOI_UNLOCK(fd->shared_fp_fd, 0, SEEK_SET, sizeof(ADIO_Offset));
  62             return;
  63         }
  64     }
  65 
  66     if (incr == 0) {goto done;}
  67 
  68     new_fp = *shared_fp + incr;
  69 
  70     ADIO_WriteContig(fd->shared_fp_fd, &new_fp, sizeof(ADIO_Offset), 
  71                     MPI_BYTE, ADIO_EXPLICIT_OFFSET, 0, &status, error_code);
  72 done:
  73     ADIOI_UNLOCK(fd->shared_fp_fd, 0, SEEK_SET, sizeof(ADIO_Offset));
  74 }

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