Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / systest1.c
1 #include "mpi.h"
2 #include <stdio.h>
3
4 #define MAX2(a,b) (((a)>(b)) ? (a) : (b))
5
6 int  GlobalReadInteger();
7 void Hello();
8 /*
9 void Ring();
10 void Stress();
11 void Globals();
12 */
13
14 int main(argc,argv)
15 int argc;
16 char **argv;
17 {
18
19     int me, option;
20
21     MPI_Init(&argc, &argv);
22     MPI_Comm_rank(MPI_COMM_WORLD,&me);
23
24     fprintf(stderr,"Process %d is alive\n",me);
25
26     while (1) {
27
28         MPI_Barrier(MPI_COMM_WORLD);
29
30       again:
31         if (me == 0) {
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);
36         }
37         option = GlobalReadInteger();
38         if ( (option < 0) || (option > 4) )
39             goto again;
40
41         switch (option) {
42           case 0:
43             MPI_Finalize();
44             return;
45           case 1:
46             Hello();     break;
47 /*
48           case 2:
49             Ring();      break;
50           case 3:
51             Stress();    break;
52           case 4:
53             Globals();   break;
54 */
55           default:
56             fprintf(stderr,"systest: invalid option %d\n", option);   break;
57         }
58     }
59 }
60
61 int GlobalReadInteger()
62 /*
63   Process zero reads an integer from stdin and broadcasts
64   to everyone else
65 */
66 {
67     int me, value, *msg, msg_len, type=999 ,zero=0;
68
69     MPI_Comm_rank(MPI_COMM_WORLD, &me);
70     if (me == 0) {
71         if (scanf("%d", &value) != 1)
72             fprintf(stderr,"failed reading integer value from stdin\n");
73     }
74     MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
75     return value;
76 }
77
78 static void Hello()
79 /*
80   Everyone exchanges a hello message with everyone else.
81   The hello message just comprises the sending and target nodes.
82 */
83 {
84     int nproc, me;
85     int type = 1;
86     int buffer[2], node, length;
87     MPI_Status status;
88
89     MPI_Comm_rank(MPI_COMM_WORLD, &me);
90     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
91
92     if (me == 0) {
93         printf("\nHello test ... show network integrity\n----------\n\n");
94         fflush(stdout);
95     }
96
97     for (node = 0; node<nproc; node++) {
98         if (node != me) {
99             buffer[0] = me;
100             buffer[1] = 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);
104
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);
109             }
110
111             printf("Hello from %d to %d\n", me, node);
112             fflush(stdout);
113         }
114     }
115 }