00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <mpi.h>
00015 #include <stdint.h>
00016 #include <math.h>
00017 #include <stdio.h>
00018
00019 #define CHECK(fn) {int errcode; errcode = (fn); if (errcode != MPI_SUCCESS) handle_error(errcode, NULL); }
00020
00021
00022 static void handle_error(int errcode, char *str)
00023 {
00024 char msg[MPI_MAX_ERROR_STRING];
00025 int resultlen;
00026 MPI_Error_string(errcode, msg, &resultlen);
00027 fprintf(stderr, "%s: %s\n", str, msg);
00028 MPI_Abort(MPI_COMM_WORLD, 1);
00029 }
00030
00031 static void typestats(MPI_Datatype type)
00032 {
00033 MPI_Aint lb, extent;
00034 int size;
00035
00036 MPI_Type_get_extent(type, &lb, &extent);
00037 MPI_Type_size(type, &size);
00038
00039 printf("dtype %d: lb = %ld extent = %ld size = %d...",
00040 type, (long)lb, (long)extent, size);
00041
00042 }
00043
00044 static int verify_type(char *filename, MPI_Datatype type,
00045 int64_t expected_extent, int do_coll)
00046 {
00047 int rank, canary, tsize;
00048 int compare=-1;
00049 int errs=0, toterrs=0;
00050 MPI_Status status;
00051 MPI_File fh;
00052
00053 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00054
00055 CHECK( MPI_File_open(MPI_COMM_WORLD, filename,
00056 MPI_MODE_CREATE|MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
00057 CHECK( MPI_File_set_view(fh, rank*sizeof(int),
00058 MPI_BYTE, type, "native", MPI_INFO_NULL));
00059
00060 MPI_Type_size(type, &tsize);
00061
00062 canary=rank+1000000;
00063
00064
00065 if (do_coll) {
00066 CHECK( MPI_File_write_at_all(fh, tsize, &canary, 1, MPI_INT, &status));
00067 } else {
00068 CHECK( MPI_File_write_at(fh, tsize, &canary, 1, MPI_INT, &status));
00069 }
00070
00071 CHECK( MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, "native",
00072 MPI_INFO_NULL));
00073
00074 if (do_coll) {
00075 CHECK( MPI_File_read_at_all(fh, expected_extent/sizeof(int)+rank,
00076 &compare, 1, MPI_INT, &status));
00077 } else {
00078 CHECK( MPI_File_read_at(fh, expected_extent/sizeof(int)+rank,
00079 &compare, 1, MPI_INT, &status));
00080 }
00081
00082 if (compare != canary)
00083 errs=1;
00084 MPI_Allreduce(&errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
00085
00086 MPI_File_close(&fh);
00087
00088 if (toterrs) {
00089 printf("%d: got %d expected %d\n", rank, compare, canary);
00090
00091 } else {
00092 if (rank == 0) MPI_File_delete(filename, MPI_INFO_NULL);
00093 }
00094
00095 return (toterrs);
00096
00097 }
00098
00099 static int testtype(char *filename, MPI_Datatype type, int64_t expected_extent)
00100 {
00101 int rank, ret, errs=0;
00102 int collective=1, nocollective=0;
00103
00104 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00105 if (!rank) typestats(type);
00106
00107 ret = verify_type(filename, type, expected_extent, nocollective);
00108 if (ret) {
00109 errs++;
00110 fprintf(stderr, "type %d failed indep\n", type);
00111 } else
00112 if (!rank) printf("indep: OK ");
00113
00114 ret = verify_type(filename, type, expected_extent, collective);
00115 if (ret) {
00116 errs++;
00117 fprintf(stderr, "type %d failed collective\n", type);
00118 } else
00119 if (!rank) printf("coll: OK\n");
00120
00121 return errs;
00122 }
00123
00124 int main(int argc, char **argv)
00125 {
00126 int count=2;
00127 int blocks[2];
00128 int disps[2];
00129
00130 int ndims=2;
00131 int sizes[2];
00132 int subs[2];
00133 int starts[2];
00134
00135 MPI_Datatype baseindex, indexed1G, indexed3G, indexed6G;
00136 MPI_Datatype subarray1G, subarray3G, subarray6G;
00137 int ret, rank;
00138
00139 MPI_Init(&argc, &argv);
00140
00141 if (argc != 2) {
00142 fprintf(stderr, "usage: %s <filename>\n", argv[0]);
00143 MPI_Abort(MPI_COMM_WORLD, 1);
00144 }
00145
00146 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00147
00148
00149 count = 2;
00150 blocks[0] = 1;
00151 disps[0] = 0;
00152 blocks[1] = 1;
00153 disps[1] = 1024*256-1;
00154
00155 MPI_Type_indexed(count, blocks, disps, MPI_INT, &baseindex);
00156
00157 MPI_Type_contiguous(1024, baseindex, &indexed1G);
00158 MPI_Type_commit(&indexed1G);
00159
00160
00161 MPI_Type_contiguous(3072, baseindex, &indexed3G);
00162 MPI_Type_commit(&indexed3G);
00163
00164
00165 MPI_Type_contiguous(6144, baseindex, &indexed6G);
00166 MPI_Type_commit(&indexed6G);
00167
00168
00169
00170
00171 sizes[0] = 1024*16;
00172 sizes[1] = 1024*16;
00173 subs[0] = subs[1] = 256;
00174 starts[0] = starts[1] = 0;
00175
00176 MPI_Type_create_subarray(ndims, sizes, subs, starts,
00177 MPI_ORDER_C, MPI_INT, &subarray1G);
00178 MPI_Type_commit(&subarray1G);
00179
00180 sizes[1] = 1024*16*3;
00181 MPI_Type_create_subarray(ndims, sizes, subs, starts,
00182 MPI_ORDER_C, MPI_INT, &subarray3G);
00183 MPI_Type_commit(&subarray3G);
00184
00185 sizes[1] = 1024*16*6;
00186 MPI_Type_create_subarray(ndims, sizes, subs, starts,
00187 MPI_ORDER_C, MPI_INT, &subarray6G);
00188 MPI_Type_commit(&subarray6G);
00189
00190
00191 ret = testtype(argv[1], indexed1G, (int64_t)1024*1024*1024);
00192
00193 ret = testtype(argv[1], indexed3G, (int64_t)1024*1024*1024*3);
00194
00195 ret = testtype(argv[1], indexed6G, (int64_t)1024*1024*1024*6);
00196
00197 ret = testtype(argv[1], subarray1G, (int64_t)1024*1024*1024);
00198
00199 ret = testtype(argv[1], subarray3G, (int64_t)1024*1024*1024*3);
00200
00201 ret = testtype(argv[1], subarray6G, (int64_t)1024*1024*1024*6);
00202
00203 if(!ret && !rank) fprintf(stderr, " No Errors\n");
00204
00205 MPI_Finalize();
00206 return (-ret);
00207
00208 }
00209
00210
00211