annotate src/fftw-3.3.3/mpi/testsched.c @ 169:223a55898ab9 tip default

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