00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <mpi.h>
00011
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 #include <time.h>
00015
00016 #include <sys/types.h>
00017 #include <unistd.h>
00018
00019 #include <string.h>
00020
00021 #define BUFSIZE 512
00022
00023 static void handle_error(int errcode, char *str)
00024 {
00025 char msg[MPI_MAX_ERROR_STRING];
00026 int resultlen;
00027 MPI_Error_string(errcode, msg, &resultlen);
00028 fprintf(stderr, "%s: %s\n", str, msg);
00029 MPI_Abort(MPI_COMM_WORLD, 1);
00030 }
00031
00032 int main(int argc, char ** argv)
00033 {
00034 MPI_Info info = MPI_INFO_NULL;
00035 MPI_File fh;
00036 MPI_Offset off=0;
00037 MPI_Status status;
00038 int errcode;
00039 int i, rank, errs=0, toterrs, buffer[BUFSIZE], buf2[BUFSIZE];
00040
00041 MPI_Init(&argc, &argv);
00042
00043 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00044
00045 MPI_Info_create(&info);
00046 MPI_Info_set(info, "romio_cb_write", "enable");
00047 MPI_Info_set(info, "cb_nodes", "1");
00048
00049 for (i=0; i<BUFSIZE; i++) {
00050 buffer[i] = 10000+rank;
00051 }
00052 off = rank*sizeof(buffer);
00053
00054 errcode = MPI_File_open(MPI_COMM_WORLD, argv[1],
00055 MPI_MODE_WRONLY|MPI_MODE_CREATE, info, &fh);
00056 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_open");
00057 errcode = MPI_File_write_at_all(fh, off, buffer, BUFSIZE,
00058 MPI_INT, &status);
00059 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_write_at_all");
00060 errcode = MPI_File_close(&fh);
00061 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_close");
00062
00063 errcode = MPI_File_open(MPI_COMM_WORLD, argv[1],
00064 MPI_MODE_RDONLY, info, &fh);
00065 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_open");
00066 errcode = MPI_File_read_at_all(fh, off, buf2, BUFSIZE,
00067 MPI_INT, &status);
00068 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_read_at_all");
00069 errcode = MPI_File_close(&fh);
00070 if (errcode != MPI_SUCCESS) handle_error(errcode, "MPI_File_close");
00071
00072 for (i=0; i<BUFSIZE; i++) {
00073 if (buf2[i] != 10000+rank)
00074 errs++;
00075 }
00076 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
00077 if (rank == 0) {
00078 if( toterrs > 0) {
00079 fprintf( stderr, "Found %d errors\n", toterrs );
00080 }
00081 else {
00082 fprintf( stdout, " No Errors\n" );
00083 }
00084 }
00085 MPI_Info_free(&info);
00086 MPI_Finalize();
00087
00088 return 0;
00089 }