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
00018
00019
00020 int main(int argc, char **argv)
00021 {
00022 int *buf, i, rank, nints, len;
00023 char *filename, *tmp;
00024 int errs=0, toterrs;
00025 MPI_File fh;
00026 MPI_Status status;
00027
00028 PMPI_Init(&argc,&argv);
00029 PMPI_Comm_rank(MPI_COMM_WORLD, &rank);
00030
00031
00032
00033 if (!rank) {
00034 i = 1;
00035 while ((i < argc) && strcmp("-fname", *argv)) {
00036 i++;
00037 argv++;
00038 }
00039 if (i >= argc) {
00040 fprintf(stderr, "\n*# Usage: simple -fname filename\n\n");
00041 PMPI_Abort(MPI_COMM_WORLD, 1);
00042 }
00043 argv++;
00044 len = strlen(*argv);
00045 filename = (char *) malloc(len+10);
00046 strcpy(filename, *argv);
00047 PMPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00048 PMPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
00049 }
00050 else {
00051 PMPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00052 filename = (char *) malloc(len+10);
00053 PMPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
00054 }
00055
00056
00057 buf = (int *) malloc(SIZE);
00058 nints = SIZE/sizeof(int);
00059 for (i=0; i<nints; i++) buf[i] = rank*100000 + i;
00060
00061
00062 tmp = (char *) malloc(len+10);
00063 strcpy(tmp, filename);
00064 sprintf(filename, "%s.%d", tmp, rank);
00065
00066 PMPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR,
00067 MPI_INFO_NULL, &fh);
00068 PMPI_File_write(fh, buf, nints, MPI_INT, &status);
00069 PMPI_File_close(&fh);
00070
00071
00072
00073 for (i=0; i<nints; i++) buf[i] = 0;
00074 PMPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR,
00075 MPI_INFO_NULL, &fh);
00076 PMPI_File_read(fh, buf, nints, MPI_INT, &status);
00077 PMPI_File_close(&fh);
00078
00079
00080 for (i=0; i<nints; i++) {
00081 if (buf[i] != (rank*100000 + i)) {
00082 errs++;
00083 fprintf(stderr, "Process %d: error, read %d, should be %d\n", rank, buf[i], rank*100000+i);
00084 }
00085 }
00086
00087 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
00088 if (rank == 0) {
00089 if( toterrs > 0) {
00090 fprintf( stderr, "Found %d errors\n", toterrs );
00091 }
00092 else {
00093 fprintf( stdout, " No Errors\n" );
00094 }
00095 }
00096
00097 free(buf);
00098 free(filename);
00099 free(tmp);
00100
00101 PMPI_Finalize();
00102 return 0;
00103 }