annotate fft/fftw/fftw-3.3.4/mpi/testsched.c @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 /*
Chris@19 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@19 3 * Copyright (c) 1999-2003, 2007-8 Massachusetts Institute of Technology
Chris@19 4 *
Chris@19 5 * This program is free software; you can redistribute it and/or modify
Chris@19 6 * it under the terms of the GNU General Public License as published by
Chris@19 7 * the Free Software Foundation; either version 2 of the License, or
Chris@19 8 * (at your option) any later version.
Chris@19 9 *
Chris@19 10 * This program is distributed in the hope that it will be useful,
Chris@19 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@19 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@19 13 * GNU General Public License for more details.
Chris@19 14 *
Chris@19 15 * You should have received a copy of the GNU General Public License
Chris@19 16 * along with this program; if not, write to the Free Software
Chris@19 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@19 18 *
Chris@19 19 */
Chris@19 20
Chris@19 21 /**********************************************************************/
Chris@19 22 /* This is a modified and combined version of the sched.c and
Chris@19 23 test_sched.c files shipped with FFTW 2, written to implement and
Chris@19 24 test various all-to-all communications scheduling patterns.
Chris@19 25
Chris@19 26 It is not used in FFTW 3, but I keep it around in case we ever want
Chris@19 27 to play with this again or to change algorithms. In particular, I
Chris@19 28 used it to implement and test the fill1_comm_sched routine in
Chris@19 29 transpose-pairwise.c, which allows us to create a schedule for one
Chris@19 30 process at a time and is much more compact than the FFTW 2 code.
Chris@19 31
Chris@19 32 Note that the scheduling algorithm is somewhat modified from that
Chris@19 33 of FFTW 2. Originally, I thought that one "stall" in the schedule
Chris@19 34 was unavoidable for odd numbers of processes, since this is the
Chris@19 35 case for the soccer-timetabling problem. However, because of the
Chris@19 36 self-communication step, we can use the self-communication to fill
Chris@19 37 in the stalls. (Thanks to Ralf Wildenhues for pointing this out.)
Chris@19 38 This greatly simplifies the process re-sorting algorithm. */
Chris@19 39
Chris@19 40 /**********************************************************************/
Chris@19 41
Chris@19 42 #include <stdio.h>
Chris@19 43 #include <stdlib.h>
Chris@19 44
Chris@19 45 /* This file contains routines to compute communications schedules for
Chris@19 46 all-to-all communications (complete exchanges) that are performed
Chris@19 47 in-place. (That is, the block that processor x sends to processor
Chris@19 48 y gets replaced on processor x by a block received from processor y.)
Chris@19 49
Chris@19 50 A schedule, int **sched, is a two-dimensional array where
Chris@19 51 sched[pe][i] is the processor that pe expects to exchange a message
Chris@19 52 with on the i-th step of the exchange. sched[pe][i] == -1 for the
Chris@19 53 i after the last exchange scheduled on pe.
Chris@19 54
Chris@19 55 Here, processors (pe's, for processing elements), are numbered from
Chris@19 56 0 to npes-1.
Chris@19 57
Chris@19 58 There are a couple of constraints that a schedule should satisfy
Chris@19 59 (besides the obvious one that every processor has to communicate
Chris@19 60 with every other processor exactly once).
Chris@19 61
Chris@19 62 * First, and most importantly, there must be no deadlocks.
Chris@19 63
Chris@19 64 * Second, we would like to overlap communications as much as possible,
Chris@19 65 so that all exchanges occur in parallel. It turns out that perfect
Chris@19 66 overlap is possible for all number of processes (npes).
Chris@19 67
Chris@19 68 It turns out that this scheduling problem is actually well-studied,
Chris@19 69 and good solutions are known. The problem is known as a
Chris@19 70 "time-tabling" problem, and is specifically the problem of
Chris@19 71 scheduling a sports competition (where n teams must compete exactly
Chris@19 72 once with every other team). The problem is discussed and
Chris@19 73 algorithms are presented in:
Chris@19 74
Chris@19 75 [1] J. A. M. Schreuder, "Constructing Timetables for Sport
Chris@19 76 Competitions," Mathematical Programming Study 13, pp. 58-67 (1980).
Chris@19 77
Chris@19 78 [2] A. Schaerf, "Scheduling Sport Tournaments using Constraint
Chris@19 79 Logic Programming," Proc. of 12th Europ. Conf. on
Chris@19 80 Artif. Intell. (ECAI-96), pp. 634-639 (Budapest 1996).
Chris@19 81 http://hermes.dis.uniromal.it/~aschaerf/publications.html
Chris@19 82
Chris@19 83 (These people actually impose a lot of additional constraints that
Chris@19 84 we don't care about, so they are solving harder problems. [1] gives
Chris@19 85 a simple enough algorithm for our purposes, though.)
Chris@19 86
Chris@19 87 In the timetabling problem, N teams can all play one another in N-1
Chris@19 88 steps if N is even, and N steps if N is odd. Here, however,
Chris@19 89 there is a "self-communication" step (a team must also "play itself")
Chris@19 90 and so we can always make an optimal N-step schedule regardless of N.
Chris@19 91
Chris@19 92 However, we have to do more: for a particular processor, the
Chris@19 93 communications schedule must be sorted in ascending or descending
Chris@19 94 order of processor index. (This is necessary so that the data
Chris@19 95 coming in for the transpose does not overwrite data that will be
Chris@19 96 sent later; for that processor the incoming and outgoing blocks are
Chris@19 97 of different non-zero sizes.) Fortunately, because the schedule
Chris@19 98 is stall free, each parallel step of the schedule is independent
Chris@19 99 of every other step, and we can reorder the steps arbitrarily
Chris@19 100 to achieve any desired order on a particular process.
Chris@19 101 */
Chris@19 102
Chris@19 103 void free_comm_schedule(int **sched, int npes)
Chris@19 104 {
Chris@19 105 if (sched) {
Chris@19 106 int i;
Chris@19 107
Chris@19 108 for (i = 0; i < npes; ++i)
Chris@19 109 free(sched[i]);
Chris@19 110 free(sched);
Chris@19 111 }
Chris@19 112 }
Chris@19 113
Chris@19 114 void empty_comm_schedule(int **sched, int npes)
Chris@19 115 {
Chris@19 116 int i;
Chris@19 117 for (i = 0; i < npes; ++i)
Chris@19 118 sched[i][0] = -1;
Chris@19 119 }
Chris@19 120
Chris@19 121 extern void fill_comm_schedule(int **sched, int npes);
Chris@19 122
Chris@19 123 /* Create a new communications schedule for a given number of processors.
Chris@19 124 The schedule is initialized to a deadlock-free, maximum overlap
Chris@19 125 schedule. Returns NULL on an error (may print a message to
Chris@19 126 stderr if there is a program bug detected). */
Chris@19 127 int **make_comm_schedule(int npes)
Chris@19 128 {
Chris@19 129 int **sched;
Chris@19 130 int i;
Chris@19 131
Chris@19 132 sched = (int **) malloc(sizeof(int *) * npes);
Chris@19 133 if (!sched)
Chris@19 134 return NULL;
Chris@19 135
Chris@19 136 for (i = 0; i < npes; ++i)
Chris@19 137 sched[i] = NULL;
Chris@19 138
Chris@19 139 for (i = 0; i < npes; ++i) {
Chris@19 140 sched[i] = (int *) malloc(sizeof(int) * 10 * (npes + 1));
Chris@19 141 if (!sched[i]) {
Chris@19 142 free_comm_schedule(sched,npes);
Chris@19 143 return NULL;
Chris@19 144 }
Chris@19 145 }
Chris@19 146
Chris@19 147 empty_comm_schedule(sched,npes);
Chris@19 148 fill_comm_schedule(sched,npes);
Chris@19 149
Chris@19 150 if (!check_comm_schedule(sched,npes)) {
Chris@19 151 free_comm_schedule(sched,npes);
Chris@19 152 return NULL;
Chris@19 153 }
Chris@19 154
Chris@19 155 return sched;
Chris@19 156 }
Chris@19 157
Chris@19 158 static void add_dest_to_comm_schedule(int **sched, int pe, int dest)
Chris@19 159 {
Chris@19 160 int i;
Chris@19 161
Chris@19 162 for (i = 0; sched[pe][i] != -1; ++i)
Chris@19 163 ;
Chris@19 164
Chris@19 165 sched[pe][i] = dest;
Chris@19 166 sched[pe][i+1] = -1;
Chris@19 167 }
Chris@19 168
Chris@19 169 static void add_pair_to_comm_schedule(int **sched, int pe1, int pe2)
Chris@19 170 {
Chris@19 171 add_dest_to_comm_schedule(sched, pe1, pe2);
Chris@19 172 if (pe1 != pe2)
Chris@19 173 add_dest_to_comm_schedule(sched, pe2, pe1);
Chris@19 174 }
Chris@19 175
Chris@19 176 /* Simplification of algorithm presented in [1] (we have fewer
Chris@19 177 constraints). Produces a perfect schedule (npes steps). */
Chris@19 178
Chris@19 179 void fill_comm_schedule(int **sched, int npes)
Chris@19 180 {
Chris@19 181 int pe, i, n;
Chris@19 182
Chris@19 183 if (npes % 2 == 0) {
Chris@19 184 n = npes;
Chris@19 185 for (pe = 0; pe < npes; ++pe)
Chris@19 186 add_pair_to_comm_schedule(sched,pe,pe);
Chris@19 187 }
Chris@19 188 else
Chris@19 189 n = npes + 1;
Chris@19 190
Chris@19 191 for (pe = 0; pe < n - 1; ++pe) {
Chris@19 192 add_pair_to_comm_schedule(sched, pe, npes % 2 == 0 ? npes - 1 : pe);
Chris@19 193
Chris@19 194 for (i = 1; i < n/2; ++i) {
Chris@19 195 int pe_a, pe_b;
Chris@19 196
Chris@19 197 pe_a = pe - i;
Chris@19 198 if (pe_a < 0)
Chris@19 199 pe_a += n - 1;
Chris@19 200
Chris@19 201 pe_b = (pe + i) % (n - 1);
Chris@19 202
Chris@19 203 add_pair_to_comm_schedule(sched,pe_a,pe_b);
Chris@19 204 }
Chris@19 205 }
Chris@19 206 }
Chris@19 207
Chris@19 208 /* given an array sched[npes], fills it with the communications
Chris@19 209 schedule for process pe. */
Chris@19 210 void fill1_comm_sched(int *sched, int which_pe, int npes)
Chris@19 211 {
Chris@19 212 int pe, i, n, s = 0;
Chris@19 213 if (npes % 2 == 0) {
Chris@19 214 n = npes;
Chris@19 215 sched[s++] = which_pe;
Chris@19 216 }
Chris@19 217 else
Chris@19 218 n = npes + 1;
Chris@19 219 for (pe = 0; pe < n - 1; ++pe) {
Chris@19 220 if (npes % 2 == 0) {
Chris@19 221 if (pe == which_pe) sched[s++] = npes - 1;
Chris@19 222 else if (npes - 1 == which_pe) sched[s++] = pe;
Chris@19 223 }
Chris@19 224 else if (pe == which_pe) sched[s++] = pe;
Chris@19 225
Chris@19 226 if (pe != which_pe && which_pe < n - 1) {
Chris@19 227 i = (pe - which_pe + (n - 1)) % (n - 1);
Chris@19 228 if (i < n/2)
Chris@19 229 sched[s++] = (pe + i) % (n - 1);
Chris@19 230
Chris@19 231 i = (which_pe - pe + (n - 1)) % (n - 1);
Chris@19 232 if (i < n/2)
Chris@19 233 sched[s++] = (pe - i + (n - 1)) % (n - 1);
Chris@19 234 }
Chris@19 235 }
Chris@19 236 if (s != npes) {
Chris@19 237 fprintf(stderr, "bug in fill1_com_schedule (%d, %d/%d)\n",
Chris@19 238 s, which_pe, npes);
Chris@19 239 exit(EXIT_FAILURE);
Chris@19 240 }
Chris@19 241 }
Chris@19 242
Chris@19 243 /* sort the communication schedule sched for npes so that the schedule
Chris@19 244 on process sortpe is ascending or descending (!ascending). */
Chris@19 245 static void sort1_comm_sched(int *sched, int npes, int sortpe, int ascending)
Chris@19 246 {
Chris@19 247 int *sortsched, i;
Chris@19 248 sortsched = (int *) malloc(npes * sizeof(int) * 2);
Chris@19 249 fill1_comm_sched(sortsched, sortpe, npes);
Chris@19 250 if (ascending)
Chris@19 251 for (i = 0; i < npes; ++i)
Chris@19 252 sortsched[npes + sortsched[i]] = sched[i];
Chris@19 253 else
Chris@19 254 for (i = 0; i < npes; ++i)
Chris@19 255 sortsched[2*npes - 1 - sortsched[i]] = sched[i];
Chris@19 256 for (i = 0; i < npes; ++i)
Chris@19 257 sched[i] = sortsched[npes + i];
Chris@19 258 free(sortsched);
Chris@19 259 }
Chris@19 260
Chris@19 261 /* Below, we have various checks in case of bugs: */
Chris@19 262
Chris@19 263 /* check for deadlocks by simulating the schedule and looking for
Chris@19 264 cycles in the dependency list; returns 0 if there are deadlocks
Chris@19 265 (or other errors) */
Chris@19 266 static int check_schedule_deadlock(int **sched, int npes)
Chris@19 267 {
Chris@19 268 int *step, *depend, *visited, pe, pe2, period, done = 0;
Chris@19 269 int counter = 0;
Chris@19 270
Chris@19 271 /* step[pe] is the step in the schedule that a given pe is on */
Chris@19 272 step = (int *) malloc(sizeof(int) * npes);
Chris@19 273
Chris@19 274 /* depend[pe] is the pe' that pe is currently waiting for a message
Chris@19 275 from (-1 if none) */
Chris@19 276 depend = (int *) malloc(sizeof(int) * npes);
Chris@19 277
Chris@19 278 /* visited[pe] tells whether we have visited the current pe already
Chris@19 279 when we are looking for cycles. */
Chris@19 280 visited = (int *) malloc(sizeof(int) * npes);
Chris@19 281
Chris@19 282 if (!step || !depend || !visited) {
Chris@19 283 free(step); free(depend); free(visited);
Chris@19 284 return 0;
Chris@19 285 }
Chris@19 286
Chris@19 287 for (pe = 0; pe < npes; ++pe)
Chris@19 288 step[pe] = 0;
Chris@19 289
Chris@19 290 while (!done) {
Chris@19 291 ++counter;
Chris@19 292
Chris@19 293 for (pe = 0; pe < npes; ++pe)
Chris@19 294 depend[pe] = sched[pe][step[pe]];
Chris@19 295
Chris@19 296 /* now look for cycles in the dependencies with period > 2: */
Chris@19 297 for (pe = 0; pe < npes; ++pe)
Chris@19 298 if (depend[pe] != -1) {
Chris@19 299 for (pe2 = 0; pe2 < npes; ++pe2)
Chris@19 300 visited[pe2] = 0;
Chris@19 301
Chris@19 302 period = 0;
Chris@19 303 pe2 = pe;
Chris@19 304 do {
Chris@19 305 visited[pe2] = period + 1;
Chris@19 306 pe2 = depend[pe2];
Chris@19 307 period++;
Chris@19 308 } while (pe2 != -1 && !visited[pe2]);
Chris@19 309
Chris@19 310 if (pe2 == -1) {
Chris@19 311 fprintf(stderr,
Chris@19 312 "BUG: unterminated cycle in schedule!\n");
Chris@19 313 free(step); free(depend);
Chris@19 314 free(visited);
Chris@19 315 return 0;
Chris@19 316 }
Chris@19 317 if (period - (visited[pe2] - 1) > 2) {
Chris@19 318 fprintf(stderr,"BUG: deadlock in schedule!\n");
Chris@19 319 free(step); free(depend);
Chris@19 320 free(visited);
Chris@19 321 return 0;
Chris@19 322 }
Chris@19 323
Chris@19 324 if (pe2 == pe)
Chris@19 325 step[pe]++;
Chris@19 326 }
Chris@19 327
Chris@19 328 done = 1;
Chris@19 329 for (pe = 0; pe < npes; ++pe)
Chris@19 330 if (sched[pe][step[pe]] != -1) {
Chris@19 331 done = 0;
Chris@19 332 break;
Chris@19 333 }
Chris@19 334 }
Chris@19 335
Chris@19 336 free(step); free(depend); free(visited);
Chris@19 337 return (counter > 0 ? counter : 1);
Chris@19 338 }
Chris@19 339
Chris@19 340 /* sanity checks; prints message and returns 0 on failure.
Chris@19 341 undocumented feature: the return value on success is actually the
Chris@19 342 number of steps required for the schedule to complete, counting
Chris@19 343 stalls. */
Chris@19 344 int check_comm_schedule(int **sched, int npes)
Chris@19 345 {
Chris@19 346 int pe, i, comm_pe;
Chris@19 347
Chris@19 348 for (pe = 0; pe < npes; ++pe) {
Chris@19 349 for (comm_pe = 0; comm_pe < npes; ++comm_pe) {
Chris@19 350 for (i = 0; sched[pe][i] != -1 && sched[pe][i] != comm_pe; ++i)
Chris@19 351 ;
Chris@19 352 if (sched[pe][i] == -1) {
Chris@19 353 fprintf(stderr,"BUG: schedule never sends message from "
Chris@19 354 "%d to %d.\n",pe,comm_pe);
Chris@19 355 return 0; /* never send message to comm_pe */
Chris@19 356 }
Chris@19 357 }
Chris@19 358 for (i = 0; sched[pe][i] != -1; ++i)
Chris@19 359 ;
Chris@19 360 if (i != npes) {
Chris@19 361 fprintf(stderr,"BUG: schedule sends too many messages from "
Chris@19 362 "%d\n",pe);
Chris@19 363 return 0;
Chris@19 364 }
Chris@19 365 }
Chris@19 366 return check_schedule_deadlock(sched,npes);
Chris@19 367 }
Chris@19 368
Chris@19 369 /* invert the order of all the schedules; this has no effect on
Chris@19 370 its required properties. */
Chris@19 371 void invert_comm_schedule(int **sched, int npes)
Chris@19 372 {
Chris@19 373 int pe, i;
Chris@19 374
Chris@19 375 for (pe = 0; pe < npes; ++pe)
Chris@19 376 for (i = 0; i < npes/2; ++i) {
Chris@19 377 int dummy = sched[pe][i];
Chris@19 378 sched[pe][i] = sched[pe][npes-1-i];
Chris@19 379 sched[pe][npes-1-i] = dummy;
Chris@19 380 }
Chris@19 381 }
Chris@19 382
Chris@19 383 /* Sort the schedule for sort_pe in ascending order of processor
Chris@19 384 index. Unfortunately, for odd npes (when schedule has a stall
Chris@19 385 to begin with) this will introduce an extra stall due to
Chris@19 386 the motion of the self-communication past a stall. We could
Chris@19 387 fix this if it were really important. Actually, we don't
Chris@19 388 get an extra stall when sort_pe == 0 or npes-1, which is sufficient
Chris@19 389 for our purposes. */
Chris@19 390 void sort_comm_schedule(int **sched, int npes, int sort_pe)
Chris@19 391 {
Chris@19 392 int i,j,pe;
Chris@19 393
Chris@19 394 /* Note that we can do this sort in O(npes) swaps because we know
Chris@19 395 that the numbers we are sorting are just 0...npes-1. But we'll
Chris@19 396 just do a bubble sort for simplicity here. */
Chris@19 397
Chris@19 398 for (i = 0; i < npes - 1; ++i)
Chris@19 399 for (j = i + 1; j < npes; ++j)
Chris@19 400 if (sched[sort_pe][i] > sched[sort_pe][j]) {
Chris@19 401 for (pe = 0; pe < npes; ++pe) {
Chris@19 402 int s = sched[pe][i];
Chris@19 403 sched[pe][i] = sched[pe][j];
Chris@19 404 sched[pe][j] = s;
Chris@19 405 }
Chris@19 406 }
Chris@19 407 }
Chris@19 408
Chris@19 409 /* print the schedule (for debugging purposes) */
Chris@19 410 void print_comm_schedule(int **sched, int npes)
Chris@19 411 {
Chris@19 412 int pe, i, width;
Chris@19 413
Chris@19 414 if (npes < 10)
Chris@19 415 width = 1;
Chris@19 416 else if (npes < 100)
Chris@19 417 width = 2;
Chris@19 418 else
Chris@19 419 width = 3;
Chris@19 420
Chris@19 421 for (pe = 0; pe < npes; ++pe) {
Chris@19 422 printf("pe %*d schedule:", width, pe);
Chris@19 423 for (i = 0; sched[pe][i] != -1; ++i)
Chris@19 424 printf(" %*d",width,sched[pe][i]);
Chris@19 425 printf("\n");
Chris@19 426 }
Chris@19 427 }
Chris@19 428
Chris@19 429 int main(int argc, char **argv)
Chris@19 430 {
Chris@19 431 int **sched;
Chris@19 432 int npes = -1, sortpe = -1, steps, i;
Chris@19 433
Chris@19 434 if (argc >= 2) {
Chris@19 435 npes = atoi(argv[1]);
Chris@19 436 if (npes <= 0) {
Chris@19 437 fprintf(stderr,"npes must be positive!");
Chris@19 438 return 1;
Chris@19 439 }
Chris@19 440 }
Chris@19 441 if (argc >= 3) {
Chris@19 442 sortpe = atoi(argv[2]);
Chris@19 443 if (sortpe < 0 || sortpe >= npes) {
Chris@19 444 fprintf(stderr,"sortpe must be between 0 and npes-1.\n");
Chris@19 445 return 1;
Chris@19 446 }
Chris@19 447 }
Chris@19 448
Chris@19 449 if (npes != -1) {
Chris@19 450 printf("Computing schedule for npes = %d:\n",npes);
Chris@19 451 sched = make_comm_schedule(npes);
Chris@19 452 if (!sched) {
Chris@19 453 fprintf(stderr,"Out of memory!");
Chris@19 454 return 6;
Chris@19 455 }
Chris@19 456
Chris@19 457 if (steps = check_comm_schedule(sched,npes))
Chris@19 458 printf("schedule OK (takes %d steps to complete).\n", steps);
Chris@19 459 else
Chris@19 460 printf("schedule not OK.\n");
Chris@19 461
Chris@19 462 print_comm_schedule(sched, npes);
Chris@19 463
Chris@19 464 if (sortpe != -1) {
Chris@19 465 printf("\nRe-creating schedule for pe = %d...\n", sortpe);
Chris@19 466 int *sched1 = (int*) malloc(sizeof(int) * npes);
Chris@19 467 for (i = 0; i < npes; ++i) sched1[i] = -1;
Chris@19 468 fill1_comm_sched(sched1, sortpe, npes);
Chris@19 469 printf(" =");
Chris@19 470 for (i = 0; i < npes; ++i)
Chris@19 471 printf(" %*d", npes < 10 ? 1 : (npes < 100 ? 2 : 3),
Chris@19 472 sched1[i]);
Chris@19 473 printf("\n");
Chris@19 474
Chris@19 475 printf("\nSorting schedule for sortpe = %d...\n", sortpe);
Chris@19 476 sort_comm_schedule(sched,npes,sortpe);
Chris@19 477
Chris@19 478 if (steps = check_comm_schedule(sched,npes))
Chris@19 479 printf("schedule OK (takes %d steps to complete).\n",
Chris@19 480 steps);
Chris@19 481 else
Chris@19 482 printf("schedule not OK.\n");
Chris@19 483
Chris@19 484 print_comm_schedule(sched, npes);
Chris@19 485
Chris@19 486 printf("\nInverting schedule...\n");
Chris@19 487 invert_comm_schedule(sched,npes);
Chris@19 488
Chris@19 489 if (steps = check_comm_schedule(sched,npes))
Chris@19 490 printf("schedule OK (takes %d steps to complete).\n",
Chris@19 491 steps);
Chris@19 492 else
Chris@19 493 printf("schedule not OK.\n");
Chris@19 494
Chris@19 495 print_comm_schedule(sched, npes);
Chris@19 496
Chris@19 497 free_comm_schedule(sched,npes);
Chris@19 498
Chris@19 499 free(sched1);
Chris@19 500 }
Chris@19 501 }
Chris@19 502 else {
Chris@19 503 printf("Doing infinite tests...\n");
Chris@19 504 for (npes = 1; ; ++npes) {
Chris@19 505 int *sched1 = (int*) malloc(sizeof(int) * npes);
Chris@19 506 printf("npes = %d...",npes);
Chris@19 507 sched = make_comm_schedule(npes);
Chris@19 508 if (!sched) {
Chris@19 509 fprintf(stderr,"Out of memory!\n");
Chris@19 510 return 5;
Chris@19 511 }
Chris@19 512 for (sortpe = 0; sortpe < npes; ++sortpe) {
Chris@19 513 empty_comm_schedule(sched,npes);
Chris@19 514 fill_comm_schedule(sched,npes);
Chris@19 515 if (!check_comm_schedule(sched,npes)) {
Chris@19 516 fprintf(stderr,
Chris@19 517 "\n -- fill error for sortpe = %d!\n",sortpe);
Chris@19 518 return 2;
Chris@19 519 }
Chris@19 520
Chris@19 521 for (i = 0; i < npes; ++i) sched1[i] = -1;
Chris@19 522 fill1_comm_sched(sched1, sortpe, npes);
Chris@19 523 for (i = 0; i < npes; ++i)
Chris@19 524 if (sched1[i] != sched[sortpe][i])
Chris@19 525 fprintf(stderr,
Chris@19 526 "\n -- fill1 error for pe = %d!\n",
Chris@19 527 sortpe);
Chris@19 528
Chris@19 529 sort_comm_schedule(sched,npes,sortpe);
Chris@19 530 if (!check_comm_schedule(sched,npes)) {
Chris@19 531 fprintf(stderr,
Chris@19 532 "\n -- sort error for sortpe = %d!\n",sortpe);
Chris@19 533 return 3;
Chris@19 534 }
Chris@19 535 invert_comm_schedule(sched,npes);
Chris@19 536 if (!check_comm_schedule(sched,npes)) {
Chris@19 537 fprintf(stderr,
Chris@19 538 "\n -- invert error for sortpe = %d!\n",
Chris@19 539 sortpe);
Chris@19 540 return 4;
Chris@19 541 }
Chris@19 542 }
Chris@19 543 free_comm_schedule(sched,npes);
Chris@19 544 printf("OK\n");
Chris@19 545 if (npes % 50 == 0)
Chris@19 546 printf("(...Hit Ctrl-C to stop...)\n");
Chris@19 547 free(sched1);
Chris@19 548 }
Chris@19 549 }
Chris@19 550
Chris@19 551 return 0;
Chris@19 552 }