00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_pfs.h"
00010 #include "adio_extern.h"
00011
00012 void ADIOI_PFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
00013 {
00014 MPI_Datatype copy_etype, copy_filetype;
00015 int combiner, i, j, k, filetype_is_contig, err;
00016 ADIOI_Flatlist_node *flat_file;
00017 int iomod, np_total, np_comm;
00018 #ifndef PRINT_ERR_MSG
00019 static char myname[] = "ADIOI_PFS_FCNTL";
00020 #endif
00021
00022 switch(flag) {
00023 case ADIO_FCNTL_SET_VIEW:
00024
00025
00026
00027 MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);
00028 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));
00029
00030 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00031 if (!filetype_is_contig) ADIOI_Delete_flattened(fd->filetype);
00032
00033 MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);
00034 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));
00035
00036
00037 ADIO_SetInfo(fd, fcntl_struct->info, &err);
00038
00039
00040
00041 MPI_Type_get_envelope(fcntl_struct->etype, &i, &j, &k, &combiner);
00042 if (combiner == MPI_COMBINER_NAMED) fd->etype = fcntl_struct->etype;
00043 else {
00044 MPI_Type_contiguous(1, fcntl_struct->etype, ©_etype);
00045 MPI_Type_commit(©_etype);
00046 fd->etype = copy_etype;
00047 }
00048 MPI_Type_get_envelope(fcntl_struct->filetype, &i, &j, &k, &combiner);
00049 if (combiner == MPI_COMBINER_NAMED)
00050 fd->filetype = fcntl_struct->filetype;
00051 else {
00052 MPI_Type_contiguous(1, fcntl_struct->filetype, ©_filetype);
00053 MPI_Type_commit(©_filetype);
00054 fd->filetype = copy_filetype;
00055 ADIOI_Flatten_datatype(fd->filetype);
00056
00057
00058 }
00059
00060 MPI_Type_size(fd->etype, &(fd->etype_size));
00061 fd->disp = fcntl_struct->disp;
00062
00063
00064
00065
00066 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00067 if (filetype_is_contig) fd->fp_ind = fcntl_struct->disp;
00068 else {
00069 flat_file = ADIOI_Flatlist;
00070 while (flat_file->type != fd->filetype)
00071 flat_file = flat_file->next;
00072 for (i=0; i<flat_file->count; i++) {
00073 if (flat_file->blocklens[i]) {
00074 fd->fp_ind = fcntl_struct->disp + flat_file->indices[i];
00075 break;
00076 }
00077 }
00078 }
00079 *error_code = MPI_SUCCESS;
00080 break;
00081
00082 case ADIO_FCNTL_GET_FSIZE:
00083 if (!(fd->atomicity)) {
00084
00085
00086
00087
00088 MPI_Comm_size(MPI_COMM_WORLD, &np_total);
00089 MPI_Comm_size(fd->comm, &np_comm);
00090 if (np_total == np_comm) {
00091 err = _setiomode(fd->fd_sys, M_UNIX);
00092 err = _setiomode(fd->fd_sys, M_ASYNC);
00093 }
00094
00095 }
00096 fcntl_struct->fsize = lseek(fd->fd_sys, 0, SEEK_END);
00097 if (fd->fp_sys_posn != -1)
00098 lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00099 *error_code = MPI_SUCCESS;
00100 break;
00101
00102 case ADIO_FCNTL_SET_DISKSPACE:
00103 err = _lsize(fd->fd_sys, fcntl_struct->diskspace, SEEK_SET);
00104 #ifdef PRINT_ERR_MSG
00105 *error_code = (err == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS ;
00106 #else
00107 if (err == -1) {
00108 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00109 myname, "I/O Error", "%s", strerror(errno));
00110 ADIOI_Error(fd, *error_code, myname);
00111 }
00112 else *error_code = MPI_SUCCESS;
00113 #endif
00114 break;
00115
00116 case ADIO_FCNTL_SET_IOMODE:
00117
00118
00119 if (fd->iomode != fcntl_struct->iomode) {
00120 fd->iomode = fcntl_struct->iomode;
00121 setiomode(fd->fd_sys, iomode);
00122
00123 }
00124 *error_code = MPI_SUCCESS;
00125 break;
00126
00127 case ADIO_FCNTL_SET_ATOMICITY:
00128 MPI_Comm_size(MPI_COMM_WORLD, &np_total);
00129 MPI_Comm_size(fd->comm, &np_comm);
00130 if (np_total == np_comm) {
00131 iomod = (fcntl_struct->atomicity == 0) ? M_ASYNC : M_UNIX;
00132 err = _setiomode(fd->fd_sys, iomod);
00133 }
00134
00135
00136
00137
00138 fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
00139 #ifdef PRINT_ERR_MSG
00140 *error_code = (err == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS ;
00141 #else
00142 if (err == -1) {
00143 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00144 myname, "I/O Error", "%s", strerror(errno));
00145 ADIOI_Error(fd, *error_code, myname);
00146 }
00147 else *error_code = MPI_SUCCESS;
00148 #endif
00149 break;
00150
00151 default:
00152 FPRINTF(stderr, "Unknown flag passed to ADIOI_PFS_Fcntl\n");
00153 MPI_Abort(MPI_COMM_WORLD, 1);
00154 }
00155 }