00001
00002
00003
00004
00005
00006 #include "mpi.h"
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include <stdlib.h>
00010
00011
00012
00013
00014
00015
00016
00017 #define BUFSIZE 10000
00018 #define VERBOSE 0
00019 int main(int argc, char **argv)
00020 {
00021 int *writebuf, *readbuf, i, mynod, nprocs, len, err;
00022 char *filename;
00023 int errs=0, toterrs;
00024 MPI_Datatype newtype;
00025 MPI_File fh;
00026 MPI_Status status;
00027 MPI_Info info;
00028
00029 MPI_Init(&argc,&argv);
00030 MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
00031 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
00032
00033
00034
00035 if (!mynod) {
00036 i = 1;
00037 while ((i < argc) && strcmp("-fname", *argv)) {
00038 i++;
00039 argv++;
00040 }
00041 if (i >= argc) {
00042 fprintf(stderr, "\n*# Usage: coll_test -fname filename\n\n");
00043 MPI_Abort(MPI_COMM_WORLD, 1);
00044 }
00045 argv++;
00046 len = strlen(*argv);
00047 filename = (char *) malloc(len+1);
00048 strcpy(filename, *argv);
00049 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00050 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
00051 }
00052 else {
00053 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00054 filename = (char *) malloc(len+1);
00055 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
00056 }
00057
00058 writebuf = (int *) malloc(BUFSIZE*sizeof(int));
00059 readbuf = (int *) malloc(BUFSIZE*sizeof(int));
00060
00061
00062
00063
00064 if (!mynod) {
00065 MPI_File_delete(filename, MPI_INFO_NULL);
00066 MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE |
00067 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00068 for (i=0; i<BUFSIZE; i++) writebuf[i] = 0;
00069 MPI_File_write(fh, writebuf, BUFSIZE, MPI_INT, &status);
00070 MPI_File_close(&fh);
00071 #if VERBOSE
00072 fprintf(stderr, "\ntesting contiguous accesses\n");
00073 #endif
00074 }
00075 MPI_Barrier(MPI_COMM_WORLD);
00076
00077 for (i=0; i<BUFSIZE; i++) writebuf[i] = 10;
00078 for (i=0; i<BUFSIZE; i++) readbuf[i] = 20;
00079
00080 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00081 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00082
00083
00084 err = MPI_File_set_atomicity(fh, 1);
00085 if (err != MPI_SUCCESS) {
00086 fprintf(stderr, "Atomic mode not supported on this file system.\n");fflush(stderr);
00087 MPI_Abort(MPI_COMM_WORLD, 1);
00088 }
00089
00090 MPI_Barrier(MPI_COMM_WORLD);
00091
00092
00093
00094
00095
00096 if (!mynod) MPI_File_write(fh, writebuf, BUFSIZE, MPI_INT, &status);
00097 else {
00098 err = MPI_File_read(fh, readbuf, BUFSIZE, MPI_INT, &status);
00099 if (err == MPI_SUCCESS) {
00100 if (readbuf[0] == 0) {
00101 for (i=1; i<BUFSIZE; i++)
00102 if (readbuf[i] != 0) {
00103 errs++;
00104 fprintf(stderr, "Process %d: readbuf[%d] is %d, should be 0\n", mynod, i, readbuf[i]);
00105 MPI_Abort(MPI_COMM_WORLD, 1);
00106 }
00107 }
00108 else if (readbuf[0] == 10) {
00109 for (i=1; i<BUFSIZE; i++)
00110 if (readbuf[i] != 10) {
00111 errs++;
00112 fprintf(stderr, "Process %d: readbuf[%d] is %d, should be 10\n", mynod, i, readbuf[i]);
00113 MPI_Abort(MPI_COMM_WORLD, 1);
00114 }
00115 }
00116 else {
00117 errs++;
00118 fprintf(stderr, "Process %d: readbuf[0] is %d, should be either 0 or 10\n", mynod, readbuf[0]);
00119 }
00120 }
00121 }
00122
00123 MPI_File_close(&fh);
00124
00125 MPI_Barrier(MPI_COMM_WORLD);
00126
00127
00128
00129
00130 MPI_Type_vector(BUFSIZE, 1, 2, MPI_INT, &newtype);
00131 MPI_Type_commit(&newtype);
00132
00133 MPI_Info_create(&info);
00134
00135
00136 MPI_Info_set(info, "ind_rd_buffer_size", "1209");
00137 MPI_Info_set(info, "ind_wr_buffer_size", "1107");
00138
00139 if (!mynod) {
00140 MPI_File_delete(filename, MPI_INFO_NULL);
00141 MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE |
00142 MPI_MODE_RDWR, info, &fh);
00143 for (i=0; i<BUFSIZE; i++) writebuf[i] = 0;
00144 MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", info);
00145 MPI_File_write(fh, writebuf, BUFSIZE, MPI_INT, &status);
00146 MPI_File_close(&fh);
00147 #if VERBOSE
00148 fprintf(stderr, "\ntesting noncontiguous accesses\n");
00149 #endif
00150 }
00151 MPI_Barrier(MPI_COMM_WORLD);
00152
00153 for (i=0; i<BUFSIZE; i++) writebuf[i] = 10;
00154 for (i=0; i<BUFSIZE; i++) readbuf[i] = 20;
00155
00156 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00157 MPI_MODE_RDWR, info, &fh);
00158 MPI_File_set_atomicity(fh, 1);
00159 MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", info);
00160 MPI_Barrier(MPI_COMM_WORLD);
00161
00162 if (!mynod) MPI_File_write(fh, writebuf, BUFSIZE, MPI_INT, &status);
00163 else {
00164 err = MPI_File_read(fh, readbuf, BUFSIZE, MPI_INT, &status);
00165 if (err == MPI_SUCCESS) {
00166 if (readbuf[0] == 0) {
00167 for (i=1; i<BUFSIZE; i++)
00168 if (readbuf[i] != 0) {
00169 errs++;
00170 fprintf(stderr, "Process %d: readbuf[%d] is %d, should be 0\n", mynod, i, readbuf[i]);
00171 MPI_Abort(MPI_COMM_WORLD, 1);
00172 }
00173 }
00174 else if (readbuf[0] == 10) {
00175 for (i=1; i<BUFSIZE; i++)
00176 if (readbuf[i] != 10) {
00177 errs++;
00178 fprintf(stderr, "Process %d: readbuf[%d] is %d, should be 10\n", mynod, i, readbuf[i]);
00179 MPI_Abort(MPI_COMM_WORLD, 1);
00180 }
00181 }
00182 else {
00183 errs++;
00184 fprintf(stderr, "Process %d: readbuf[0] is %d, should be either 0 or 10\n", mynod, readbuf[0]);
00185 }
00186 }
00187 }
00188
00189 MPI_File_close(&fh);
00190
00191 MPI_Barrier(MPI_COMM_WORLD);
00192
00193 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
00194 if (mynod == 0) {
00195 if( toterrs > 0) {
00196 fprintf( stderr, "Found %d errors\n", toterrs );
00197 }
00198 else {
00199 fprintf( stdout, " No Errors\n" );
00200 }
00201 }
00202 MPI_Type_free(&newtype);
00203 MPI_Info_free(&info);
00204 free(writebuf);
00205 free(readbuf);
00206 free(filename);
00207
00208 MPI_Finalize();
00209 return 0;
00210 }