Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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 "ampi.hpp"
34 #include <smpi/sampi.h>
35 namespace simgrid {
36 namespace smpi {
37 namespace plugin {
38 namespace ampi {
39   simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_iteration_in;
40   simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_iteration_out;
41 }
42 }
43 }
44 }
45
46 /* FIXME The following contains several times "rank() + 1". This works for one
47  * instance, but we need to find a way to deal with this for several instances and
48  * for daemons: If we just replace this with the process id, we will get id's that
49  * don't start at 0 if we start daemons as well.
50  */
51 int APMPI_Iteration_in(MPI_Comm comm)
52 {
53   smpi_bench_end();
54   TRACE_Iteration_in(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_in")); // implemented on instr_smpi.c
55   smpi_bench_begin();
56   return 1;
57 }
58
59 int APMPI_Iteration_out(MPI_Comm comm)
60 {
61   smpi_bench_end();
62   TRACE_Iteration_out(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_out"));
63   smpi_bench_begin();
64   return 1;
65 }
66
67 void APMPI_Migrate(MPI_Comm comm)
68 {
69   smpi_bench_end();
70   int my_proc_id = simgrid::s4u::this_actor::get_pid();
71   TRACE_migration_call(comm->rank() + 1, new simgrid::instr::AmpiMigrateTIData(memory_size[my_proc_id]));
72   smpi_bench_begin();
73 }
74
75 int AMPI_Iteration_in(MPI_Comm comm)
76 {
77   return APMPI_Iteration_in(comm);
78 }
79
80 int AMPI_Iteration_out(MPI_Comm comm)
81 {
82   return APMPI_Iteration_out(comm);
83 }
84
85 void AMPI_Migrate(MPI_Comm comm)
86 {
87   APMPI_Migrate(comm);
88 }