00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #include "adio.h"
00018 #include "mpi.h"
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include "mpipr.h"
00022 
00023 #ifdef HAVE_MALLOC_H
00024 #include <malloc.h>
00025 #endif
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 #define FPRINTF fprintf
00034 
00035 void *ADIOI_Malloc_fn(size_t size, int lineno, const char *fname);
00036 void *ADIOI_Calloc_fn(size_t nelem, size_t elsize, int lineno, const char *fname);
00037 void *ADIOI_Realloc_fn(void *ptr, size_t size, int lineno, const char *fname);
00038 void ADIOI_Free_fn(void *ptr, int lineno, const char *fname);
00039 
00040 void *ADIOI_Malloc_fn(size_t size, int lineno, const char *fname)
00041 {
00042     void *new;
00043 
00044 #ifdef ROMIO_XFS
00045     new = (void *) memalign(XFS_MEMALIGN, size);
00046 #else
00047 #ifdef HAVE_MPIU_FUNCS
00048     new = (void *) MPIU_Malloc(size);
00049 #else
00050     new = (void *) malloc(size);
00051 #endif
00052 #endif
00053     if (!new) {
00054     FPRINTF(stderr, "Out of memory in file %s, line %d\n", fname, lineno);
00055     MPI_Abort(MPI_COMM_WORLD, 1);
00056     }
00057     DBG_FPRINTF(stderr, "ADIOI_Malloc %s:<%d> %p (%#zX)\n", fname, lineno, new, size);
00058     return new;
00059 }
00060 
00061 
00062 void *ADIOI_Calloc_fn(size_t nelem, size_t elsize, int lineno, const char *fname)
00063 {
00064     void *new;
00065 
00066 #ifdef HAVE_MPIU_FUNCS
00067     new = (void *) MPIU_Calloc(nelem, elsize);
00068 #else
00069     new = (void *) calloc(nelem, elsize);
00070 #endif
00071     if (!new) {
00072     FPRINTF(stderr, "Out of memory in file %s, line %d\n", fname, lineno);
00073     MPI_Abort(MPI_COMM_WORLD, 1);
00074     }
00075     DBG_FPRINTF(stderr, "ADIOI_Calloc %s:<%d> %p\n", fname, lineno, new);
00076     return new;
00077 }
00078 
00079 
00080 void *ADIOI_Realloc_fn(void *ptr, size_t size, int lineno, const char *fname)
00081 {
00082     void *new;
00083 
00084 #ifdef HAVE_MPIU_FUNCS
00085     new = (void *) MPIU_Realloc(ptr, size);
00086 #else
00087     new = (void *) realloc(ptr, size);
00088 #endif
00089     if (!new) {
00090     FPRINTF(stderr, "realloc failed in file %s, line %d\n", fname, lineno);
00091     MPI_Abort(MPI_COMM_WORLD, 1);
00092     }
00093     DBG_FPRINTF(stderr, "ADIOI_Realloc %s:<%d> %p\n", fname, lineno, new);
00094     return new;
00095 }
00096 
00097 
00098 void ADIOI_Free_fn(void *ptr, int lineno, const char *fname)
00099 {
00100     DBG_FPRINTF(stderr, "ADIOI_Free %s:<%d> %p\n", fname, lineno, ptr);
00101     if (!ptr) {
00102     FPRINTF(stderr, "Attempt to free null pointer in file %s, line %d\n", fname, lineno);
00103     MPI_Abort(MPI_COMM_WORLD, 1);
00104     }
00105 
00106 #ifdef HAVE_MPIU_FUNCS
00107     MPIU_Free(ptr);
00108 #else
00109     free(ptr);
00110 #endif
00111 }
00112 
00113