/* * hello.c - test mpi program * * $Id: hello.c 326 2006-01-24 21:35:26Z pw $ * * Copyright (C) 2000-6 Pete Wyckoff */ #include #include #include #include #include #include #ifdef __GNUC__ # define ATTR_UNUSED __attribute__ ((unused)) #else # define ATTR_UNUSED #endif static char hostname[1024]; /* * "Fake" the MPI calls to test comm=none. */ #if 0 const int MPI_COMM_WORLD = 0; static void MPI_Init(int *x, char ***y) { } static void MPI_Comm_size(int n, int *np) { *np = 1; } static void MPI_Comm_rank(int n, int *np) { *np = 0; } static void MPI_Finalize(void) { } #else #include "mpi.h" #endif static void handle(int sig ATTR_UNUSED) { const char *opts = getenv("GMPI_OPTS"); unsigned long *ul = 0; printf("hello: %s %s MPI_Init did not finish\n", hostname, opts ? opts : ""); sleep(2); *ul = 0; exit(1); } int main(int argc, char *argv[]) { int myid, numproc; int readlines = 0, doze = 0, segv = -1, segvearly = 0; int abort = -1, mixup = 0; int *exitval = 0, numexitval = 0; struct sigaction act; char buf[1024]; FILE *fp = stdout; int i; for (i=1; i= 0) printf("hello %d %s -> %s\n", myid, s, buf); } } #endif if (mixup) { const char *mixstr = "The rain in spain falls mainly in the plain.\n"; int len = strlen(mixstr); int pos = 0, top; srand48(time(0) + myid); for (i=0; i<40; i++) { do { top = (int)(drand48() * len / 3); top += pos; top %= len; } while (pos == top); #if 0 /* add text of who says what */ putchar('<'); if (myid < 10) putchar(myid + '0'); else if (myid < 10 + 26) putchar(myid - 10 + 'A'); else putchar('|'); #endif while (pos != top) { putchar(mixstr[pos]); if (++pos == len) pos = 0; } usleep((int)(1000000. * drand48())); } while (pos != 0) { putchar(mixstr[pos]); if (++pos == len) pos = 0; } } if (readlines) while (fgets(buf, sizeof(buf), stdin)) fprintf(fp, "hello %d got line: %s", myid, buf); if (abort == myid) { sleep(2); MPI_Abort(MPI_COMM_WORLD, 4269); } if (doze) { /* close everything and wait awhile */ (void) close(0); (void) close(1); (void) close(2); sleep(6); } if (segv == myid) { unsigned long *ul = 0; sleep(2); *ul = 0; } MPI_Finalize(); if (myid < numexitval) return exitval[myid]; else return 0; }