-/* 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. */
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);
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);
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);
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);
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;
}
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);
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);
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)
{
}
int rank = MSG_comm_waitany(dyn);
- xbt_free(comms);
+ delete[] comms;
xbt_dynar_free(&dyn);
return rank;
}
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);
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];
}
/* 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)
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);
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) {
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
{
#if HAVE_THREAD_CONTEXTS
delete raw_parmap;
- xbt_free(raw_workers_context);
+ delete[] raw_workers_context;
#endif
}
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);
}
#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
{
#if HAVE_THREAD_CONTEXTS
delete sysv_parmap;
- xbt_free(sysv_workers_context);
+ delete[] sysv_workers_context;
#endif
}
/* 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;
}
}
}
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);
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;
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) {
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) {
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);
}
}
- 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;
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]);
}
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);
}
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;
if (lat)
*lat += static_cast<surf::LinkImpl*>(link)->latency();
}
- size++;
}
if (hierarchy_ == RoutingMode::recursive) {
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)
{
}
};
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 {
~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
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 */
};
}
}
{
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_;
}
}
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++) {
// 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_" +
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);
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)
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++)
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++)
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*>();
/* 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*>();
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_;
}
}
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)
{
if (route) {
delete route->link_list;
- xbt_free(route);
+ delete route;
}
}
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);
XBT_DEBUG(" %s -> %s", previous_name, current_name);
delete route->link_list;
- xbt_free(route);
+ delete route;
}
}
}
{
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,
/********************************* 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; }
/* 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;
}
-/* 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
#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)");
/* 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);
#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");
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]));
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;
}
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;
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;
L07Action::~L07Action(){
delete hostList_;
- free(communicationAmount_);
- free(computationAmount_);
+ delete[] communicationAmount_;
+ delete[] computationAmount_;
}
void L07Action::updateBound()
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);
};
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;