Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move name from msg_task_t to simgrid::msg::Task
[simgrid.git] / src / msg / msg_gos.cpp
index 9573554..d73f7fd 100644 (file)
@@ -46,8 +46,7 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo
   e_smx_state_t comp_state;
   msg_error_t status = MSG_OK;
 
-
-  xbt_assert((not simdata->compute) && not task->simdata->isused,
+  xbt_assert((not simdata->compute) && not task->simdata->is_used,
              "This task is executed somewhere else. Go fix your code!");
 
   XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
@@ -60,13 +59,13 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo
     simgrid::instr::Container::by_name(instr_pid(MSG_process_self()))->get_state("ACTOR_STATE")->push_event("execute");
 
   try {
-    simdata->setUsed();
+    simdata->set_used();
 
     if (simdata->host_nb > 0) {
       simdata->compute =
           boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(simcall_execution_parallel_start(
-              task->name ?: "", simdata->host_nb, simdata->host_list, simdata->flops_parallel_amount,
-              simdata->bytes_parallel_amount, -1.0, timeout));
+              std::move(task->simdata->get_name()), simdata->host_nb, simdata->host_list,
+              simdata->flops_parallel_amount, simdata->bytes_parallel_amount, -1.0, timeout));
       XBT_DEBUG("Parallel execution action created: %p", simdata->compute.get());
       if (task->category != nullptr)
         simgrid::simix::simcall([task] { task->simdata->compute->set_category(task->category); });
@@ -74,8 +73,7 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo
       sg_host_t host   = MSG_process_get_host(MSG_process_self());
       simdata->compute = simgrid::simix::simcall([task, host] {
         return simgrid::kernel::activity::ExecImplPtr(
-            new simgrid::kernel::activity::ExecImpl(task->name ?: "", task->category ?: "",
-                                                    /*timeout_detector*/ nullptr, host));
+            new simgrid::kernel::activity::ExecImpl(std::move(task->simdata->get_name()), task->category ?: "", host));
       });
       /* checking for infinite values */
       xbt_assert(std::isfinite(simdata->flops_amount), "flops_amount is not finite!");
@@ -86,9 +84,9 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo
 
     comp_state = simcall_execution_wait(simdata->compute);
 
-    simdata->setNotUsed();
+    simdata->set_not_used();
 
-    XBT_DEBUG("Execution task '%s' finished in state %d", task->name, (int)comp_state);
+    XBT_DEBUG("Execution task '%s' finished in state %d", task->simdata->get_cname(), (int)comp_state);
   } catch (simgrid::HostFailureException& e) {
     status = MSG_HOST_FAILURE;
   } catch (simgrid::TimeoutError& e) {
@@ -253,14 +251,14 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, d
         ->set_rate(rate)
         ->wait_for(timeout);
     *task = static_cast<msg_task_t>(payload);
-    XBT_DEBUG("Got task %s from %s", (*task)->name, alias);
-    (*task)->simdata->setNotUsed();
+    XBT_DEBUG("Got task %s from %s", (*task)->simdata->get_cname(), alias);
+    (*task)->simdata->set_not_used();
   } catch (simgrid::HostFailureException& e) {
     ret = MSG_HOST_FAILURE;
   } catch (simgrid::TimeoutError& e) {
     ret = MSG_TIMEOUT;
   } catch (simgrid::CancelException& e) {
-    ret = MSG_HOST_FAILURE;
+    ret = MSG_TASK_CANCELED;
   } catch (xbt_ex& e) {
     if (e.category == network_error)
       ret = MSG_TRANSFER_FAILURE;
@@ -268,8 +266,11 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, d
       throw;
   }
 
-  if (ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) {
-    TRACE_msg_task_get_end(*task);
+  if (TRACE_actor_is_enabled() && ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) {
+    container_t process_container = simgrid::instr::Container::by_name(instr_pid(MSG_process_self()));
+
+    std::string key = std::string("p") + std::to_string((*task)->counter);
+    simgrid::instr::Container::get_root()->get_link("ACTOR_TASK_LINK")->end_event(process_container, "SR", key);
   }
   return ret;
 }
