Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
refactor with templated method
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 11 May 2018 11:41:46 +0000 (13:41 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 11 May 2018 11:41:46 +0000 (13:41 +0200)
src/instr/instr_interface.cpp
src/instr/instr_paje_containers.cpp
src/instr/instr_paje_types.cpp
src/instr/instr_paje_types.hpp
src/instr/instr_platform.cpp
src/smpi/colls/smpi_automatic_selector.cpp

index 3715437..75b55ab 100644 (file)
@@ -147,7 +147,7 @@ void TRACE_declare_mark(const char *mark_type)
   }
 
   XBT_DEBUG("MARK,declare %s", mark_type);
-  simgrid::instr::Container::getRoot()->type_->getOrCreateEventType(mark_type);
+  simgrid::instr::Container::getRoot()->type_->by_name_or_create<simgrid::instr::EventType>(mark_type);
   declared_marks.insert(mark_type);
 }
 
@@ -178,7 +178,7 @@ void TRACE_declare_mark_value_with_color (const char *mark_type, const char *mar
     THROWF (tracing_error, 1, "mark_value is nullptr");
 
   simgrid::instr::EventType* type =
-      static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::getRoot()->type_->byName(mark_type));
+      static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::getRoot()->type_->by_name(mark_type));
   if (not type) {
     THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
   } else {
@@ -234,7 +234,7 @@ void TRACE_mark(const char *mark_type, const char *mark_value)
 
   //check if mark_type is already declared
   simgrid::instr::EventType* type =
-      static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::getRoot()->type_->byName(mark_type));
+      static_cast<simgrid::instr::EventType*>(simgrid::instr::Container::getRoot()->type_->by_name(mark_type));
   if (not type) {
     THROWF (tracing_error, 1, "mark_type with name (%s) is not declared", mark_type);
   } else {
index fa9527e..f5428d8 100644 (file)
@@ -38,7 +38,8 @@ NetZoneContainer::NetZoneContainer(std::string name, unsigned int level, NetZone
   netpoint_ = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name);
   xbt_assert(netpoint_, "Element '%s' not found", name.c_str());
   if (father_) {
-    type_ = father_->type_->getOrCreateContainerType(std::string("L") + std::to_string(level));
+    std::string type_name = std::string("L") + std::to_string(level);
+    type_                 = father_->type_->by_name_or_create<ContainerType>(type_name);
     father_->children_.insert({get_name(), this});
     logCreation();
   } else {
@@ -78,7 +79,7 @@ Container::Container(std::string name, std::string type_name, Container* father)
     XBT_DEBUG("new container %s, child of %s", name.c_str(), father->name_.c_str());
 
     if (not type_name.empty()) {
-      type_ = father_->type_->getOrCreateContainerType(type_name);
+      type_ = father_->type_->by_name_or_create<ContainerType>(type_name);
       father_->children_.insert({name_, this});
       logCreation();
     }
@@ -207,21 +208,21 @@ void Container::logDestruction()
 
 StateType* Container::getState(std::string name)
 {
-  StateType* ret = dynamic_cast<StateType*>(type_->byName(name));
+  StateType* ret = dynamic_cast<StateType*>(type_->by_name(name));
   ret->setCallingContainer(this);
   return ret;
 }
 
 LinkType* Container::getLink(std::string name)
 {
-  LinkType* ret = dynamic_cast<LinkType*>(type_->byName(name));
+  LinkType* ret = dynamic_cast<LinkType*>(type_->by_name(name));
   ret->setCallingContainer(this);
   return ret;
 }
 
 VariableType* Container::getVariable(std::string name)
 {
-  VariableType* ret = dynamic_cast<VariableType*>(type_->byName(name));
+  VariableType* ret = dynamic_cast<VariableType*>(type_->by_name(name));
   ret->setCallingContainer(this);
   return ret;
 }
index 7343396..6a1556d 100644 (file)
@@ -177,7 +177,7 @@ void Type::logDefinition(simgrid::instr::Type* source, simgrid::instr::Type* des
   tracing_file << stream_.str() << std::endl;
 }
 
-Type* Type::byName(std::string name)
+Type* Type::by_name(std::string name)
 {
   Type* ret = nullptr;
   for (auto elm : children_) {
@@ -222,32 +222,14 @@ EntityValue* ValueType::getEntityValue(std::string name)
   return ret->second;
 }
 
-ContainerType* Type::getOrCreateContainerType(std::string name)
-{
-  auto cont = children_.find(name);
-  return cont == children_.end() ? new ContainerType(name, this) : static_cast<ContainerType*>(cont->second);
-}
-
-EventType* Type::getOrCreateEventType(std::string name)
-{
-  auto cont = children_.find(name);
-  return cont == children_.end() ? new EventType(name, this) : static_cast<EventType*>(cont->second);
-}
-
-StateType* Type::getOrCreateStateType(std::string name)
-{
-  auto cont = children_.find(name);
-  return cont == children_.end() ? new StateType(name, this) : static_cast<StateType*>(cont->second);
-}
-
-VariableType* Type::getOrCreateVariableType(std::string name, std::string color)
+VariableType* Type::by_name_or_create(std::string name, std::string color)
 {
   auto cont = children_.find(name);
   std::string mycolor = color.empty() ? "1 1 1" : color;
   return cont == children_.end() ? new VariableType(name, mycolor, this) : static_cast<VariableType*>(cont->second);
 }
 
-LinkType* Type::getOrCreateLinkType(std::string name, Type* source, Type* dest)
+LinkType* Type::by_name_or_create(std::string name, Type* source, Type* dest)
 {
   std::string alias = name + "-" + std::to_string(source->id_) + "-" + std::to_string(dest->id_);
   auto it           = children_.find(alias);
index 6f33a2c..4ac25a5 100644 (file)
@@ -35,12 +35,15 @@ public:
   long long int get_id() { return id_; }
   bool isColored() { return not color_.empty(); }
 
-  Type* byName(std::string name);
-  ContainerType* getOrCreateContainerType(std::string name);
-  EventType* getOrCreateEventType(std::string name);
-  LinkType* getOrCreateLinkType(std::string name, Type* source, Type* dest);
-  StateType* getOrCreateStateType(std::string name);
-  VariableType* getOrCreateVariableType(std::string name, std::string color);
+  Type* by_name(std::string name);
+  LinkType* by_name_or_create(std::string name, Type* source, Type* dest);
+  VariableType* by_name_or_create(std::string name, std::string color);
+
+  template <class T> T* by_name_or_create(std::string name)
+  {
+    auto cont = children_.find(name);
+    return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second);
+  }
 
   void setCallingContainer(Container* container) { issuer_ = container; }
 
index 71cd307..329dedd 100644 (file)
@@ -100,7 +100,7 @@ static void linkContainers(container_t src, container_t dst, std::set<std::strin
   std::string link_typename = father->type_->get_name() + "-" + src->type_->get_name() +
                               std::to_string(src->type_->get_id()) + "-" + dst->type_->get_name() +
                               std::to_string(dst->type_->get_id());
-  simgrid::instr::LinkType* link = father->type_->getOrCreateLinkType(link_typename, src->type_, dst->type_);
+  simgrid::instr::LinkType* link = father->type_->by_name_or_create(link_typename, src->type_, dst->type_);
   link->setCallingContainer(father);
 
   // register EDGE types for triva configuration
@@ -159,13 +159,13 @@ static void instr_netzone_on_creation(simgrid::s4u::NetZone& netzone)
     simgrid::instr::NetZoneContainer* root = new simgrid::instr::NetZoneContainer(id, 0, nullptr);
 
     if (TRACE_smpi_is_enabled()) {
-      simgrid::instr::Type* mpi = root->type_->getOrCreateContainerType("MPI");
+      simgrid::instr::ContainerType* mpi = root->type_->by_name_or_create<simgrid::instr::ContainerType>("MPI");
       if (not TRACE_smpi_is_grouped())
-        mpi->getOrCreateStateType("MPI_STATE");
-      root->type_->getOrCreateLinkType("MPI_LINK", mpi, mpi);
+        mpi->by_name_or_create<simgrid::instr::StateType>("MPI_STATE");
+      root->type_->by_name_or_create("MPI_LINK", mpi, mpi);
       // TODO See if we can move this to the LoadBalancer plugin
-      root->type_->getOrCreateLinkType("MIGRATE_LINK", mpi, mpi);
-      mpi->getOrCreateStateType("MIGRATE_STATE");
+      root->type_->by_name_or_create("MIGRATE_LINK", mpi, mpi);
+      mpi->by_name_or_create<simgrid::instr::StateType>("MIGRATE_STATE");
     }
 
     if (TRACE_needs_platform()) {
@@ -196,15 +196,15 @@ static void instr_link_on_creation(simgrid::s4u::Link& link)
   container_t container = new simgrid::instr::Container(link.get_name(), "LINK", currentContainer.back());
 
   if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_link())) {
-    simgrid::instr::VariableType* bandwidth = container->type_->getOrCreateVariableType("bandwidth", "");
+    simgrid::instr::VariableType* bandwidth = container->type_->by_name_or_create("bandwidth", "");
     bandwidth->setCallingContainer(container);
     bandwidth->setEvent(0, link.bandwidth());
-    simgrid::instr::VariableType* latency = container->type_->getOrCreateVariableType("latency", "");
+    simgrid::instr::VariableType* latency = container->type_->by_name_or_create("latency", "");
     latency->setCallingContainer(container);
     latency->setEvent(0, link.latency());
   }
   if (TRACE_uncategorized()) {
-    container->type_->getOrCreateVariableType("bandwidth_used", "0.5 0.5 0.5");
+    container->type_->by_name_or_create("bandwidth_used", "0.5 0.5 0.5");
   }
 }
 
@@ -214,20 +214,20 @@ static void instr_host_on_creation(simgrid::s4u::Host& host)
   container_t root      = simgrid::instr::Container::getRoot();
 
   if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_speed())) {
-    simgrid::instr::VariableType* power = container->type_->getOrCreateVariableType("power", "");
+    simgrid::instr::VariableType* power = container->type_->by_name_or_create("power", "");
     power->setCallingContainer(container);
     power->setEvent(0, host.getSpeed());
   }
 
   if (TRACE_uncategorized())
