4 #define MAX2(a,b) (((a)>(b)) ? (a) : (b))
6 int GlobalReadInteger();
21 MPI_Init(&argc, &argv);
22 MPI_Comm_rank(MPI_COMM_WORLD,&me);
24 fprintf(stderr,"Process %d is alive\n",me);
28 MPI_Barrier(MPI_COMM_WORLD);
32 /* Read user input for action */
33 (void) printf("\nOptions: 0=quit, 1=Hello, 2=Ring, 3=Stress, ");
34 (void) printf("4=Globals : ");
35 (void) fflush(stdout);
37 option = GlobalReadInteger();
38 if ( (option < 0) || (option > 4) )
56 fprintf(stderr,"systest: invalid option %d\n", option); break;
61 int GlobalReadInteger()
63 Process zero reads an integer from stdin and broadcasts
67 int me, value, *msg, msg_len, type=999 ,zero=0;
69 MPI_Comm_rank(MPI_COMM_WORLD, &me);
71 if (scanf("%d", &value) != 1)
72 fprintf(stderr,"failed reading integer value from stdin\n");
74 MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
80 Everyone exchanges a hello message with everyone else.
81 The hello message just comprises the sending and target nodes.
86 int buffer[2], node, length;
89 MPI_Comm_rank(MPI_COMM_WORLD, &me);
90 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
93 printf("\nHello test ... show network integrity\n----------\n\n");
97 for (node = 0; node<nproc; node++) {
101 MPI_Send(buffer, 2, MPI_INT, node, type, MPI_COMM_WORLD);
102 buffer[0] = buffer[1] = 7777;
103 MPI_Recv(buffer, 2, MPI_INT, node, type, MPI_COMM_WORLD, &status);
105 if ( (buffer[0] != node) || (buffer[1] != me) ) {
106 (void) fprintf(stderr, "Hello: %d!=%d or %d!=%d\n",
107 buffer[0], node, buffer[1], me);
108 printf("Mismatch on hello process ids; node = %d\n", node);
111 printf("Hello from %d to %d\n", me, node);