Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finish the tutorial for new model and api
authornavarro <navarro@caraja.(none)>
Fri, 12 Oct 2012 12:42:32 +0000 (14:42 +0200)
committernavarro <navarro@caraja.(none)>
Fri, 12 Oct 2012 12:42:32 +0000 (14:42 +0200)
include/simgrid/simix.h
src/include/surf/surf.h
src/surf/new_model.c
src/surf/surf.c
src/surf/surf_config.c

index 003500a..d1af9c2 100644 (file)
@@ -464,5 +464,10 @@ XBT_PUBLIC(xbt_dict_t) SIMIX_asr_get_properties(const char *name);
 /************************** AS router simcalls ***************************/
 XBT_PUBLIC(xbt_dict_t) simcall_asr_get_properties(const char *name);
 
+/************************** New API simcalls **********************************/
+/* TUTORIAL: New API                                                          */
+/******************************************************************************/
+XBT_PUBLIC(int) simcall_new_api_fct(const char* param1, double param2);
+
 SG_END_DECL()
 #endif                          /* _SIMIX_SIMIX_H */
index d072e4b..2790a3d 100644 (file)
@@ -153,17 +153,16 @@ typedef struct surf_action_state {
 typedef struct s_routing_platf s_routing_platf_t, *routing_platf_t;
 XBT_PUBLIC_DATA(routing_platf_t) routing_platf;
 
-/**
+/*******************************************
  *  TUTORIAL: New model
  *  New model extension public
  *  Public functions specific to a New model.
  */
-
 typedef struct surf_new_model_extension_public {
   surf_action_t(*fct) ();
   void* (*create_resource) ();
 } s_surf_model_extension_new_model_t;
-
+/*******************************************/
 
 /** \ingroup SURF_models
  *  \brief Private data available on all models
@@ -342,7 +341,10 @@ typedef struct surf_model {
     s_surf_model_extension_network_t network;
     s_surf_model_extension_storage_t storage;
     s_surf_model_extension_workstation_t workstation;
+    /*******************************************/
+    /* TUTORIAL: New model                     */
     s_surf_model_extension_new_model_t new_model;
+    /*******************************************/
   } extension;
 } s_surf_model_t;
 
@@ -655,6 +657,13 @@ XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(void);
 XBT_PUBLIC_DATA(s_surf_model_description_t)
     surf_workstation_model_description[];
 
+/*******************************************
+ *  TUTORIAL: New model
+ */
+XBT_PUBLIC(void) surf_new_model_init_default(void);
+XBT_PUBLIC_DATA(s_surf_model_description_t) surf_new_model_description[];
+/*******************************************/
+
 /** \ingroup SURF_models
  *  \brief List of initialized models
  */
index 76a6086..2db0dad 100644 (file)
@@ -51,18 +51,25 @@ static void* new_model_create_resource(const char* id, const char* model,const c
 
 static void new_model_finalize(void)
 {
-  THROW_UNIMPLEMENTED;
+  lmm_system_free(new_model_maxmin_system);
+  new_model_maxmin_system = NULL;
+
+  surf_model_exit(surf_new_model);
+  surf_new_model = NULL;
+
+  xbt_swag_free
+      (new_model_running_action_set_that_does_not_need_being_checked);
+  new_model_running_action_set_that_does_not_need_being_checked = NULL;
 }
 
 static void new_model_update_actions_state(double now, double delta)
 {
-  THROW_UNIMPLEMENTED;
+  return;
 }
 
 static double new_model_share_resources(double NOW)
 {
-  THROW_UNIMPLEMENTED;
-  return 0;
+  return -1;
 }
 
 static int new_model_resource_used(void *resource_id)
@@ -131,7 +138,7 @@ static void new_model_define_callbacks()
 {
 }
 
-static void surf_new_model_model_init_internal(void)
+static void surf_new_model_init_internal(void)
 {
   s_surf_action_t action;
 
@@ -141,7 +148,7 @@ static void surf_new_model_model_init_internal(void)
   new_model_running_action_set_that_does_not_need_being_checked =
       xbt_swag_new(xbt_swag_offset(action, state_hookup));
 
-  surf_new_model->name = "Storage";
+  surf_new_model->name = "New Model";
   surf_new_model->action_unref = new_model_action_unref;
   surf_new_model->action_cancel = new_model_action_cancel;
   surf_new_model->action_state_set = new_model_action_state_set;
@@ -167,9 +174,9 @@ static void surf_new_model_model_init_internal(void)
 
 }
 
-void surf_new_model_model_init_default(void)
+void surf_new_model_init_default(void)
 {
-  surf_new_model_model_init_internal();
+  surf_new_model_init_internal();
   new_model_define_callbacks();
 
   xbt_dynar_push(model_list, &surf_new_model);
index 5fb7317..729e6c3 100644 (file)
@@ -189,6 +189,16 @@ s_surf_model_description_t surf_storage_model_description[] = {
   {NULL, NULL,  NULL}      /* this array must be NULL terminated */
 };
 
+/* ********************************************************************* */
+/* TUTORIAL: New model                                                   */
+s_surf_model_description_t surf_new_model_description[] = {
+  {"default",
+   "Tutorial model.",
+   surf_new_model_init_default},
+  {NULL, NULL,  NULL}      /* this array must be NULL terminated */
+};
+/* ********************************************************************* */
+
 #ifdef CONTEXT_THREADS
 static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */
 #endif
index 8aa63e3..6108c02 100644 (file)
@@ -378,6 +378,23 @@ void surf_config_init(int *argc, char **argv)
                      &default_value, 1, 1, &_surf_cfg_cb__storage_mode,
                      NULL);
 
+    /* ********************************************************************* */
+    /* TUTORIAL: New model                                                   */
+    sprintf(description,
+            "The model to use for the New model. Possible values: ");
+    p = description;
+    while (*(++p) != '\0');
+    for (i = 0; surf_new_model_description[i].name; i++)
+      p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
+                   surf_new_model_description[i].name);
+    sprintf(p,
+            ".\n       (use 'help' as a value to see the long description of each model)");
+    default_value = xbt_strdup("default");
+    xbt_cfg_register(&_surf_cfg_set, "new_model/model", description, xbt_cfgelm_string,
+                     &default_value, 1, 1, &_surf_cfg_cb__storage_mode,
+                     NULL);
+    /* ********************************************************************* */
+
     sprintf(description,
             "The model to use for the network. Possible values: ");
     p = description;
@@ -726,4 +743,14 @@ void surf_config_models_setup()
   XBT_DEBUG("Call storage_model_init");
   storage_id = find_model_description(surf_storage_model_description, storage_model_name);
   surf_storage_model_description[storage_id].model_init_preparse();
+
+  /* ********************************************************************* */
+  /* TUTORIAL: New model                                                   */
+  int new_model_id = -1;
+  char *new_model_name = NULL;
+  new_model_name = xbt_cfg_get_string(_surf_cfg_set, "new_model/model");
+  XBT_DEBUG("Call new model_init");
+  new_model_id = find_model_description(surf_new_model_description, new_model_name);
+  surf_new_model_description[new_model_id].model_init_preparse();
+  /* ********************************************************************* */
 }