Logo AND Algorithmique Numérique Distribuée

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