00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "adio.h"
00010 #include "adio_extern.h"
00011 #include "adio_cb_config_list.h"
00012 #ifdef MPISGI
00013 #include "mpisgi2.h"
00014 #endif
00015
00016 ADIO_File ADIO_Open(MPI_Comm orig_comm,
00017 MPI_Comm comm, char *filename, int file_system,
00018 int access_mode, ADIO_Offset disp, MPI_Datatype etype,
00019 MPI_Datatype filetype, int iomode,
00020 MPI_Info info, int perm, int *error_code)
00021 {
00022 ADIO_File fd;
00023 ADIO_cb_name_array array;
00024 int orig_amode, err, rank, procs;
00025 char *value;
00026 #ifndef PRINT_ERR_MSG
00027 static char myname[] = "ADIO_OPEN";
00028 #endif
00029
00030 int rank_ct;
00031 int *tmp_ranklist;
00032
00033 *error_code = MPI_SUCCESS;
00034
00035 fd = (ADIO_File) ADIOI_Malloc(sizeof(struct ADIOI_FileD));
00036 if (fd == NULL) {
00037
00038 }
00039
00040 fd->cookie = ADIOI_FILE_COOKIE;
00041 fd->fp_ind = disp;
00042 fd->fp_sys_posn = 0;
00043 fd->comm = comm;
00044 fd->filename = strdup(filename);
00045 fd->file_system = file_system;
00046 fd->disp = disp;
00047 fd->split_coll_count = 0;
00048 fd->shared_fp_fd = ADIO_FILE_NULL;
00049 fd->atomicity = 0;
00050
00051 fd->etype = etype;
00052 fd->filetype = filetype;
00053 fd->etype_size = 1;
00054
00055 fd->perm = perm;
00056
00057 fd->iomode = iomode;
00058 fd->async_count = 0;
00059
00060 fd->err_handler = ADIOI_DFLT_ERR_HANDLER;
00061
00062
00063 ADIOI_SetFunctions(fd);
00064
00065
00066 fd->hints = (ADIOI_Hints *)ADIOI_Malloc(sizeof(struct ADIOI_Hints_struct));
00067 if (fd->hints == NULL) {
00068
00069 }
00070 fd->hints->cb_config_list = NULL;
00071 fd->hints->ranklist = NULL;
00072 fd->hints->initialized = 0;
00073 fd->info = MPI_INFO_NULL;
00074 ADIO_SetInfo(fd, info, &err);
00075
00076
00077
00078
00079
00080
00081
00082 ADIOI_cb_gather_name_array(orig_comm, comm, &array);
00083
00084
00085 MPI_Comm_rank(comm, &rank);
00086 if (rank == 0) {
00087 MPI_Comm_size(comm, &procs);
00088 tmp_ranklist = (int *) ADIOI_Malloc(sizeof(int) * procs);
00089 if (tmp_ranklist == NULL) {
00090
00091 }
00092
00093 rank_ct = ADIOI_cb_config_list_parse(fd->hints->cb_config_list,
00094 array, tmp_ranklist,
00095 fd->hints->cb_nodes);
00096
00097
00098 if (rank_ct > 0) {
00099 fd->hints->ranklist = (int *) ADIOI_Malloc(sizeof(int) * rank_ct);
00100 memcpy(fd->hints->ranklist, tmp_ranklist, sizeof(int) * rank_ct);
00101 }
00102 ADIOI_Free(tmp_ranklist);
00103 fd->hints->cb_nodes = rank_ct;
00104
00105 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00106 sprintf(value, "%d", rank_ct);
00107 MPI_Info_set(fd->info, "cb_nodes", value);
00108 ADIOI_Free(value);
00109 }
00110
00111
00112
00113 ADIOI_cb_bcast_rank_map(fd);
00114 if (fd->hints->cb_nodes <= 0) {
00115 #ifdef PRINT_ERR_MSG
00116 *error_code = MPI_ERR_UNKNOWN;
00117 #else
00118 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR, myname,
00119 "Open Error", "%s",
00120 "No aggregators match");
00121 ADIOI_Error(MPI_FILE_NULL, *error_code, myname);
00122 #endif
00123 fd = ADIO_FILE_NULL;
00124 return fd;
00125 }
00126
00127
00128
00129
00130
00131
00132 orig_amode = access_mode;
00133 if (access_mode & ADIO_WRONLY) {
00134 access_mode = access_mode ^ ADIO_WRONLY;
00135 access_mode = access_mode | ADIO_RDWR;
00136 }
00137 fd->access_mode = access_mode;
00138
00139 (*(fd->fns->ADIOI_xxx_Open))(fd, error_code);
00140
00141 fd->access_mode = orig_amode;
00142
00143
00144
00145 if (*error_code != MPI_SUCCESS)
00146 (*(fd->fns->ADIOI_xxx_Open))(fd, error_code);
00147
00148
00149 if (*error_code != MPI_SUCCESS) {
00150 ADIOI_Free(fd->fns);
00151 MPI_Comm_free(&(fd->comm));
00152 free(fd->filename);
00153 MPI_Info_free(&(fd->info));
00154 ADIOI_Free(fd);
00155 fd = ADIO_FILE_NULL;
00156 }
00157
00158 return fd;
00159 }