| 1 |
/* |
| 2 |
* Copyright (C) by Argonne National Laboratory |
| 3 |
* See COPYRIGHT in top-level directory |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "mpioimpl.h" |
| 7 |
|
| 8 |
/* Hooks for allocation of MPI_File handles. |
| 9 |
* |
| 10 |
* Three functions are used in ROMIO for allocation/deallocation |
| 11 |
* of MPI_File structures: |
| 12 |
* - MPIO_File_create(size) |
| 13 |
* - MPIO_File_resolve(mpi_fh) |
| 14 |
* - MPIO_File_free(mpi_fh) |
| 15 |
* |
| 16 |
*/ |
| 17 |
|
| 18 |
MPI_File MPIO_File_create(int size) |
| 19 |
{ |
| 20 |
MPI_File mpi_fh; |
| 21 |
|
| 22 |
mpi_fh = (MPI_File) ADIOI_Calloc(size, 1); |
| 23 |
return mpi_fh; |
| 24 |
} |
| 25 |
|
| 26 |
ADIO_File MPIO_File_resolve(MPI_File mpi_fh) |
| 27 |
{ |
| 28 |
return mpi_fh; |
| 29 |
} |
| 30 |
|
| 31 |
void MPIO_File_free(MPI_File * mpi_fh) |
| 32 |
{ |
| 33 |
ADIOI_Free(*mpi_fh); |
| 34 |
*mpi_fh = MPI_FILE_NULL; |
| 35 |
} |
| 36 |
|
| 37 |
extern ADIO_File *ADIOI_Ftable; |
| 38 |
extern int ADIOI_Ftable_ptr; |
| 39 |
extern int ADIOI_Ftable_max; |
| 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) |
| 51 |
return MPI_FILE_NULL; |
| 52 |
if ((fh < 0) || (fh > ADIOI_Ftable_ptr)) { |
| 53 |
FPRINTF(stderr, "MPI_File_f2c: Invalid file handle\n"); |
| 54 |
/* there is no way to return an error from MPI_File_f2c */ |
| 55 |
return MPI_FILE_NULL; |
| 56 |
} |
| 57 |
return ADIOI_Ftable[fh]; |
| 58 |
#endif |
| 59 |
} |
| 60 |
|
| 61 |
MPI_Fint MPIO_File_c2f(MPI_File fh) |
| 62 |
{ |
| 63 |
#ifndef INT_LT_POINTER |
| 64 |
return (MPI_Fint) fh; |
| 65 |
#else |
| 66 |
int i; |
| 67 |
|
| 68 |
if ((fh == MPI_FILE_NULL) || (fh->cookie != ADIOI_FILE_COOKIE)) |
| 69 |
return (MPI_Fint) 0; |
| 70 |
if (!ADIOI_Ftable) { |
| 71 |
ADIOI_Ftable_max = 1024; |
| 72 |
ADIOI_Ftable = (MPI_File *) |
| 73 |
ADIOI_Malloc(ADIOI_Ftable_max * sizeof(MPI_File)); |
| 74 |
ADIOI_Ftable_ptr = 0; /* 0 can't be used though, because |
| 75 |
* MPI_FILE_NULL=0 */ |
| 76 |
for (i = 0; i < ADIOI_Ftable_max; i++) |
| 77 |
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 |
} |