Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
disk not mount
[simgrid.git] / examples / smpi / ampi_test / ampi_test.cpp
1 /* Copyright (c) 2009-2019. 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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_plugin_load_balancer_example, smpi, "Simple tracing test for SAMPI functions");
11
12 int main(int argc, char* argv[])
13 {
14   MPI_Init(&argc, &argv);
15   void* pointer = malloc(100 * sizeof(int));
16   free(pointer);
17   pointer = malloc(100 * sizeof(int));
18   int rank;
19   int err = MPI_Comm_rank(MPI_COMM_WORLD, &rank);   /* Get id of this process */
20   if (err != MPI_SUCCESS) {
21     fprintf(stderr, "MPI_Comm_rank failed: %d", err);
22     MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
23     exit(EXIT_FAILURE);
24   }
25   AMPI_Iteration_in(MPI_COMM_WORLD);
26   simgrid::s4u::this_actor::sleep_for(rank);
27   AMPI_Iteration_out(MPI_COMM_WORLD);
28
29   AMPI_Iteration_in(MPI_COMM_WORLD);
30   simgrid::s4u::this_actor::sleep_for(rank);
31   AMPI_Iteration_out(MPI_COMM_WORLD);
32   if (rank == 0) {
33     free(pointer);
34     pointer = nullptr;
35   }
36   AMPI_Migrate(MPI_COMM_WORLD);
37   if (rank != 0)
38     free(pointer);
39
40   MPI_Finalize();
41   return 0;
42 }
43