Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Dead store.
[simgrid.git] / src / smpi / plugins / ampi / ampi.cpp
1 #include <simgrid/plugins/load_balancer.h>
2 #include <simgrid/s4u/Actor.hpp>
3 #include <src/smpi/include/smpi_comm.hpp>
4 #include <src/smpi/include/smpi_actor.hpp>
5 #include <src/smpi/plugins/ampi/instr_ampi.hpp>
6 #include <src/instr/instr_smpi.hpp>
7 #include <xbt/replay.hpp>
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(plugin_pampi, smpi, "Logging specific to the AMPI functions");
10
11 static std::vector<size_t> memory_size(500, 0); // FIXME cheinrich This needs to be dynamic
12 static std::map</*address*/ void*, size_t> alloc_table; // Keep track of all allocations
13 extern "C" XBT_PUBLIC void* _sampi_malloc(size_t);
14 extern "C" XBT_PUBLIC void _sampi_free(void* ptr);
15 extern "C" void* _sampi_malloc(size_t size)
16 {
17   void* result = malloc (size); // We need the space here to prevent recursive substitution
18   alloc_table.insert({result, size});
19   if (not simgrid::s4u::this_actor::is_maestro()) {
20     memory_size[simgrid::s4u::this_actor::get_pid()] += size;
21   }
22   return result;
23 }
24
25 extern "C" void _sampi_free(void* ptr)
26 {
27   size_t alloc_size = alloc_table.at(ptr);
28   int my_proc_id    = simgrid::s4u::this_actor::get_pid();
29   memory_size[my_proc_id] -= alloc_size;
30   free(ptr);
31 }
32
33 #include <smpi/sampi.h>
34 namespace simgrid {
35 namespace smpi {
36 namespace plugin {
37 namespace ampi {
38   simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_iteration_in;
39   simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_iteration_out;
40 }
41 }
42 }
43 }
44
45 /* FIXME The following contains several times "rank() + 1". This works for one
46  * instance, but we need to find a way to deal with this for several instances and
47  * for daemons: If we just replace this with the process id, we will get id's that
48  * don't start at 0 if we start daemons as well.
49  */
50 int APMPI_Iteration_in(MPI_Comm comm)
51 {
52   smpi_bench_end();
53   TRACE_Iteration_in(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_in")); // implemented on instr_smpi.c
54   smpi_bench_begin();
55   return 1;
56 }
57
58 int APMPI_Iteration_out(MPI_Comm comm)
59 {
60   smpi_bench_end();
61   TRACE_Iteration_out(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_out"));
62   smpi_bench_begin();
63   return 1;
64 }
65
66 void APMPI_Migrate(MPI_Comm comm)
67 {
68   smpi_bench_end();
69   int my_proc_id = simgrid::s4u::this_actor::get_pid();
70   TRACE_migration_call(comm->rank() + 1, new simgrid::instr::AmpiMigrateTIData(memory_size[my_proc_id]));
71   smpi_bench_begin();
72 }
73
74 int AMPI_Iteration_in(MPI_Comm comm)
75 {
76   return APMPI_Iteration_in(comm);
77 }
78
79 int AMPI_Iteration_out(MPI_Comm comm)
80 {
81   return APMPI_Iteration_out(comm);
82 }
83
84 void AMPI_Migrate(MPI_Comm comm)
85 {
86   APMPI_Migrate(comm);
87 }