-    container->type_->getOrCreateVariableType("power_used", "0.5 0.5 0.5");
+    container->type_->by_name_or_create("power_used", "0.5 0.5 0.5");
 
   if (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped()) {
-    simgrid::instr::ContainerType* mpi = container->type_->getOrCreateContainerType("MPI");
-    mpi->getOrCreateStateType("MPI_STATE");
+    simgrid::instr::ContainerType* mpi = container->type_->by_name_or_create<simgrid::instr::ContainerType>("MPI");
+    mpi->by_name_or_create<simgrid::instr::StateType>("MPI_STATE");
     // TODO See if we can move this to the LoadBalancer plugin
-    root->type_->getOrCreateLinkType("MIGRATE_LINK", mpi, mpi);
-    mpi->getOrCreateStateType("MIGRATE_STATE");
+    root->type_->by_name_or_create("MIGRATE_LINK", mpi, mpi);
+    mpi->by_name_or_create<simgrid::instr::StateType>("MIGRATE_STATE");
   }
 }
 
@@ -264,15 +264,16 @@ static void instr_actor_on_creation(simgrid::s4u::ActorPtr actor)
   container_t container = simgrid::instr::Container::byName(actor->get_host()->get_name());
 
   container->createChild(instr_pid(actor.get()), "ACTOR");
