Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 13 Oct 2017 09:11:47 +0000 (11:11 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 13 Oct 2017 09:11:47 +0000 (11:11 +0200)
19 files changed:
examples/msg/energy-ptask/energy-ptask.c
src/bindings/java/jmsg_comm.cpp
src/bindings/java/jmsg_task.cpp
src/kernel/context/ContextRaw.cpp
src/kernel/context/ContextUnix.cpp
src/kernel/routing/DijkstraZone.cpp
src/kernel/routing/DijkstraZone.hpp
src/kernel/routing/DragonflyZone.cpp
src/kernel/routing/FloydZone.cpp
src/kernel/routing/FullZone.cpp
src/kernel/routing/RoutedZone.cpp
src/msg/msg_private.hpp
src/msg/msg_task.cpp
src/simdag/sd_task.cpp
src/simix/smx_host.cpp
src/surf/HostImpl.cpp
src/surf/ptask_L07.cpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp

index 2764151..d368bb1 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2017. The SimGrid 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. */
@@ -38,7 +38,8 @@ static int runner(int argc, char *argv[])
     MSG_parallel_task_create("parallel task", hosts_count, hosts, computation_amounts, communication_amounts, NULL);
   MSG_parallel_task_execute(ptask);
   MSG_task_destroy(ptask);
-  /* The arrays communication_amounts and computation_amounts are not to be freed manually */
+  xbt_free(communication_amounts);
+  xbt_free(computation_amounts);
 
   XBT_INFO("We can do the same with a timeout of one second enabled.");
   computation_amounts   = xbt_new0(double, hosts_count);
@@ -53,6 +54,8 @@ static int runner(int argc, char *argv[])
   msg_error_t errcode = MSG_parallel_task_execute_with_timeout(ptask, 1 /* timeout (in seconds)*/);
   xbt_assert(errcode == MSG_TIMEOUT, "Woops, this did not timeout as expected... Please report that bug.");
   MSG_task_destroy(ptask);
+  xbt_free(communication_amounts);
+  xbt_free(computation_amounts);
 
   XBT_INFO("Then, build a parallel task involving only computations and no communication (1 Gflop per node)");
   computation_amounts = xbt_new0(double, hosts_count);
@@ -61,6 +64,7 @@ static int runner(int argc, char *argv[])
   ptask = MSG_parallel_task_create("parallel exec", hosts_count, hosts, computation_amounts, NULL/* no comm */, NULL);
   MSG_parallel_task_execute(ptask);
   MSG_task_destroy(ptask);
+  xbt_free(computation_amounts);
 
   XBT_INFO("Then, build a parallel task with no computation nor communication (synchro only)");
   computation_amounts = xbt_new0(double, hosts_count);
@@ -68,8 +72,10 @@ static int runner(int argc, char *argv[])
   ptask = MSG_parallel_task_create("parallel sync", hosts_count, hosts, computation_amounts, communication_amounts, NULL);
   MSG_parallel_task_execute(ptask);
   MSG_task_destroy(ptask);
+  xbt_free(communication_amounts);
+  xbt_free(computation_amounts);
 
-   XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", MSG_host_get_name(hosts[1]));
+  XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", MSG_host_get_name(hosts[1]));
   computation_amounts = xbt_new0(double, 1);
   computation_amounts[0] = 1e9; // 1 Gflop
   msg_host_t *remote = xbt_new(msg_host_t,1);
@@ -77,10 +83,11 @@ static int runner(int argc, char *argv[])
   ptask = MSG_parallel_task_create("remote exec", 1, remote, computation_amounts, NULL/* no comm */, NULL);
   MSG_parallel_task_execute(ptask);
   MSG_task_destroy(ptask);
-  free(remote);
+  xbt_free(remote);
+  xbt_free(computation_amounts);
 
   XBT_INFO("Goodbye now!");
-  free(hosts);
+  xbt_free(hosts);
   return 0;
 }
 
index d3e4127..da8c34d 100644 (file)
@@ -65,7 +65,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, job
   msg_task_t *task_received;
 
   task_received = (msg_task_t*)  (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_taskBind);
-  xbt_free(task_received);
+  delete task_received;
 
   comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
   MSG_comm_destroy(comm);
