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 int main(int argc, char **argv)
00016 {
00017 int *buf, i, rank, nints, len, count, elements;
00018 char *filename, *tmp;
00019 int errs=0, toterrs;
00020 MPI_File fh;
00021 MPI_Status status;
00022
00023 MPI_Init(&argc,&argv);
00024 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00025
00026
00027
00028 if (!rank) {
00029 i = 1;
00030 while ((i < argc) && strcmp("-fname", *argv)) {
00031 i++;
00032 argv++;
00033 }
00034 if (i >= argc) {
00035 fprintf(stderr, "\n*# Usage: simple -fname filename\n\n");
00036 MPI_Abort(MPI_COMM_WORLD, 1);
00037 }
00038 argv++;
00039 len = strlen(*argv);
00040 filename = (char *) malloc(len+10);
00041 strcpy(filename, *argv);
00042 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00043 MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
00044 }
00045 else {
00046 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00047 filename = (char *) malloc(len+10);
00048 MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
00049 }
00050
00051 buf = (int *) malloc(SIZE);
00052 nints = SIZE/sizeof(int);
00053
00054
00055 tmp = (char *) malloc(len+10);
00056 strcpy(tmp, filename);
00057 sprintf(filename, "%s.%d", tmp, rank);
00058
00059 MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR,
00060 MPI_INFO_NULL, &fh);
00061 MPI_File_write(fh, buf, nints, MPI_INT, &status);
00062
00063 MPI_Get_count(&status, MPI_INT, &count);
00064 MPI_Get_elements(&status, MPI_INT, &elements);
00065 if (!rank) {
00066 if (count != nints) {
00067 errs++;
00068 printf("count = %d, should be %d\n", count, nints);
00069 }
00070 if (elements != nints) {
00071 errs++;
00072 printf("elements = %d, should be %d\n", elements, nints);
00073 }
00074 }
00075
00076 MPI_File_close(&fh);
00077
00078 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
00079 if (rank == 0) {
00080 if( toterrs > 0) {
00081 fprintf( stderr, "Found %d errors\n", toterrs );
00082 }
00083 else {
00084 fprintf( stdout, " No Errors\n" );
00085 }
00086 }
00087 free(buf);
00088 free(filename);
00089 free(tmp);
00090
00091 MPI_Finalize();
00092 return 0;
00093 }