Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MPI_INFO_ENV ... Still does nothing for now
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / sendflood.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2008 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include "mpi.h"
10
11 /*
12  * Run this test with 8 processes.  This test was submitted by xxx
13  * as a result of problems seen with the ch3:shm device on a Solaris
14  * system.  The symptom is that the test hangs; this is due to losing
15  * a message, probably due to a race condition in a message-queue update.
16  * As a test for race conditions, it may need to be run multiple times
17  * to expose a problem if a problem does exist.
18  */
19
20 #define LOOP_COUNT  10000
21 #define DATA_SIZE   4
22 #define MP_TAG      999
23
24 #define PROGRESS_COUNT 0xfff
25 static int verbose = 0;
26 static int loopProgress = 0;
27
28 int main(int argc, char *argv[])
29 {
30     int nProc, rank;
31     int i, j, status;
32     FILE *pf = 0;
33
34     MPI_Init(&argc, &argv);
35     MPI_Comm_size(MPI_COMM_WORLD, &nProc);
36     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
37
38     for (i = 1; i < argc; i++) {
39         if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0)
40             verbose = 1;
41         else if (strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--progress") == 0)
42             loopProgress = 1;
43         else {
44             if (rank == 0) {
45                 fprintf(stderr, "%s: [ -v | --verbose ] [ -p | --progress ]\n", argv[0]);
46                 fflush(stderr);
47             }
48         }
49     }
50
51     if (verbose) {
52         char buf[128];
53         sprintf(buf, "fast_mpi_%d.dmp", rank);
54         pf = fopen(buf, "w");
55     }
56     else if (loopProgress) {
57         pf = stdout;
58     }
59
60     if (!rank) {
61         int **psend;
62         int **precv;
63         psend = (int **) calloc(nProc, sizeof(int *));
64         precv = (int **) calloc(nProc, sizeof(int *));
65         for (i = 0; i < nProc; i++) {
66             psend[i] = (int *) calloc(DATA_SIZE, sizeof(int));
67             precv[i] = (int *) calloc(DATA_SIZE, sizeof(int));
68         }
69         for (i = 0; i < LOOP_COUNT; i++) {
70             if (verbose) {
71                 fprintf(pf, "Master : loop %d\n", i);
72                 fflush(pf);
73             }
74             else if (loopProgress && (i & PROGRESS_COUNT) == 0) {
75                 fprintf(pf, "Master: loop %d\n", i);
76                 fflush(pf);
77             }
78             for (j = 1; j < nProc; j++) {
79                 if (verbose) {
80                     fprintf(pf, "  read from child %d\n", j);
81                     fflush(pf);
82                 }
83                 status = MPI_Recv(precv[j], DATA_SIZE, MPI_INT, j, MP_TAG,
84                                   MPI_COMM_WORLD, MPI_STATUS_IGNORE);
85                 if (verbose) {
86                     fprintf(pf, "  read from child %d done, status = %d\n", j, status);
87                     fflush(pf);
88                 }
89             }
90             for (j = 1; j < nProc; j++) {
91                 if (verbose) {
92                     fprintf(pf, "  send to child %d\n", j);
93                     fflush(pf);
94                 }
95                 status = MPI_Send(psend[j], DATA_SIZE - 1, MPI_INT, j, MP_TAG, MPI_COMM_WORLD);
96                 if (verbose) {
97                     fprintf(pf, "  send to child %d done, status = %d\n", j, status);
98                     fflush(pf);
99                 }
100             }
101         }
102         for (i = 0; i < nProc; i++) {
103             free(psend[i]);
104             free(precv[i]);
105         }
106         free(psend);
107         free(precv);
108     }
109     else {
110         int *psend;
111         int *precv;
112         psend = (int *) calloc(DATA_SIZE, sizeof(int));
113         precv = (int *) calloc(DATA_SIZE, sizeof(int));
114         for (i = 0; i < LOOP_COUNT; i++) {
115             if (verbose) {
116                 fprintf(pf, "  send to master\n");
117                 fflush(pf);
118             }
119             /*
120              * else if (loopProgress && (i & PROGRESS_COUNT) == 0) {
121              * fprintf(pf, "Slave: loop %d\n", i); fflush(pf);
122              * }
123              */
124             status = MPI_Send(psend, DATA_SIZE - 1, MPI_INT, 0, MP_TAG, MPI_COMM_WORLD);
125             if (verbose) {
126                 fprintf(pf, "  send to master done, status = %d\n", status);
127                 fflush(pf);
128                 fprintf(pf, "  read from master\n");
129                 fflush(pf);
130             }
131             status = MPI_Recv(precv, DATA_SIZE, MPI_INT, 0, MP_TAG,
132                               MPI_COMM_WORLD, MPI_STATUS_IGNORE);
133             if (verbose) {
134                 fprintf(pf, "  read from master done, status = %d\n", status);
135                 fflush(pf);
136             }
137         }
138         free(psend);
139         free(precv);
140     }
141     if (verbose) {
142         fclose(pf);
143     }
144     MPI_Finalize();
145
146     /* This test fails if it hangs */
147     if (rank == 0) {
148         printf(" No Errors\n");
149     }
150
151     return 0;
152 }