root/ompi/mca/io/romio321/romio/mpi-io/glue/default/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 /* Hooks for allocation of MPI_File handles.
  11  *
  12  * Three functions are used in ROMIO for allocation/deallocation
  13  * of MPI_File structures:
  14  * - MPIO_File_create(size)
  15  * - MPIO_File_resolve(mpi_fh)
  16  * - MPIO_File_free(mpi_fh)
  17  *
  18  */
  19 
  20 MPI_File MPIO_File_create(int size)
  21 {
  22     MPI_File mpi_fh;
  23 
  24     mpi_fh = (MPI_File) ADIOI_Calloc(size,1);
  25     return mpi_fh;
  26 }
  27 
  28 ADIO_File MPIO_File_resolve(MPI_File mpi_fh)
  29 {
  30     return mpi_fh;
  31 }
  32 
  33 void MPIO_File_free(MPI_File *mpi_fh)
  34 {
  35     ADIOI_Free(*mpi_fh);
  36     *mpi_fh = MPI_FILE_NULL;
  37 }
  38 
  39 extern ADIO_File *ADIOI_Ftable;
  40 extern int ADIOI_Ftable_ptr;
  41 extern int ADIOI_Ftable_max;
  42 
  43 MPI_File MPIO_File_f2c(MPI_Fint fh)
  44 {
  45 #ifndef INT_LT_POINTER
  46     return (MPI_File) ((void *) fh);  
  47     /* the extra cast is to get rid of a compiler warning on Exemplar.
  48        The warning is because MPI_File points to a structure containing
  49        longlongs, which may be 8-byte aligned. But MPI_Fint itself
  50        may not be 8-byte aligned.*/
  51 #else
  52     if (!fh) return MPI_FILE_NULL;
  53     if ((fh < 0) || (fh > ADIOI_Ftable_ptr)) {
  54         FPRINTF(stderr, "MPI_File_f2c: Invalid file handle\n");
  55         /* there is no way to return an error from MPI_File_f2c */
  56         return MPI_FILE_NULL;
  57     }
  58     return ADIOI_Ftable[fh];
  59 #endif
  60 }
  61 
  62 MPI_Fint MPIO_File_c2f(MPI_File fh)
  63 {
  64 #ifndef INT_LT_POINTER
  65     return (MPI_Fint) fh;
  66 #else
  67     int i;
  68 
  69     if ((fh == NULL) || (fh->cookie != ADIOI_FILE_COOKIE))
  70         return (MPI_Fint) 0;
  71     if (!ADIOI_Ftable) {
  72         ADIOI_Ftable_max = 1024;
  73         ADIOI_Ftable = (MPI_File *)
  74             ADIOI_Malloc(ADIOI_Ftable_max*sizeof(MPI_File)); 
  75         ADIOI_Ftable_ptr = 0;  /* 0 can't be used though, because 
  76                                   MPI_FILE_NULL=0 */
  77         for (i=0; i<ADIOI_Ftable_max; i++) ADIOI_Ftable[i] = MPI_FILE_NULL;
  78     }
  79     if (ADIOI_Ftable_ptr == ADIOI_Ftable_max-1) {
  80         ADIOI_Ftable = (MPI_File *) ADIOI_Realloc(ADIOI_Ftable, 
  81                            (ADIOI_Ftable_max+1024)*sizeof(MPI_File));
  82         for (i=ADIOI_Ftable_max; i<ADIOI_Ftable_max+1024; i++) 
  83             ADIOI_Ftable[i] = MPI_FILE_NULL;
  84         ADIOI_Ftable_max += 1024;
  85     }
  86     ADIOI_Ftable_ptr++;
  87     ADIOI_Ftable[ADIOI_Ftable_ptr] = fh;
  88     return (MPI_Fint) ADIOI_Ftable_ptr;
  89 #endif
  90 }

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