@@ -286,8 +287,7 @@ static inline msg_comm_t MSG_task_isend_internal(msg_task_t task, const char* al
   /* Prepare the task to send */
   t_simdata = task->simdata;
   t_simdata->sender = myself;
-  t_simdata->source = MSG_host_self();
-  t_simdata->setUsed();
+  t_simdata->set_used();
   t_simdata->comm = nullptr;
   msg_global->sent_msg++;
 
@@ -451,13 +451,13 @@ int MSG_comm_test(msg_comm_t comm)
     finished = comm->s_comm->test();
     if (finished && comm->task_received != nullptr) {
       /* I am the receiver */
-      (*comm->task_received)->simdata->setNotUsed();
+      (*comm->task_received)->simdata->set_not_used();
     }
   } catch (simgrid::TimeoutError& e) {
     comm->status = MSG_TIMEOUT;
     finished     = true;
   } catch (simgrid::CancelException& e) {
-    comm->status = MSG_HOST_FAILURE;
+    comm->status = MSG_TASK_CANCELED;
     finished     = true;
   }
   catch (xbt_ex& e) {
@@ -500,7 +500,7 @@ int MSG_comm_testany(xbt_dynar_t comms)
     status         = MSG_TIMEOUT;
   } catch (simgrid::CancelException& e) {
     finished_index = e.value;
-    status         = MSG_HOST_FAILURE;
+    status         = MSG_TASK_CANCELED;
   }
   catch (xbt_ex& e) {
     if (e.category != network_error)
@@ -516,7 +516,7 @@ int MSG_comm_testany(xbt_dynar_t comms)
 
     if (status == MSG_OK && comm->task_received != nullptr) {
       /* I am the receiver */
-      (*comm->task_received)->simdata->setNotUsed();
+      (*comm->task_received)->simdata->set_not_used();
     }
   }
 
@@ -544,14 +544,14 @@ msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
 
     if (comm->task_received != nullptr) {
       /* I am the receiver */
-      (*comm->task_received)->simdata->setNotUsed();
+      (*comm->task_received)->simdata->set_not_used();
     }
 
     /* FIXME: these functions are not traceable */
   } catch (simgrid::TimeoutError& e) {
     comm->status = MSG_TIMEOUT;
   } catch (simgrid::CancelException& e) {
-    comm->status = MSG_HOST_FAILURE;
+    comm->status = MSG_TASK_CANCELED;
   }
   catch (xbt_ex& e) {
     if (e.category == network_error)
@@ -601,7 +601,7 @@ int MSG_comm_waitany(xbt_dynar_t comms)
     status         = MSG_TIMEOUT;
   } catch (simgrid::CancelException& e) {
     finished_index = e.value;
-    status         = MSG_HOST_FAILURE;
+    status         = MSG_TASK_CANCELED;
   }
   catch(xbt_ex& e) {
     if (e.category == network_error) {
@@ -620,7 +620,7 @@ int MSG_comm_waitany(xbt_dynar_t comms)
 
   if (comm->task_received != nullptr) {
     /* I am the receiver */
-    (*comm->task_received)->simdata->setNotUsed();
+    (*comm->task_received)->simdata->set_not_used();
   }
 
   return finished_index;
@@ -730,8 +730,7 @@ msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, doubl
   /* Prepare the task to send */
   simdata_task_t t_simdata = task->simdata;
   t_simdata->sender        = MSG_process_self();
-  t_simdata->source = MSG_host_self();
-  t_simdata->setUsed();
+  t_simdata->set_used();
 
   msg_global->sent_msg++;
 
@@ -755,7 +754,7 @@ msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, doubl
       throw;
 
     /* If the send failed, it is not used anymore */
-    t_simdata->setNotUsed();
+    t_simdata->set_not_used();
   }
 
   return ret;
@@ -817,7 +816,19 @@ int MSG_task_listen_from(const char *alias)
  */
 void MSG_task_set_category (msg_task_t task, const char *category)
 {
-  TRACE_msg_set_task_category (task, category);
+  xbt_assert(task->category == nullptr, "Task %p(%s) already has a category (%s).", task, task->simdata->get_cname(),
+             task->category);
+
+  // if user provides a nullptr category, task is no longer traced
+  if (category == nullptr) {
+    xbt_free(task->category);
+    task->category = nullptr;
+    XBT_DEBUG("MSG task %p(%s), category removed", task, task->simdata->get_cname());
+  } else {
+    // set task category
+    task->category = xbt_strdup(category);
+    XBT_DEBUG("MSG task %p(%s), category %s", task, task->simdata->get_cname(), task->category);
+  }
 }
 
 /**