Logo AND Algorithmique Numérique Distribuée

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