00001
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include <mpi.h>
00006
00007 #define YLEN 5
00008 #define XLEN 10
00009 #define SUB_XLEN 3
00010
00011
00012 char compare_buf[XLEN*4][YLEN*4] = {
00013 {'0','1','2',0,0,'3','4','5',0,0,'D','E','F',0,0,'G','H','I'},
00014 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00015 {'6','7','8',0,0,'9',':',';',0,0,'J','K','L',0,0,'M','N','O'},
00016 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00017 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00018 {'X','Y','Z',0,0,'[','\\',']',0,0,'l','m','n',0,0,'o','p','q'},
00019 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00020 {'^','_','`',0,0,'a','b','c',0,0,'r','s','t',0,0,'u','v','w'},
00021 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00022 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00023 {'0','1','2',0,0,'3','4','5',0,0,'D','E','F',0,0,'G','H','I'},
00024 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00025 {'6','7','8',0,0,'9',':',';',0,0,'J','K','L',0,0,'M','N','O'},
00026 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00027 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00028 {'X','Y','Z',0,0,'[','\\',']',0,0,'l','m','n',0,0,'o','p','q'},
00029 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00030 {'^','_','`',0,0,'a','b','c',0,0,'r','s','t',0,0,'u','v','w'},
00031 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
00032 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
00033 };
00034
00035
00036
00037
00038
00039
00040
00041 int main(int argc, char **argv) {
00042 int i, j, err, rank, np, num_io;
00043 char *buf, *filename;
00044 int rank_dim[2], array_of_sizes[2];
00045 int array_of_subsizes[2];
00046 int count, *blocklengths, global_array_size, ftype_size;
00047 MPI_Aint *displacements;
00048 MPI_File fh;
00049 MPI_Datatype ftype;
00050 MPI_Status status;
00051 MPI_Offset offset=0;
00052 int nr_errors=0;
00053 #ifdef VERBOSE
00054 int k;
00055 #endif
00056
00057 MPI_Init(&argc, &argv);
00058 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00059 MPI_Comm_size(MPI_COMM_WORLD, &np);
00060
00061 if (np != 4) {
00062 if (!rank) printf("Please run with 4 processes. Exiting ...\n\n");
00063 MPI_Finalize();
00064 return 1;
00065 }
00066
00067 filename = argv[1];
00068
00069 num_io = 2;
00070
00071
00072
00073 rank_dim[0] = rank / 2;
00074 rank_dim[1] = rank % 2;
00075
00076
00077 array_of_sizes[0] = YLEN * 2;
00078 array_of_sizes[1] = XLEN * 2;
00079
00080 global_array_size = array_of_sizes[0] * array_of_sizes[1];
00081
00082 array_of_subsizes[0] = YLEN / 2;
00083 array_of_subsizes[1] = XLEN * SUB_XLEN / 5;
00084
00085 offset = rank_dim[0] * YLEN * array_of_sizes[1] +
00086 rank_dim[1] * XLEN;
00087
00088
00089 count = array_of_subsizes[0] * 2;
00090 blocklengths = (int*) malloc(count*sizeof(int));
00091 displacements = (MPI_Aint*)malloc(count*sizeof(MPI_Aint));
00092 for (i=0; i<count; i++)
00093 blocklengths[i] = array_of_subsizes[1] / 2;
00094 for (i=0; i<array_of_subsizes[0]; i++)
00095 for (j=0; j<2; j++)
00096 displacements[i*2+j] = offset + i*2*array_of_sizes[1] + j * XLEN/2;
00097 MPI_Type_create_hindexed(count, blocklengths, displacements, MPI_CHAR, &ftype);
00098 MPI_Type_commit(&ftype);
00099 MPI_Type_size(ftype, &ftype_size);
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 buf = (char*) malloc(array_of_subsizes[0]*array_of_subsizes[1]);
00132 for (i=0; i<array_of_subsizes[0]*array_of_subsizes[1]; i++)
00133 buf[i] = '0' + rank*20 + i%79;
00134
00135
00136 if (rank == 0) {
00137 char *wr_buf = (char*) calloc(num_io*global_array_size,1);
00138 MPI_File_open(MPI_COMM_SELF, filename,
00139 MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &fh);
00140 MPI_File_write(fh, wr_buf, num_io*global_array_size, MPI_CHAR, &status);
00141 MPI_File_close(&fh);
00142 free(wr_buf);
00143 }
00144
00145 err = MPI_File_open(MPI_COMM_WORLD, filename,
00146 MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &fh);
00147 if (err != MPI_SUCCESS) {
00148 printf("Error: MPI_File_open() filename %s\n",filename);
00149 MPI_Abort(MPI_COMM_WORLD, -1);
00150 exit(1);
00151 }
00152
00153
00154 for (i=0; i<num_io; i++) {
00155 offset = i * global_array_size;
00156
00157 MPI_File_set_view(fh, offset, MPI_BYTE, ftype, "native", MPI_INFO_NULL);
00158 MPI_File_write_all(fh, buf, ftype_size, MPI_CHAR, &status);
00159 }
00160 MPI_File_close(&fh);
00161
00162
00163 if (rank == 0) {
00164 char *ptr;
00165 char *rd_buf = (char*) calloc(num_io*global_array_size,1);
00166 MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &fh);
00167 MPI_File_read(fh, rd_buf, num_io*global_array_size, MPI_CHAR, &status);
00168 MPI_File_close(&fh);
00169
00170 #ifdef VERBOSE
00171 printf("-------------------------------------------------------\n");
00172 printf(" [");
00173 for (i=0; i<2; i++) {
00174 for (j=0; j<XLEN; j++) printf(" %d",j);
00175 printf(" ");
00176 }
00177 printf("]\n\n");
00178
00179
00180 ptr = rd_buf;
00181 for (k=0; k<num_io; k++) {
00182 for (i=0; i<2*YLEN; i++) {
00183 printf("[%2d]",k*2*YLEN+i);
00184 for (j=0; j<2*XLEN; j++) {
00185 if (j>0 && j%XLEN==0) printf(" ");
00186 if (*ptr != 0)
00187 printf(" %c",*ptr);
00188 else
00189 printf(" ");
00190 ptr++;
00191 }
00192 printf("\n");
00193 }
00194 printf("\n");
00195 }
00196 #endif
00197 ptr = rd_buf;
00198 for(i=0; i<2*YLEN*num_io; i++) {
00199 for(j=0; j<2*XLEN; j++) {
00200 if( *ptr != compare_buf[i][j]) {
00201 fprintf(stderr, "expected %d got %d at [%d][%d]\n",
00202 *ptr, compare_buf[i][j], i, j);
00203 nr_errors++;
00204 }
00205 ptr++;
00206 }
00207 }
00208 free(rd_buf);
00209
00210 if (nr_errors == 0)
00211 fprintf(stdout, " No Errors\n");
00212 else
00213 fprintf(stderr, "Found %d errors\n", nr_errors);
00214 }
00215
00216 free(blocklengths);
00217 free(displacements);
00218 free(buf);
00219 MPI_Type_free(&ftype);
00220 MPI_Finalize();
00221 return 0;
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253