Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sed -i -e 's/\t/ /g' [sources] Please people, stop using tabs
[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   
9   int recv_x = 1, size, rank;
10   MPI_Status status;
11
12   MPI_Init(&argc, &argv);
13   
14   MPI_Comm_size(MPI_COMM_WORLD, &size);   /* Get nr of tasks */
15   MPI_Comm_rank(MPI_COMM_WORLD, &rank);   /* Get id of this process */
16   
17   MC_ignore(&(status.count), sizeof(status.count));
18
19   if(rank==0){
20     while (recv_x>=0) {
21       MPI_Recv(&recv_x, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
22     }
23   }else{
24     
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 }