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);
+ msg_host_t* hosts = new msg_host_t[host_count];
double* computeDurations = xbt_new0(double, host_count);
for (int index = 0; index < host_count; index++) {
jobject jhost = env->GetObjectArrayElement(jhosts, index);
/* associate the java task object and the native task */
jtask_bind(jtask, task, env);
+
+ delete[] hosts;
}
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);
+ graph_node_map_element_t elm = new s_graph_node_map_element_t;
elm->node = node;
graphNodeMap_.insert({id, elm});
graph_node_map_element_t src_elm = nodeMapSearch(src_id);
graph_node_map_element_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->node))->graph_id;
+ int dst_node_id = static_cast<graph_node_data_t>(xbt_graph_node_get_data(dst_elm->node))->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);
} else { /* 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);
+ double* cost_arr = new double[nr_nodes]; /* link cost from src to other hosts */
+ pred_arr = new int[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);
+ delete[] 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 (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 = new s_route_cache_element_t;
elm->pred_arr = pred_arr;
elm->size = size;
routeCache_.insert({src_id, elm});
}
if (routeCache_.empty())
- xbt_free(pred_arr);
+ delete[] pred_arr;
}
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 */
{
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,
};
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;