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