void mpi_file_get_view_(MPI_Fint * fh, MPI_Offset * disp, MPI_Fint * etype, MPI_Fint * filetype, char *datarep, MPI_Fint * ierr, int str_len) { MPI_File fh_c; MPI_Datatype etype_c, filetype_c; int i, tmpreplen; char *tmprep; if (datarep <= (char *) 0) { FPRINTF(stderr, "MPI_File_get_view: datarep is an invalid address\n"); MPI_Abort(MPI_COMM_WORLD, 1); } tmprep = (char *) ADIOI_Malloc((MPI_MAX_DATAREP_STRING + 1) * sizeof(char)); fh_c = MPI_File_f2c(*fh); *ierr = MPI_File_get_view(fh_c, disp, &etype_c, &filetype_c, tmprep); tmpreplen = strlen(tmprep); if (tmpreplen <= str_len) { ADIOI_Strncpy(datarep, tmprep, tmpreplen); /* blank pad the remaining space */ for (i = tmpreplen; i < str_len; i++) datarep[i] = ' '; } else { /* not enough space */ ADIOI_Strncpy(datarep, tmprep, str_len); /* this should be flagged as an error. */ *ierr = MPI_ERR_UNKNOWN; } *etype = MPI_Type_c2f(etype_c); *filetype = MPI_Type_c2f(filetype_c); ADIOI_Free(tmprep); }
void mpi_file_get_view_(MPI_Fint * fh, MPI_Offset * disp, MPI_Fint * etype, MPI_Fint * filetype, _fcd datarep_fcd, MPI_Fint * ierr) { char *datarep = _fcdtocp(datarep_fcd); int str_len = _fcdlen(datarep_fcd); #else /* Prototype to keep compiler happy */ FORTRAN_API void FORT_CALL mpi_file_get_view_(MPI_Fint * fh, MPI_Offset * disp, MPI_Fint * etype, MPI_Fint * filetype, char *datarep FORT_MIXED_LEN_DECL, MPI_Fint * ierr FORT_END_LEN_DECL); FORTRAN_API void FORT_CALL mpi_file_get_view_(MPI_Fint * fh, MPI_Offset * disp, MPI_Fint * etype, MPI_Fint * filetype, char *datarep FORT_MIXED_LEN(str_len), MPI_Fint * ierr FORT_END_LEN(str_len)) { #endif MPI_File fh_c; int i, tmpreplen; MPI_Datatype etype_c, filetype_c; char *tmprep; /* Initialize the string to all blanks */ if (datarep <= (char *) 0) { FPRINTF(stderr, "MPI_File_get_view: datarep is an invalid address\n"); MPI_Abort(MPI_COMM_WORLD, 1); } tmprep = (char *) ADIOI_Malloc((MPI_MAX_DATAREP_STRING + 1) * sizeof(char)); fh_c = MPI_File_f2c(*fh); etype_c = MPI_Type_f2c(*etype); filetype_c = MPI_Type_f2c(*filetype); *ierr = MPI_File_get_view(fh_c, disp, &etype_c, &filetype_c, tmprep); tmpreplen = strlen(tmprep); if (tmpreplen <= str_len) { ADIOI_Strncpy(datarep, tmprep, tmpreplen); /* blank pad the remaining space */ for (i = tmpreplen; i < str_len; i++) datarep[i] = ' '; } else { /* not enough space */ ADIOI_Strncpy(datarep, tmprep, str_len); /* this should be flagged as an error. */ *ierr = MPI_ERR_UNKNOWN; } *etype = MPI_Type_c2f(etype_c); *filetype = MPI_Type_c2f(filetype_c); ADIOI_Free(tmprep); }
void ompi_file_get_view_f(MPI_Fint *fh, MPI_Offset *disp, MPI_Fint *etype, MPI_Fint *filetype, char *datarep, MPI_Fint *ierr, int datarep_len) { int c_ierr; MPI_File c_fh = MPI_File_f2c(*fh); MPI_Datatype c_etype, c_filetype; MPI_Offset c_disp; char c_datarep[MPI_MAX_DATAREP_STRING]; c_ierr = MPI_File_get_view(c_fh, &c_disp, &c_etype, &c_filetype, c_datarep); if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr); if (MPI_SUCCESS == c_ierr) { *disp = (MPI_Offset) c_disp; *etype = MPI_Type_c2f(c_etype); *filetype = MPI_Type_c2f(c_filetype); ompi_fortran_string_c2f(c_datarep, datarep, datarep_len); } }
#ifdef F77_NAME_UPPER #define mpi_file_get_view_ MPI_FILE_GET_VIEW #elif defined(F77_NAME_LOWER_2USCORE) #define mpi_file_get_view_ mpi_file_get_view__ #elif !defined(F77_NAME_LOWER_USCORE) #define mpi_file_get_view_ mpi_file_get_view /* Else leave name alone */ #endif #endif /* MPICH_MPI_FROM_PMPI */ /* Prototypes for the Fortran interfaces */ #include "fproto.h" FORT_DLL_SPEC void FORT_CALL mpi_file_get_view_ ( MPI_Fint *v1, MPI_Offset*v2, MPI_Fint *v3, MPI_Fint *v4, char *v5 FORT_MIXED_LEN(d5), MPI_Fint *ierr FORT_END_LEN(d5) ){ #ifdef MPI_MODE_RDONLY char *p5; p5 = (char *)MPIU_Malloc( d5 + 1 ); *ierr = MPI_File_get_view( MPI_File_f2c(*v1), v2, (MPI_Datatype *)(v3), (MPI_Datatype *)(v4), p5 ); if (!*ierr) {char *p = v5, *pc=p5; while (*pc) {*p++ = *pc++;} while ((p-v5) < d5) { *p++ = ' '; } } MPIU_Free( p5 ); #else *ierr = MPI_ERR_INTERN; #endif }
int main(int argc, char **argv) { int buf[1024], amode, flag, mynod, len, i; MPI_File fh; MPI_Status status; MPI_Datatype newtype; MPI_Offset disp, offset; MPI_Group group; MPI_Datatype etype, filetype; char datarep[25], *filename; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &mynod); /* process 0 takes the file name as a command-line argument and broadcasts it to other processes */ if (!mynod) { i = 1; while ((i < argc) && strcmp("-fname", *argv)) { i++; argv++; } if (i >= argc) { printf("\n*# Usage: misc <mpiparameter> -- -fname filename\n\n"); MPI_Abort(MPI_COMM_WORLD, 1); } argv++; len = strlen(*argv); filename = (char *) malloc(len+1); strcpy(filename, *argv); MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD); } else { MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); filename = (char *) malloc(len+1); MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD); } MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); MPI_File_write(fh, buf, 1024, MPI_INT, &status); MPI_File_sync(fh); MPI_File_get_amode(fh, &amode); if (!mynod) printf("testing MPI_File_get_amode\n"); if (amode != (MPI_MODE_CREATE | MPI_MODE_RDWR)) printf("amode is %d, should be %d\n\n", amode, MPI_MODE_CREATE | MPI_MODE_RDWR); MPI_File_get_atomicity(fh, &flag); if (flag) printf("atomicity is %d, should be 0\n", flag); if (!mynod) printf("setting atomic mode\n"); MPI_File_set_atomicity(fh, 1); MPI_File_get_atomicity(fh, &flag); if (!flag) printf("atomicity is %d, should be 1\n", flag); MPI_File_set_atomicity(fh, 0); if (!mynod) printf("reverting back to nonatomic mode\n"); MPI_Type_vector(10, 10, 20, MPI_INT, &newtype); MPI_Type_commit(&newtype); MPI_File_set_view(fh, 1000, MPI_INT, newtype, "native", MPI_INFO_NULL); if (!mynod) printf("testing MPI_File_get_view\n"); MPI_File_get_view(fh, &disp, &etype, &filetype, datarep); if ((disp != 1000) || strcmp(datarep, "native")) printf("disp = %I64, datarep = %s, should be 1000, native\n\n", disp, datarep); if (!mynod) printf("testing MPI_File_get_byte_offset\n"); MPI_File_get_byte_offset(fh, 10, &disp); if (disp != (1000+20*sizeof(int))) printf("byte offset = %I64, should be %d\n\n", disp, (int) (1000+20*sizeof(int))); MPI_File_get_group(fh, &group); if (!mynod) printf("testing MPI_File_set_size\n"); MPI_File_set_size(fh, 1000+15*sizeof(int)); MPI_Barrier(MPI_COMM_WORLD); MPI_File_sync(fh); MPI_File_get_size(fh, &disp); if (disp != 1000+15*sizeof(int)) printf("file size = %I64, should be %d\n\n", disp, (int) (1000+15*sizeof(int))); if (!mynod) printf("seeking to eof and testing MPI_File_get_position\n"); MPI_File_seek(fh, 0, MPI_SEEK_END); MPI_File_get_position(fh, &disp); if (disp != 10) printf("file pointer posn = %I64, should be 10\n\n", disp); if (!mynod) printf("testing MPI_File_get_byte_offset\n"); MPI_File_get_byte_offset(fh, disp, &offset); if (offset != (1000+20*sizeof(int))) printf("byte offset = %I64, should be %d\n\n", offset, (int) (1000+20*sizeof(int))); MPI_Barrier(MPI_COMM_WORLD); if (!mynod) printf("testing MPI_File_seek with MPI_SEEK_CUR\n"); MPI_File_seek(fh, -10, MPI_SEEK_CUR); MPI_File_get_position(fh, &disp); MPI_File_get_byte_offset(fh, disp, &offset); if (offset != 1000) printf("file pointer posn in bytes = %I64, should be 1000\n\n", offset); if (!mynod) printf("preallocating disk space up to 8192 bytes\n"); MPI_File_preallocate(fh, 8192); if (!mynod) printf("closing the file and deleting it\n"); MPI_File_close(&fh); MPI_Barrier(MPI_COMM_WORLD); if (!mynod) MPI_File_delete(filename, MPI_INFO_NULL); MPI_Type_free(&newtype); MPI_Type_free(&filetype); MPI_Group_free(&group); free(filename); MPI_Finalize(); return 0; }