annotate src/fftw-3.3.8/mpi/testsched.c @ 82:d0c2a83c1364

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