Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add missing copyright notices.
[simgrid.git] / examples / smpi / mc / non_termination4.c
1 /* Copyright (c) 2015-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <stdio.h>
7 #include <mpi.h>
8 #include <simgrid/modelchecker.h>
9
10 int x = 20;
11
12 int main(int argc, char **argv) {
13   int recv_x = 1;
14   int size;
15   int rank;
16   MPI_Status status;
17
18   MPI_Init(&argc, &argv);
19
20   MPI_Comm_size(MPI_COMM_WORLD, &size);   /* Get nr of tasks */
21   MPI_Comm_rank(MPI_COMM_WORLD, &rank);   /* Get id of this process */
22
23   MC_ignore(&status.count, sizeof status.count);
24
25   if(rank==0){
26     while (recv_x>=0) {
27       MPI_Recv(&recv_x, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
28     }
29   }else{
30     while (x >= 0) {
31       if (MC_random(0,1) == 0) {
32         x -= 1;
33       } else {
34         x += 1;
35       }
36       printf("x=%d\n", x);
37       MPI_Send(&x, 1, MPI_INT, 0, 42, MPI_COMM_WORLD);
38     }
39   }
40
41   MPI_Finalize();
42
43   return 0;
44 }