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 #define SIZE 5000
00014
00015 #define VERBOSE 0
00016
00017 int main(int argc, char **argv)
00018 {
00019 int *buf, i, mynod, nprocs, len, b[3];
00020 int errs=0, toterrs;
00021 MPI_Aint d[3];
00022 MPI_File fh;
00023 MPI_Status status;
00024 char *filename;
00025 MPI_Datatype typevec, newtype, t[3];
00026 MPIO_Request req;
00027
00028 MPI_Init(&argc,&argv);
00029 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
00030 MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
00031
00032 if (nprocs != 2) {
00033 fprintf(stderr, "Run this program on two processes\n");
00034 MPI_Abort(MPI_COMM_WORLD, 1);
00035 }
00036
00037
00038
00039 if (!mynod) {
00040 i = 1;
00041 while ((i < argc) && strcmp("-fname", *argv)) {
00042 i++;
00043 argv++;
00044 }
00045 if (i >= argc) {
00046 fprintf(stderr, "\n*# Usage: i_noncontig -fname filename\n\n");
00047 MPI_Abort(MPI_COMM_WORLD, 1);
00048 }
00049 argv++;
00050 len = strlen(*argv);
00051 filename = (char *) malloc(len+1);
00052 strcpy(filename, *argv);
00053 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00054 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
00055 }
00056 else {
00057 MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
00058 filename = (char *) malloc(len+1);
00059 MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD);
00060 }
00061
00062 buf = (int *) malloc(SIZE*sizeof(int));
00063
00064 MPI_Type_vector(SIZE/2, 1, 2, MPI_INT, &typevec);
00065
00066 b[0] = b[1] = b[2] = 1;
00067 d[0] = 0;
00068 d[1] = mynod*sizeof(int);
00069 d[2] = SIZE*sizeof(int);
00070 t[0] = MPI_LB;
00071 t[1] = typevec;
00072 t[2] = MPI_UB;
00073
00074 MPI_Type_struct(3, b, d, t, &newtype);
00075 MPI_Type_commit(&newtype);
00076 MPI_Type_free(&typevec);
00077
00078 if (!mynod) {
00079 #if VERBOSE
00080 fprintf(stderr, "\ntesting noncontiguous in memory, noncontiguous in file using nonblocking I/O\n");
00081 #endif
00082 MPI_File_delete(filename, MPI_INFO_NULL);
00083 }
00084 MPI_Barrier(MPI_COMM_WORLD);
00085
00086 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00087 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00088
00089 MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL);
00090
00091 for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE;
00092 MPI_File_iwrite(fh, buf, 1, newtype, &req);
00093 #ifdef MPIO_USES_MPI_REQUEST
00094 MPI_Wait(&req, &status);
00095 #else
00096 MPIO_Wait(&req, &status);
00097 #endif
00098
00099 MPI_Barrier(MPI_COMM_WORLD);
00100
00101 for (i=0; i<SIZE; i++) buf[i] = -1;
00102
00103 MPI_File_iread_at(fh, 0, buf, 1, newtype, &req);
00104 #ifdef MPIO_USES_MPI_REQUEST
00105 MPI_Wait(&req, &status);
00106 #else
00107 MPIO_Wait(&req, &status);
00108 #endif
00109
00110 for (i=0; i<SIZE; i++) {
00111 if (!mynod) {
00112 if ((i%2) && (buf[i] != -1)) {
00113 errs++;
00114 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n",
00115 mynod, i, buf[i]);
00116 }
00117 if (!(i%2) && (buf[i] != i)) {
00118 errs++;
00119 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
00120 mynod, i, buf[i], i);
00121 }
00122 }
00123 else {
00124 if ((i%2) && (buf[i] != i + mynod*SIZE)) {
00125 errs++;
00126 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
00127 mynod, i, buf[i], i + mynod*SIZE);
00128 }
00129 if (!(i%2) && (buf[i] != -1)) {
00130 errs++;
00131 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n",
00132 mynod, i, buf[i]);
00133 }
00134 }
00135 }
00136
00137 MPI_File_close(&fh);
00138
00139 MPI_Barrier(MPI_COMM_WORLD);
00140
00141 if (!mynod) {
00142 #if VERBOSE
00143 fprintf(stderr, "\ntesting noncontiguous in memory, contiguous in file using nonblocking I/O\n");
00144 #endif
00145 MPI_File_delete(filename, MPI_INFO_NULL);
00146 }
00147 MPI_Barrier(MPI_COMM_WORLD);
00148
00149 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00150 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00151
00152 for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE;
00153 MPI_File_iwrite_at(fh, mynod*(SIZE/2)*sizeof(int), buf, 1, newtype, &req);
00154 #ifdef MPIO_USES_MPI_REQUEST
00155 MPI_Wait(&req, &status);
00156 #else
00157 MPIO_Wait(&req, &status);
00158 #endif
00159
00160 MPI_Barrier(MPI_COMM_WORLD);
00161
00162 for (i=0; i<SIZE; i++) buf[i] = -1;
00163
00164 MPI_File_iread_at(fh, mynod*(SIZE/2)*sizeof(int), buf, 1, newtype, &req);
00165 #ifdef MPIO_USES_MPI_REQUEST
00166 MPI_Wait(&req, &status);
00167 #else
00168 MPIO_Wait(&req, &status);
00169 #endif
00170
00171 for (i=0; i<SIZE; i++) {
00172 if (!mynod) {
00173 if ((i%2) && (buf[i] != -1)) {
00174 errs++;
00175 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n",
00176 mynod, i, buf[i]);
00177 }
00178 if (!(i%2) && (buf[i] != i)) {
00179 errs++;
00180 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
00181 mynod, i, buf[i], i);
00182 }
00183 }
00184 else {
00185 if ((i%2) && (buf[i] != i + mynod*SIZE)) {
00186 errs++;
00187 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
00188 mynod, i, buf[i], i + mynod*SIZE);
00189 }
00190 if (!(i%2) && (buf[i] != -1)) {
00191 errs++;
00192 fprintf(stderr, "Process %d: buf %d is %d, should be -1\n",
00193 mynod, i, buf[i]);
00194 }
00195 }
00196 }
00197
00198 MPI_File_close(&fh);
00199
00200 MPI_Barrier(MPI_COMM_WORLD);
00201
00202 if (!mynod) {
00203 #if VERBOSE
00204 fprintf(stderr, "\ntesting contiguous in memory, noncontiguous in file using nonblocking I/O\n");
00205 #endif
00206 MPI_File_delete(filename, MPI_INFO_NULL);
00207 }
00208 MPI_Barrier(MPI_COMM_WORLD);
00209
00210 MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE |
00211 MPI_MODE_RDWR, MPI_INFO_NULL, &fh);
00212
00213 MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL);
00214
00215 for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE;
00216 MPI_File_iwrite(fh, buf, SIZE, MPI_INT, &req);
00217 #ifdef MPIO_USES_MPI_REQUEST
00218 MPI_Wait(&req, &status);
00219 #else
00220 MPIO_Wait(&req, &status);
00221 #endif
00222
00223 MPI_Barrier(MPI_COMM_WORLD);
00224
00225 for (i=0; i<SIZE; i++) buf[i] = -1;
00226
00227 MPI_File_iread_at(fh, 0, buf, SIZE, MPI_INT, &req);
00228 #ifdef MPIO_USES_MPI_REQUEST
00229 MPI_Wait(&req, &status);
00230 #else
00231 MPIO_Wait(&req, &status);
00232 #endif
00233
00234 for (i=0; i<SIZE; i++) {
00235 if (!mynod) {
00236 if (buf[i] != i) {
00237 errs++;
00238 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
00239 mynod, i, buf[i], i);
00240 }
00241 }
00242 else {
00243 if (buf[i] != i + mynod*SIZE) {
00244 errs++;
00245 fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
00246 mynod, i, buf[i], i + mynod*SIZE);
00247 }
00248 }
00249 }
00250
00251 MPI_File_close(&fh);
00252
00253 MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
00254 if (mynod == 0) {
00255 if( toterrs > 0) {
00256 fprintf( stderr, "Found %d errors\n", toterrs );
00257 }
00258 else {
00259 fprintf( stdout, " No Errors\n" );
00260 }
00261 }
00262 MPI_Type_free(&newtype);
00263 free(buf);
00264 free(filename);
00265 MPI_Finalize();
00266 return 0;
00267 }