00001
00002
00003
00004
00005
00006 #include "mpi.h"
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include <stdlib.h>
00010
00011 #define SIZE (65536)
00012
00013
00014
00015
00016
00017 void handle_error(int errcode, char *str);
00018
00019 void handle_error(int errcode, char *str)
00020 {
00021 char msg[MPI_MAX_ERROR_STRING];
00022 int resultlen;
00023 MPI_Error_string(errcode, msg, &resultlen);
00024 fprintf(stderr, "%s: %s\n", str, msg);
00025 MPI_Abort(MPI_COMM_WORLD, 1);
00026 }
00027 int main(int argc, char **argv)
00028 {
00029 int *buf, i, rank, nints, len;
00030 char *filename, *tmp;
00031 int errs=0, toterrs;
00032 MPI_File fh;
00033 MPI_Status status;
00034 MPIO_Request request;
00035 int errcode = 0;
00036
00037 MPI_Init(&argc,&argv);
00038 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00039
00040
00041
00042 if (!rank) {
00043 i = 1;
00044 while ((i < argc) && strcmp("-fname", *argv)) {
00045 i++;
00046 argv++;
00047 }
00048 if (i >= argc) {
00049 fprintf(stderr, "\n*# Usage: async -fname filename\n\n");
00050 MPI_Abort(MPI_COMM_WORLD, 1);
00051 }
00052 argv++;
00053 len = strlen(*argv);
00054 filename = (char *) malloc(len+10);
00055 strcpy(filename, *argv);
00056 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00057 MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
00058 }
00059 else {
00060 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00061 filename = (char *) malloc(len+10);
00062 MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
00063 }
00064
00065
00066 buf = (int *) malloc(SIZE);
00067 nints = SIZE/sizeof(int);
00068 for (i=0; i<nints; i++) buf[i] = rank*100000 + i;
00069
00070
00071 tmp = (char *) malloc(len+10);
00072 strcpy(tmp, filename);
00073 sprintf(filename, "%s.%d", tmp, rank);
00074
00075 errcode = MPI_File_open(MPI_COMM_SELF, filename,
00076 MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00077 if (errcode != MPI_SUCCESS) {
00078 handle_error(errcode, "MPI_File_open");
00079 }
00080 MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL);
00081 errcode = MPI_File_iwrite(fh, buf, nints, MPI_INT, &request);
00082 if (errcode != MPI_SUCCESS) {
00083 handle_error(errcode, "MPI_File_iwrite");
00084 }
00085 #ifdef MPIO_USES_MPI_REQUEST
00086 MPI_Wait( &request, &status );
00087 #else
00088 MPIO_Wait(&request, &status);
00089 #endif
00090 MPI_File_close(&fh);
00091
00092
00093
00094 for (i=0; i<nints; i++) buf[i] = 0;
00095 errcode = MPI_File_open(MPI_COMM_SELF, filename,
00096 MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00097 if (errcode != MPI_SUCCESS) {
00098 handle_error(errcode, "MPI_File_open");
00099 }
00100
00101 MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL);
00102 errcode = MPI_File_iread(fh, buf, nints, MPI_INT, &request);
00103 if (errcode != MPI_SUCCESS) {
00104 handle_error(errcode, "MPI_File_open");
00105 }
00106 #ifdef MPIO_USES_MPI_REQUEST
00107 MPI_Wait( &request, &status );
00108 #else
00109 MPIO_Wait(&request, &status);
00110 #endif
00111
00112 MPI_File_close(&fh);
00113
00114
00115 for (i=0; i<nints; i++) {
00116 if (buf[i] != (rank*100000 + i)) {
00117 errs++;
00118 fprintf(stderr, "Process %d: error, read %d, should be %d\n", rank, buf[i], rank*100000+i);
00119 }
00120 }
00121
00122 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
00123 if (rank == 0) {
00124 if( toterrs > 0) {
00125 fprintf( stderr, "Found %d errors\n", toterrs );
00126 }
00127 else {
00128 fprintf( stdout, " No Errors\n" );
00129 }
00130 }
00131
00132 free(buf);
00133 free(filename);
00134 free(tmp);
00135
00136 MPI_Finalize();
00137 return 0;
00138 }