00001
00002
00003
00004
00005
00006
00007 #include "../adio/include/adio.h"
00008 #include "../adio/include/adioi.h"
00009 #include "../adio/include/adio_extern.h"
00010 #include "mpi.h"
00011
00012 #define PREDEF_TESTS 5
00013 #define MAX_OFF_LENS 4
00014
00015 typedef struct {
00016 ADIO_Offset offset;
00017 int count;
00018 int type_blocklens[MAX_OFF_LENS];
00019 int type_indices[MAX_OFF_LENS];
00020 MPI_Datatype type_oldtypes[MAX_OFF_LENS];
00021 int type_count;
00022
00023 ADIO_Offset correct_st_offset;
00024 ADIO_Offset correct_end_offset;
00025 } test_param_t;
00026
00027 int run_test (test_param_t *test);
00028 int setup_predefined (test_param_t *tests_arr, int count);
00029 int print_usage (void);
00030 int print_test_params (test_param_t *test);
00031
00032 int main (int argc, char **argv) {
00033 int rank;
00034 int run_test_number = 0;
00035 int failed;
00036 int while_condition;
00037 int i;
00038
00039 test_param_t predefined_tests[PREDEF_TESTS];
00040
00041 MPI_Init (&argc, &argv);
00042 MPI_Comm_rank (MPI_COMM_WORLD, &rank);
00043
00044 if (argc != 1) {
00045 if (!rank) {
00046 printf ("Use only one process\n");
00047 print_usage ();
00048 }
00049 MPI_Finalize();
00050 return 1;
00051 }
00052 i = 1;
00053 while (i < argc) {
00054 if (!strcmp (argv[i], "-A")) {
00055 run_test_number = 0;
00056 i++;
00057 }
00058 else if (!strcmp (argv[i], "-T")) {
00059 run_test_number = atoi (argv[i+1]);
00060 if ((run_test_number > PREDEF_TESTS) || (run_test_number < 1)) {
00061 if (!rank)
00062 printf ("Invalid test number, only %d tests\n",
00063 PREDEF_TESTS);
00064 MPI_Finalize ();
00065 return 1;
00066 }
00067 i += 2;
00068 }
00069 else {
00070 if (!rank) {
00071 printf ("Invalid Argument: %s\n", argv[i]);
00072 print_usage ();
00073 }
00074 i++;
00075 }
00076 }
00077
00078 setup_predefined (predefined_tests, PREDEF_TESTS);
00079
00080 if (!run_test_number) {
00081 i = 0;
00082 while_condition = PREDEF_TESTS;
00083 }
00084 else {
00085 i = run_test_number - 1;
00086 while_condition = run_test_number;
00087 }
00088 while (i < while_condition) {
00089 printf ("***** Test %d *****\n", i+1);
00090 failed = run_test (&predefined_tests[i]);
00091 printf ("******************\n");
00092 i++;
00093 }
00094
00095 MPI_Finalize ();
00096
00097 return 0;
00098 }
00099
00100 int run_test (test_param_t *test) {
00101 ADIO_Offset st_offset, end_offset;
00102 MPI_File fh;
00103 int is_contig;
00104 int ind_err = 0, exp_err = 0;
00105
00106 MPI_Datatype filetype;
00107
00108 MPI_Type_struct (test->type_count, test->type_blocklens,
00109 test->type_indices, test->type_oldtypes, &filetype);
00110 MPI_Type_commit (&filetype);
00111
00112 MPI_File_open (MPI_COMM_WORLD, "test_file.txt" , MPI_MODE_RDWR,
00113 MPI_INFO_NULL, &fh);
00114
00115 MPI_File_set_view (fh, 0, MPI_BYTE, filetype, "native", MPI_INFO_NULL);
00116
00117 MPI_File_seek (fh, test->offset, MPI_SEEK_SET);
00118 ADIOI_Calc_bounds ((ADIO_File) fh, test->count, MPI_BYTE, ADIO_INDIVIDUAL,
00119 test->offset, &st_offset, &end_offset);
00120
00121 ind_err = 0;
00122 if (st_offset != test->correct_st_offset) {
00123 printf ("Individual st_offset = %lld end_offset = %lld\n",
00124 st_offset, end_offset);
00125 ind_err = 1;
00126 }
00127 if (end_offset != test->correct_end_offset) {
00128 printf ("Individual st_offset = %lld end_offset = %lld\n",
00129 st_offset, end_offset);
00130 ind_err = 1;
00131 }
00132 MPI_File_close (&fh);
00133 if (ind_err)
00134 printf ("Individual Calc FAILED\n");
00135
00136 MPI_File_open (MPI_COMM_WORLD, "test_file.txt" , MPI_MODE_RDWR,
00137 MPI_INFO_NULL, &fh);
00138
00139 if (!is_contig)
00140 MPI_File_set_view (fh, 0, MPI_BYTE, filetype, "native", MPI_INFO_NULL);
00141
00142 MPI_File_seek (fh, 0, MPI_SEEK_SET);
00143 ADIOI_Calc_bounds ((ADIO_File) fh, test->count, MPI_BYTE,
00144 ADIO_EXPLICIT_OFFSET, test->offset, &st_offset,
00145 &end_offset);
00146
00147 exp_err = 0;
00148 if (st_offset != test->correct_st_offset) {
00149 printf ("Explicit st_offset = %lld end_offset = %lld\n",
00150 st_offset, end_offset);
00151 exp_err = 1;
00152 }
00153 if (end_offset != test->correct_end_offset) {
00154 printf ("Explicit st_offset = %lld end_offset = %lld\n",
00155 st_offset, end_offset);
00156 exp_err = 1;
00157 }
00158 if (exp_err)
00159 printf ("Explicit Calc FAILED\n");
00160
00161 MPI_File_close (&fh);
00162
00163 if (!is_contig)
00164 MPI_Type_free (&filetype);
00165
00166 return (exp_err || ind_err);
00167 }
00168
00169 int print_usage ()
00170 {
00171 printf (
00172 "Usage:\n"
00173 " io_bounds_test -A -T <test #>\n");
00174 }
00175
00176 int print_test_params (test_param_t *test)
00177 {
00178 int i;
00179 printf (
00180 "I/O offset: %lld\n"
00181 "bytes: %d\n"
00182 "Filetype [n](disp, lens, type):\n",
00183 test->offset, test->count);
00184
00185 for (i=0; i<test->type_count; i++) {
00186 printf (
00187 " [%d](%lld, %d, ",
00188 i,
00189 test->type_blocklens[i],
00190 test->type_indices[i]);
00191 if (test->type_oldtypes[i] == MPI_BYTE) {
00192 printf ( "%s)\n", "MPI_BYTE");
00193 }
00194 else if (test->type_oldtypes[i] == MPI_UB) {
00195 printf ( "%s)\n", "MPI_UB");
00196 }
00197 else if (test->type_oldtypes[i] == MPI_LB) {
00198 printf ( "%s)\n", "MPI_LB");
00199 }
00200 }
00201 printf (
00202 "Expected Start offset: %lld\n"
00203 "Expected End offset: %lld\n",
00204 test->correct_st_offset,
00205 test->correct_end_offset);
00206 }
00207
00208 int setup_predefined (test_param_t *tests_arr, int count)
00209 {
00210 int i;
00211 for (i=0; i < PREDEF_TESTS; i++) {
00212 switch (i)
00213 {
00214 case 0:
00215 tests_arr[i].offset = 0;
00216 tests_arr[i].count = 0;
00217 tests_arr[i].type_count = 0;
00218 tests_arr[i].type_indices[0] = 0;
00219 tests_arr[i].type_blocklens[0] = 0;
00220 tests_arr[i].type_oldtypes[0] = MPI_BYTE;
00221 tests_arr[i].type_indices[1] = 0;
00222 tests_arr[i].type_blocklens[1] = 0;
00223 tests_arr[i].type_oldtypes[1] = MPI_BYTE;
00224 tests_arr[i].type_indices[2] = 0;
00225 tests_arr[i].type_blocklens[2] = 0;
00226 tests_arr[i].type_oldtypes[2] = MPI_BYTE;
00227 tests_arr[i].type_indices[3] = 0;
00228 tests_arr[i].type_blocklens[3] = 0;
00229 tests_arr[i].type_oldtypes[3] = MPI_BYTE;
00230 break;
00231 case 1:
00232 tests_arr[i].offset = 0;
00233 tests_arr[i].count = 0;
00234 tests_arr[i].type_count = 0;
00235 tests_arr[i].type_indices[0] = 0;
00236 tests_arr[i].type_blocklens[0] = 0;
00237 tests_arr[i].type_oldtypes[0] = MPI_BYTE;
00238 tests_arr[i].type_indices[1] = 0;
00239 tests_arr[i].type_blocklens[1] = 0;
00240 tests_arr[i].type_oldtypes[1] = MPI_BYTE;
00241 tests_arr[i].type_indices[2] = 0;
00242 tests_arr[i].type_blocklens[2] = 0;
00243 tests_arr[i].type_oldtypes[2] = MPI_BYTE;
00244 tests_arr[i].type_indices[3] = 0;
00245 tests_arr[i].type_blocklens[3] = 0;
00246 tests_arr[i].type_oldtypes[3] = MPI_BYTE;
00247 break;
00248 case 2:
00249 tests_arr[i].offset = 0;
00250 tests_arr[i].count = 0;
00251 tests_arr[i].type_count = 0;
00252 tests_arr[i].type_indices[0] = 0;
00253 tests_arr[i].type_blocklens[0] = 0;
00254 tests_arr[i].type_oldtypes[0] = MPI_BYTE;
00255 tests_arr[i].type_indices[1] = 0;
00256 tests_arr[i].type_blocklens[1] = 0;
00257 tests_arr[i].type_oldtypes[1] = MPI_BYTE;
00258 tests_arr[i].type_indices[2] = 0;
00259 tests_arr[i].type_blocklens[2] = 0;
00260 tests_arr[i].type_oldtypes[2] = MPI_BYTE;
00261 tests_arr[i].type_indices[3] = 0;
00262 tests_arr[i].type_blocklens[3] = 0;
00263 tests_arr[i].type_oldtypes[3] = MPI_BYTE;
00264 break;
00265 case 3:
00266 tests_arr[i].offset = 0;
00267 tests_arr[i].count = 0;
00268 tests_arr[i].type_count = 0;
00269 tests_arr[i].type_indices[0] = 0;
00270 tests_arr[i].type_blocklens[0] = 0;
00271 tests_arr[i].type_oldtypes[0] = MPI_BYTE;
00272 tests_arr[i].type_indices[1] = 0;
00273 tests_arr[i].type_blocklens[1] = 0;
00274 tests_arr[i].type_oldtypes[1] = MPI_BYTE;
00275 tests_arr[i].type_indices[2] = 0;
00276 tests_arr[i].type_blocklens[2] = 0;
00277 tests_arr[i].type_oldtypes[2] = MPI_BYTE;
00278 tests_arr[i].type_indices[3] = 0;
00279 tests_arr[i].type_blocklens[3] = 0;
00280 tests_arr[i].type_oldtypes[3] = MPI_BYTE;
00281 break;
00282 case 4:
00283 tests_arr[i].offset = 0;
00284 tests_arr[i].count = 0;
00285 tests_arr[i].type_count = 0;
00286 tests_arr[i].type_indices[0] = 0;
00287 tests_arr[i].type_blocklens[0] = 0;
00288 tests_arr[i].type_oldtypes[0] = MPI_BYTE;
00289 tests_arr[i].type_indices[1] = 0;
00290 tests_arr[i].type_blocklens[1] = 0;
00291 tests_arr[i].type_oldtypes[1] = MPI_BYTE;
00292 tests_arr[i].type_indices[2] = 0;
00293 tests_arr[i].type_blocklens[2] = 0;
00294 tests_arr[i].type_oldtypes[2] = MPI_BYTE;
00295 tests_arr[i].type_indices[3] = 0;
00296 tests_arr[i].type_blocklens[3] = 0;
00297 tests_arr[i].type_oldtypes[3] = MPI_BYTE;
00298 break;
00299 }
00300 }
00301 return 0;
00302 }