1 /* Copyright (c) 2018. The SimGrid Team. All rights reserved. */
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. */
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>
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(plugin_pampi, smpi, "Logging specific to the AMPI functions");
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)
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;
30 extern "C" void _sampi_free(void* ptr)
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;
39 #include <smpi/sampi.h>
44 simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_iteration_in;
45 simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_iteration_out;
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.
56 int APMPI_Iteration_in(MPI_Comm comm)
59 TRACE_Iteration_in(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_in")); // implemented on instr_smpi.c
64 int APMPI_Iteration_out(MPI_Comm comm)
67 TRACE_Iteration_out(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_out"));
72 void APMPI_Migrate(MPI_Comm comm)
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]));
80 int AMPI_Iteration_in(MPI_Comm comm)
82 return APMPI_Iteration_in(comm);
85 int AMPI_Iteration_out(MPI_Comm comm)
87 return APMPI_Iteration_out(comm);
90 void AMPI_Migrate(MPI_Comm comm)