Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / examples / smpi / mc / non_termination4.c
1 #include <stdio.h>
2 #include <mpi.h>
3 #include <simgrid/modelchecker.h>
4
5 int x = 20;
6
7 int main(int argc, char **argv) {
8   int recv_x = 1, size, rank;
9   MPI_Status status;
10
11   MPI_Init(&argc, &argv);
12
13   MPI_Comm_size(MPI_COMM_WORLD, &size);   /* Get nr of tasks */
14   MPI_Comm_rank(MPI_COMM_WORLD, &rank);   /* Get id of this process */
15
16   MC_ignore(&(status.count), sizeof(status.count));
17
18   if(rank==0){
19     while (recv_x>=0) {
20       MPI_Recv(&recv_x, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
21     }
22   }else{
23     while (x >= 0) {
24       if (MC_random(0,1) == 0) {
25         x -= 1;
26       } else {
27         x += 1;
28       }
29       printf("x=%d\n", x);
30       MPI_Send(&x, 1, MPI_INT, 0, 42, MPI_COMM_WORLD);
31     }
32   }
33
34   MPI_Finalize();
35
36   return 0;
37 }