@@ -123,7 +123,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, job
 static msg_comm_t* jarray_to_commArray(JNIEnv *env, jobjectArray jcomms, /* OUT */ int *count)
 {
   *count = env->GetArrayLength(jcomms);
-  msg_comm_t* comms = xbt_new(msg_comm_t, *count);
+  msg_comm_t* comms = new msg_comm_t[*count];
 
   for (int i=0; i < *count; i++) {
      jobject jcomm = env->GetObjectArrayElement(jcomms, i);
@@ -148,7 +148,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitAll(JNIEnv *env, jclass cls
     return;
 
   MSG_comm_waitall(comms, count, static_cast<double>(timeout));
-  xbt_free(comms);
+  delete[] comms;
 }
 JNIEXPORT int JNICALL Java_org_simgrid_msg_Comm_waitAny(JNIEnv *env, jclass cls, jobjectArray jcomms)
 {
@@ -162,7 +162,7 @@ JNIEXPORT int JNICALL Java_org_simgrid_msg_Comm_waitAny(JNIEnv *env, jclass cls,
   }
 
   int rank = MSG_comm_waitany(dyn);
-  xbt_free(comms);
+  delete[] comms;
   xbt_dynar_free(&dyn);
   return rank;
 }
index 7a473f6..f07d543 100644 (file)
@@ -76,8 +76,8 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_parallelCreate(JNIEnv * env, jo
   int host_count = static_cast<int>(env->GetArrayLength(jhosts));
 
   jdouble* jcomputeDurations = env->GetDoubleArrayElements(jcomputeDurations_arg, 0);
-  msg_host_t* hosts          = xbt_new0(msg_host_t, host_count);
-  double* computeDurations   = xbt_new0(double, host_count);
+  msg_host_t* hosts          = new msg_host_t[host_count];
+  double* computeDurations   = new double[host_count];
   for (int index = 0; index < host_count; index++) {
     jobject jhost           = env->GetObjectArrayElement(jhosts, index);
     hosts[index] = jhost_get_native(env, jhost);
@@ -86,7 +86,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_parallelCreate(JNIEnv * env, jo
   env->ReleaseDoubleArrayElements(jcomputeDurations_arg, jcomputeDurations, 0);
 
   jdouble* jmessageSizes = env->GetDoubleArrayElements(jmessageSizes_arg, 0);
-  double* messageSizes   = xbt_new0(double, host_count* host_count);
+  double* messageSizes   = new double[host_count * host_count];
   for (int index = 0; index < host_count * host_count; index++) {
     messageSizes[index] = jmessageSizes[index];
   }
@@ -99,6 +99,10 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_parallelCreate(JNIEnv * env, jo
 
   /* associate the java task object and the native task */
   jtask_bind(jtask, task, env);
+
+  delete[] hosts;
+  delete[] computeDurations;
+  delete[] messageSizes;
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_cancel(JNIEnv * env, jobject jtask)
@@ -303,8 +307,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass c
     return nullptr;
 
   //pointer to store the task object pointer.
-  msg_task_t *task = xbt_new(msg_task_t,1);
-  *task = nullptr;
+  msg_task_t* task = new msg_task_t(nullptr);
   /* There should be a cache here */
 
   jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
@@ -358,7 +361,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_irecvBounded(JNIEnv * env, j
     return nullptr;
 
   // pointer to store the task object pointer.
-  msg_task_t* task = xbt_new0(msg_task_t, 1);
+  msg_task_t* task = new msg_task_t(nullptr);
 
   jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
   if (not jcomm) {
index 1df1de7..1cd6340 100644 (file)
@@ -267,7 +267,7 @@ RawContextFactory::RawContextFactory()
     xbt_os_thread_key_create(&raw_worker_id_key);
     // TODO, lazily init
     raw_parmap = nullptr;
-    raw_workers_context = xbt_new(RawContext*, nthreads);
+    raw_workers_context = new RawContext*[nthreads];
     raw_maestro_context = nullptr;
 #endif
     // TODO: choose dynamically when SIMIX_context_get_parallel_threshold() > 1
@@ -278,7 +278,7 @@ RawContextFactory::~RawContextFactory()
 {
 #if HAVE_THREAD_CONTEXTS
   delete raw_parmap;
-  xbt_free(raw_workers_context);
+  delete[] raw_workers_context;
 #endif
 }
 
@@ -408,7 +408,7 @@ void RawContext::suspend_parallel()
     XBT_DEBUG("No more processes to run");
     uintptr_t worker_id = (uintptr_t)
       xbt_os_thread_get_specific(raw_worker_id_key);
-    next_context = static_cast<RawContext*>(raw_workers_context[worker_id]);
+    next_context = raw_workers_context[worker_id];
     XBT_DEBUG("Restoring worker stack %zu (working threads = %zu)",
         worker_id, raw_threads_working);
   }
index ae143b8..26d629d 100644 (file)
@@ -130,7 +130,7 @@ UContextFactory::UContextFactory() : ContextFactory("UContextFactory")
 #if HAVE_THREAD_CONTEXTS  /* To use parallel ucontexts a thread pool is needed */
     int nthreads = SIMIX_context_get_nthreads();
     sysv_parmap = nullptr;
-    sysv_workers_context = xbt_new(ParallelUContext*, nthreads);
+    sysv_workers_context = new ParallelUContext*[nthreads];
     sysv_maestro_context = nullptr;
     xbt_os_thread_key_create(&sysv_worker_id_key);
 #else
@@ -145,7 +145,7 @@ UContextFactory::~UContextFactory()
 {
 #if HAVE_THREAD_CONTEXTS
   delete sysv_parmap;
-  xbt_free(sysv_workers_context);
+  delete[] sysv_workers_context;
 #endif
 }
 
index cf1dc01..c6f52a0 100644 (file)
@@ -13,12 +13,18 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_dijkstra, surf, "Routing part of surf
 
 /* Free functions */
 
+static void graph_node_data_free(void* n)
+{
+  graph_node_data_t data = static_cast<graph_node_data_t>(n);
+  delete data;
+}
+
 static void graph_edge_data_free(void* e) // FIXME: useless code duplication
 {
-  sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t)e;
+  sg_platf_route_cbarg_t e_route = static_cast<sg_platf_route_cbarg_t>(e);
   if (e_route) {
     delete e_route->link_list;
-    xbt_free(e_route);
+    delete e_route;
   }
 }
 
@@ -51,7 +57,7 @@ void DijkstraZone::seal()
       }
 
       if (not found) {
-        sg_platf_route_cbarg_t e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+        sg_platf_route_cbarg_t e_route = new s_sg_platf_route_cbarg_t;
         e_route->link_list             = new std::vector<surf::LinkImpl*>();
         e_route->link_list->push_back(surf_network_model->loopback_);
         xbt_graph_new_edge(routeGraph_, node, node, e_route);
@@ -63,26 +69,24 @@ void DijkstraZone::seal()
   xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_);
 
   xbt_dynar_foreach (nodes, cursor, node) {
-    graph_node_data_t data = (graph_node_data_t)xbt_graph_node_get_data(node);
+    graph_node_data_t data = static_cast<graph_node_data_t>(xbt_graph_node_get_data(node));
     data->graph_id         = cursor;
   }
 }
 
 xbt_node_t DijkstraZone::routeGraphNewNode(int id, int graph_id)
 {
-  graph_node_data_t data = xbt_new0(s_graph_node_data_t, 1);
+  graph_node_data_t data = new s_graph_node_data_t;
   data->id       = id;
   data->graph_id = graph_id;
 
   xbt_node_t node                = xbt_graph_new_node(routeGraph_, data);
-  graph_node_map_element_t elm   = xbt_new0(s_graph_node_map_element_t, 1);
-  elm->node = node;
-  graphNodeMap_.insert({id, elm});
+  graphNodeMap_.emplace(id, node);
 
   return node;
 }
 
-graph_node_map_element_t DijkstraZone::nodeMapSearch(int id)
+xbt_node_t DijkstraZone::nodeMapSearch(int id)
 {
   auto ret = graphNodeMap_.find(id);
   return ret == graphNodeMap_.end() ? nullptr : ret->second;
@@ -96,14 +100,14 @@ void DijkstraZone::newRoute(int src_id, int dst_id, sg_platf_route_cbarg_t e_rou
   xbt_node_t src = nullptr;
   xbt_node_t dst = nullptr;
 
-  graph_node_map_element_t src_elm = nodeMapSearch(src_id);
-  graph_node_map_element_t dst_elm = nodeMapSearch(dst_id);
+  xbt_node_t src_elm = nodeMapSearch(src_id);
+  xbt_node_t dst_elm = nodeMapSearch(dst_id);
 
   if (src_elm)
-    src = src_elm->node;
+    src = src_elm;
 
   if (dst_elm)
-    dst = dst_elm->node;
+    dst = dst_elm;
 
   /* add nodes if they don't exist in the graph */
   if (src_id == dst_id && src == nullptr && dst == nullptr) {
@@ -128,16 +132,14 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
   int src_id = src->id();
   int dst_id = dst->id();
 
-  int* pred_arr     = nullptr;
-  int size          = 0;
   xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_);
 
   /* Use the graph_node id mapping set to quickly find the nodes */
-  graph_node_map_element_t src_elm = nodeMapSearch(src_id);
-  graph_node_map_element_t dst_elm = nodeMapSearch(dst_id);
+  xbt_node_t src_elm = nodeMapSearch(src_id);
+  xbt_node_t dst_elm = nodeMapSearch(dst_id);
 
-  int src_node_id = ((graph_node_data_t)xbt_graph_node_get_data(src_elm->node))->graph_id;
-  int dst_node_id = ((graph_node_data_t)xbt_graph_node_get_data(dst_elm->node))->graph_id;
+  int src_node_id = static_cast<graph_node_data_t>(xbt_graph_node_get_data(src_elm))->graph_id;
+  int dst_node_id = static_cast<graph_node_data_t>(xbt_graph_node_get_data(dst_elm))->graph_id;
 
   /* if the src and dst are the same */
   if (src_node_id == dst_node_id) {
@@ -149,7 +151,7 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
     if (edge == nullptr)
       THROWF(arg_error, 0, "No route from '%s' to '%s'", src->name().c_str(), dst->name().c_str());
 
-    sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t)xbt_graph_edge_get_data(edge);
+    sg_platf_route_cbarg_t e_route = static_cast<sg_platf_route_cbarg_t>(xbt_graph_edge_get_data(edge));
 
     for (auto const& link : *e_route->link_list) {
       route->link_list->insert(route->link_list->begin(), link);
@@ -158,20 +160,14 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
     }
   }
 
-  route_cache_element_t elm = nullptr;
-  if (not routeCache_.empty()) { /* cache mode  */
-    auto it = routeCache_.find(src_id);
-    elm     = (it == routeCache_.end()) ? nullptr : it->second;
-  }
-
-  if (elm) { /* cached mode and cache hit */
-    pred_arr = elm->pred_arr;
-  } else { /* not cached mode, or cache miss */
+  auto elm                   = routeCache_.emplace(src_id, std::vector<int>());
+  std::vector<int>& pred_arr = elm.first->second;
 
+  if (elm.second) { /* new element was inserted (not cached mode, or cache miss) */
     int nr_nodes      = xbt_dynar_length(nodes);
-    double* cost_arr  = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
-    pred_arr          = xbt_new0(int, nr_nodes);    /* predecessors in path from src */
-    xbt_heap_t pqueue = xbt_heap_new(nr_nodes, xbt_free_f);
+    std::vector<double> cost_arr(nr_nodes); /* link cost from src to other hosts */
+    pred_arr.resize(nr_nodes);              /* predecessors in path from src */
+    xbt_heap_t pqueue = xbt_heap_new(nr_nodes, nullptr);
 
     /* initialize */
     cost_arr[src_node_id] = 0.0;
@@ -184,8 +180,7 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
       pred_arr[i] = 0;
 
       /* initialize priority queue */
-      int* nodeid = xbt_new0(int, 1);
-      *nodeid     = i;
+      int* nodeid = new int(i);
       xbt_heap_push(pqueue, nodeid, cost_arr[i]);
     }
 
@@ -198,25 +193,22 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
 
       xbt_dynar_foreach (xbt_graph_node_get_outedges(v_node), cursor, edge) {
         xbt_node_t u_node                  = xbt_graph_edge_get_target(edge);
-        graph_node_data_t data             = (graph_node_data_t)xbt_graph_node_get_data(u_node);
+        graph_node_data_t data             = static_cast<graph_node_data_t>(xbt_graph_node_get_data(u_node));
         int u_id                           = data->graph_id;
-        sg_platf_route_cbarg_t tmp_e_route = (sg_platf_route_cbarg_t)xbt_graph_edge_get_data(edge);
+        sg_platf_route_cbarg_t tmp_e_route = static_cast<sg_platf_route_cbarg_t>(xbt_graph_edge_get_data(edge));
         int cost_v_u                       = tmp_e_route->link_list->size(); /* count of links, old model assume 1 */
 
         if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
           pred_arr[u_id] = *v_id;
           cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
-          int* nodeid    = xbt_new0(int, 1);
-          *nodeid        = u_id;
+          int* nodeid    = new int(u_id);
           xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
         }
       }
 
       /* free item popped from pqueue */
-      xbt_free(v_id);
+      delete v_id;
     }
-
-    xbt_free(cost_arr);
     xbt_heap_free(pqueue);
   }
 
@@ -233,7 +225,7 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
     if (edge == nullptr)
       THROWF(arg_error, 0, "No route from '%s' to '%s'", src->name().c_str(), dst->name().c_str());
 
-    sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t)xbt_graph_edge_get_data(edge);
+    sg_platf_route_cbarg_t e_route = static_cast<sg_platf_route_cbarg_t>(xbt_graph_edge_get_data(edge));
 
     NetPoint* prev_gw_src          = gw_src;
     gw_src                         = e_route->gw_src;
@@ -263,7 +255,6 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
       if (lat)
         *lat += static_cast<surf::LinkImpl*>(link)->latency();
     }
-    size++;
   }
 
   if (hierarchy_ == RoutingMode::recursive) {
@@ -271,26 +262,18 @@ void DijkstraZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cb
     route->gw_dst = first_gw;
   }
 
