root/ompi/mca/io/romio321/romio/mpi-io/glue/mpich/mpio_file.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPIO_File_create
  2. MPIO_File_resolve
  3. MPIO_File_free
  4. MPIO_File_f2c
  5. MPIO_File_c2f

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 2004 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "mpioimpl.h"
   9 
  10 #include "adio_extern.h"
  11 
  12 /* Hooks for allocation of MPI_File handles.
  13  *
  14  * Three functions are used in ROMIO for allocation/deallocation
  15  * of MPI_File structures:
  16  * - MPIO_File_create(size)
  17  * - MPIO_File_resolve(mpi_fh)
  18  * - MPIO_File_free(mpi_fh)
  19  *
  20  */
  21 
  22 MPI_File MPIO_File_create(int size)
  23 {
  24     MPI_File mpi_fh;
  25 
  26     mpi_fh = (MPI_File) ADIOI_Calloc(size,1);
  27     return mpi_fh;
  28 }
  29 
  30 ADIO_File MPIO_File_resolve(MPI_File mpi_fh)
  31 {
  32     return mpi_fh;
  33 }
  34 
  35 void MPIO_File_free(MPI_File *mpi_fh)
  36 {
  37     ADIOI_Free(*mpi_fh);
  38     *mpi_fh = MPI_FILE_NULL;
  39 }
  40 
  41 MPI_File MPIO_File_f2c(MPI_Fint fh)
  42 {
  43 #ifndef INT_LT_POINTER
  44     return (MPI_File) ((void *) fh);  
  45     /* the extra cast is to get rid of a compiler warning on Exemplar.
  46        The warning is because MPI_File points to a structure containing
  47        longlongs, which may be 8-byte aligned. But MPI_Fint itself
  48        may not be 8-byte aligned.*/
  49 #else
  50     if (!fh) return MPI_FILE_NULL;
  51     if ((fh < 0) || (fh > ADIOI_Ftable_ptr)) {
  52         /* there is no way to return an error from MPI_File_f2c */
  53         return MPI_FILE_NULL;
  54     }
  55     return ADIOI_Ftable[fh];
  56 #endif
  57 }
  58 
  59 MPI_Fint MPIO_File_c2f(MPI_File fh)
  60 {
  61 #ifndef INT_LT_POINTER
  62     return (MPI_Fint) fh;
  63 #else
  64     int i;
  65 
  66     if ((fh == NULL) || (fh->cookie != ADIOI_FILE_COOKIE))
  67         return (MPI_Fint) 0;
  68 
  69     if (fh->fortran_handle != -1)
  70         return fh->fortran_handle;
  71 
  72     if (!ADIOI_Ftable) {
  73         ADIOI_Ftable_max = 1024;
  74         ADIOI_Ftable = (MPI_File *)
  75             ADIOI_Malloc(ADIOI_Ftable_max*sizeof(MPI_File)); 
  76         ADIOI_Ftable_ptr = 0;  /* 0 can't be used though, because 
  77                                   MPI_FILE_NULL=0 */
  78         for (i=0; i<ADIOI_Ftable_max; i++) ADIOI_Ftable[i] = MPI_FILE_NULL;
  79     }
  80     if (ADIOI_Ftable_ptr == ADIOI_Ftable_max-1) {
  81         ADIOI_Ftable = (MPI_File *) ADIOI_Realloc(ADIOI_Ftable, 
  82                            (ADIOI_Ftable_max+1024)*sizeof(MPI_File));
  83         for (i=ADIOI_Ftable_max; i<ADIOI_Ftable_max+1024; i++) 
  84             ADIOI_Ftable[i] = MPI_FILE_NULL;
  85         ADIOI_Ftable_max += 1024;
  86     }
  87     ADIOI_Ftable_ptr++;
  88     ADIOI_Ftable[ADIOI_Ftable_ptr] = fh;
  89     fh->fortran_handle = ADIOI_Ftable_ptr;
  90     return (MPI_Fint) ADIOI_Ftable_ptr;
  91 #endif
  92 }

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