Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'clean_events' of github.com:Takishipp/simgrid into clean_events
[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;
9   int size;
10   int rank;
11   MPI_Status status;
12
13   MPI_Init(&argc, &argv);
14
15   MPI_Comm_size(MPI_COMM_WORLD, &size);   /* Get nr of tasks */
16   MPI_Comm_rank(MPI_COMM_WORLD, &rank);   /* Get id of this process */
17
18   MC_ignore(&(status.count), sizeof(status.count));
19
20   if(rank==0){
21     while (recv_x>=0) {
22       MPI_Recv(&recv_x, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
23     }
24   }else{
25     while (x >= 0) {
26       if (MC_random(0,1) == 0) {
27         x -= 1;
28       } else {
29         x += 1;
30       }
31       printf("x=%d\n", x);
32       MPI_Send(&x, 1, MPI_INT, 0, 42, MPI_COMM_WORLD);
33     }
34   }
35
36   MPI_Finalize();
37
38   return 0;
39 }