-  if (not routeCache_.empty() && elm == nullptr) {
-    /* add to predecessor list of the current src-host to cache */
-    elm           = xbt_new0(s_route_cache_element_t, 1);
-    elm->pred_arr = pred_arr;
-    elm->size     = size;
-    routeCache_.insert({src_id, elm});
-  }
-
-  if (routeCache_.empty())
-    xbt_free(pred_arr);
+  if (not cached_)
+    routeCache_.clear();
 }
 
 DijkstraZone::~DijkstraZone()
 {
-  xbt_graph_free_graph(routeGraph_, &xbt_free_f, &graph_edge_data_free, &xbt_free_f);
+  xbt_graph_free_graph(routeGraph_, &graph_node_data_free, &graph_edge_data_free, nullptr);
 }
 
 /* Creation routing model functions */
 
-DijkstraZone::DijkstraZone(NetZone* father, std::string name, bool cached) : RoutedZone(father, name)
+DijkstraZone::DijkstraZone(NetZone* father, std::string name, bool cached) : RoutedZone(father, name), cached_(cached)
 {
 }
 
index e627d5d..f7fc503 100644 (file)
@@ -14,17 +14,6 @@ struct s_graph_node_data_t {
 };
 typedef s_graph_node_data_t* graph_node_data_t;
 
