Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'pikachuyann/simgrid-xbt_random'
[simgrid.git] / src / smpi / plugins / ampi / instr_ampi.cpp
1 /* Copyright (c) 2010-2020. 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 "src/smpi/plugins/ampi/instr_ampi.hpp"
7 #include "smpi/smpi.h"
8 #include "src/instr/instr_private.hpp"
9 #include <src/instr/instr_smpi.hpp>
10 #include <src/smpi/include/smpi_actor.hpp>
11
12 static std::map<std::string, std::string> ampi_colors = {{"migrate", "0.2 0.5 0.2"},
13   {"iteration", "0.5 0.5 0.5"}
14 };
15
16 void TRACE_Iteration_in(int rank, simgrid::instr::TIData* extra)
17 {
18   if (not TRACE_smpi_is_enabled()) {
19     delete extra;
20     return;
21   }
22   smpi_container(rank)->get_state("MPI_STATE")->add_entity_value("iteration", ampi_colors["iteration"]);
23   smpi_container(rank)->get_state("MPI_STATE")->push_event("iteration", extra);
24 }
25
26 void TRACE_Iteration_out(int rank, simgrid::instr::TIData* extra)
27 {
28   if (not TRACE_smpi_is_enabled()) return;
29
30   smpi_container(rank)->get_state("MPI_STATE")->pop_event(extra);
31 }
32
33 void TRACE_migration_call(int rank, simgrid::instr::TIData* extra)
34 {
35   if (not TRACE_smpi_is_enabled()) return;
36
37   const std::string operation = "migrate";
38   if(smpi_process()->replaying()) {//When replaying, we register an event.
39     smpi_container(rank)->get_state("MIGRATE_STATE")->add_entity_value(operation);
40
41     simgrid::instr::EventType* type =
42       static_cast<simgrid::instr::EventType*>(smpi_container(rank)->type_->by_name(operation));
43     new simgrid::instr::NewEvent(smpi_process()->simulated_elapsed(), smpi_container(rank), type,
44                                  type->get_entity_value(operation));
45   } else {
46     // FIXME From rktesser: Ugly workaround!
47     // TI tracing uses states as events, and does not support printing events.
48     // So, we need a different code than for replay in order to be able to
49     // generate ti_traces for the migration calls.
50     if (!TRACE_smpi_is_enabled()) {
51       delete extra;
52       return;
53     }
54     smpi_container(rank)->get_state("MIGRATE_STATE")->add_entity_value(operation, ampi_colors[operation.c_str()]);
55     smpi_container(rank)->get_state("MIGRATE_STATE")->push_event(operation, extra);
56     smpi_container(rank)->get_state("MIGRATE_STATE")->pop_event();
57   }
58 }