Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SD_SCHED_NO_COST: Constant to use as cost in SD_task_schedule()
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 3 Mar 2010 16:06:23 +0000 (16:06 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 3 Mar 2010 16:06:23 +0000 (16:06 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7174 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
examples/simdag/sd_test2.c
include/simdag/simdag.h
src/simdag/sd_task.c

index dcb6a2c..5aec950 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,9 @@ SimGrid (3.3.5-svn) unstable; urgency=low
   * Kill the useless "rate" argument of SD_task_get_execution_time()
     Everyone used to provide -1 as a value, it was not used, and the
     semantic of a possible use wasn't even clear.
   * Kill the useless "rate" argument of SD_task_get_execution_time()
     Everyone used to provide -1 as a value, it was not used, and the
     semantic of a possible use wasn't even clear.
+  * SD_SCHED_NO_COST: Constant to use as cost in SD_task_schedule()
+    either as comm costs or compute costs to mean that there is no
+    such thing for that specific task. 
  MSG: 
   * In trace replay, allow to have one trace file per process.
     Give the specific trace file as argument of each process, 
  MSG: 
   * In trace replay, allow to have one trace file per process.
     Give the specific trace file as argument of each process, 
index 893654c..99a85c7 100644 (file)
@@ -31,7 +31,6 @@ int main(int argc, char **argv)
   SD_task_t InterRedist;
   SD_task_t taskFinal;
   SD_task_t ParComp_wcomm2;
   SD_task_t InterRedist;
   SD_task_t taskFinal;
   SD_task_t ParComp_wcomm2;
-  const double no_cost[] = { 1.0, 1.0 };
   SD_workstation_t PtoPcomm1_hosts[2];
   SD_workstation_t PtoPcomm2_hosts[2];
   double PtoPcomm1_table[] = { 0, 12500000, 0, 0 };     /* 100Mb */
   SD_workstation_t PtoPcomm1_hosts[2];
   SD_workstation_t PtoPcomm2_hosts[2];
   double PtoPcomm1_table[] = { 0, 12500000, 0, 0 };     /* 100Mb */
@@ -171,10 +170,10 @@ int main(int argc, char **argv)
 
 
   /* scheduling the tasks */
 
 
   /* scheduling the tasks */
-  SD_task_schedule(taskInit, 1, hosts, no_cost, no_cost, -1.0);
-  SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, no_cost, PtoPcomm1_table,
+  SD_task_schedule(taskInit, 1, hosts, SD_SCHED_NO_COST, SD_SCHED_NO_COST, -1.0);
+  SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, SD_SCHED_NO_COST, PtoPcomm1_table,
                    -1.0);
                    -1.0);
-  SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, no_cost, PtoPcomm2_table,
+  SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, SD_SCHED_NO_COST, PtoPcomm2_table,
                    -1.0);
   SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts,
                    ParComp_wocomm_cost, ParComp_wocomm_table, -1.0);
                    -1.0);
   SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts,
                    ParComp_wocomm_cost, ParComp_wocomm_table, -1.0);
@@ -186,7 +185,7 @@ int main(int argc, char **argv)
                    InterRedist_table, -1.0);
   SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts,
                    ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0);
                    InterRedist_table, -1.0);
   SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts,
                    ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0);
-  SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost, no_cost, -1.0);
+  SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost, SD_SCHED_NO_COST, -1.0);
 
   /* let's launch the simulation! */
   changed_tasks = SD_simulate(-1.0);
 
   /* let's launch the simulation! */
   changed_tasks = SD_simulate(-1.0);
