/************************** 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);
/************************** 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);
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,
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);
- 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;
+
}
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;
}
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);
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;
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;
+}
+
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 (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)
*/
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;
/********************************* 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.
*
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 = 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()) {
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)
{
* \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)
{
/****************************** 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);
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();
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");
}
}
+/**
+ * \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 */
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 )
}
/******************************** 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);
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");
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;
return;
}
+
void __SIMIX_cond_wait(smx_cond_t cond)
{
smx_process_t self = SIMIX_process_self();
}
+/**
+ * \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");
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");
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 )
}
}
+/**
+ * \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");