00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_piofs.h"
00010
00011 void ADIOI_PIOFS_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code)
00012 {
00013 piofs_create_t piofs_create;
00014 piofs_statfs_t piofs_statfs;
00015 char *value, *path, *slash;
00016 int flag, tmp_val, str_factor=-1, str_unit=-1, start_iodev=-1;
00017 int err, myrank, perm, old_mask, nioservers;
00018
00019 if (!(fd->info)) {
00020
00021
00022 MPI_Info_create(&(fd->info));
00023
00024
00025
00026 if (users_info != MPI_INFO_NULL) {
00027 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00028
00029 MPI_Info_get(users_info, "striping_factor", MPI_MAX_INFO_VAL,
00030 value, &flag);
00031 if (flag) {
00032 str_factor=atoi(value);
00033 tmp_val = str_factor;
00034 MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
00035 if (tmp_val != str_factor) {
00036 FPRINTF(stderr, "ADIOI_PIOFS_SetInfo: the value for key \"striping_factor\" must be the same on all processes\n");
00037 MPI_Abort(MPI_COMM_WORLD, 1);
00038 }
00039 }
00040
00041 MPI_Info_get(users_info, "striping_unit", MPI_MAX_INFO_VAL,
00042 value, &flag);
00043 if (flag) {
00044 str_unit=atoi(value);
00045 tmp_val = str_unit;
00046 MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
00047 if (tmp_val != str_unit) {
00048 FPRINTF(stderr, "ADIOI_PIOFS_SetInfo: the value for key \"striping_unit\" must be the same on all processes\n");
00049 MPI_Abort(MPI_COMM_WORLD, 1);
00050 }
00051 }
00052
00053 MPI_Info_get(users_info, "start_iodevice", MPI_MAX_INFO_VAL,
00054 value, &flag);
00055 if (flag) {
00056 start_iodev=atoi(value);
00057 tmp_val = start_iodev;
00058 MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
00059 if (tmp_val != start_iodev) {
00060 FPRINTF(stderr, "ADIOI_PIOFS_SetInfo: the value for key \"start_iodevice\" must be the same on all processes\n");
00061 MPI_Abort(MPI_COMM_WORLD, 1);
00062 }
00063 }
00064
00065 ADIOI_Free(value);
00066
00067
00068 if ((str_factor > 0) || (str_unit > 0) || (start_iodev >= 0)) {
00069 MPI_Comm_rank(fd->comm, &myrank);
00070 if (!myrank) {
00071 if (fd->perm == ADIO_PERM_NULL) {
00072 old_mask = umask(022);
00073 umask(old_mask);
00074 perm = old_mask ^ 0666;
00075 }
00076 else perm = fd->perm;
00077
00078
00079
00080
00081 path = strdup(fd->filename);
00082 slash = strrchr(path, '/');
00083 if (!slash) strcpy(path, ".");
00084 else {
00085 if (slash == path) *(path + 1) = '\0';
00086 else *slash = '\0';
00087 }
00088 strcpy(piofs_statfs.name, path);
00089 err = piofsioctl(0, PIOFS_STATFS, &piofs_statfs);
00090 nioservers = (err) ? -1 : piofs_statfs.f_nodes;
00091
00092 free(path);
00093
00094 str_factor = ADIOI_MIN(nioservers, str_factor);
00095 if (start_iodev >= nioservers) start_iodev = -1;
00096
00097 strcpy(piofs_create.name, fd->filename);
00098 piofs_create.bsu = (str_unit > 0) ? str_unit : -1;
00099 piofs_create.cells = (str_factor > 0) ? str_factor : -1;
00100 piofs_create.permissions = perm;
00101 piofs_create.base_node = (start_iodev >= 0) ?
00102 start_iodev : -1;
00103 piofs_create.flags = 0;
00104
00105 err = piofsioctl(0, PIOFS_CREATE, &piofs_create);
00106 }
00107 MPI_Barrier(fd->comm);
00108 }
00109 }
00110 }
00111
00112
00113 ADIOI_GEN_SetInfo(fd, users_info, error_code);
00114
00115 *error_code = MPI_SUCCESS;
00116 }