Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Removed SIMIX_global_init_args and SIMIX_process_create_with_arguments.
authordonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 10 Apr 2007 10:52:42 +0000 (10:52 +0000)
committerdonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 10 Apr 2007 10:52:42 +0000 (10:52 +0000)
Added SIMIX_action_parallel_execute, MSG_parallel_task_create and MSG_parallel_task_execute (not tested).

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3369 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/include/simix/simix.h
src/msg_simix/msg_simix_gos.c
src/msg_simix/msg_simix_process.c
src/msg_simix/msg_simix_task.c
src/simix/smx_action.c
src/simix/smx_deployment.c
src/simix/smx_global.c
src/simix/smx_process.c
src/simix/smx_synchro.c

index 5ba522b..83c9f33 100644 (file)
@@ -19,7 +19,6 @@ SG_BEGIN_DECL()
 /************************** Global ******************************************/
 XBT_PUBLIC(void) SIMIX_config(const char *name, va_list pa);
 XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv);
 /************************** Global ******************************************/
 XBT_PUBLIC(void) SIMIX_config(const char *name, va_list pa);
 XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv);
-XBT_PUBLIC(void) SIMIX_global_init_args(int *argc, char **argv);
 XBT_PUBLIC(void) SIMIX_clean(void);
 XBT_PUBLIC(void) SIMIX_function_register(const char *name, smx_process_code_t code);
 XBT_PUBLIC(smx_process_code_t) SIMIX_get_registered_function(const char *name);
 XBT_PUBLIC(void) SIMIX_clean(void);
 XBT_PUBLIC(void) SIMIX_function_register(const char *name, smx_process_code_t code);
 XBT_PUBLIC(smx_process_code_t) SIMIX_get_registered_function(const char *name);
@@ -68,9 +67,6 @@ XBT_PUBLIC(int) SIMIX_host_get_state(smx_host_t host);
 
 /************************** Process handling *********************************/
 XBT_PUBLIC(smx_process_t) SIMIX_process_create(const char *name,
 
 /************************** Process handling *********************************/
 XBT_PUBLIC(smx_process_t) SIMIX_process_create(const char *name,
-                              smx_process_code_t code, void *data,
-                              const char * hostname, void * clean_process_function);
-XBT_PUBLIC(smx_process_t) SIMIX_process_create_with_arguments(const char *name,
                                              smx_process_code_t code, void *data,
                                              const char * hostname, int argc, char **argv, void * clean_process_function);
 XBT_PUBLIC(void) SIMIX_process_kill(smx_process_t process);
                                              smx_process_code_t code, void *data,
                                              const char * hostname, int argc, char **argv, void * clean_process_function);
 XBT_PUBLIC(void) SIMIX_process_kill(smx_process_t process);
@@ -121,7 +117,8 @@ XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action, smx_con
 XBT_PUBLIC(double) SIMIX_action_get_remains(smx_action_t action);
 
 /*Not implemented yet */
 XBT_PUBLIC(double) SIMIX_action_get_remains(smx_action_t action);
 
 /*Not implemented yet */
