00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009 #include "adio_extern.h"
00010
00011 #ifdef HAVE_UNISTD_H
00012 #include <unistd.h>
00013 #endif
00014
00015 void ADIO_Close(ADIO_File fd, int *error_code)
00016 {
00017 int i, j, k, combiner, myrank, err, is_contig;
00018 static char myname[] = "ADIO_CLOSE";
00019
00020 if (fd->async_count) {
00021 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00022 myname, __LINE__, MPI_ERR_IO, "**io",
00023 "**io %s", strerror(errno));
00024 return;
00025 }
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 if (fd->agg_comm != MPI_COMM_NULL) {
00039 (*(fd->fns->ADIOI_xxx_Close))(fd, error_code);
00040 } else {
00041 if(fd->is_open) {
00042 (*(fd->fns->ADIOI_xxx_Close))(fd, error_code);
00043 } else {
00044 *error_code = MPI_SUCCESS;
00045 }
00046
00047 }
00048
00049 if (fd->access_mode & ADIO_DELETE_ON_CLOSE) {
00050
00051
00052
00053 MPI_Comm_rank(fd->comm, &myrank);
00054 if (myrank == fd->hints->ranklist[0]) {
00055 ADIO_Delete(fd->filename, &err);
00056 }
00057 MPI_Barrier(fd->comm);
00058 }
00059
00060 if (fd->fortran_handle != -1) {
00061 CtvAccess(ADIOI_Ftable)[fd->fortran_handle] = MPI_FILE_NULL;
00062 }
00063
00064 if (fd->hints && fd->hints->ranklist) ADIOI_Free(fd->hints->ranklist);
00065 if (fd->hints && fd->hints->cb_config_list) ADIOI_Free(fd->hints->cb_config_list);
00066
00067
00068 if (fd->hints->cb_pfr == ADIOI_HINT_ENABLE) {
00069
00070 if (1) {
00071 ADIOI_Delete_flattened (fd->file_realm_types[0]);
00072 MPI_Type_free (&fd->file_realm_types[0]);
00073 }
00074 else {
00075 for (i=0; i<fd->hints->cb_nodes; i++) {
00076 ADIOI_Datatype_iscontig(fd->file_realm_types[i], &is_contig);
00077 if (!is_contig)
00078 ADIOI_Delete_flattened(fd->file_realm_types[i]);
00079 MPI_Type_free (&fd->file_realm_types[i]);
00080 }
00081 }
00082 ADIOI_Free(fd->file_realm_st_offs);
00083 ADIOI_Free(fd->file_realm_types);
00084 }
00085 if (fd->hints) ADIOI_Free(fd->hints);
00086
00087
00088
00089 MPI_Comm_free(&(fd->comm));
00090
00091 if (fd->agg_comm != MPI_COMM_NULL) {
00092 MPI_Comm_free(&(fd->agg_comm));
00093 }
00094 ADIOI_Free(fd->filename);
00095
00096 MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);
00097 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));
00098
00099 ADIOI_Datatype_iscontig(fd->filetype, &is_contig);
00100 if (!is_contig) ADIOI_Delete_flattened(fd->filetype);
00101
00102 MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);
00103 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));
00104
00105 MPI_Info_free(&(fd->info));
00106
00107
00108 }