, block_length(block_length){};
Message(e_message_type type, int peer_id, simgrid::s4u::Mailbox* return_mailbox, int piece)
: type(type), peer_id(peer_id), return_mailbox(return_mailbox), piece(piece){};
- ~Message() = default;
};
class HostBittorrent {
- RngStream stream_;
+ std::unique_ptr<std::remove_pointer<RngStream>::type, std::function<void(RngStream)>> stream_ = {
+ nullptr, [](RngStream stream) { RngStream_DeleteStream(&stream); }};
simgrid::s4u::Host* host = nullptr;
public:
explicit HostBittorrent(simgrid::s4u::Host* ptr) : host(ptr)
{
std::string descr = std::string("RngSream<") + host->get_cname() + ">";
- stream_ = RngStream_CreateStream(descr.c_str());
+ stream_.reset(RngStream_CreateStream(descr.c_str()));
}
HostBittorrent(const HostBittorrent&) = delete;
HostBittorrent& operator=(const HostBittorrent&) = delete;
- ~HostBittorrent() { RngStream_DeleteStream(&stream_); };
-
- RngStream getStream() { return stream_; };
+ RngStream getStream() { return stream_.get(); };
};
#endif /* BITTORRENT_BITTORRENT_HPP_ */
bitfield_ = (1U << FILE_PIECES) - 1U;
bitfield_blocks = (1ULL << (FILE_PIECES * PIECES_BLOCKS)) - 1ULL;
}
- pieces_count = new short[FILE_PIECES]{0};
+ pieces_count.resize(FILE_PIECES);
XBT_INFO("Hi, I'm joining the network with id %d", id);
}
-Peer::~Peer()
-{
- for (auto const& peer : connected_peers)
- delete peer.second;
- delete[] pieces_count;
-}
-
/** Peer main function */
void Peer::operator()()
{
try {
TrackerAnswer* answer = static_cast<TrackerAnswer*>(mailbox_->get(GET_PEERS_TIMEOUT));
// Add the peers the tracker gave us to our peer list.
- for (auto const& peer_id : *answer->getPeers())
+ for (auto const& peer_id : answer->getPeers())
if (id != peer_id)
- connected_peers[peer_id] = new Connection(peer_id);
+ connected_peers.emplace(peer_id, Connection(peer_id));
delete answer;
} catch (simgrid::TimeoutError& e) {
XBT_DEBUG("Timeout expired when requesting peers to tracker");
void Peer::sendHandshakeToAllPeers()
{
for (auto const& kv : connected_peers) {
- Connection* remote_peer = kv.second;
+ const Connection& remote_peer = kv.second;
Message* handshake = new Message(MESSAGE_HANDSHAKE, id, mailbox_);
- remote_peer->mailbox_->put_init(handshake, MESSAGE_HANDSHAKE_SIZE)->detach();
- XBT_DEBUG("Sending a HANDSHAKE to %d", remote_peer->id);
+ remote_peer.mailbox_->put_init(handshake, MESSAGE_HANDSHAKE_SIZE)->detach();
+ XBT_DEBUG("Sending a HANDSHAKE to %d", remote_peer.id);
}
}
{
XBT_DEBUG("Sending HAVE message to all my peers");
for (auto const& kv : connected_peers) {
- Connection* remote_peer = kv.second;
- remote_peer->mailbox_->put_init(new Message(MESSAGE_HAVE, id, mailbox_, piece), MESSAGE_HAVE_SIZE)->detach();
+ const Connection& remote_peer = kv.second;
+ remote_peer.mailbox_->put_init(new Message(MESSAGE_HAVE, id, mailbox_, piece), MESSAGE_HAVE_SIZE)->detach();
}
}
{
int nb = 0;
for (auto const& kv : connected_peers)
- if (kv.second->interested)
+ if (kv.second.interested)
nb++;
return nb;
}
XBT_DEBUG("Received a %s message from %s", type_names[message->type], message->return_mailbox->get_cname());
auto known_peer = connected_peers.find(message->peer_id);
- Connection* remote_peer = (known_peer == connected_peers.end()) ? nullptr : known_peer->second;
+ Connection* remote_peer = (known_peer == connected_peers.end()) ? nullptr : &known_peer->second;
xbt_assert(remote_peer != nullptr || message->type == MESSAGE_HANDSHAKE,
"The impossible did happened: A not-in-our-list peer sent us a message.");
// Check if the peer is in our connection list.
if (remote_peer == nullptr) {
XBT_DEBUG("This peer %d was unknown, answer to its handshake", message->peer_id);
- connected_peers[message->peer_id] = new Connection(message->peer_id);
+ connected_peers.emplace(message->peer_id, Connection(message->peer_id));
sendMessage(message->return_mailbox, MESSAGE_HANDSHAKE, MESSAGE_HANDSHAKE_SIZE);
}
// Send our bitfield to the peer
/**If we are currently seeding, we unchoke the peer which has been unchoked the last time.*/
if (hasFinished()) {
- Connection* remote_peer;
double unchoke_time = simgrid::s4u::Engine::get_clock() + 1;
- for (auto const& kv : connected_peers) {
- remote_peer = kv.second;
- if (remote_peer->last_unchoke < unchoke_time && remote_peer->interested && remote_peer->choked_upload) {
- unchoke_time = remote_peer->last_unchoke;
- chosen_peer = remote_peer;
+ for (auto& kv : connected_peers) {
+ Connection& remote_peer = kv.second;
+ if (remote_peer.last_unchoke < unchoke_time && remote_peer.interested && remote_peer.choked_upload) {
+ unchoke_time = remote_peer.last_unchoke;
+ chosen_peer = &remote_peer;
}
}
} else {
int j = 0;
do {
// We choose a random peer to unchoke.
- std::unordered_map<int, Connection*>::iterator chosen_peer_it = connected_peers.begin();
+ std::unordered_map<int, Connection>::iterator chosen_peer_it = connected_peers.begin();
std::advance(chosen_peer_it, RngStream_RandInt(stream, 0, connected_peers.size() - 1));
- chosen_peer = chosen_peer_it->second;
- if (chosen_peer == nullptr)
- THROWF(unknown_error, 0, "A peer should have be selected at this point");
- else if (not chosen_peer->interested || not chosen_peer->choked_upload)
+ chosen_peer = &chosen_peer_it->second;
+ if (not chosen_peer->interested || not chosen_peer->choked_upload)
chosen_peer = nullptr;
else
XBT_DEBUG("Nothing to do, keep going");
} else {
// Use the "fastest download" policy.
double fastest_speed = 0.0;
- for (auto const& kv : connected_peers) {
- Connection* remote_peer = kv.second;
- if (remote_peer->peer_speed > fastest_speed && remote_peer->choked_upload && remote_peer->interested) {
- chosen_peer = remote_peer;
- fastest_speed = remote_peer->peer_speed;
+ for (auto& kv : connected_peers) {
+ Connection& remote_peer = kv.second;
+ if (remote_peer.peer_speed > fastest_speed && remote_peer.choked_upload && remote_peer.interested) {
+ fastest_speed = remote_peer.peer_speed;
+ chosen_peer = &remote_peer;
}
}
}
/** @brief Update "interested" state of peers: send "not interested" to peers that don't have any more pieces we want.*/
void Peer::updateInterestedAfterReceive()
{
- for (auto const& kv : connected_peers) {
- Connection* remote_peer = kv.second;
- if (remote_peer->am_interested) {
+ for (auto& kv : connected_peers) {
+ Connection& remote_peer = kv.second;
+ if (remote_peer.am_interested) {
bool interested = false;
// Check if the peer still has a piece we want.
for (unsigned int i = 0; i < FILE_PIECES; i++)
- if (hasNotPiece(i) && remote_peer->hasPiece(i)) {
+ if (hasNotPiece(i) && remote_peer.hasPiece(i)) {
interested = true;
break;
}
if (not interested) { // no more piece to download from connection
- remote_peer->am_interested = false;
- sendMessage(remote_peer->mailbox_, MESSAGE_NOTINTERESTED, MESSAGE_NOTINTERESTED_SIZE);
+ remote_peer.am_interested = false;
+ sendMessage(remote_peer.mailbox_, MESSAGE_NOTINTERESTED, MESSAGE_NOTINTERESTED_SIZE);
}
}
}
bool choked_download = true; // Indicates if the peer has choked the current peer
explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::by_name(std::to_string(id))){};
- ~Connection() = default;
void addSpeedValue(double speed) { peer_speed = peer_speed * 0.6 + speed * 0.4; }
bool hasPiece(unsigned int piece) { return bitfield & 1U << piece; }
};
double deadline;
RngStream stream;
simgrid::s4u::Mailbox* mailbox_;
- std::unordered_map<int, Connection*> connected_peers;
+ std::unordered_map<int, Connection> connected_peers;
std::set<Connection*> active_peers; // active peers list
unsigned int bitfield_ = 0; // list of pieces the peer has.
unsigned long long bitfield_blocks = 0; // list of blocks the peer has.
- short* pieces_count = nullptr; // number of peers that have each piece.
+ std::vector<short> pieces_count; // number of peers that have each piece.
unsigned int current_pieces = 0; // current pieces the peer is downloading
double begin_receive_time = 0; // time when the receiving communication has begun, useful for calculating host speed.
int round_ = 0; // current round for the chocking algorithm.
explicit Peer(std::vector<std::string> args);
Peer(const Peer&) = delete;
Peer& operator=(const Peer&) = delete;
- ~Peer();
void operator()();
std::string getStatus();
do {
next_peer = known_peers.begin();
std::advance(next_peer, RngStream_RandInt(stream, 0, nb_known_peers - 1));
- } while (ta->getPeers()->find(*next_peer) != ta->getPeers()->end());
+ } while (ta->getPeers().find(*next_peer) != ta->getPeers().end());
ta->addPeer(*next_peer);
tried++;
}
public:
explicit TrackerQuery(int peer_id, simgrid::s4u::Mailbox* return_mailbox)
: peer_id(peer_id), return_mailbox(return_mailbox){};
- ~TrackerQuery() = default;
int getPeerId() { return peer_id; }
simgrid::s4u::Mailbox* getReturnMailbox() { return return_mailbox; }
};
class TrackerAnswer {
// int interval; // how often the peer should contact the tracker (unused for now)
- std::set<int>* peers; // the peer list the peer has asked for.
+ std::set<int> peers; // the peer list the peer has asked for.
public:
- explicit TrackerAnswer(int /*interval*/) /*: interval(interval)*/ { peers = new std::set<int>; }
- TrackerAnswer(const TrackerAnswer&) = delete;
- TrackerAnswer& operator=(const TrackerAnswer&) = delete;
- ~TrackerAnswer() { delete peers; };
- void addPeer(int peer) { peers->insert(peer); }
- std::set<int>* getPeers() { return peers; }
+ explicit TrackerAnswer(int /*interval*/) /*: interval(interval)*/ {}
+ void addPeer(int peer) { peers.insert(peer); }
+ const std::set<int>& getPeers() { return peers; }
};
class Tracker {
stream = simgrid::s4u::this_actor::get_host()->extension<HostChord>()->getStream();
mailbox_ = simgrid::s4u::Mailbox::by_name(std::to_string(id_));
next_finger_to_fix = 0;
- fingers_ = new int[nb_bits];
-
- for (int i = 0; i < nb_bits; i++) {
- fingers_[i] = id_;
- }
+ fingers_.resize(nb_bits, id_);
if (args.size() == 3) { // first ring
deadline_ = std::stod(args[2]);
}
}
-Node::~Node()
-{
- delete[] fingers_;
-}
/* Makes the current node join the ring, knowing the id of a node already in the ring
*
* @param known_id id of a node already in the ring
extern int timeout;
class HostChord {
- RngStream stream_;
+ std::unique_ptr<std::remove_pointer<RngStream>::type, std::function<void(RngStream)>> stream_ = {
+ nullptr, [](RngStream stream) { RngStream_DeleteStream(&stream); }};
simgrid::s4u::Host* host = nullptr;
public:
explicit HostChord(simgrid::s4u::Host* ptr) : host(ptr)
{
std::string descr = std::string("RngSream<") + host->get_cname() + ">";
- stream_ = RngStream_CreateStream(descr.c_str());
+ stream_.reset(RngStream_CreateStream(descr.c_str()));
}
HostChord(const HostChord&) = delete;
HostChord& operator=(const HostChord&) = delete;
- ~HostChord() { RngStream_DeleteStream(&stream_); };
-
- RngStream getStream() { return stream_; };
+ RngStream getStream() { return stream_.get(); };
};
/* Types of tasks exchanged between nodes. */
{
}
- ~ChordMessage() = default;
-
static void destroy(void* message);
};
int id_; // my id
int pred_id_ = -1; // predecessor id
simgrid::s4u::Mailbox* mailbox_; // my mailbox
- int* fingers_; // finger table,(fingers[0] is my successor)
+ std::vector<int> fingers_; // finger table,(fingers[0] is my successor)
int next_finger_to_fix; // index of the next finger to fix in fix_fingers()
RngStream stream;
explicit Node(std::vector<std::string> args);
Node(const Node&) = delete;
Node& operator=(const Node&) = delete;
- ~Node();
void join(int known_id);
void leave();
void notifyAndQuit();
static void test_host(const std::string& hostname)
{
simgrid::s4u::Host* thehost = simgrid::s4u::Host::by_name(hostname);
- std::unordered_map<std::string, std::string>* props = thehost->get_properties();
+ const std::unordered_map<std::string, std::string>* props = thehost->get_properties();
const char* noexist = "Unknown";
const char* exist = "Hdd";
const char* value;
XBT_INFO(" Zone property: author -> %s", root->get_property("author"));
/* Get the property list of current bob process */
- std::unordered_map<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
+ const std::unordered_map<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
const char* noexist = "UnknownProcessProp";
XBT_ATTRIB_UNUSED const char* value;
unsigned int group_;
unsigned int chassis_;
unsigned int blade_;
- resource::LinkImpl** blue_links_ = nullptr;
- resource::LinkImpl** black_links_ = nullptr;
- resource::LinkImpl** green_links_ = nullptr;
- resource::LinkImpl** my_nodes_ = nullptr;
- DragonflyRouter(int i, int j, int k);
- DragonflyRouter(const DragonflyRouter&) = delete;
- DragonflyRouter& operator=(const DragonflyRouter&) = delete;
- ~DragonflyRouter();
+ resource::LinkImpl* blue_link_ = nullptr;
+ std::vector<resource::LinkImpl*> black_links_;
+ std::vector<resource::LinkImpl*> green_links_;
+ std::vector<resource::LinkImpl*> my_nodes_;
+ DragonflyRouter(unsigned group, unsigned chassis, unsigned blade) : group_(group), chassis_(chassis), blade_(blade) {}
};
/** @ingroup ROUTING_API
class XBT_PUBLIC DragonflyZone : public ClusterZone {
public:
explicit DragonflyZone(NetZoneImpl* father, const std::string& name, resource::NetworkModel* netmodel);
- DragonflyZone(const DragonflyZone&) = delete;
- DragonflyZone& operator=(const DragonflyZone&) = delete;
- ~DragonflyZone() override;
// void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position) override;
void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
void parse_specific_arguments(ClusterCreationArgs* cluster) override;
unsigned int num_links_black_ = 0;
unsigned int num_links_blue_ = 0;
unsigned int num_links_per_link_ = 1; // splitduplex -> 2, only for local link
- DragonflyRouter** routers_ = nullptr;
+ std::vector<DragonflyRouter> routers_;
};
} // namespace routing
} // namespace kernel
/** @brief Make a host within that NetZone */
simgrid::s4u::Host* create_host(const char* name, const std::vector<double>& speed_per_pstate, int core_count,
- std::map<std::string, std::string>* props);
+ const std::map<std::string, std::string>* props);
/** @brief Creates a new route in this NetZone */
virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
std::vector<resource::LinkImpl*>& link_list, bool symmetrical);
/** Retrieve the user data of the Activity */
void* get_user_data() { return user_data_; }
- kernel::activity::ActivityImplPtr get_impl() { return pimpl_; }
+ kernel::activity::ActivityImpl* get_impl() const { return pimpl_.get(); }
#ifndef DOXYGEN
XBT_ATTRIB_DEPRECATED_v324("Please use Activity::wait_for()") virtual void wait(double timeout) = 0;
// ***** Actor creation *****
/** Retrieve a reference to myself */
- static ActorPtr self();
+ static Actor* self();
/** Signal to others that a new actor has been created **/
static xbt::signal<void(Actor&)> on_creation;
kernel::actor::ActorImpl* get_impl() const { return pimpl_; }
/** Retrieve the property value (or nullptr if not set) */
- std::unordered_map<std::string, std::string>*
+ const std::unordered_map<std::string, std::string>*
get_properties() const; // FIXME: do not export the map, but only the keys or something
const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
/** Retrieve the size of the received data. Not to be mixed with @ref Activity::set_remaining() */
size_t get_dst_data_size();
- s4u::ActorPtr get_sender();
+ Actor* get_sender();
#ifndef DOXYGEN
XBT_ATTRIB_DEPRECATED_v324("Please use Comm::wait_for()") void wait(double t) override { wait_for(t); }
const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
- std::unordered_map<std::string, std::string>* get_properties();
+ const std::unordered_map<std::string, std::string>* get_properties() const;
+ void set_properties(const std::map<std::string, std::string>& properties);
void set_state_profile(kernel::profile::Profile* p);
void set_speed_profile(kernel::profile::Profile* p);
public:
enum class SharingPolicy { SPLITDUPLEX = 2, SHARED = 1, FATPIPE = 0 };
- kernel::resource::LinkImpl* get_impl() { return pimpl_; }
+ kernel::resource::LinkImpl* get_impl() const { return pimpl_; }
/** @brief Retrieve a link from its name */
static Link* by_name(const std::string& name);
* The profile must contain absolute values */
void set_latency_profile(kernel::profile::Profile* profile);
- const char* get_property(const std::string& key);
+ const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
/* The signals */
public:
/** private function, do not use. FIXME: make me protected */
- kernel::activity::MailboxImpl* get_impl() { return pimpl_; }
+ kernel::activity::MailboxImpl* get_impl() const { return pimpl_; }
/** @brief Retrieves the name of that mailbox as a C++ string */
const xbt::string& get_name() const;
std::vector<Host*> get_all_hosts();
int get_host_count();
- kernel::routing::NetZoneImpl* get_impl() { return pimpl_; }
+ kernel::routing::NetZoneImpl* get_impl() const { return pimpl_; }
private:
kernel::routing::NetZoneImpl* const pimpl_;
public:
/** Get the properties assigned to a netzone */
- std::unordered_map<std::string, std::string>* get_properties();
+ const std::unordered_map<std::string, std::string>* get_properties() const;
std::vector<NetZone*> get_children();
/** Retrieve the property value (or nullptr if not set) */
- const char* get_property(const std::string& key);
+ const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
/* Add content to the netzone, at parsing time. It should be sealed afterward. */
Host* get_host() { return attached_to_; };
void set_host(Host* host) { attached_to_ = host; }
- std::unordered_map<std::string, std::string>* get_properties();
- const char* get_property(const std::string& key);
+ const std::unordered_map<std::string, std::string>* get_properties() const;
+ const char* get_property(const std::string& key) const;
void set_property(const std::string&, const std::string& value);
void set_data(void* data) { userdata_ = data; }
IoPtr write_async(sg_size_t size);
sg_size_t write(sg_size_t size);
- kernel::resource::StorageImpl* get_impl() { return pimpl_; }
+ kernel::resource::StorageImpl* get_impl() const { return pimpl_; }
private:
Host* attached_to_ = nullptr;
*/
template<class T, T... N>
class integer_sequence {
- static constexpr std::size_t size()
- {
- return std::tuple_size<decltype(std::make_tuple(N...))>::value;
- }
};
namespace bits {
virtual void finish() = 0;
virtual void register_simcall(smx_simcall_t simcall);
- virtual void clean_action();
+ void clean_action();
virtual double get_remaining() const;
// boost::intrusive_ptr<ActivityImpl> support:
friend XBT_PUBLIC void intrusive_ptr_add_ref(ActivityImpl* activity);
void ConditionVariableImpl::wait(smx_mutex_t mutex, double timeout, actor::ActorImpl* issuer, smx_simcall_t simcall)
{
- XBT_IN("(%p, %p, %f, %p,%p)", this, mutex, timeout, issuer, simcall);
- RawImplPtr synchro = nullptr;
-
XBT_DEBUG("Wait condition %p", this);
/* If there is a mutex unlock it */
mutex->unlock(issuer);
}
- synchro = RawImplPtr(new RawImpl());
+ RawImplPtr synchro(new RawImpl());
(*synchro).set_host(issuer->get_host()).set_timeout(timeout).start();
synchro->simcalls_.push_front(simcall);
- issuer->waiting_synchro = synchro;
+ issuer->waiting_synchro = std::move(synchro);
sleeping_.push_back(*simcall->issuer);
- XBT_OUT();
}
// boost::intrusive_ptr<ConditionVariableImpl> support:
XBT_DEBUG("RawImpl::finish(): host '%s' failed", simcall->issuer->get_host()->get_cname());
simcall->issuer->context_->iwannadie = true;
simcall->issuer->exception_ = std::make_exception_ptr(HostFailureException(XBT_THROW_POINT, "Host failed"));
- } else if (state_ == SIMIX_SRC_TIMEOUT) {
- simcall->issuer->exception_ = std::make_exception_ptr(TimeoutError(XBT_THROW_POINT, "Synchronization timeout"));
- } else {
+ } else if (state_ != SIMIX_SRC_TIMEOUT) {
xbt_die("Internal error in RawImpl::finish() unexpected synchro state %d", static_cast<int>(state_));
}
*/
ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* host,
- std::unordered_map<std::string, std::string>* properties)
+ const std::unordered_map<std::string, std::string>* properties)
{
// This is mostly a copy/paste from create(), it'd be nice to share some code between those two functions.
/* Add properties */
if (properties != nullptr)
- for (auto const& kv : *properties)
- actor->set_property(kv.first, kv.second);
+ actor->set_properties(*properties);
/* Add the process to it's host process list */
host->pimpl_->process_list_.push_back(*actor);
}
ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
- std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
+ const std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
{
XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
/* Add properties */
if (properties != nullptr)
- for (auto const& kv : *properties)
- actor->set_property(kv.first, kv.second);
+ actor->set_properties(*properties);
actor->start(code);
ActorImpl* start(const simix::ActorCode& code);
static ActorImplPtr create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
- std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor);
+ const std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor);
static ActorImplPtr attach(const std::string& name, void* data, s4u::Host* host,
- std::unordered_map<std::string, std::string>* properties);
+ const std::unordered_map<std::string, std::string>* properties);
static void detach();
void cleanup();
void exit();
void* data = nullptr;
s4u::Host* host = nullptr;
double kill_time = 0.0;
- std::shared_ptr<std::unordered_map<std::string, std::string>> properties = nullptr;
+ std::shared_ptr<const std::unordered_map<std::string, std::string>> properties = nullptr;
bool auto_restart = false;
bool daemon_ = false;
ProcessArg() = default;
"Cluster routing: no links attached to the source node - did you use host_link tag?");
if ((src->id() == dst->id()) && has_loopback_) {
- xbt_assert(not src->is_router(), "Routing from a cluster private router to itself is meaningless");
-
- std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos(src->id()));
- route->link_list.push_back(info.first);
- if (lat)
- *lat += info.first->get_latency();
+ if (src->is_router()) {
+ XBT_WARN("Routing from a cluster private router to itself is meaningless");
+ } else {
+ std::pair<resource::LinkImpl*, resource::LinkImpl*> info = private_links_.at(node_pos(src->id()));
+ route->link_list.push_back(info.first);
+ if (lat)
+ *lat += info.first->get_latency();
+ }
return;
}
{
}
-DragonflyZone::~DragonflyZone()
-{
- if (this->routers_ != nullptr) {
- for (unsigned int i = 0; i < this->num_groups_ * this->num_chassis_per_group_ * this->num_blades_per_chassis_; i++)
- delete routers_[i];
- delete[] routers_;
- }
-}
-
void DragonflyZone::rankId_to_coords(int rankId, unsigned int coords[4])
{
// coords : group, chassis, blade, node
this->generate_links();
}
-DragonflyRouter::DragonflyRouter(int group, int chassis, int blade) : group_(group), chassis_(chassis), blade_(blade)
-{
-}
-
-DragonflyRouter::~DragonflyRouter()
-{
- delete[] my_nodes_;
- delete[] green_links_;
- delete[] black_links_;
- delete blue_links_;
-}
-
void DragonflyZone::generate_routers()
{
- this->routers_ =
- new DragonflyRouter*[this->num_groups_ * this->num_chassis_per_group_ * this->num_blades_per_chassis_];
-
- for (unsigned int i = 0; i < this->num_groups_; i++) {
- for (unsigned int j = 0; j < this->num_chassis_per_group_; j++) {
- for (unsigned int k = 0; k < this->num_blades_per_chassis_; k++) {
- DragonflyRouter* router = new DragonflyRouter(i, j, k);
- this->routers_[i * this->num_chassis_per_group_ * this->num_blades_per_chassis_ +
- j * this->num_blades_per_chassis_ + k] = router;
- }
- }
- }
+ this->routers_.reserve(this->num_groups_ * this->num_chassis_per_group_ * this->num_blades_per_chassis_);
+ for (unsigned int i = 0; i < this->num_groups_; i++)
+ for (unsigned int j = 0; j < this->num_chassis_per_group_; j++)
+ for (unsigned int k = 0; k < this->num_blades_per_chassis_; k++)
+ this->routers_.emplace_back(i, j, k);
}
void DragonflyZone::create_link(const std::string& id, int numlinks, resource::LinkImpl** linkup,
// Links from routers to their local nodes.
for (unsigned int i = 0; i < numRouters; i++) {
// allocate structures
- this->routers_[i]->my_nodes_ = new resource::LinkImpl*[num_links_per_link_ * this->num_nodes_per_blade_];
- this->routers_[i]->green_links_ = new resource::LinkImpl*[this->num_blades_per_chassis_];
- this->routers_[i]->black_links_ = new resource::LinkImpl*[this->num_chassis_per_group_];
+ this->routers_[i].my_nodes_.resize(num_links_per_link_ * this->num_nodes_per_blade_);
+ this->routers_[i].green_links_.resize(this->num_blades_per_chassis_);
+ this->routers_[i].black_links_.resize(this->num_chassis_per_group_);
for (unsigned int j = 0; j < num_links_per_link_ * this->num_nodes_per_blade_; j += num_links_per_link_) {
std::string id = "local_link_from_router_" + std::to_string(i) + "_to_node_" +
std::to_string(j / num_links_per_link_) + "_" + std::to_string(uniqueId);
this->create_link(id, 1, &linkup, &linkdown);
- this->routers_[i]->my_nodes_[j] = linkup;
+ this->routers_[i].my_nodes_[j] = linkup;
if (this->sharing_policy_ == s4u::Link::SharingPolicy::SPLITDUPLEX)
- this->routers_[i]->my_nodes_[j + 1] = linkdown;
+ this->routers_[i].my_nodes_[j + 1] = linkdown;
uniqueId++;
}
std::to_string(j) + "_and_" + std::to_string(k) + "_" + std::to_string(uniqueId);
this->create_link(id, this->num_links_green_, &linkup, &linkdown);
- this->routers_[i * num_blades_per_chassis_ + j]->green_links_[k] = linkup;
- this->routers_[i * num_blades_per_chassis_ + k]->green_links_[j] = linkdown;
+ this->routers_[i * num_blades_per_chassis_ + j].green_links_[k] = linkup;
+ this->routers_[i * num_blades_per_chassis_ + k].green_links_[j] = linkdown;
uniqueId++;
}
}
this->create_link(id, this->num_links_black_, &linkup, &linkdown);
this->routers_[i * num_blades_per_chassis_ * num_chassis_per_group_ + j * num_blades_per_chassis_ + l]
- ->black_links_[k] = linkup;
+ .black_links_[k] = linkup;
this->routers_[i * num_blades_per_chassis_ * num_chassis_per_group_ + k * num_blades_per_chassis_ + l]
- ->black_links_[j] = linkdown;
+ .black_links_[j] = linkdown;
uniqueId++;
}
}
for (unsigned int j = i + 1; j < this->num_groups_; j++) {
unsigned int routernumi = i * num_blades_per_chassis_ * num_chassis_per_group_ + j;
unsigned int routernumj = j * num_blades_per_chassis_ * num_chassis_per_group_ + i;
- this->routers_[routernumi]->blue_links_ = new resource::LinkImpl*;
- this->routers_[routernumj]->blue_links_ = new resource::LinkImpl*;
std::string id = "blue_link_between_group_"+ std::to_string(i) +"_and_" + std::to_string(j) +"_routers_" +
std::to_string(routernumi) + "_and_" + std::to_string(routernumj) + "_" + std::to_string(uniqueId);
this->create_link(id, this->num_links_blue_, &linkup, &linkdown);
- this->routers_[routernumi]->blue_links_[0] = linkup;
- this->routers_[routernumj]->blue_links_[0] = linkdown;
+ this->routers_[routernumi].blue_link_ = linkup;
+ this->routers_[routernumj].blue_link_ = linkdown;
uniqueId++;
}
}
XBT_DEBUG("dst : %u group, %u chassis, %u blade, %u node", targetCoords[0], targetCoords[1], targetCoords[2],
targetCoords[3]);
- DragonflyRouter* myRouter = routers_[myCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) +
- myCoords[1] * num_blades_per_chassis_ + myCoords[2]];
- DragonflyRouter* targetRouter = routers_[targetCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) +
- targetCoords[1] * num_blades_per_chassis_ + targetCoords[2]];
+ DragonflyRouter* myRouter = &routers_[myCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) +
+ myCoords[1] * num_blades_per_chassis_ + myCoords[2]];
+ DragonflyRouter* targetRouter = &routers_[targetCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) +
+ targetCoords[1] * num_blades_per_chassis_ + targetCoords[2]];
DragonflyRouter* currentRouter = myRouter;
// node->router local link
route->link_list.push_back(currentRouter->green_links_[targetCoords[0]]);
if (latency)
*latency += currentRouter->green_links_[targetCoords[0]]->get_latency();
- currentRouter = routers_[myCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) +
- myCoords[1] * num_blades_per_chassis_ + targetCoords[0]];
+ currentRouter = &routers_[myCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) +
+ myCoords[1] * num_blades_per_chassis_ + targetCoords[0]];
}
if (currentRouter->chassis_ != 0) {
route->link_list.push_back(currentRouter->black_links_[0]);
if (latency)
*latency += currentRouter->black_links_[0]->get_latency();
- currentRouter = routers_[myCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + targetCoords[0]];
+ currentRouter = &routers_[myCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + targetCoords[0]];
}
// go to destination group - the only optical hop
- route->link_list.push_back(currentRouter->blue_links_[0]);
+ route->link_list.push_back(currentRouter->blue_link_);
if (latency)
- *latency += currentRouter->blue_links_[0]->get_latency();
- currentRouter = routers_[targetCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + myCoords[0]];
+ *latency += currentRouter->blue_link_->get_latency();
+ currentRouter = &routers_[targetCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + myCoords[0]];
}
// same group, but same blade ?
route->link_list.push_back(currentRouter->green_links_[targetCoords[2]]);
if (latency)
*latency += currentRouter->green_links_[targetCoords[2]]->get_latency();
- currentRouter = routers_[targetCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + targetCoords[2]];
+ currentRouter = &routers_[targetCoords[0] * (num_chassis_per_group_ * num_blades_per_chassis_) + targetCoords[2]];
}
// same blade, but same chassis ?
}
simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, const std::vector<double>& speed_per_pstate,
- int coreAmount, std::map<std::string, std::string>* props)
+ int coreAmount, const std::map<std::string, std::string>* props)
{
simgrid::s4u::Host* res = new simgrid::s4u::Host(name);
surf_cpu_model_pm->create_cpu(res, speed_per_pstate, coreAmount);
if (props != nullptr)
- for (auto const& kv : *props)
- res->set_property(kv.first, kv.second);
+ res->set_properties(*props);
simgrid::s4u::Host::on_creation(*res); // notify the signal
msg_comm_t comm;
unsigned int cursor;
xbt_dynar_foreach (comms, cursor, comm) {
- s_comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(comm->s_comm->get_impl().get()));
+ s_comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(comm->s_comm->get_impl()));
}
msg_error_t status = MSG_OK;
msg_comm_t comm;
unsigned int cursor;
xbt_dynar_foreach (comms, cursor, comm) {
- s_comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(comm->s_comm->get_impl().get()));
+ s_comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(comm->s_comm->get_impl()));
}
msg_error_t status = MSG_OK;
s4u::Actor* Task::get_sender()
{
- return comm ? comm->get_sender().get() : nullptr;
+ return comm ? comm->get_sender() : nullptr;
}
s4u::Host* Task::get_source()
xbt::signal<void(Actor const&)> s4u::Actor::on_destruction;
// ***** Actor creation *****
-ActorPtr Actor::self()
+Actor* Actor::self()
{
kernel::context::Context* self_context = kernel::context::Context::self();
if (self_context == nullptr)
- return ActorPtr();
+ return nullptr;
- return self_context->get_actor()->iface();
+ return self_context->get_actor()->ciface();
}
ActorPtr Actor::init(const std::string& name, s4u::Host* host)
{
smx_actor_t self = SIMIX_process_self();
kernel::actor::ActorImpl* actor = simix::simcall([self, &name, host] { return self->init(name, host).get(); });
- return actor->ciface();
+ return actor->iface();
}
ActorPtr Actor::start(const std::function<void()>& code)
simix::simcall([self] { self->kill_all(); });
}
-std::unordered_map<std::string, std::string>* Actor::get_properties() const
+const std::unordered_map<std::string, std::string>* Actor::get_properties() const
{
return pimpl_->get_properties();
}
{
xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::unordered_map<std::string, std::string>* props = actor->get_properties();
+ const std::unordered_map<std::string, std::string>* props = actor->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& kv : *props) {
return mailbox_;
}
-ActorPtr Comm::get_sender()
+Actor* Comm::get_sender()
{
- return sender_ ? sender_->iface() : nullptr;
+ return sender_ ? sender_->ciface() : nullptr;
}
void intrusive_ptr_release(simgrid::s4u::Comm* c)
}
/** Get the properties assigned to a host */
-std::unordered_map<std::string, std::string>* Host::get_properties()
+const std::unordered_map<std::string, std::string>* Host::get_properties() const
{
- return simix::simcall([this] { return this->pimpl_->get_properties(); });
+ return this->pimpl_->get_properties();
}
/** Retrieve the property value (or nullptr if not set) */
{
simix::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
}
+
+void Host::set_properties(const std::map<std::string, std::string>& properties)
+{
+ simix::simcall([this, &properties] { this->pimpl_->set_properties(properties); });
+}
+
/** Specify a profile turning the host on and off according to a exhaustive list or a stochastic law.
* The profile must contain boolean values. */
void Host::set_state_profile(kernel::profile::Profile* p)
xbt_dict_t sg_host_get_properties(sg_host_t host)
{
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::unordered_map<std::string, std::string>* props = host->get_properties();
+ const std::unordered_map<std::string, std::string>* props = host->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& elm : *props) {
XBT_INFO("Displaying host %s", host->get_cname());
XBT_INFO(" - speed: %.0f", host->get_speed());
XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host));
- std::unordered_map<std::string, std::string>* props = host->get_properties();
+ const std::unordered_map<std::string, std::string>* props = host->get_properties();
if (not props->empty()) {
XBT_INFO(" - properties:");
simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); });
}
-const char* Link::get_property(const std::string& key)
+const char* Link::get_property(const std::string& key) const
{
return this->pimpl_->get_property(key);
}
{
}
-std::unordered_map<std::string, std::string>* NetZone::get_properties()
+const std::unordered_map<std::string, std::string>* NetZone::get_properties() const
{
- return simix::simcall([this] { return &properties_; });
+ return &properties_;
}
/** Retrieve the property value (or nullptr if not set) */
-const char* NetZone::get_property(const std::string& key)
+const char* NetZone::get_property(const std::string& key) const
{
- return properties_.at(key).c_str();
+ auto prop = properties_.find(key);
+ return prop == properties_.end() ? nullptr : prop->second.c_str();
}
+
void NetZone::set_property(const std::string& key, const std::string& value)
{
simix::simcall([this, &key, &value] { properties_[key] = value; });
return pimpl_->typeId_.c_str();
}
-std::unordered_map<std::string, std::string>* Storage::get_properties()
+const std::unordered_map<std::string, std::string>* Storage::get_properties() const
{
- return simix::simcall([this] { return pimpl_->get_properties(); });
+ return pimpl_->get_properties();
}
-const char* Storage::get_property(const std::string& key)
+const char* Storage::get_property(const std::string& key) const
{
return this->pimpl_->get_property(key);
}
{
xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::unordered_map<std::string, std::string>* props = storage->get_properties();
+ const std::unordered_map<std::string, std::string>* props = storage->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& elm : *props) {
intrusive_ptr_release(actor);
}
#if SIMGRID_HAVE_MC
- xbt_dynar_reset(simix_global->dead_actors_vector);
+ xbt_dynar_reset(dead_actors_vector);
#endif
}
/**
- * @brief Executes the actors in simix_global->actors_to_run.
+ * @brief Executes the actors in actors_to_run.
*
- * The actors in simix_global->actors_to_run are run (in parallel if possible). On exit, simix_global->actors_to_run
- * is empty, and simix_global->actors_that_ran contains the list of actors that just ran.
- * The two lists are swapped so, be careful when using them before and after a call to this function.
+ * The actors in actors_to_run are run (in parallel if possible). On exit, actors_to_run is empty, and actors_that_ran
+ * contains the list of actors that just ran. The two lists are swapped so, be careful when using them before and after
+ * a call to this function.
*/
void Global::run_all_actors()
{
SIMIX_context_runall();
- simix_global->actors_to_run.swap(simix_global->actors_that_ran);
- simix_global->actors_to_run.clear();
+ actors_to_run.swap(actors_that_ran);
+ actors_to_run.clear();
}
simgrid::config::Flag<double> breakpoint{"simix/breakpoint",
try {
timer->callback();
} catch (...) {
- xbt_die("Exception thrown ouf of timer callback");
+ xbt_die("Exception thrown out of timer callback");
}
delete timer;
}
}
void mpi_get_processor_name_(char *name, int *resultlen, int* ierr){
+ //fortran does not handle string endings cleanly, so initialize everything before
+ memset(name, 0, MPI_MAX_PROCESSOR_NAME);
*ierr = MPI_Get_processor_name(name, resultlen);
}
#include "xbt/log.h"
#include "xbt/sysdep.h"
#include <boost/tokenizer.hpp>
+#include "src/surf/xml/platf_private.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)");
}
} else {
try {
- fact.values.push_back(std::stod(*factor_iter));
+ fact.values.push_back(surf_parse_get_time((*factor_iter).c_str(), "smpi factor", std::to_string(smpi_factor.size() + 1) + ": " + *factor_iter));
} catch (std::invalid_argument& ia) {
throw std::invalid_argument(std::string("Invalid factor value ") + std::to_string(iteration) + " in chunk " +
std::to_string(smpi_factor.size() + 1) + ": " + *factor_iter);
int main(int argc, char* argv[])
{
- if (simgrid::s4u::Actor::self().get() == nullptr) {
+ if (simgrid::s4u::Actor::self() == nullptr) {
printf("smpireplaymain should not be called directly. Please use smpirun -replay instead.\n");
return 1;
}
#include "PropertyHolder.hpp"
+#include <map>
+
namespace simgrid {
namespace surf {
-PropertyHolder::~PropertyHolder() {
- delete properties_;
-}
-
/** @brief Return the property associated to the provided key (or nullptr if not existing) */
const char* PropertyHolder::get_property(const std::string& key) const
{
- if (properties_ == nullptr)
+ if (not properties_)
return nullptr;
auto prop = properties_->find(key);
return prop == properties_->end() ? nullptr : prop->second.c_str();
void PropertyHolder::set_property(const std::string& key, const std::string& value)
{
if (not properties_)
- properties_ = new std::unordered_map<std::string, std::string>;
+ properties_.reset(new std::unordered_map<std::string, std::string>);
(*properties_)[key] = value;
}
/** @brief Return the whole set of properties. Don't mess with it, dude! */
-std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
+const std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
{
if (not properties_)
- properties_ = new std::unordered_map<std::string, std::string>;
- return properties_;
+ properties_.reset(new std::unordered_map<std::string, std::string>);
+ return properties_.get();
}
+/** @brief Change the value of the given keys in the property set */
+template <class Assoc> void PropertyHolder::set_properties(const Assoc& properties)
+{
+ if (not properties_)
+ properties_.reset(new std::unordered_map<std::string, std::string>);
+ std::unordered_map<std::string, std::string> props(properties.cbegin(), properties.cend());
+#if __cplusplus >= 201703L
+ props.merge(properties_);
+#else
+ props.insert(properties_->cbegin(), properties_->cend());
+#endif
+ properties_->swap(props);
+}
+
+template void PropertyHolder::set_properties(const std::map<std::string, std::string>& properties);
+template void PropertyHolder::set_properties(const std::unordered_map<std::string, std::string>& properties);
+
} /* namespace surf */
} /* namespace simgrid */
#ifndef SRC_SURF_PROPERTYHOLDER_HPP_
#define SRC_SURF_PROPERTYHOLDER_HPP_
+
+#include <memory>
#include <string>
#include <unordered_map>
PropertyHolder() = default;
PropertyHolder(const PropertyHolder&) = delete;
PropertyHolder& operator=(const PropertyHolder&) = delete;
- ~PropertyHolder();
const char* get_property(const std::string& key) const;
void set_property(const std::string& id, const std::string& value);
- /* FIXME: This should not be exposed, as users may do bad things with the map they got (it's not a copy).
- * But some user API expose this call so removing it is not so easy.
- */
- std::unordered_map<std::string, std::string>* get_properties();
+ const std::unordered_map<std::string, std::string>* get_properties();
+ template <class Assoc> void set_properties(const Assoc& properties);
private:
- std::unordered_map<std::string, std::string>* properties_ = nullptr;
+ std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
};
} /* namespace surf */
#include "src/surf/surf_interface.hpp"
#include "surf/surf.hpp"
+#include <algorithm>
+
constexpr double EPSILON = 0.000000001;
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf_cpu, "Logging specific to the SURF CPU TRACE INTEGRATION module");
{
double integral = 0;
double time = 0;
- int i = 0;
- nb_points_ = profile->event_list.size() + 1;
- time_points_ = new double[nb_points_];
- integral_ = new double[nb_points_];
+ unsigned nb_points = profile->event_list.size() + 1;
+ time_points_.reserve(nb_points);
+ integral_.reserve(nb_points);
for (auto const& val : profile->event_list) {
- time_points_[i] = time;
- integral_[i] = integral;
- integral += val.date_ * val.value_;
+ time_points_.push_back(time);
+ integral_.push_back(integral);
time += val.date_;
- i++;
+ integral += val.date_ * val.value_;
}
- time_points_[i] = time;
- integral_[i] = integral;
-}
-
-CpuTiProfile::~CpuTiProfile()
-{
- delete[] time_points_;
- delete [] integral_;
+ time_points_.push_back(time);
+ integral_.push_back(integral);
}
CpuTiTmgr::~CpuTiTmgr()
{
double integral = 0;
double a_aux = a;
- int ind = binary_search(time_points_, a, 0, nb_points_ - 1);
+ int ind = binary_search(time_points_, a);
integral += integral_[ind];
XBT_DEBUG("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f", a, ind, integral, integral_[ind + 1],
double CpuTiProfile::solve_simple(double a, double amount)
{
double integral_a = integrate_simple_point(a);
- int ind = binary_search(integral_, integral_a + amount, 0, nb_points_ - 1);
+ int ind = binary_search(integral_, integral_a + amount);
double time = time_points_[ind];
time += (integral_a + amount - integral_[ind]) /
((integral_[ind + 1] - integral_[ind]) / (time_points_[ind + 1] - time_points_[ind]));
double CpuTiTmgr::get_power_scale(double a)
{
double reduced_a = a - floor(a / last_time_) * last_time_;
- int point = profile_->binary_search(profile_->time_points_, reduced_a, 0, profile_->nb_points_ - 1);
+ int point = profile_->binary_search(profile_->time_points_, reduced_a);
kernel::profile::DatedValue val = speed_profile_->event_list.at(point);
return val.value_;
}
/**
* @brief Binary search in array.
- * It returns the first point of the interval in which "a" is.
+ * It returns the last point of the interval in which "a" is.
* @param array Array
* @param a Value to search
- * @param low Low bound to search in array
- * @param high Upper bound to search in array
* @return Index of point
*/
-int CpuTiProfile::binary_search(double* array, double a, int low, int high)
+int CpuTiProfile::binary_search(const std::vector<double>& array, double a)
{
- xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than high (%d)", low, high);
-
- do {
- int mid = low + (high - low) / 2;
- XBT_DEBUG("a %f low %d high %d mid %d value %f", a, low, high, mid, array[mid]);
-
- if (array[mid] > a)
- high = mid;
- else
- low = mid;
- }
- while (low < high - 1);
-
- return low;
+ if (array[0] > a)
+ return 0;
+ auto pos = std::upper_bound(begin(array), end(array), a);
+ return std::distance(begin(array), pos) - 1;
}
/*********
class CpuTiProfile {
public:
explicit CpuTiProfile(profile::Profile* profile);
- CpuTiProfile(const CpuTiProfile&) = delete;
- CpuTiProfile& operator=(const CpuTiProfile&) = delete;
- ~CpuTiProfile();
double integrate_simple(double a, double b);
double integrate_simple_point(double a);
double solve_simple(double a, double amount);
- double* time_points_;
- double *integral_;
- int nb_points_;
- int binary_search(double* array, double a, int low, int high);
+ std::vector<double> time_points_;
+ std::vector<double> integral_;
+ static int binary_search(const std::vector<double>& array, double a);
};
class CpuTiTmgr {
using simgrid::kernel::resource::NetworkIBModel;
static int id=0;
- // pour t->id -> rajouter une nouvelle struct dans le dict, pour stocker les comms actives
-
- IBNode* act = new IBNode(id);
+ ((NetworkIBModel*)surf_network_model)->active_nodes.emplace(host.get_name(), IBNode(id));
id++;
- ((NetworkIBModel*)surf_network_model)->active_nodes.insert({host.get_name(), act});
}
static void IB_action_state_changed_callback(simgrid::kernel::resource::NetworkAction& action,
simgrid::s4u::Host* dst)
{
simgrid::kernel::resource::NetworkIBModel* ibModel = (simgrid::kernel::resource::NetworkIBModel*)surf_network_model;
- simgrid::kernel::resource::IBNode* act_src;
- simgrid::kernel::resource::IBNode* act_dst;
-
- auto asrc = ibModel->active_nodes.find(src->get_name());
- if (asrc != ibModel->active_nodes.end()) {
- act_src = asrc->second;
- } else {
- throw std::out_of_range(std::string("Could not find '") + src->get_cname() + "' active comms !");
- }
-
- auto adst = ibModel->active_nodes.find(dst->get_name());
- if (adst != ibModel->active_nodes.end()) {
- act_dst = adst->second;
- } else {
- throw std::out_of_range(std::string("Could not find '") + dst->get_cname() + "' active comms !");
- }
+ simgrid::kernel::resource::IBNode* act_src = &ibModel->active_nodes.at(src->get_name());
+ simgrid::kernel::resource::IBNode* act_dst = &ibModel->active_nodes.at(dst->get_name());
ibModel->active_comms[&action] = std::make_pair(act_src, act_dst);
-
ibModel->updateIBfactors(&action, act_src, act_dst, 0);
}
}
}
-NetworkIBModel::~NetworkIBModel()
-{
- for (auto const& instance : active_nodes)
- delete instance.second;
-}
-
void NetworkIBModel::computeIBfactors(IBNode* root)
{
double num_comm_out = static_cast<double>(root->ActiveCommsUp.size());
explicit NetworkIBModel(const char* name);
NetworkIBModel(const NetworkIBModel&) = delete;
NetworkIBModel& operator=(const NetworkIBModel&) = delete;
- ~NetworkIBModel() override;
void updateIBfactors(NetworkAction* action, IBNode* from, IBNode* to, int remove);
- std::unordered_map<std::string, IBNode*> active_nodes;
+ std::unordered_map<std::string, IBNode> active_nodes;
std::unordered_map<NetworkAction*, std::pair<IBNode*, IBNode*>> active_comms;
};
surf_network_model->create_link(link_name, link->bandwidth, link->latency, link->policy);
if (link->properties) {
- for (auto const& elm : *link->properties)
- l->set_property(elm.first, elm.second);
+ l->set_properties(*link->properties);
}
if (link->latency_trace)
auto s = surf_storage_model->createStorage(storage->id, stype->id, storage->content, storage->attach);
if (storage->properties) {
- for (auto const& elm : *storage->properties)
- s->set_property(elm.first, elm.second);
+ s->set_properties(*storage->properties);
delete storage->properties;
}
}
if (ptr == string)
surf_parse_error(std::string("cannot parse number:") + string);
if (ptr[0] == '\0') {
- if (res == 0)
- return res; // Ok, 0 can be unit-less
-
- XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
ptr = (char*)default_unit;
}
auto u = units.find(ptr);
std::unordered_map<std::string, action_fun> action_funs;
static std::unordered_map<std::string, std::queue<ReplayAction*>*> action_queues;
-static void read_and_trim_line(std::ifstream* fs, std::string* line)
+static void read_and_trim_line(std::ifstream& fs, std::string* line)
{
do {
- std::getline(*fs, *line);
+ std::getline(fs, *line);
boost::trim(*line);
- } while (not fs->eof() && (line->length() == 0 || line->front() == '#'));
+ } while (not fs.eof() && (line->length() == 0 || line->front() == '#'));
XBT_DEBUG("got from trace: %s", line->c_str());
}
class ReplayReader {
- std::ifstream* fs;
+ std::ifstream fs;
std::string line;
public:
- explicit ReplayReader(const char* filename)
+ explicit ReplayReader(const char* filename) : fs(filename, std::ifstream::in)
{
XBT_VERB("Prepare to replay file '%s'", filename);
- fs = new std::ifstream(filename, std::ifstream::in);
- xbt_assert(fs->is_open(), "Cannot read replay file '%s'", filename);
+ xbt_assert(fs.is_open(), "Cannot read replay file '%s'", filename);
}
ReplayReader(const ReplayReader&) = delete;
ReplayReader& operator=(const ReplayReader&) = delete;
- ~ReplayReader()
- {
- delete fs;
- }
bool get(ReplayAction* action);
};
read_and_trim_line(fs, &line);
boost::split(*action, line, boost::is_any_of(" \t"), boost::token_compress_on);
- return not fs->eof();
+ return not fs.eof();
}
static ReplayAction* get_action(const char* name)
// Read lines until I reach something for me (which breaks in loop body) or end of file reached
while (true) {
std::string action_line;
- read_and_trim_line(action_fs, &action_line);
+ read_and_trim_line(*action_fs, &action_line);
if (action_fs->eof())
break;
/* we cannot split in place here because we parse&store several lines for the colleagues... */
static void display_storage_properties(simgrid::s4u::Storage* storage)
{
- std::unordered_map<std::string, std::string>* props = storage->get_properties();
+ const std::unordered_map<std::string, std::string>* props = storage->get_properties();
if (not props->empty()) {
XBT_INFO("\tProperties of mounted storage: %s", storage->get_cname());
> [ 1.207952] (server@alice) Storage name: Disk2, mount name: c:
> [ 1.207952] (server@alice) Free size: 534479367024 bytes
> [ 1.207952] (server@alice) Used size: 2391544976 bytes
-> [ 1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 ***
-> [ 1.207952] (client@bob) Get data: 'No User Data'
-> [ 1.207952] (client@bob) Set and get data: 'Some data'
> [ 1.207952] (server@alice) No property attached.
> [ 1.207952] (server@alice) *** Dump a storage element ***
> [ 1.207952] (server@alice) Print the content of the storage element: Disk2
> [ 1.207952] (server@alice) \Windows\winhlp32.exe size: 10752 bytes
> [ 1.207952] (server@alice) \Windows\write.exe size: 10752 bytes
> [ 1.207952] (server@alice) Storage Disk1 is attached to bob
+> [ 1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 ***
+> [ 1.207952] (client@bob) Get data: 'No User Data'
+> [ 1.207952] (client@bob) Set and get data: 'Some data'
> [ 1.207952] (server@alice) Storage Disk2 is attached to alice
> [ 1.207952] (server@alice) Storage Disk3 is attached to carl
> [ 1.207952] (server@alice) Storage Disk4 is attached to denise
static void dump_hosts()
{
- std::unordered_map<std::string, std::string>* props = nullptr;
unsigned int totalHosts = sg_host_count();
sg_host_t* hosts = sg_host_list();
std::sort(hosts, hosts + totalHosts,
for (unsigned int i = 0; i < totalHosts; i++) {
std::printf(" <host id=\"%s\" speed=\"%.0f\"", hosts[i]->get_cname(), sg_host_speed(hosts[i]));
- props = hosts[i]->get_properties();
+ const std::unordered_map<std::string, std::string>* props = hosts[i]->get_properties();
if (hosts[i]->get_core_count() > 1) {
std::printf(" core=\"%d\"", hosts[i]->get_core_count());
}