00001
00002
00003
00004
00005
00006 #include "mpi.h"
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include <stdlib.h>
00010
00011 #define VERBOSE 0
00012
00013
00014 int main(int argc, char **argv)
00015 {
00016 int i, rank, len, err;
00017 int errs = 0;
00018 char *filename, *tmp;
00019 MPI_File fh;
00020 char string[MPI_MAX_ERROR_STRING];
00021
00022 MPI_Init(&argc,&argv);
00023 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00024
00025 #if VERBOSE
00026 if (!rank) {
00027 fprintf(stderr, "Tests if errors are reported correctly...\n");
00028 fprintf(stderr, "Should say \"Invalid displacement argument\"\n\n");
00029 }
00030 #endif
00031
00032
00033
00034 if (!rank) {
00035 i = 1;
00036 while ((i < argc) && strcmp("-fname", *argv)) {
00037 i++;
00038 argv++;
00039 }
00040 if (i >= argc) {
00041 fprintf(stderr, "\n*# Usage: simple -fname filename\n\n");
00042 MPI_Abort(MPI_COMM_WORLD, 1);
00043 }
00044 argv++;
00045 len = strlen(*argv);
00046 filename = (char *) malloc(len+10);
00047 strcpy(filename, *argv);
00048 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00049 MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
00050 }
00051 else {
00052 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00053 filename = (char *) malloc(len+10);
00054 MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
00055 }
00056
00057
00058 tmp = (char *) malloc(len+10);
00059 strcpy(tmp, filename);
00060 sprintf(filename, "%s.%d", tmp, rank);
00061
00062 err = MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE+MPI_MODE_RDWR,
00063 MPI_INFO_NULL, &fh);
00064 err = MPI_File_set_view(fh, -1, MPI_BYTE, MPI_BYTE, "native",
00065 MPI_INFO_NULL);
00066
00067
00068
00069
00070 if (err != MPI_SUCCESS) {
00071 MPI_Error_string(err, string, &len);
00072 if (!rank) {
00073 #if VERBOSE
00074 fprintf(stderr, "%s\n", string);
00075 #else
00076
00077
00078 if (strstr( string, "displacement" ) == 0) {
00079 fprintf( stderr, "Unexpected error message %s\n", string );
00080 errs++;
00081 }
00082 #endif
00083 }
00084 }
00085 else {
00086 errs++;
00087 fprintf( stderr, "File set view did not return an error\n" );
00088 }
00089
00090 MPI_File_close(&fh);
00091
00092 free(filename);
00093 free(tmp);
00094
00095 if (!rank) {
00096 if (errs == 0) {
00097 printf( " No Errors\n" );
00098 }
00099 else {
00100 printf( " Found %d errors\n", errs );
00101 }
00102 }
00103
00104 MPI_Finalize();
00105 return 0;
00106 }