Repository navigation
Expand file tree
/
Copy pathEngine.cpp
More file actions
106 lines (87 loc) · 4.26 KB
/
Copy pathEngine.cpp
File metadata and controls
106 lines (87 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Copyright (c) 2022-2026. The SWAT Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include <simgrid/s4u/Actor.hpp>
#include <simgrid/s4u/MessageQueue.hpp>
#include "dtlmod/DTL.hpp"
#include "dtlmod/FileTransport.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(dtlmod_engine, dtlmod, "DTL logging about Engines");
namespace sg4 = simgrid::s4u;
namespace dtlmod {
////////////////////////////////////////////
///////////// PUBLIC INTERFACE /////////////
////////////////////////////////////////////
/// All put and get operations must take place within a transaction (in a sense close to that used for databases).
/// When multiple actors have opened the same Stream and thus subscribed to the same Engine, only one of them has to
/// do the following when a transaction begins, this function is a no-op for the other subscribers:
/// 1. if no transaction is currently in progress, start one, exit otherwise
/// 2. if this is the first transaction for that Engine, create a synchronization barrier among all the subscribers.
/// 3. Otherwise, wait for the completion of the simulated activities started by the previous transaction.
void Engine::begin_transaction()
{
publishers_.contains(sg4::Actor::self()) ? begin_pub_transaction() : begin_sub_transaction();
}
/// The actual data transport is delegated to the Transport method associated to the Engine.
void Engine::put(const std::shared_ptr<Variable>& var) const
{
if (var->is_reduced()) {
// Perform an Exec activity before putting the variable into the DTL to account for the time needed to reduce it.
sg4::this_actor::execute(var->get_reduction_method()->get_flop_amount_to_reduce_variable(var));
XBT_DEBUG("Variable %s has been reduced!", var->get_cname());
// Now put the reduced version of the variable into the DTL, i.e., using its reduced local size.
XBT_DEBUG("Put this reduced version of %s (initial size = %lu, reduced size = %lu)", var->get_cname(),
var->get_local_size(), var->get_reduction_method()->get_reduced_variable_local_size(var));
transport_->put(var, var->get_reduction_method()->get_reduced_variable_local_size(var));
} else
transport_->put(var, var->get_local_size());
}
void Engine::put(const std::shared_ptr<Variable>& var, size_t simulated_size_in_bytes) const
{
transport_->put(var, simulated_size_in_bytes);
}
/// The actual data transport is delegated to the Transport method associated to the Engine.
void Engine::get(const std::shared_ptr<Variable>& var) const
{
if (var->is_reduced() && var->is_reduced_by_subscriber()) {
var->is_reduced_with_->reduce_variable(var);
// Perform an Exec activity before putting the variable into the DTL to account for the time needed to reduce it.
sg4::this_actor::execute(var->get_reduction_method()->get_flop_amount_to_reduce_variable(var));
}
transport_->get(var);
}
/// This function first synchronizes all the subscribers thanks to the internal barrier. When the last subscriber
/// enters the barrier, all the simulated activities registered for the current transaction are started.
///
/// Then it marks the transaction as done.
void Engine::end_transaction()
{
publishers_.contains(sg4::Actor::self()) ? end_pub_transaction() : end_sub_transaction();
}
/// This function is called by all the actors that have opened that Stream. The first subscriber to enter that
/// function waits for the completion of the activities of last transaction on that Engine. Then all the subscribers
/// are synchronized before the Engine is properly closed (and destroyed).
void Engine::close()
{
publishers_.contains(sg4::Actor::self()) ? pub_close() : sub_close();
}
////////////////////////////////////////////
///////////////// INTERNALS ////////////////
////////////////////////////////////////////
/// \cond EXCLUDE_FROM_DOCUMENTATION
void Engine::add_publisher(sg4::ActorPtr actor)
{
transport_->add_publisher(publishers_.count());
publishers_.add(actor);
}
void Engine::add_subscriber(sg4::ActorPtr actor)
{
transport_->add_subscriber(subscribers_.count());
subscribers_.add(actor);
}
void Engine::close_stream() const
{
if (auto s = stream_.lock())
s->close();
}
/// \endcond
} // namespace dtlmod