Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / examples / smpi / mc / non_termination1.c
1 /* Copyright (c) 2015-2023. 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 = 5;
11 int y = 8;
12
13 int main(int argc, char **argv) {
14   int recv_buff;
15   int size;
16   int rank;
17   MPI_Status status;
18
19   MPI_Init(&argc, &argv);
20
21   MPI_Comm_size(MPI_COMM_WORLD, &size);   /* Get nr of tasks */
22   MPI_Comm_rank(MPI_COMM_WORLD, &rank);   /* Get id of this process */
23
24   MC_ignore(&status.count, sizeof status.count);
25
26   if (rank == 0) {
27     while (1) {
28       MPI_Recv(&recv_buff, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
29     }
30   } else {
31     while (1) {
32       int old_x = x;
33       x = -y;
34       y = old_x;
35       printf("x = %d, y = %d\n", x, y);
36       MPI_Send(&rank, 1, MPI_INT, 0, 42, MPI_COMM_WORLD);
37     }
38   }
39
40   MPI_Finalize();
41
42   return 0;
43 }