-struct s_graph_node_map_element_t {
-  xbt_node_t node;
-};
-typedef s_graph_node_map_element_t* graph_node_map_element_t;
-
-struct s_route_cache_element_t {
-  int* pred_arr;
-  int size;
-};
-typedef s_route_cache_element_t* route_cache_element_t;
-
 namespace simgrid {
 namespace kernel {
 namespace routing {
@@ -48,7 +37,7 @@ public:
 
   ~DijkstraZone() override;
   xbt_node_t routeGraphNewNode(int id, int graph_id);
-  graph_node_map_element_t nodeMapSearch(int id);
+  xbt_node_t nodeMapSearch(int id);
   void newRoute(int src_id, int dst_id, sg_platf_route_cbarg_t e_route);
   /* For each vertex (node) already in the graph,
    * make sure it also has a loopback link; this loopback
@@ -65,8 +54,9 @@ public:
   void addRoute(sg_platf_route_cbarg_t route) override;
 
   xbt_graph_t routeGraph_  = nullptr; /* xbt_graph */
-  std::map<int, graph_node_map_element_t> graphNodeMap_; /* map */
-  std::map<int, route_cache_element_t> routeCache_;      /* use in cache mode */
+  std::map<int, xbt_node_t> graphNodeMap_;     /* map */
+  bool cached_;                                /* cache mode */
+  std::map<int, std::vector<int>> routeCache_; /* use in cache mode */
 };
 }
 }
