From 2f4b313c80827568ce888a6bc1575739d002a6c3 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 18 Nov 2017 18:02:02 +0100 Subject: [PATCH] Use a std::vector. --- src/surf/network_ib.cpp | 16 +++++++--------- src/surf/network_ib.hpp | 5 +++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 9f0e10ca24..8a051ec09b 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -183,18 +183,18 @@ void NetworkIBModel::computeIBfactors(IBNode* root) XBT_DEBUG("Finished computing IB penalties"); } -void NetworkIBModel::updateIBfactors_rec(IBNode* root, bool* updatedlist) +void NetworkIBModel::updateIBfactors_rec(IBNode* root, std::vector& updatedlist) { - if (updatedlist[root->id] == 0) { + if (not updatedlist[root->id]) { XBT_DEBUG("IB - Updating rec %d", root->id); computeIBfactors(root); - updatedlist[root->id] = 1; + updatedlist[root->id] = true; for (std::vector::iterator it = root->ActiveCommsUp.begin(); it != root->ActiveCommsUp.end(); ++it) { - if (updatedlist[(*it)->destination->id] != 1) + if (not updatedlist[(*it)->destination->id]) updateIBfactors_rec((*it)->destination, updatedlist); } for (std::map::iterator it = root->ActiveCommsDown.begin(); it != root->ActiveCommsDown.end(); ++it) { - if (updatedlist[it->first->id] != 1) + if (not updatedlist[it->first->id]) updateIBfactors_rec(it->first, updatedlist); } } @@ -205,7 +205,6 @@ void NetworkIBModel::updateIBfactors(NetworkAction* action, IBNode* from, IBNode if (from == to) // disregard local comms (should use loopback) return; - bool* updated = (bool*)xbt_malloc0(active_nodes.size() * sizeof(bool)); ActiveComm* comm = nullptr; if (remove) { if (to->ActiveCommsDown[from] == 1) @@ -233,11 +232,10 @@ void NetworkIBModel::updateIBfactors(NetworkAction* action, IBNode* from, IBNode to->nbActiveCommsDown++; } XBT_DEBUG("IB - Updating %d", from->id); + std::vector updated(active_nodes.size(), false); updateIBfactors_rec(from, updated); XBT_DEBUG("IB - Finished updating %d", from->id); - if (comm) - delete comm; - xbt_free(updated); + delete comm; } } } diff --git a/src/surf/network_ib.hpp b/src/surf/network_ib.hpp index ceab7b9d08..df41a8873a 100644 --- a/src/surf/network_ib.hpp +++ b/src/surf/network_ib.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2015. The SimGrid Team. +/* Copyright (c) 2014-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -11,6 +11,7 @@ #include "xbt/base.h" #include +#include namespace simgrid { namespace surf { @@ -42,7 +43,7 @@ namespace simgrid { class XBT_PRIVATE NetworkIBModel : public NetworkSmpiModel { private: - void updateIBfactors_rec(IBNode *root, bool* updatedlist); + void updateIBfactors_rec(IBNode* root, std::vector& updatedlist); void computeIBfactors(IBNode *root); public: NetworkIBModel(); -- 2.20.1