index 9b48418..8dcf5fb 100644 (file)
@@ -145,6 +145,18 @@ XBT_PUBLIC(SD_task_t) SD_task_create_comm_e2e(const char*name,void *data,double
 XBT_PUBLIC(void) SD_task_schedulev(SD_task_t task, int count, const SD_workstation_t*list);
 XBT_PUBLIC(void) SD_task_schedulel(SD_task_t task, int count, ...);
 
 XBT_PUBLIC(void) SD_task_schedulev(SD_task_t task, int count, const SD_workstation_t*list);
 XBT_PUBLIC(void) SD_task_schedulel(SD_task_t task, int count, ...);
 
+/** @brief A constant to use in SD_task_schedule to mean that there is no cost.
+ *
+ *  For example, create a pure computation task (no comm) like this:
+ *
+ *  SD_task_schedule(task, my_workstation_nb,
+ *                   my_workstation_list,
+ *                   my_computation_amount,
+ *                   SD_TASK_SCHED_NO_COST,
+ *                   my_rate);
+ */
+#define SD_SCHED_NO_COST NULL
+
 /** @} */
 
 
 /** @} */
 
 
index 959eebd..b5728f1 100644 (file)
@@ -711,14 +711,22 @@ void SD_task_schedule(SD_task_t task, int workstation_count,
   task->workstation_nb = workstation_count;
   task->rate = rate;
 
   task->workstation_nb = workstation_count;
   task->rate = rate;
 
-  task->computation_amount = xbt_new(double, workstation_count);
-  memcpy(task->computation_amount, computation_amount,
-         sizeof(double) * workstation_count);
+  if (computation_amount) {
+    task->computation_amount = xbt_new(double, workstation_count);
+    memcpy(task->computation_amount, computation_amount,
+        sizeof(double) * workstation_count);
+  } else {
+    task->computation_amount = NULL;
+  }
 
   communication_nb = workstation_count * workstation_count;
 
   communication_nb = workstation_count * workstation_count;
-  task->communication_amount = xbt_new(double, communication_nb);
-  memcpy(task->communication_amount, communication_amount,
-         sizeof(double) * communication_nb);
+  if (communication_amount) {
+    task->communication_amount = xbt_new(double, communication_nb);
+    memcpy(task->communication_amount, communication_amount,
+        sizeof(double) * communication_nb);
+  } else {
+    task->communication_amount = NULL;
+  }
 
   task->workstation_list = xbt_new(SD_workstation_t, workstation_count);
   memcpy(task->workstation_list, workstation_list,
 
   task->workstation_list = xbt_new(SD_workstation_t, workstation_count);
   memcpy(task->workstation_list, workstation_list,
@@ -816,31 +824,34 @@ void __SD_task_really_run(SD_task_t task)
   /* we have to create a Surf workstation array instead of the SimDag workstation array */
   surf_workstations = xbt_new(void *, task->workstation_nb);
 
   /* we have to create a Surf workstation array instead of the SimDag workstation array */
   surf_workstations = xbt_new(void *, task->workstation_nb);
 
-  for (i = 0; i < task->workstation_nb; i++) {
+  for (i = 0; i < task->workstation_nb; i++)
     surf_workstations[i] = task->workstation_list[i]->surf_workstation;
     surf_workstations[i] = task->workstation_list[i]->surf_workstation;
-  }
+
+  /* It's allowed to pass a NULL vector as cost to mean vector of 0.0 (easing user's life). Let's deal with it */
+#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
 
   task->surf_action = NULL;
 
   task->surf_action = NULL;
-  if ((task->workstation_nb == 1) && (task->communication_amount[0] == 0.0)) {
+  if ((task->workstation_nb == 1) && (cost_or_zero(task->communication_amount,0) == 0.0)) {
     task->surf_action =
       surf_workstation_model->extension.
     task->surf_action =
       surf_workstation_model->extension.
-      workstation.execute(surf_workstations[0], task->computation_amount[0]);
+      workstation.execute(surf_workstations[0], cost_or_zero(task->computation_amount,0));
   } else if ((task->workstation_nb == 1)
   } else if ((task->workstation_nb == 1)
-             && (task->computation_amount[0] == 0.0)) {
+             && (cost_or_zero(task->computation_amount,0) == 0.0)) {
+
     task->surf_action =
       surf_workstation_model->extension.
       workstation.communicate(surf_workstations[0], surf_workstations[0],
     task->surf_action =
       surf_workstation_model->extension.
       workstation.communicate(surf_workstations[0], surf_workstations[0],
-                              task->communication_amount[0], task->rate);
+                              cost_or_zero(task->communication_amount,0), task->rate);
   } else if ((task->workstation_nb == 2)
   } else if ((task->workstation_nb == 2)
-             && (task->computation_amount[0] == 0.0)
-             && (task->computation_amount[1] == 0.0)) {
+             && (cost_or_zero(task->computation_amount,0) == 0.0)
+             && (cost_or_zero(task->computation_amount,1) == 0.0)) {
     int nb = 0;
     double value = 0.0;
 
     for (i = 0; i < task->workstation_nb * task->workstation_nb; i++) {
     int nb = 0;
     double value = 0.0;
 
     for (i = 0; i < task->workstation_nb * task->workstation_nb; i++) {
-      if (task->communication_amount[i] > 0.0) {
+      if (cost_or_zero(task->communication_amount,i) > 0.0) {
         nb++;
         nb++;
-        value = task->communication_amount[i];
+        value = cost_or_zero(task->communication_amount,i);
       }
     }
     if (nb == 1) {
       }
     }
     if (nb == 1) {
@@ -850,6 +861,8 @@ void __SD_task_really_run(SD_task_t task)
                                 value, task->rate);
     }
   }
                                 value, task->rate);
     }
   }
+#undef cost_or_zero
+
   if (!task->surf_action) {
     double *computation_amount = xbt_new(double, task->workstation_nb);
     double *communication_amount = xbt_new(double, task->workstation_nb *
   if (!task->surf_action) {
     double *computation_amount = xbt_new(double, task->workstation_nb);
     double *communication_amount = xbt_new(double, task->workstation_nb *