From: Frederic Suter Date: Tue, 9 Aug 2016 15:01:49 +0000 (+0200) Subject: dynar to std::vector X-Git-Tag: v3_14~594^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/90a471de6cd70b41223dd16a09fafe6ac3e18269 dynar to std::vector --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 3616544458..bc29606acd 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -370,9 +370,7 @@ XBT_PUBLIC(int) surf_host_file_move(sg_host_t host, surf_file_t fd, const char* * - SEEK_END: end of the file * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED */ -XBT_PUBLIC(int) surf_host_file_seek(sg_host_t host, - surf_file_t fd, sg_offset_t offset, - int origin); +XBT_PUBLIC(int) surf_host_file_seek(sg_host_t host, surf_file_t fd, sg_offset_t offset, int origin); /** * @brief Get the content of a storage @@ -693,11 +691,6 @@ XBT_PUBLIC(void) surf_vm_model_init_HL13(); */ XBT_PUBLIC_DATA(s_surf_model_description_t) surf_vm_model_description[]; -/** \ingroup SURF_models - * \brief List of initialized models - */ -XBT_PUBLIC_DATA(xbt_dynar_t) all_existing_models; - /** \ingroup SURF_simulation * \brief List of hosts that have just restarted and whose autorestart process should be restarted. */ diff --git a/src/simdag/sd_global.cpp b/src/simdag/sd_global.cpp index 6879f57923..7b8a101ae1 100644 --- a/src/simdag/sd_global.cpp +++ b/src/simdag/sd_global.cpp @@ -46,7 +46,6 @@ std::set* simulate(double how_long){ double total_time = 0.0; /* main loop */ while (elapsed_time >= 0 && (how_long < 0 || 0.00001 < (how_long -total_time)) && !sd_global->watch_point_reached) { - surf_model_t model = nullptr; XBT_DEBUG("Total time: %f", total_time); @@ -56,8 +55,7 @@ std::set* simulate(double how_long){ total_time += elapsed_time; /* let's see which tasks are done */ - unsigned int iter; - xbt_dynar_foreach(all_existing_models, iter, model) { + for (auto model : *all_existing_models) { surf_action_t action = surf_model_extract_done_action_set(model); while (action != nullptr) { SD_task_t task = static_cast(action->getData()); diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 32e9b58123..90a9c486c0 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -348,11 +348,9 @@ static int process_syscall_color(void *p) /** Wake up all processes waiting for a Surf action to finish */ static void SIMIX_wake_processes() { - unsigned int iter; - surf_model_t model; surf_action_t action; - xbt_dynar_foreach(all_existing_models, iter, model) { + for(auto model : *all_existing_models) { XBT_DEBUG("Handling the processes whose action failed (if any)"); while ((action = surf_model_extract_failed_action_set(model))) { XBT_DEBUG(" Handling Action %p",action); diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index c7e5ec9a0d..eef87951b8 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -13,8 +13,7 @@ #include "network_interface.hpp" #include "virtual_machine.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, - "Logging specific to the SURF host module"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module"); simgrid::surf::HostModel *surf_host_model = nullptr; @@ -100,9 +99,7 @@ Action *HostModel::executeParallelTask(int host_nb, } } if (nb == 1) { - action = surf_network_model->communicate(host_list[0]->pimpl_netcard, - host_list[1]->pimpl_netcard, - value, rate); + action = surf_network_model->communicate(host_list[0]->pimpl_netcard, host_list[1]->pimpl_netcard, value, rate); } else if (nb == 0) { xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the ptask model"); } else { @@ -183,15 +180,15 @@ simgrid::surf::Storage *HostImpl::findStorageOnMountList(const char* mount) unsigned int cursor; XBT_DEBUG("Search for storage name '%s' on '%s'", mount, getName()); - xbt_dynar_foreach(p_storage,cursor,mnt) - { + xbt_dynar_foreach(p_storage,cursor,mnt){ XBT_DEBUG("See '%s'",mnt.name); if(!strcmp(mount,mnt.name)){ st = static_cast(mnt.storage); break; } } - if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, getName()); + if(!st) + xbt_die("Can't find mount '%s' for '%s'", mount, getName()); return st; } diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index d361db65c6..6321e49c0f 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -26,10 +26,10 @@ void surf_cpu_model_init_Cas01() } surf_cpu_model_pm = new simgrid::surf::CpuCas01Model(); - xbt_dynar_push(all_existing_models, &surf_cpu_model_pm); + all_existing_models->push_back(surf_cpu_model_pm); surf_cpu_model_vm = new simgrid::surf::CpuCas01Model(); - xbt_dynar_push(all_existing_models, &surf_cpu_model_vm); + all_existing_models->push_back(surf_cpu_model_vm); } namespace simgrid { diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 64df3a05c2..c6e5c23c21 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -334,10 +334,10 @@ void surf_cpu_model_init_ti() xbt_assert(!surf_cpu_model_vm,"CPU model already initialized. This should not happen."); surf_cpu_model_pm = new simgrid::surf::CpuTiModel(); - xbt_dynar_push(all_existing_models, &surf_cpu_model_pm); + all_existing_models->push_back(surf_cpu_model_pm); surf_cpu_model_vm = new simgrid::surf::CpuTiModel(); - xbt_dynar_push(all_existing_models, &surf_cpu_model_vm); + all_existing_models->push_back(surf_cpu_model_vm); } namespace simgrid { diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index b7241b2567..0c95e43d7c 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -31,7 +31,7 @@ void surf_host_model_init_current_default() surf_cpu_model_init_Cas01(); surf_network_model_init_LegrandVelho(); - xbt_dynar_push(all_existing_models, &surf_host_model); + all_existing_models->push_back(surf_host_model); } void surf_host_model_init_compound() @@ -40,7 +40,7 @@ void surf_host_model_init_compound() xbt_assert(surf_network_model, "No network model defined yet!"); surf_host_model = new simgrid::surf::HostCLM03Model(); - xbt_dynar_push(all_existing_models, &surf_host_model); + all_existing_models->push_back(surf_host_model); } namespace simgrid { diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 77f3801a9f..a2f7152a70 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -41,7 +41,7 @@ void surf_network_model_init_LegrandVelho() return; surf_network_model = new simgrid::surf::NetworkCm02Model(); - xbt_dynar_push(all_existing_models, &surf_network_model); + all_existing_models->push_back(surf_network_model); xbt_cfg_setdefault_double("network/latency-factor", 13.01); xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97); @@ -66,7 +66,7 @@ void surf_network_model_init_CM02() return; surf_network_model = new simgrid::surf::NetworkCm02Model(); - xbt_dynar_push(all_existing_models, &surf_network_model); + all_existing_models->push_back(surf_network_model); xbt_cfg_setdefault_double("network/latency-factor", 1.0); xbt_cfg_setdefault_double("network/bandwidth-factor", 1.0); @@ -89,7 +89,7 @@ void surf_network_model_init_Reno() return; surf_network_model = new simgrid::surf::NetworkCm02Model(); - xbt_dynar_push(all_existing_models, &surf_network_model); + all_existing_models->push_back(surf_network_model); lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi); surf_network_model->f_networkSolve = lagrange_solve; @@ -106,7 +106,7 @@ void surf_network_model_init_Reno2() return; surf_network_model = new simgrid::surf::NetworkCm02Model(); - xbt_dynar_push(all_existing_models, &surf_network_model); + all_existing_models->push_back(surf_network_model); lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp, func_reno2_fpi); surf_network_model->f_networkSolve = lagrange_solve; @@ -122,7 +122,7 @@ void surf_network_model_init_Vegas() return; surf_network_model = new simgrid::surf::NetworkCm02Model(); - xbt_dynar_push(all_existing_models, &surf_network_model); + all_existing_models->push_back(surf_network_model); lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi); surf_network_model->f_networkSolve = lagrange_solve; diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index 1564f4d8bf..297a9645a6 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -15,7 +15,7 @@ void surf_network_model_init_Constant() { xbt_assert(surf_network_model == nullptr); surf_network_model = new simgrid::surf::NetworkConstantModel(); - xbt_dynar_push(all_existing_models, &surf_network_model); + all_existing_models->push_back(surf_network_model); routing_model_create(nullptr); } diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 2dd9bc4165..2c170bbd9d 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -88,7 +88,7 @@ void surf_network_model_init_IB() return; surf_network_model = new simgrid::surf::NetworkIBModel(); - xbt_dynar_push(all_existing_models, &surf_network_model); + all_existing_models->push_back(surf_network_model); networkActionStateChangedCallbacks.connect(IB_action_state_changed_callback); Link::onCommunicate.connect(IB_action_init_callback); simgrid::s4u::Host::onCreation.connect(IB_create_host_callback); diff --git a/src/surf/network_smpi.cpp b/src/surf/network_smpi.cpp index bb83b01a34..298d06c25e 100644 --- a/src/surf/network_smpi.cpp +++ b/src/surf/network_smpi.cpp @@ -88,7 +88,7 @@ void surf_network_model_init_SMPI() if (surf_network_model) return; surf_network_model = new simgrid::surf::NetworkSmpiModel(); - xbt_dynar_push(all_existing_models, &surf_network_model); + all_existing_models->push_back(surf_network_model); xbt_cfg_setdefault_double("network/sender-gap", 10e-6); xbt_cfg_setdefault_double("network/weight-S", 8775); diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index f28844b217..437bd9c813 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -27,7 +27,7 @@ void surf_host_model_init_ptask_L07() xbt_assert(!surf_network_model, "network model type already defined"); surf_host_model = new simgrid::surf::HostL07Model(); - xbt_dynar_push(all_existing_models, &surf_host_model); + all_existing_models->push_back(surf_host_model); } diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index 8fd56a833a..df308271d7 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -8,8 +8,7 @@ #include "surf_private.h" #include "xbt/file.h" /* xbt_getline */ -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, - "Logging specific to the SURF storage module"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module"); xbt_lib_t file_lib; xbt_lib_t storage_lib; diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 39a791712d..07146a7c09 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -57,7 +57,7 @@ void storage_register_callbacks() void surf_storage_model_init_default() { surf_storage_model = new simgrid::surf::StorageN11Model(); - xbt_dynar_push(all_existing_models, &surf_storage_model); + all_existing_models->push_back(surf_storage_model); } namespace simgrid { diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index f3262aeb36..561b457718 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -33,8 +33,6 @@ void surf_presolve() tmgr_trace_iterator_t event = nullptr; double value = -1.0; simgrid::surf::Resource *resource = nullptr; - simgrid::surf::Model *model = nullptr; - unsigned int iter; XBT_DEBUG ("Consume all trace events occurring before the starting time."); while ((next_event_date = future_evt_set->next_date()) != -1.0) { @@ -49,7 +47,7 @@ void surf_presolve() } XBT_DEBUG ("Set every models in the right state by updating them to 0."); - xbt_dynar_foreach(all_existing_models, iter, model) + for (auto model : *all_existing_models) model->updateActionsState(NOW, 0.0); } @@ -60,9 +58,7 @@ double surf_solve(double max_date) double model_next_action_end = -1.0; double value = -1.0; simgrid::surf::Resource *resource = nullptr; - simgrid::surf::Model *model = nullptr; tmgr_trace_iterator_t event = nullptr; - unsigned int iter; if (max_date > 0.0) { xbt_assert(max_date > NOW,"You asked to simulate up to %f, but that's in the past already", max_date); @@ -147,7 +143,7 @@ double surf_solve(double max_date) NOW = NOW + time_delta; // Inform the models of the date change - xbt_dynar_foreach(all_existing_models, iter, model) { + for (auto model : *all_existing_models) { model->updateActionsState(NOW, time_delta); } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 65102243e3..8a7caad677 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -27,7 +27,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (ke /* model_list_invoke contains only surf_host and surf_vm. * The callback functions of cpu_model and network_model will be called from those of these host models. */ -xbt_dynar_t all_existing_models = nullptr; /* to destroy models correctly */ +std::vector * all_existing_models = nullptr; /* to destroy models correctly */ xbt_dynar_t model_list_invoke = nullptr; /* to invoke callbacks */ simgrid::trace_mgr::future_evt_set *future_evt_set = nullptr; @@ -305,7 +305,7 @@ void surf_init(int *argc, char **argv) xbt_init(argc, argv); if (!all_existing_models) - all_existing_models = xbt_dynar_new(sizeof(simgrid::surf::Model*), nullptr); + all_existing_models = new std::vector(); if (!model_list_invoke) model_list_invoke = xbt_dynar_new(sizeof(simgrid::surf::Model*), nullptr); if (!future_evt_set) @@ -322,11 +322,7 @@ void surf_init(int *argc, char **argv) void surf_exit() { - unsigned int iter; - simgrid::surf::Model *model = nullptr; - - TRACE_end(); /* Just in case it was not called by the upper - * layer (or there is no upper layer) */ + TRACE_end(); /* Just in case it was not called by the upper layer (or there is no upper layer) */ sg_config_finalize(); @@ -341,9 +337,9 @@ void surf_exit() xbt_lib_free(&file_lib); xbt_dict_free(&watched_hosts_lib); - xbt_dynar_foreach(all_existing_models, iter, model) + for (auto model : *all_existing_models) delete model; - xbt_dynar_free(&all_existing_models); + delete all_existing_models; xbt_dynar_free(&model_list_invoke); routing_exit(); diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 819ed572cc..13749c224c 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -80,7 +80,10 @@ XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list; XBT_PRIVATE void surf_action_lmm_update_index_heap(void *action, int i); -XBT_PUBLIC_DATA(xbt_dynar_t) all_existing_models; +/** \ingroup SURF_models + * \brief List of initialized models + */ +XBT_PUBLIC_DATA(std::vector*) all_existing_models; namespace simgrid { namespace surf { diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 47bb68d24e..4a4d61b4b4 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -14,8 +14,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_vm); void surf_vm_model_init_HL13(){ if (surf_cpu_model_vm) { surf_vm_model = new simgrid::surf::VMHL13Model(); - simgrid::surf::Model *model = surf_vm_model; - xbt_dynar_push(all_existing_models, &model); + all_existing_models->push_back(surf_vm_model); } } diff --git a/teshsuite/surf/surf_usage2/surf_usage2.cpp b/teshsuite/surf/surf_usage2/surf_usage2.cpp index da719bf576..f849953e4f 100644 --- a/teshsuite/surf/surf_usage2/surf_usage2.cpp +++ b/teshsuite/surf/surf_usage2/surf_usage2.cpp @@ -48,14 +48,12 @@ int main(int argc, char **argv) surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */ do { surf_action_t action = nullptr; - unsigned int iter; - surf_model_t model = nullptr; running = 0; now = surf_get_clock(); XBT_INFO("Next Event : %g", now); - xbt_dynar_foreach(all_existing_models, iter, model) { + for (auto model: *all_existing_models) { if (surf_model_running_action_set_size((surf_model_t)model)) { XBT_DEBUG("\t Running that model"); running = 1;