-  simgrid::instr::ContainerType* actor_type = container->type_->getOrCreateContainerType("ACTOR");
-  simgrid::instr::StateType* state          = actor_type->getOrCreateStateType("ACTOR_STATE");
+  simgrid::instr::ContainerType* actor_type =
+      container->type_->by_name_or_create<simgrid::instr::ContainerType>("ACTOR");
+  simgrid::instr::StateType* state = actor_type->by_name_or_create<simgrid::instr::StateType>("ACTOR_STATE");
   state->addEntityValue("suspend", "1 0 1");
   state->addEntityValue("sleep", "1 1 0");
   state->addEntityValue("receive", "1 0 0");
   state->addEntityValue("send", "0 0 1");
   state->addEntityValue("task_execute", "0 1 1");
-  root->type_->getOrCreateLinkType("ACTOR_LINK", actor_type, actor_type);
-  root->type_->getOrCreateLinkType("ACTOR_TASK_LINK", actor_type, actor_type);
+  root->type_->by_name_or_create("ACTOR_LINK", actor_type, actor_type);
+  root->type_->by_name_or_create("ACTOR_TASK_LINK", actor_type, actor_type);
 }
 
 static void instr_actor_on_suspend(simgrid::s4u::ActorPtr actor)
@@ -310,17 +311,17 @@ static void instr_actor_on_migration_end(simgrid::s4u::ActorPtr actor)
 
 static void instr_vm_on_creation(simgrid::s4u::Host& host)
 {
-  container_t container                 = new simgrid::instr::HostContainer(host, currentContainer.back());
-  container_t root                      = simgrid::instr::Container::getRoot();
-  simgrid::instr::ContainerType* msg_vm = container->type_->getOrCreateContainerType("VM");
-  simgrid::instr::StateType* state      = msg_vm->getOrCreateStateType("VM_STATE");
+  container_t container             = new simgrid::instr::HostContainer(host, currentContainer.back());
+  container_t root                  = simgrid::instr::Container::getRoot();
+  simgrid::instr::ContainerType* vm = container->type_->by_name_or_create<simgrid::instr::ContainerType>("VM");
+  simgrid::instr::StateType* state  = vm->by_name_or_create<simgrid::instr::StateType>("VM_STATE");
   state->addEntityValue("suspend", "1 0 1");
   state->addEntityValue("sleep", "1 1 0");
   state->addEntityValue("receive", "1 0 0");
   state->addEntityValue("send", "0 0 1");
   state->addEntityValue("task_execute", "0 1 1");
-  root->type_->getOrCreateLinkType("VM_LINK", msg_vm, msg_vm);
-  root->type_->getOrCreateLinkType("VM_ACTOR_LINK", msg_vm, msg_vm);
+  root->type_->by_name_or_create("VM_LINK", vm, vm);
+  root->type_->by_name_or_create("VM_ACTOR_LINK", vm, vm);
 }
 
 static void instr_vm_on_start(simgrid::s4u::VirtualMachine& vm)