-XBT_PUBLIC(smx_action_t) SIMIX_action_parallel_execute(int workstation_nb,      
+XBT_PUBLIC(smx_action_t) SIMIX_action_parallel_execute(char * name, 
+                                                                                                                                                                                                                       int workstation_nb,      
                                                                                                                                                                                                                        void **workstation_list,
                                                                                                                                                                                                                        double *computation_amount,
                                                                                                                                                                                                                        double *communication_amount,
                                                                                                                                                                                                                        void **workstation_list,
                                                                                                                                                                                                                        double *computation_amount,
                                                                                                                                                                                                                        double *communication_amount,
index 1772e8f..f34fd64 100644 (file)
@@ -554,9 +554,38 @@ m_task_t MSG_parallel_task_create(const char *name,
                                  double *communication_amount,
                                  void *data)
 {
                                  double *communication_amount,
                                  void *data)
 {
+  int i;
+  simdata_task_t simdata = xbt_new0(s_simdata_task_t,1);
   m_task_t task = xbt_new0(s_m_task_t,1);
   m_task_t task = xbt_new0(s_m_task_t,1);
-       xbt_die("not implemented yet");
+  task->simdata = simdata;
+
+  /* Task structure */
+  task->name = xbt_strdup(name);
+  task->data = data;
+
+  /* Simulator Data */
+  simdata->computation_amount = 0;
+  simdata->message_size = 0;
+       simdata->cond = SIMIX_cond_init();
+       simdata->mutex = SIMIX_mutex_init();
+       simdata->compute = NULL;
+       simdata->comm = NULL;
+  simdata->rate = -1.0;
+  simdata->using = 1;
+  simdata->sender = NULL;
+  simdata->receiver = NULL;
+  simdata->source = NULL;
+
+  simdata->host_nb = host_nb;
+  simdata->host_list = xbt_new0(void *, host_nb);
+  simdata->comp_amount = computation_amount;
+  simdata->comm_amount = communication_amount;
+
+  for(i=0;i<host_nb;i++)
+    simdata->host_list[i] = host_list[i]->simdata->host;
+
   return task;
   return task;
+
 }
 
 
 }
 
 
@@ -567,7 +596,34 @@ static void __MSG_parallel_task_execute(m_process_t process, m_task_t task)
 
 MSG_error_t MSG_parallel_task_execute(m_task_t task)
 {
 
 MSG_error_t MSG_parallel_task_execute(m_task_t task)
 {
+       simdata_task_t simdata = NULL;
+       m_process_t self = MSG_process_self();
+  CHECK_HOST();
+
+  simdata = task->simdata;
+  xbt_assert0((!simdata->compute)&&(task->simdata->using==1),
+             "This taks is executed somewhere else. Go fix your code!");
+
+  xbt_assert0(simdata->host_nb,"This is not a parallel task. Go to hell.");
+       
+       DEBUG1("Computing on %s", MSG_process_self()->simdata->host->name);
+  simdata->using++;
+       SIMIX_mutex_lock(simdata->mutex);
+  simdata->compute = SIMIX_action_parallel_execute(task->name, simdata->host_nb, simdata->host_list, simdata->comp_amount, simdata->comm_amount, 1.0, -1.0);
 
 
+       self->simdata->waiting_task = task;
+       SIMIX_register_action_to_condition(simdata->compute, simdata->cond);
+       SIMIX_register_condition_to_action(simdata->compute, simdata->cond);
+       SIMIX_cond_wait(simdata->cond, simdata->mutex);
+       self->simdata->waiting_task = NULL;
+
+       /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+       simdata->comm = NULL;
+       simdata->compute = NULL;
+
+       SIMIX_mutex_unlock(simdata->mutex);
+  simdata->using--;
+       MSG_RETURN(MSG_OK);
        xbt_die("not implemented yet");
   return MSG_OK;  
 }
        xbt_die("not implemented yet");
   return MSG_OK;  
 }
index 869d0c4..9942d60 100644 (file)
@@ -96,7 +96,7 @@ m_process_t MSG_process_create_with_arguments(const char *name,
   simdata->host = host;
   simdata->argc = argc;
   simdata->argv = argv;
   simdata->host = host;
   simdata->argc = argc;
   simdata->argv = argv;
-       simdata->smx_process = SIMIX_process_create_with_arguments(name, (smx_process_code_t)code, (void*)process, host->name, argc, argv, MSG_process_cleanup );
+       simdata->smx_process = SIMIX_process_create(name, (smx_process_code_t)code, (void*)process, host->name, argc, argv, MSG_process_cleanup );
 
        if (SIMIX_process_self()) {
                simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
 
        if (SIMIX_process_self()) {
                simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
index e5c7e36..1402b57 100644 (file)
@@ -52,6 +52,7 @@ m_task_t MSG_task_create(const char *name, double compute_duration,
   simdata->priority = 1.0;
   simdata->using = 1;
   simdata->sender = NULL;
   simdata->priority = 1.0;
   simdata->using = 1;
   simdata->sender = NULL;
+  simdata->receiver = NULL;
        simdata->cond = SIMIX_cond_init();
        simdata->mutex = SIMIX_mutex_init();
        simdata->compute = NULL;
        simdata->cond = SIMIX_cond_init();
        simdata->mutex = SIMIX_mutex_init();
        simdata->compute = NULL;
index 213f648..d20336a 100644 (file)
@@ -204,3 +204,24 @@ double SIMIX_action_get_remains(smx_action_t action)
   xbt_assert0((action != NULL), "Invalid parameter");
        return action->simdata->surf_action->remains;
 }
   xbt_assert0((action != NULL), "Invalid parameter");
        return action->simdata->surf_action->remains;
 }
+
+smx_action_t SIMIX_action_parallel_execute(char *name, int workstation_nb, void **workstation_list, double *computation_amount, double *communication_amount, double amount, double rate)
+{
+
+       /* alloc structures */
+       smx_action_t act = xbt_new0(s_smx_action_t,1);
+       act->simdata = xbt_new0(s_smx_simdata_action_t,1);
+       smx_simdata_action_t simdata = act->simdata;
+       act->cond_list = xbt_fifo_new();
+       
+       /* initialize them */
+       act-> name = xbt_strdup(name);
+
+       /* set communication */
+  simdata->surf_action = surf_workstation_resource->extension_public->execute_parallel_task(workstation_nb, workstation_list, computation_amount, communication_amount, amount, rate);
+
+       surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act);
+
+       return act;
+}
+
index fbd7d09..8844f45 100644 (file)
@@ -62,7 +62,7 @@ static void parse_process_finalize(void)
                 if (simix_global->create_process_function)
                         surf_timer_resource->extension_public->set(start_time, (void*) simix_global->create_process_function, arg);
                 else
                 if (simix_global->create_process_function)
                         surf_timer_resource->extension_public->set(start_time, (void*) simix_global->create_process_function, arg);
                 else
-                        surf_timer_resource->extension_public->set(start_time, (void*) &SIMIX_process_create_with_arguments, arg);
+                        surf_timer_resource->extension_public->set(start_time, (void*) &SIMIX_process_create, arg);
 
   }
   if((start_time<0) || (start_time==SIMIX_get_clock())) {
 
   }
   if((start_time<0) || (start_time==SIMIX_get_clock())) {
@@ -71,7 +71,7 @@ static void parse_process_finalize(void)
                if (simix_global->create_process_function)
                        process = simix_global->create_process_function(parse_argv[0], parse_code, NULL, parse_host,    parse_argc,parse_argv);
                else
                if (simix_global->create_process_function)
                        process = simix_global->create_process_function(parse_argv[0], parse_code, NULL, parse_host,    parse_argc,parse_argv);
                else
-                       process = SIMIX_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host,      parse_argc,parse_argv, NULL);
+                       process = SIMIX_process_create(parse_argv[0], parse_code, NULL, parse_host,     parse_argc,parse_argv, NULL);
 
                if(kill_time > SIMIX_get_clock()) {
                        if (simix_global->kill_process_function)
 
                if(kill_time > SIMIX_get_clock()) {
                        if (simix_global->kill_process_function)
@@ -99,7 +99,7 @@ static void parse_process_finalize(void)
  */
 void SIMIX_launch_application(const char *file) 
 {
  */
 void SIMIX_launch_application(const char *file) 
 {
-  xbt_assert0(simix_global,"SIMIX_global_init_args has to be called before SIMIX_launch_application.");
+  xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_launch_application.");
   STag_surfxml_process_fun = parse_process_init;
   ETag_surfxml_argument_fun = parse_argument;
   ETag_surfxml_process_fun = parse_process_finalize;
   STag_surfxml_process_fun = parse_process_init;
   ETag_surfxml_argument_fun = parse_argument;
   ETag_surfxml_process_fun = parse_process_finalize;
index 2743795..02f8d2d 100644 (file)
@@ -17,17 +17,6 @@ SIMIX_Global_t simix_global = NULL;
 
 /********************************* SIMIX **************************************/
 
 
 /********************************* SIMIX **************************************/
 
-/** 
- * \brief Initialize some SIMIX internal data.
- *
- * \param argc Argc
- * \param argv Argv
- */
-void SIMIX_global_init_args(int *argc, char **argv)
-{
-  SIMIX_global_init(argc,argv);
-}
-
 /**
  * \brief Initialize some SIMIX internal data.
  *
 /**
  * \brief Initialize some SIMIX internal data.
  *
@@ -279,10 +268,10 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed)
 
                while (surf_timer_resource->extension_public->get(&fun,(void*)&arg)) {
                        DEBUG2("got %p %p", fun, arg);
 
                while (surf_timer_resource->extension_public->get(&fun,(void*)&arg)) {
                        DEBUG2("got %p %p", fun, arg);
-                       if(fun==SIMIX_process_create_with_arguments) {
+                       if(fun==SIMIX_process_create) {
                                process_arg_t args = arg;
                                DEBUG2("Launching %s on %s", args->name, args->hostname);
                                process_arg_t args = arg;
                                DEBUG2("Launching %s on %s", args->name, args->hostname);
-                               process = SIMIX_process_create_with_arguments(args->name, args->code, 
+                               process = SIMIX_process_create(args->name, args->code, 
                                                args->data, args->hostname,
                                                args->argc,args->argv,NULL);
                                if(args->kill_time > SIMIX_get_clock()) {
                                                args->data, args->hostname,
                                                args->argc,args->argv,NULL);
                                if(args->kill_time > SIMIX_get_clock()) {
index a40b7bc..46abe32 100644 (file)
@@ -20,12 +20,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
    providing standard arguments (\a argc, \a argv).
  * \see SIMIX_process_create_with_arguments
  */
    providing standard arguments (\a argc, \a argv).
  * \see SIMIX_process_create_with_arguments
  */
-smx_process_t SIMIX_process_create(const char *name,
-                              smx_process_code_t code, void *data,
-                              const char * hostname, void * clean_process_function)
-{
-  return SIMIX_process_create_with_arguments(name, code, data, hostname, -1, NULL, clean_process_function);
-}
+
 
 void SIMIX_process_cleanup(void *arg)
 {
 
 void SIMIX_process_cleanup(void *arg)
 {
@@ -54,7 +49,7 @@ void SIMIX_process_cleanup(void *arg)
  * \see smx_process_t
  * \return The new corresponding object.
  */
  * \see smx_process_t
  * \return The new corresponding object.
  */
-smx_process_t SIMIX_process_create_with_arguments(const char *name,
+smx_process_t SIMIX_process_create(const char *name,
                                              smx_process_code_t code, void *data,
                                              const char * hostname, int argc, char **argv, void * clean_process_function)
 {
                                              smx_process_code_t code, void *data,
                                              const char * hostname, int argc, char **argv, void * clean_process_function)
 {
index 1932708..f2feb6b 100644 (file)
@@ -17,6 +17,13 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_synchro, simix,
 /****************************** Synchronization *******************************/
 
 /*********************************** Mutex ************************************/
 /****************************** Synchronization *******************************/
 
 /*********************************** Mutex ************************************/
+
+/**
+ * \brief Initialize a mutex.
+ *
+ * Allocs and creates the data for the mutex. It have to be called before the utilisation of the mutex.
+ * \return A mutex
+ */
 smx_mutex_t SIMIX_mutex_init()
 {
        smx_mutex_t m = xbt_new0(s_smx_mutex_t,1);
 smx_mutex_t SIMIX_mutex_init()
 {
        smx_mutex_t m = xbt_new0(s_smx_mutex_t,1);
@@ -27,6 +34,12 @@ smx_mutex_t SIMIX_mutex_init()
        return m;
 }
 
        return m;
 }
 
+/**
+ * \brief Locks a mutex.
+ *
+ * Tries to lock a mutex, if the mutex isn't used yet, the process can continue its execution, else it'll be blocked here. You have to call #SIMIX_mutex_unlock to free the mutex.
+ * \param mutex The mutex
+ */
 void SIMIX_mutex_lock(smx_mutex_t mutex)
 {
        smx_process_t self = SIMIX_process_self();
 void SIMIX_mutex_lock(smx_mutex_t mutex)
 {
        smx_process_t self = SIMIX_process_self();
@@ -55,7 +68,13 @@ void SIMIX_mutex_lock(smx_mutex_t mutex)
        return;
 }
 
        return;
 }
 
-/* return 1 if the process got the mutex, else 0. */
+/**
+ * \brief Tries to lock a mutex.
+ *
+ * Tries to lock a mutex, return 1 if the mutex is free, 0 else. This function does not block the process if the mutex is used.
+ * \param mutex The mutex
+ * \return 1 - mutex free, 0 - mutex used
+ */
 int SIMIX_mutex_trylock(smx_mutex_t mutex)
 {
        xbt_assert0((mutex != NULL), "Invalid parameters");
 int SIMIX_mutex_trylock(smx_mutex_t mutex)
 {
        xbt_assert0((mutex != NULL), "Invalid parameters");
@@ -68,6 +87,12 @@ int SIMIX_mutex_trylock(smx_mutex_t mutex)
        }
 }
 
        }
 }
 
+/**
+ * \brief Unlocks a mutex.
+ *
+ * Unlocks the mutex and wakes up a process blocked on it. If there are no process sleeping, only sets the mutex as free.
+ * \param mutex The mutex
+ */
 void SIMIX_mutex_unlock(smx_mutex_t mutex)
 {
        smx_process_t p;        /*process to wake up */
 void SIMIX_mutex_unlock(smx_mutex_t mutex)
 {
        smx_process_t p;        /*process to wake up */
@@ -86,6 +111,12 @@ void SIMIX_mutex_unlock(smx_mutex_t mutex)
        return;
 }
 
        return;
 }
 
+/**
+ * \brief Destroys a mutex.
+ *
+ * Destroys and frees the mutex's memory. 
+ * \param mutex A mutex
+ */
 void SIMIX_mutex_destroy(smx_mutex_t mutex)
 {
        if ( mutex == NULL )
 void SIMIX_mutex_destroy(smx_mutex_t mutex)
 {
        if ( mutex == NULL )
@@ -98,6 +129,13 @@ void SIMIX_mutex_destroy(smx_mutex_t mutex)
 }
 
 /******************************** Conditional *********************************/
 }
 
 /******************************** Conditional *********************************/
+
+/**
+ * \brief Initialize a condition.
+ *
+ * Allocs and creates the data for the condition. It have to be called before the utilisation of the condition.
+ * \return A condition
+ */
 smx_cond_t SIMIX_cond_init()
 {
        smx_cond_t cond = xbt_new0(s_smx_cond_t,1);
 smx_cond_t SIMIX_cond_init()
 {
        smx_cond_t cond = xbt_new0(s_smx_cond_t,1);
@@ -109,6 +147,12 @@ smx_cond_t SIMIX_cond_init()
        return cond;
 }
 
        return cond;
 }
 
+/**
+ * \brief Signalizes a condition.
+ *
+ * Signalizes a condition and wakes up a sleping process. If there are no process sleeping, no action is done.
+ * \param cond A condition
+ */
 void SIMIX_cond_signal(smx_cond_t cond)
 {
        xbt_assert0((cond != NULL), "Invalid parameters");
 void SIMIX_cond_signal(smx_cond_t cond)
 {
        xbt_assert0((cond != NULL), "Invalid parameters");
@@ -122,6 +166,13 @@ void SIMIX_cond_signal(smx_cond_t cond)
        return;
 }
 
        return;
 }
 
+/**
+ * \brief Waits on a condition.
+ *
+ * Blocks a process until the signal is called. This functions frees the mutex associated and locks it after its execution.
+ * \param cond A condition
+ * \param mutex A mutex
+ */
 void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex)
 {
        smx_action_t act_sleep;
 void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex)
 {
        smx_action_t act_sleep;
@@ -148,6 +199,7 @@ void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex)
        return;
 }
 
        return;
 }
 
+
 void __SIMIX_cond_wait(smx_cond_t cond)
 {
        smx_process_t self = SIMIX_process_self();
 void __SIMIX_cond_wait(smx_cond_t cond)
 {
        smx_process_t self = SIMIX_process_self();
@@ -166,6 +218,14 @@ void __SIMIX_cond_wait(smx_cond_t cond)
 
 }
 
 
 }
 
+/**
+ * \brief Waits on a condition with timeout.
+ *
+ * Same behavior of #SIMIX_cond_wait, but waits a maximum time.
+ * \param cond A condition
+ * \param mutex A mutex
+ * \param max_duration Timeout time
+ */
 void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_duration)
 {
        xbt_assert0((mutex != NULL), "Invalid parameters");
 void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_duration)
 {
        xbt_assert0((mutex != NULL), "Invalid parameters");
@@ -187,6 +247,12 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_durat
        return;
 }
 
        return;
 }
 
+/**
+ * \brief Broadcasts a condition.
+ *
+ * Signalizes a condition and wakes up ALL sleping process. If there are no process sleeping, no action is done.
+ * \param cond A condition
+ */
 void SIMIX_cond_broadcast(smx_cond_t cond)
 {
        xbt_assert0((cond != NULL), "Invalid parameters");
 void SIMIX_cond_broadcast(smx_cond_t cond)
 {
        xbt_assert0((cond != NULL), "Invalid parameters");
@@ -201,6 +267,12 @@ void SIMIX_cond_broadcast(smx_cond_t cond)
        return;
 }
 
        return;
 }
 
+/**
+ * \brief Destroys a contidion.
+ *
+ * Destroys and frees the condition's memory. 
+ * \param cond A condition
+ */
 void SIMIX_cond_destroy(smx_cond_t cond)
 {
        if ( cond == NULL )
 void SIMIX_cond_destroy(smx_cond_t cond)
 {
        if ( cond == NULL )
@@ -214,6 +286,13 @@ void SIMIX_cond_destroy(smx_cond_t cond)
        }
 }
 
        }
 }
 
+/**
+ *     \brief Set a condition to an action
+ *
+ *     Creates the "link" between an action and a condition. You have to call this function when you create an action and want to wait its ending. 
+ *     \param action SIMIX action
+ *     \param cond SIMIX cond
+ */
 void SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond)
 {
        xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters");
 void SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond)
 {
        xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters");