start = Engine.clock
received: str = my_mailbox.get()
waiting_time = Engine.clock - start
- if waiting_time != 0.0:
+ if waiting_time > 0.0:
raise AssertionError(f"Expecting the waiting time to be 0.0 because the communication was supposedly "
f"ready, but got {waiting_time} instead")
this_actor.info(f"I got a '{received}'.")
int main()
{
- pthread_t thread1, thread2;
+ pthread_t thread1;
+ pthread_t thread2;
pthread_mutex_t mutex_dflt = PTHREAD_MUTEX_INITIALIZER; // Non-recursive mutex
pthread_mutexattr_t attr;
double energy_consumed_j_ = 0;
double last_updated_ = 0;
- explicit Battery();
+ explicit Battery() = default;
explicit Battery(const std::string& name, double state_of_charge, double nominal_charge_power_w,
double nominal_discharge_power_w, double charge_efficiency, double discharge_efficiency,
double initial_capacity_wh, int cycles);
void set_load(const std::string& name, double power_w);
void set_load(const std::string& name, bool active);
void connect_host(s4u::Host* host, bool active = true);
- std::string get_name() {return name_;}
+ std::string get_name() const { return name_; }
double get_state_of_charge();
double get_state_of_health();
double get_capacity();
double get_temp_in() { return temp_in_c_; }
double get_power() { return power_w_; }
double get_energy_consumed() { return energy_consumed_j_; }
- double get_time_to_goal_temp();
+ double get_time_to_goal_temp() const;
};
} // namespace simgrid::plugins
/** @verbatim embed:rst:inline Bind an actor name that could be found in :ref:`pf_tag_actor` tag to a class name passed as a template parameter. See the :ref:`example <s4u_ex_actors_create>`. @endverbatim */
template <class F> void register_actor(const std::string& name)
{
- kernel::actor::ActorCodeFactory code_factory = [](std::vector<std::string> args) {
- return kernel::actor::ActorCode([args = std::move(args)]() mutable {
+ kernel::actor::ActorCodeFactory code_factory = [](std::vector<std::string> args_factory) {
+ return kernel::actor::ActorCode([args = std::move(args_factory)]() mutable {
F code(std::move(args));
code();
});
/** @verbatim embed:rst:inline Bind an actor name that could be found in :ref:`pf_tag_actor` tag to a function name passed as a parameter. See the :ref:`example <s4u_ex_actors_create>`. @endverbatim */
template <class F> void register_actor(const std::string& name, F code)
{
- kernel::actor::ActorCodeFactory code_factory = [code](std::vector<std::string> args) {
- return kernel::actor::ActorCode([code, args = std::move(args)]() mutable { code(std::move(args)); });
+ kernel::actor::ActorCodeFactory code_factory = [code](std::vector<std::string> args_factory) {
+ return kernel::actor::ActorCode([code, args = std::move(args_factory)]() mutable { code(std::move(args)); });
};
register_function(name, code_factory);
}
/** @brief Get the gateway associated to this netzone */
kernel::routing::NetPoint* get_gateway() const;
kernel::routing::NetPoint* get_gateway(const std::string& name) const;
- void set_gateway(s4u::Host* router) { set_gateway(router->get_netpoint()); }
+ void set_gateway(const s4u::Host* router) { set_gateway(router->get_netpoint()); }
void set_gateway(kernel::routing::NetPoint* router);
void set_gateway(const std::string& name, kernel::routing::NetPoint* router);
virtual void fire(std::string instance);
void complete(std::string instance);
- void store_activity(ActivityPtr a, std::string instance) { current_activities_[instance].push_back(a); }
+ void store_activity(ActivityPtr a, const std::string& instance) { current_activities_[instance].push_back(a); }
virtual void add_instances(int n);
virtual void remove_instances(int n);
.def("create_router", &simgrid::s4u::NetZone::create_router, "Create a router")
.def("set_parent", &simgrid::s4u::NetZone::set_parent, "Set the parent of this zone")
.def("set_property", &simgrid::s4u::NetZone::set_property, "Add a property to this zone")
- .def("set_gateway", py::overload_cast<simgrid::s4u::Host*>(&simgrid::s4u::NetZone::set_gateway),
+ .def("set_gateway", py::overload_cast<const simgrid::s4u::Host*>(&simgrid::s4u::NetZone::set_gateway),
"Specify the gateway of this zone, to be used for inter-zone routes")
.def("set_gateway", py::overload_cast<simgrid::kernel::routing::NetPoint*>(&simgrid::s4u::NetZone::set_gateway),
"Specify the gateway of this zone, to be used for inter-zone routes")
public:
MutexAcquisitionImpl(actor::ActorImpl* issuer, MutexImpl* mutex) : issuer_(issuer), mutex_(mutex) {}
- MutexImplPtr get_mutex() { return mutex_; }
- actor::ActorImpl* get_issuer() { return issuer_; }
+ MutexImplPtr get_mutex() const { return mutex_; }
+ actor::ActorImpl* get_issuer() const { return issuer_; }
void grant() { granted_ = true; }
- bool is_granted() { return granted_; }
+ bool is_granted() const { return granted_; }
bool test(actor::ActorImpl* issuer = nullptr) override;
void wait_for(actor::ActorImpl* issuer, double timeout) override;
friend MutexAcquisitionImpl;
public:
- MutexImpl(bool recursive = false) : piface_(this), is_recursive_(recursive) {}
+ explicit MutexImpl(bool recursive = false) : piface_(this), is_recursive_(recursive) {}
MutexImpl(MutexImpl const&) = delete;
MutexImpl& operator=(MutexImpl const&) = delete;
}
std::string CommIsendSimcall::to_string() const
{
- return "CommAsyncSend(comm_id: " + std::to_string((comm_ ? comm_->get_id() : 0)) + " mbox:" +
- std::to_string(mbox_->get_id()) + " tag: " + std::to_string(tag_) + ")";
+ return "CommAsyncSend(comm_id: " + std::to_string(comm_ ? comm_->get_id() : 0) +
+ " mbox:" + std::to_string(mbox_->get_id()) + " tag: " + std::to_string(tag_) + ")";
}
void CommIrecvSimcall::serialize(std::stringstream& stream) const
std::string CommIrecvSimcall::to_string() const
{
- return "CommAsyncRecv(comm_id: " + std::to_string((comm_ ? comm_->get_id() : 0)) + " mbox:" +
- std::to_string(mbox_->get_id()) + " tag: " + std::to_string(tag_) + ")";
+ return "CommAsyncRecv(comm_id: " + std::to_string(comm_ ? comm_->get_id() : 0) +
+ " mbox:" + std::to_string(mbox_->get_id()) + " tag: " + std::to_string(tag_) + ")";
}
void MessIputSimcall::serialize(std::stringstream& stream) const
class ActorSleepSimcall final : public SimcallObserver {
public:
- ActorSleepSimcall(ActorImpl* actor) : SimcallObserver(actor) {}
+ explicit ActorSleepSimcall(ActorImpl* actor) : SimcallObserver(actor) {}
void serialize(std::stringstream& stream) const override;
std::string to_string() const override;
};
"to schedule from the wakeup tree? Trace so far:",
get_transition_in()->to_string(false).c_str(), get_transition_in()->aid_,
min_process_node.value()->get_action()->to_string(false).c_str(), min_process_node.value()->get_actor());
- for (auto elm : Exploration::get_instance()->get_textual_trace())
+ for (auto const& elm : Exploration::get_instance()->get_textual_trace())
XBT_ERROR("%s", elm.c_str());
xbt_abort();
}
"--cfg=model-check/max-depth. Here are the 100 first trace elements",
_sg_mc_max_depth.get());
auto trace = Exploration::get_instance()->get_textual_trace(100);
- for (auto elm : trace)
+ for (auto const& elm : trace)
XBT_CERROR(mc_dfs, " %s", elm.c_str());
xbt_die("Aborting now.");
}
// Search how to restore the backtracking point
std::deque<Transition*> replay_recipe;
- for (auto* s = backtracking_point.get(); s != nullptr; s = s->get_parent_state().get()) {
+ for (const auto* s = backtracking_point.get(); s != nullptr; s = s->get_parent_state().get()) {
if (s->get_transition_in() != nullptr) // The root has no transition_in
replay_recipe.push_front(s->get_transition_in().get());
}
bool ActorJoinTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::ACTOR_JOIN:
- // ActorJoin races with another event iff its target `T` is the same as
- // the actor executing the other transition. Clearly, then, we could not join
- // on that actor `T` and then run a transition by `T`, so no race is reversible
- return false;
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::ACTOR_JOIN, "Unexpected transition type %s", to_c_str(type_));
+
+ // ActorJoin races with another event iff its target `T` is the same as the actor executing the other transition.
+ // Clearly, then, we could not join on that actor `T` and then run a transition by `T`, so no race is reversible
+ return false;
}
-ActorSleepTransition::ActorSleepTransition(aid_t issuer, int times_considered, std::stringstream& stream)
+ActorSleepTransition::ActorSleepTransition(aid_t issuer, int times_considered, std::stringstream&)
: Transition(Type::ACTOR_SLEEP, issuer, times_considered)
{
XBT_DEBUG("ActorSleepTransition()");
bool ActorSleepTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::ACTOR_SLEEP:
- return true; // Always enabled
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::ACTOR_SLEEP, "Unexpected transition type %s", to_c_str(type_));
+
+ return true; // Always enabled
}
} // namespace simgrid::mc
}
bool TestAnyTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::TESTANY:
- return true; // TestAny is always enabled
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::TESTANY, "Unexpected transition type %s", to_c_str(type_));
+
+ return true; // TestAny is always enabled
}
WaitAnyTransition::WaitAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream)
}
bool WaitAnyTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::WAITANY:
- // TODO: We need to check if any of the transitions waited on occurred before `e1`
- return true; // Let's overapproximate to not miss branches
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::WAITANY, "Unexpected transition type %s", to_c_str(type_));
+
+ // TODO: We need to check if any of the transitions waited on occurred before `e1`
+ return true; // Let's overapproximate to not miss branches
}
} // namespace simgrid::mc
bool CommWaitTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::COMM_WAIT:
- // If the other event is a communication event, then we are not reversible; otherwise we are reversible.
- return other->type_ != Transition::Type::COMM_ASYNC_SEND && other->type_ != Transition::Type::COMM_ASYNC_RECV;
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::COMM_WAIT, "Unexpected transition type %s", to_c_str(type_));
+
+ // If the other event is a communication event, then we are not reversible; otherwise we are reversible.
+ return other->type_ != Transition::Type::COMM_ASYNC_SEND && other->type_ != Transition::Type::COMM_ASYNC_RECV;
}
CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, unsigned comm_, aid_t sender_,
bool CommTestTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::COMM_TEST:
- return true; // CommTest is always enabled
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::COMM_TEST, "Unexpected transition type %s", to_c_str(type_));
+ return true; // CommTest is always enabled
}
CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_, int tag_)
bool CommRecvTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::COMM_ASYNC_RECV:
- return true; // CommRecv is always enabled
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::COMM_ASYNC_RECV, "Unexpected transition type %s", to_c_str(type_));
+
+ return true; // CommRecv is always enabled
}
CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_, int tag_)
bool CommSendTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::COMM_ASYNC_SEND:
- return true; // CommSend is always enabled
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::COMM_ASYNC_SEND, "Unexpected transition type %s", to_c_str(type_));
+
+ return true; // CommSend is always enabled
}
} // namespace simgrid::mc
bool ObjectAccessTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::OBJECT_ACCESS:
- return true; // Object access is always enabled
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::OBJECT_ACCESS, "Unexpected transition type %s", to_c_str(type_));
+
+ return true; // Object access is always enabled
}
} // namespace simgrid::mc
bool RandomTransition::reversible_race(const Transition* other) const
{
- switch (type_) {
- case Type::RANDOM:
- return true; // Random is always enabled
- default:
- xbt_die("Unexpected transition type %s", to_c_str(type_));
- }
+ xbt_assert(type_ == Type::RANDOM, "Unexpected transition type %s", to_c_str(type_));
+
+ return true; // Random is always enabled
}
} // namespace simgrid::mc
return time_delta;
}
-Battery::Battery() {}
-
Battery::Battery(const std::string& name, double state_of_charge, double nominal_charge_power_w,
double nominal_discharge_power_w, double charge_efficiency, double discharge_efficiency,
double initial_capacity_wh, int cycles)
/** @ingroup plugin_chiller
* @return The time to reach to goal temp, assuming that the system remain in the same state.
*/
-double Chiller::get_time_to_goal_temp()
+double Chiller::get_time_to_goal_temp() const
{
if (goal_temp_c_ == temp_in_c_)
return 0;
return ret;
} catch (const HostFailureException& e) {
handle_failed_activities();
- throw e;
+ throw;
} catch (const NetworkFailureException& e) {
handle_failed_activities();
- throw e;
+ throw;
} catch (const StorageFailureException& e) {
handle_failed_activities();
- throw e;
+ throw;
}
}
CHECK_BUFFER(1, sendbuf, sendcount, sendtype)
CHECK_BUFFER(6, recvbuf, recvcount, recvtype)
CHECK_ARGS(sendbuf == recvbuf && sendcount > 0 && recvcount > 0, MPI_ERR_BUFFER,
- "%s: Invalid parameters 1 and 6: sendbuf and recvbuf must be disjoint", __func__);
+ "%s: Invalid parameters 1 and 6: sendbuf and recvbuf must be disjoint", __func__)
CHECK_TAG(10, recvtag)
CHECK_COMM(11)
const SmpiBenchGuard suspend_bench;
CHECK_BUFFER(1, sendbuf, sendcount, sendtype)
CHECK_BUFFER(6, recvbuf, recvcount, recvtype)
CHECK_ARGS(sendbuf == recvbuf && sendcount > 0 && recvcount > 0, MPI_ERR_BUFFER,
- "%s: Invalid parameters 1 and 6: sendbuf and recvbuf must be disjoint", __func__);
+ "%s: Invalid parameters 1 and 6: sendbuf and recvbuf must be disjoint", __func__)
CHECK_TAG(10, recvtag)
CHECK_COMM(11)
CHECK_REQUEST(12)
static int (*raw_pthread_mutexattr_init)(pthread_mutexattr_t*);
static int (*raw_pthread_mutexattr_settype)(pthread_mutexattr_t*, int);
-static int (*raw_pthread_mutexattr_gettype)(const pthread_mutexattr_t* restrict, int* restrict);
+static int (*raw_pthread_mutexattr_gettype)(const pthread_mutexattr_t*, int*);
static int (*raw_pthread_mutexattr_getrobust)(const pthread_mutexattr_t*, int*);
static int (*raw_pthread_mutexattr_setrobust)(pthread_mutexattr_t*, int);
intercepted_pthcall(mutexattr_init, (pthread_mutexattr_t * attr), (attr), ((sthread_mutexattr_t*)attr));
intercepted_pthcall(mutexattr_settype, (pthread_mutexattr_t * attr, int type), (attr, type),
((sthread_mutexattr_t*)attr, type));
-intercepted_pthcall(mutexattr_gettype, (const pthread_mutexattr_t* restrict attr, int* type), (attr, type),
+intercepted_pthcall(mutexattr_gettype, (const pthread_mutexattr_t* attr, int* type), (attr, type),
((sthread_mutexattr_t*)attr, type));
-intercepted_pthcall(mutexattr_setrobust, (pthread_mutexattr_t* restrict attr, int robustness), (attr, robustness),
+intercepted_pthcall(mutexattr_setrobust, (pthread_mutexattr_t * attr, int robustness), (attr, robustness),
+ ((sthread_mutexattr_t*)attr, robustness));
+intercepted_pthcall(mutexattr_getrobust, (const pthread_mutexattr_t* attr, int* robustness), (attr, robustness),
((sthread_mutexattr_t*)attr, robustness));
-intercepted_pthcall(mutexattr_getrobust, (const pthread_mutexattr_t* restrict attr, int* restrict robustness),
- (attr, robustness), ((sthread_mutexattr_t*)attr, robustness));
intercepted_pthcall(create, (pthread_t * thread, const pthread_attr_t* attr, void* (*start_routine)(void*), void* arg),
(thread, attr, start_routine, arg), ((sthread_t*)thread, attr, start_routine, arg));