@@ -386,10 +387,10 @@ void instr_define_callbacks()
 static void recursiveNewVariableType(std::string new_typename, std::string color, simgrid::instr::Type* root)
 {
   if (root->get_name() == "HOST" || root->get_name() == "VM")
-    root->getOrCreateVariableType(std::string("p") + new_typename, color);
+    root->by_name_or_create(std::string("p") + new_typename, color);
 
   if (root->get_name() == "LINK")
-    root->getOrCreateVariableType(std::string("b") + new_typename, color);
+    root->by_name_or_create(std::string("b") + new_typename, color);
 
   for (auto elm : root->children_) {
     recursiveNewVariableType(new_typename, color, elm.second);
@@ -405,7 +406,7 @@ static void recursiveNewUserVariableType(std::string father_type, std::string ne
                                          simgrid::instr::Type* root)
 {
   if (root->get_name() == father_type) {
-    root->getOrCreateVariableType(new_typename, color);
+    root->by_name_or_create(new_typename, color);
   }
   for (auto elm : root->children_)
     recursiveNewUserVariableType(father_type, new_typename, color, elm.second);
@@ -419,7 +420,7 @@ void instr_new_user_variable_type(std::string father_type, std::string new_typen
 static void recursiveNewUserStateType(std::string father_type, std::string new_typename, simgrid::instr::Type* root)
 {
   if (root->get_name() == father_type)
-    root->getOrCreateStateType(new_typename);
+    root->by_name_or_create<simgrid::instr::StateType>(new_typename);
 
   for (auto elm : root->children_)
     recursiveNewUserStateType(father_type, new_typename, elm.second);
index 3eee4bc..c01b6d3 100644 (file)
@@ -13,7 +13,8 @@
 //attempt to do a quick autotuning version of the collective,
 #define TRACE_AUTO_COLL(cat)                                                                                           \
   if (TRACE_is_enabled()) {                                                                                            \
-    simgrid::instr::EventType* type = simgrid::instr::Container::getRoot()->type_->getOrCreateEventType(#cat);         \
+    simgrid::instr::EventType* type =                                                                                  \
+        simgrid::instr::Container::getRoot()->type_->by_name_or_create<simgrid::instr::EventType>(#cat);               \
                                                                                                                        \
     std::string cont_name = std::string("rank-" + std::to_string(simgrid::s4u::this_actor::get_pid()));                \
     type->addEntityValue(Colls::mpi_coll_##cat##_description[i].name, "1.0 1.0 1.0");                                  \