Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use type 'bool' for boolean.
[simgrid.git] / examples / smpi / ampi_test / ampi_test.cpp
1 /* Copyright (c) 2009-2020. 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 <simgrid/s4u/Actor.hpp>
7 #include "smpi/smpi.h"
8 #include "smpi/sampi.h"
9
10 int main(int argc, char* argv[])
11 {
12   MPI_Init(&argc, &argv);
13   // useless alocations for testing and coverage
14   void* pointer = malloc(100 * sizeof(int));
15   pointer       = realloc(pointer, 50 * sizeof(int));
16   pointer       = realloc(pointer, 200 * sizeof(int));
17   free(pointer);
18   pointer = calloc(100, sizeof(int));
19   int rank;
20   int err = MPI_Comm_rank(MPI_COMM_WORLD, &rank);   /* Get id of this process */
21   if (err != MPI_SUCCESS) {
22     fprintf(stderr, "MPI_Comm_rank failed: %d", err);
23     MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
24     exit(EXIT_FAILURE);
25   }
26   AMPI_Iteration_in(MPI_COMM_WORLD);
27   simgrid::s4u::this_actor::sleep_for(rank);
28   AMPI_Iteration_out(MPI_COMM_WORLD);
29
30   AMPI_Iteration_in(MPI_COMM_WORLD);
31   simgrid::s4u::this_actor::sleep_for(rank);
32   AMPI_Iteration_out(MPI_COMM_WORLD);
33   if (rank == 0) {
34     free(pointer);
35     pointer = nullptr;
36   }
37   AMPI_Migrate(MPI_COMM_WORLD);
38   if (rank != 0)
39     free(pointer);
40
41   MPI_Finalize();
42   return 0;
43 }
44