00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009 #include "adio_extern.h"
00010
00011
00012
00013
00014
00015
00016 void ADIOI_GEN_Prealloc(ADIO_File fd, ADIO_Offset diskspace, int *error_code)
00017 {
00018 ADIO_Offset curr_fsize, alloc_size, size, len, done;
00019 ADIO_Status status;
00020 int i, ntimes;
00021 char *buf;
00022 ADIO_Fcntl_t *fcntl_struct;
00023 static char myname[] = "ADIOI_GEN_PREALLOC";
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t));
00036 ADIO_Fcntl(fd, ADIO_FCNTL_GET_FSIZE, fcntl_struct, error_code);
00037
00038 curr_fsize = fcntl_struct->fsize;
00039
00040 alloc_size = diskspace;
00041
00042 size = ADIOI_MIN(curr_fsize, alloc_size);
00043
00044 ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00045 buf = (char *) ADIOI_Malloc(ADIOI_PREALLOC_BUFSZ);
00046 done = 0;
00047
00048 for (i=0; i<ntimes; i++) {
00049 len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
00050 ADIO_ReadContig(fd, buf,
00051 len,
00052
00053 MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
00054 &status, error_code);
00055 if (*error_code != MPI_SUCCESS) {
00056 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00057 MPIR_ERR_RECOVERABLE,
00058 myname, __LINE__,
00059 MPI_ERR_IO,
00060 "**iopreallocrdwr",
00061 0);
00062 return;
00063 }
00064 ADIO_WriteContig(fd, buf,
00065 len,
00066
00067 MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00068 done, &status, error_code);
00069 if (*error_code != MPI_SUCCESS) return;
00070 done += len;
00071 }
00072
00073 if (alloc_size > curr_fsize) {
00074 memset(buf, 0, ADIOI_PREALLOC_BUFSZ);
00075 size = alloc_size - curr_fsize;
00076 ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00077 for (i=0; i<ntimes; i++) {
00078 len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
00079 ADIO_WriteContig(fd, buf,
00080 len,
00081
00082 MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00083 done, &status, error_code);
00084 if (*error_code != MPI_SUCCESS) return;
00085 done += len;
00086 }
00087 }
00088 ADIOI_Free(fcntl_struct);
00089 ADIOI_Free(buf);
00090 *error_code = MPI_SUCCESS;
00091 }