00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "mpioimpl.h"
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 MPI_File MPIO_File_create(int size)
00021 {
00022     MPI_File mpi_fh;
00023 
00024     mpi_fh = (MPI_File) ADIOI_Malloc(size);
00025     return mpi_fh;
00026 }
00027 
00028 ADIO_File MPIO_File_resolve(MPI_File mpi_fh)
00029 {
00030     return mpi_fh;
00031 }
00032 
00033 void MPIO_File_free(MPI_File *mpi_fh)
00034 {
00035     ADIOI_Free(*mpi_fh);
00036     *mpi_fh = MPI_FILE_NULL;
00037 }
00038 
00039 CtvExtern(ADIO_File*, ADIOI_Ftable);
00040 CtvExtern(int, ADIOI_Ftable_ptr);
00041 CtvExtern(int, ADIOI_Ftable_max);
00042 
00043 MPI_File MPIO_File_f2c(MPI_Fint fh)
00044 {
00045 #ifndef INT_LT_POINTER
00046     return (MPI_File) ((void *) fh);  
00047     
00048 
00049 
00050 
00051 #else
00052     if (!fh) return MPI_FILE_NULL;
00053     if ((fh < 0) || (fh > CtvAccess(ADIOI_Ftable_ptr))) {
00054     FPRINTF(stderr, "MPI_File_f2c: Invalid file handle\n");
00055     
00056     return MPI_FILE_NULL;
00057     }
00058     return CtvAccess(ADIOI_Ftable)[fh];
00059 #endif
00060 }
00061 
00062 MPI_Fint MPIO_File_c2f(MPI_File fh)
00063 {
00064 #ifndef INT_LT_POINTER
00065     return (MPI_Fint) fh;
00066 #else
00067     int i;
00068 
00069     if ((fh <= (MPI_File) 0) || (fh->cookie != ADIOI_FILE_COOKIE))
00070     return (MPI_Fint) 0;
00071     if (!CtvAccess(ADIOI_Ftable)) {
00072     CtvAccess(ADIOI_Ftable_max) = 1024;
00073     CtvAccess(ADIOI_Ftable) = (MPI_File *)
00074         ADIOI_Malloc(CtvAccess(ADIOI_Ftable_max)*sizeof(MPI_File)); 
00075         CtvAccess(ADIOI_Ftable_ptr) = 0;  
00076 
00077     for (i=0; i<CtvAccess(ADIOI_Ftable_max); i++) CtvAccess(ADIOI_Ftable)[i] = MPI_FILE_NULL;
00078     }
00079     if (CtvAccess(ADIOI_Ftable_ptr) == CtvAccess(ADIOI_Ftable_max)-1) {
00080     CtvAccess(ADIOI_Ftable) = (MPI_File *) ADIOI_Realloc(CtvAccess(ADIOI_Ftable), 
00081                            (CtvAccess(ADIOI_Ftable_max)+1024)*sizeof(MPI_File));
00082     for (i=CtvAccess(ADIOI_Ftable_max); i<CtvAccess(ADIOI_Ftable_max)+1024; i++) 
00083         CtvAccess(ADIOI_Ftable)[i] = MPI_FILE_NULL;
00084     CtvAccess(ADIOI_Ftable_max) += 1024;
00085     }
00086     CtvAccess(ADIOI_Ftable_ptr)++;
00087     CtvAccess(ADIOI_Ftable)[CtvAccess(ADIOI_Ftable_ptr)] = fh;
00088     return (MPI_Fint) CtvAccess(ADIOI_Ftable_ptr);
00089 #endif
00090 }