index 38e788f..74241c8 100644 (file)
@@ -25,8 +25,8 @@ DragonflyZone::~DragonflyZone()
 {
   if (this->routers_ != nullptr) {
     for (unsigned int i = 0; i < this->numGroups_ * this->numChassisPerGroup_ * this->numBladesPerChassis_; i++)
-      delete (routers_[i]);
-    xbt_free(routers_);
+      delete routers_[i];
+    delete[] routers_;
   }
 }
 
@@ -134,20 +134,15 @@ DragonflyRouter::DragonflyRouter(int group, int chassis, int blade) : group_(gro
 
 DragonflyRouter::~DragonflyRouter()
 {
-  if (this->myNodes_ != nullptr)
-    xbt_free(myNodes_);
-  if (this->greenLinks_ != nullptr)
-    xbt_free(greenLinks_);
-  if (this->blackLinks_ != nullptr)
-    xbt_free(blackLinks_);
-  if (this->blueLinks_ != nullptr)
-    xbt_free(blueLinks_);
+  delete[] myNodes_;
+  delete[] greenLinks_;
+  delete[] blackLinks_;
+  delete blueLinks_;
 }
 
 void DragonflyZone::generateRouters()
 {
-  this->routers_ = static_cast<DragonflyRouter**>(xbt_malloc0(this->numGroups_ * this->numChassisPerGroup_ *
-                                                              this->numBladesPerChassis_ * sizeof(DragonflyRouter*)));
+  this->routers_ = new DragonflyRouter*[this->numGroups_ * this->numChassisPerGroup_ * this->numBladesPerChassis_];
 
   for (unsigned int i = 0; i < this->numGroups_; i++) {
     for (unsigned int j = 0; j < this->numChassisPerGroup_; j++) {
@@ -201,12 +196,9 @@ void DragonflyZone::generateLinks()
   // Links from routers to their local nodes.
   for (unsigned int i = 0; i < numRouters; i++) {
     // allocate structures
-    this->routers_[i]->myNodes_ = static_cast<surf::LinkImpl**>(
-        xbt_malloc0(numLinksperLink_ * this->numNodesPerBlade_ * sizeof(surf::LinkImpl*)));
-    this->routers_[i]->greenLinks_ =
-        static_cast<surf::LinkImpl**>(xbt_malloc0(this->numBladesPerChassis_ * sizeof(surf::LinkImpl*)));
-    this->routers_[i]->blackLinks_ =
-        static_cast<surf::LinkImpl**>(xbt_malloc0(this->numChassisPerGroup_ * sizeof(surf::LinkImpl*)));
+    this->routers_[i]->myNodes_    = new surf::LinkImpl*[numLinksperLink_ * this->numNodesPerBlade_];
+    this->routers_[i]->greenLinks_ = new surf::LinkImpl*[this->numBladesPerChassis_];
+    this->routers_[i]->blackLinks_ = new surf::LinkImpl*[this->numChassisPerGroup_];
 
     for (unsigned int j = 0; j < numLinksperLink_ * this->numNodesPerBlade_; j += numLinksperLink_) {
       std::string id = "local_link_from_router_"+ std::to_string(i) + "_to_node_" +
@@ -264,8 +256,8 @@ void DragonflyZone::generateLinks()
     for (unsigned int j = i + 1; j < this->numGroups_; j++) {
       unsigned int routernumi                = i * numBladesPerChassis_ * numChassisPerGroup_ + j;
       unsigned int routernumj                = j * numBladesPerChassis_ * numChassisPerGroup_ + i;
-      this->routers_[routernumi]->blueLinks_ = static_cast<surf::LinkImpl**>(xbt_malloc0(sizeof(surf::LinkImpl*)));
-      this->routers_[routernumj]->blueLinks_ = static_cast<surf::LinkImpl**>(xbt_malloc0(sizeof(surf::LinkImpl*)));
+      this->routers_[routernumi]->blueLinks_ = new surf::LinkImpl*;
+      this->routers_[routernumj]->blueLinks_ = new surf::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->createLink(id, this->numLinksBlue_, &linkup, &linkdown);
index e680281..21302f0 100644 (file)
@@ -37,10 +37,10 @@ FloydZone::~FloydZone()
   for (unsigned int i = 0; i < table_size; i++)
     for (unsigned int j = 0; j < table_size; j++)
       routing_route_free(TO_FLOYD_LINK(i, j));
-  xbt_free(linkTable_);
+  delete[] linkTable_;
 
-  xbt_free(predecessorTable_);
-  xbt_free(costTable_);
+  delete[] predecessorTable_;
+  delete[] costTable_;
 }
 
 void FloydZone::getLocalRoute(NetPoint* src, NetPoint* dst, sg_platf_route_cbarg_t route, double* lat)
@@ -93,9 +93,9 @@ void FloydZone::addRoute(sg_platf_route_cbarg_t route)
 
   if (not linkTable_) {
     /* Create Cost, Predecessor and Link tables */
-    costTable_        = xbt_new0(double, table_size* table_size);                  /* link cost from host to host */
-    predecessorTable_ = xbt_new0(int, table_size* table_size);                     /* predecessor host numbers */
-    linkTable_        = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); /* actual link between src and dst */
+    costTable_        = new double[table_size * table_size];                 /* link cost from host to host */
+    predecessorTable_ = new int[table_size * table_size];                    /* predecessor host numbers */
+    linkTable_        = new sg_platf_route_cbarg_t[table_size * table_size]; /* actual link between src and dst */
 
     /* Initialize costs and predecessors */
     for (unsigned int i = 0; i < table_size; i++)
@@ -160,9 +160,9 @@ void FloydZone::seal()
 
   if (not linkTable_) {
     /* Create Cost, Predecessor and Link tables */
-    costTable_        = xbt_new0(double, table_size* table_size);                  /* link cost from host to host */
-    predecessorTable_ = xbt_new0(int, table_size* table_size);                     /* predecessor host numbers */
-    linkTable_        = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); /* actual link between src and dst */
+    costTable_        = new double[table_size * table_size];                 /* link cost from host to host */
+    predecessorTable_ = new int[table_size * table_size];                    /* predecessor host numbers */
+    linkTable_        = new sg_platf_route_cbarg_t[table_size * table_size]; /* actual link between src and dst */
 
     /* Initialize costs and predecessors */
     for (unsigned int i = 0; i < table_size; i++)
@@ -178,7 +178,7 @@ void FloydZone::seal()
     for (unsigned int i = 0; i < table_size; i++) {
       sg_platf_route_cbarg_t e_route = TO_FLOYD_LINK(i, i);
       if (not e_route) {
-        e_route            = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+        e_route            = new s_sg_platf_route_cbarg_t;
         e_route->gw_src    = nullptr;
         e_route->gw_dst    = nullptr;
         e_route->link_list = new std::vector<surf::LinkImpl*>();
index 429f079..5fe8ab4 100644 (file)
@@ -24,14 +24,14 @@ void FullZone::seal()
 
   /* Create table if needed */
   if (not routingTable_)
-    routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
+    routingTable_ = new sg_platf_route_cbarg_t[table_size * table_size]();
 
   /* Add the loopback if needed */
   if (surf_network_model->loopback_ && hierarchy_ == RoutingMode::base) {
     for (unsigned int i = 0; i < table_size; i++) {
       sg_platf_route_cbarg_t e_route = TO_ROUTE_FULL(i, i);
       if (not e_route) {
-        e_route            = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+        e_route            = new s_sg_platf_route_cbarg_t;
         e_route->gw_src    = nullptr;
         e_route->gw_dst    = nullptr;
         e_route->link_list = new std::vector<surf::LinkImpl*>();
@@ -51,10 +51,10 @@ FullZone::~FullZone()
       for (unsigned int j = 0; j < table_size; j++) {
         if (TO_ROUTE_FULL(i, j)) {
           delete TO_ROUTE_FULL(i, j)->link_list;
-          xbt_free(TO_ROUTE_FULL(i, j));
+          delete TO_ROUTE_FULL(i, j);
         }
       }
-    xbt_free(routingTable_);
+    delete[] routingTable_;
   }
 }
 
@@ -85,7 +85,7 @@ void FullZone::addRoute(sg_platf_route_cbarg_t route)
   unsigned int table_size = getTableSize();
 
   if (not routingTable_)
-    routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
+    routingTable_ = new sg_platf_route_cbarg_t[table_size * table_size]();
 
   /* Check that the route does not already exist */
   if (route->gw_dst) // inter-zone route (to adapt the error message, if any)
index 5c23716..cb2d000 100644 (file)
@@ -18,7 +18,7 @@ void routing_route_free(sg_platf_route_cbarg_t route)
 {
   if (route) {
     delete route->link_list;
-    xbt_free(route);
+    delete route;
   }
 }
 
@@ -78,7 +78,7 @@ void RoutedZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
       if (my_src == my_dst)
         continue;
 
-      sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+      sg_platf_route_cbarg_t route = new s_sg_platf_route_cbarg_t;
       route->link_list             = new std::vector<surf::LinkImpl*>();
 
       getLocalRoute(my_src, my_dst, route, nullptr);
@@ -119,7 +119,7 @@ void RoutedZone::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
       XBT_DEBUG("  %s -> %s", previous_name, current_name);
 
       delete route->link_list;
-      xbt_free(route);
+      delete route;
     }
   }
 }
@@ -132,7 +132,7 @@ sg_platf_route_cbarg_t RoutedZone::newExtendedRoute(RoutingMode hierarchy, sg_pl
 {
   sg_platf_route_cbarg_t result;
 
-  result            = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+  result            = new s_sg_platf_route_cbarg_t;
   result->link_list = new std::vector<surf::LinkImpl*>();
 
   xbt_assert(hierarchy == RoutingMode::base || hierarchy == RoutingMode::recursive,
index c1affe1..094dd62 100644 (file)
@@ -28,7 +28,12 @@ public:
 /********************************* Task **************************************/
 
 struct s_simdata_task_t {
-  ~s_simdata_task_t() { delete[] this->host_list; /* parallel tasks only */ }
+  ~s_simdata_task_t()
+  {
+    /* parallel tasks only */
+    delete[] this->host_list;
+    /* flops_parallel_amount and bytes_parallel_amount are automatically deleted in ~L07Action */
+  }
   void setUsed();
   void setNotUsed() { this->isused = false; }
 
index f07beb0..0f6c705 100644 (file)
@@ -92,10 +92,15 @@ msg_task_t MSG_parallel_task_create(const char *name, int host_nb, const msg_hos
   /* Simulator Data specific to parallel tasks */
   simdata->host_nb = host_nb;
   simdata->host_list             = new sg_host_t[host_nb];
-  simdata->flops_parallel_amount = flops_amount;
-  simdata->bytes_parallel_amount = bytes_amount;
-
   std::copy_n(host_list, host_nb, simdata->host_list);
+  if (flops_amount != nullptr) {
+    simdata->flops_parallel_amount = new double[host_nb];
+    std::copy_n(flops_amount, host_nb, simdata->flops_parallel_amount);
+  }
+  if (bytes_amount != nullptr) {
+    simdata->bytes_parallel_amount = new double[host_nb * host_nb];
+    std::copy_n(bytes_amount, host_nb * host_nb, simdata->bytes_parallel_amount);
+  }
 
   return task;
 }
index 978bb6b..b75326d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2016. The SimGrid Team.
+/* Copyright (c) 2006-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -7,6 +7,7 @@
 #include "simdag_private.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/surf_interface.hpp"
+#include <algorithm>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_task, sd, "Logging specific to SimDag (task)");
 
@@ -798,20 +799,16 @@ void SD_task_run(SD_task_t task)
 
   /* Copy the elements of the task into the action */
   int host_nb = task->allocation->size();
-  sg_host_t *hosts = xbt_new(sg_host_t, host_nb);
-  int i =0;
-  for (auto const& host : *task->allocation) {
-    hosts[i] = host;
-    i++;
-  }
+  sg_host_t* hosts = new sg_host_t[host_nb];
+  std::copy_n(task->allocation->begin(), host_nb, hosts);
 
-  double *flops_amount = xbt_new0(double, host_nb);
-  double *bytes_amount = xbt_new0(double, host_nb * host_nb);
+  double* flops_amount = new double[host_nb]();
+  double* bytes_amount = new double[host_nb * host_nb]();
 
   if(task->flops_amount)
-    memcpy(flops_amount, task->flops_amount, sizeof(double) * host_nb);
+    std::copy_n(task->flops_amount, host_nb, flops_amount);
   if(task->bytes_amount)
-    memcpy(bytes_amount, task->bytes_amount, sizeof(double) * host_nb * host_nb);
+    std::copy_n(task->bytes_amount, host_nb * host_nb, bytes_amount);
 
   task->surf_action = surf_host_model->executeParallelTask(host_nb, hosts, flops_amount, bytes_amount, task->rate);
 
index 855b491..b33bc4f 100644 (file)
@@ -10,6 +10,7 @@
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/surf/surf_interface.hpp"
 #include "xbt/ex.hpp"
+#include <algorithm>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts");
 
@@ -192,9 +193,8 @@ SIMIX_execution_parallel_start(const char* name, int host_nb, sg_host_t* host_li
       simgrid::kernel::activity::ExecImplPtr(new simgrid::kernel::activity::ExecImpl(name, nullptr));
 
   /* set surf's synchro */
-  sg_host_t *host_list_cpy = xbt_new0(sg_host_t, host_nb);
-  for (int i = 0; i < host_nb; i++)
-    host_list_cpy[i] = host_list[i];
+  sg_host_t* host_list_cpy = new sg_host_t[host_nb];
+  std::copy_n(host_list, host_nb, host_list_cpy);
 
   /* Check that we are not mixing VMs and PMs in the parallel task */
   bool is_a_vm = (nullptr != dynamic_cast<simgrid::s4u::VirtualMachine*>(host_list[0]));
index f3530f5..870c6fc 100644 (file)
@@ -80,13 +80,16 @@ Action* HostModel::executeParallelTask(int host_nb, simgrid::s4u::Host** host_li
       xbt_die("Cannot have a communication that is not a simple point-to-point in this model. You should consider "
           "using the ptask model");
     }
-  } else
+  } else {
     xbt_die(
         "This model only accepts one of the following. You should consider using the ptask model for the other cases.\n"
         " - execution with one host only and no communication\n"
         " - Self-comms with one host only\n"
         " - Communications with two hosts and no computation");
-  xbt_free(host_list);
+  }
+  delete[] host_list;
+  delete[] flops_amount;
+  delete[] bytes_amount;
   return action;
 }
 
index b3d5bea..1c56280 100644 (file)
@@ -226,14 +226,14 @@ L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list,
     this->setCost(1.0);
     this->setRemains(0.0);
   }
-  xbt_free(host_list);
+  delete[] host_list;
 }
 
 Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
 {
-  sg_host_t*host_list = xbt_new0(sg_host_t, 2);
-  double *flops_amount = xbt_new0(double, 2);
-  double *bytes_amount = xbt_new0(double, 4);
+  sg_host_t* host_list = new sg_host_t[2]();
+  double* flops_amount = new double[2]();
+  double* bytes_amount = new double[4]();
 
   host_list[0]    = src;
   host_list[1]    = dst;
@@ -280,8 +280,8 @@ LinkL07::LinkL07(NetworkL07Model* model, const std::string& name, double bandwid
 
 Action *CpuL07::execution_start(double size)
 {
-  sg_host_t*host_list = xbt_new0(sg_host_t, 1);
-  double *flops_amount = xbt_new0(double, 1);
+  sg_host_t* host_list = new sg_host_t[1]();
+  double* flops_amount = new double[1]();
 
   host_list[0] = getHost();
   flops_amount[0] = size;
@@ -392,8 +392,8 @@ LinkL07::~LinkL07() = default;
 
 L07Action::~L07Action(){
   delete hostList_;
-  free(communicationAmount_);
-  free(computationAmount_);
+  delete[] communicationAmount_;
+  delete[] computationAmount_;
 }
 
 void L07Action::updateBound()
index 6d56517..660c6db 100644 (file)
@@ -600,10 +600,10 @@ simgrid::s4u::NetZone* sg_platf_new_Zone_begin(ZoneCreationArgs* zone)
       new_zone = new simgrid::kernel::routing::FatTreeZone(current_routing, zone->id);
       break;
     case A_surfxml_AS_routing_Dijkstra:
-      new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, 0);
+      new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, false);
       break;
     case A_surfxml_AS_routing_DijkstraCache:
-      new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, 1);
+      new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, true);
       break;
     case A_surfxml_AS_routing_Floyd:
       new_zone = new simgrid::kernel::routing::FloydZone(current_routing, zone->id);
index 93b710e..db80cd7 100644 (file)
@@ -84,12 +84,12 @@ public:
 };
 
 struct s_sg_platf_route_cbarg_t {
-  bool symmetrical;
-  sg_netpoint_t src;
-  sg_netpoint_t dst;
-  sg_netpoint_t gw_src;
-  sg_netpoint_t gw_dst;
-  std::vector<simgrid::surf::LinkImpl*>* link_list;
+  bool symmetrical                                 = false;
+  sg_netpoint_t src                                = nullptr;
+  sg_netpoint_t dst                                = nullptr;
+  sg_netpoint_t gw_src                             = nullptr;
+  sg_netpoint_t gw_dst                             = nullptr;
+  std::vector<simgrid::surf::LinkImpl*>* link_list = nullptr;
 };
 typedef s_sg_platf_route_cbarg_t* sg_platf_route_cbarg_t;