From: donassbr Date: Tue, 27 Mar 2007 13:09:37 +0000 (+0000) Subject: Functions implemented, task_execute tested with a small example. X-Git-Tag: v3.3~1996 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e6aa3874e6796bf161c68e19f9986782385f90d5 Functions implemented, task_execute tested with a small example. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3364 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/msg_simix/msg_simix_deployment.c b/src/msg_simix/msg_simix_deployment.c index b7e14f48b7..6f5487aba0 100644 --- a/src/msg_simix/msg_simix_deployment.c +++ b/src/msg_simix/msg_simix_deployment.c @@ -21,7 +21,10 @@ */ void MSG_launch_application(const char *file) { + xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application."); + SIMIX_function_register_process_create(&__MSG_process_create_with_arguments); + SIMIX_function_register_process_kill(&MSG_process_kill); SIMIX_launch_application(file); return; diff --git a/src/msg_simix/msg_simix_global.c b/src/msg_simix/msg_simix_global.c index 1a46780ace..b7a76642c1 100644 --- a/src/msg_simix/msg_simix_global.c +++ b/src/msg_simix/msg_simix_global.c @@ -170,8 +170,20 @@ MSG_error_t MSG_main(void) */ int MSG_process_killall(int reset_PIDs) { - xbt_die("not implemented yet"); - return 0; + m_process_t p = NULL; + m_process_t self = MSG_process_self(); + + while((p=xbt_fifo_pop(msg_global->process_list))) { + if(p!=self) MSG_process_kill(p); + } + + if(reset_PIDs>0) { + msg_global->PID = reset_PIDs; + msg_global->session++; + } + + return msg_global->PID; + } /** \ingroup msg_simulation diff --git a/src/msg_simix/msg_simix_gos.c b/src/msg_simix/msg_simix_gos.c index 3f6cc382c9..583266bc1f 100644 --- a/src/msg_simix/msg_simix_gos.c +++ b/src/msg_simix/msg_simix_gos.c @@ -251,7 +251,28 @@ MSG_error_t MSG_task_put_bounded(m_task_t task, */ MSG_error_t MSG_task_execute(m_task_t task) { - MSG_RETURN(MSG_OK); + simdata_task_t simdata = NULL; + + CHECK_HOST(); + + simdata = task->simdata; + xbt_assert0((!simdata->compute)&&(task->simdata->using==1), + "This taks is executed somewhere else. Go fix your code!"); + simdata->using++; + SIMIX_mutex_lock(simdata->mutex); + simdata->compute = SIMIX_action_execute(SIMIX_host_self(), task->name, simdata->computation_amount); + SIMIX_action_set_priority(simdata->compute, simdata->priority); + + 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); + + SIMIX_mutex_unlock(simdata->mutex); + simdata->using--; + +// MSG_RETURN(MSG_OK); + return MSG_OK; } void __MSG_task_execute(m_process_t process, m_task_t task) diff --git a/src/msg_simix/msg_simix_private.h b/src/msg_simix/msg_simix_private.h index 069086b129..dbc1a6414c 100644 --- a/src/msg_simix/msg_simix_private.h +++ b/src/msg_simix/msg_simix_private.h @@ -8,6 +8,7 @@ #ifndef METASIMGRID_PRIVATE_H #define METASIMGRID_PRIVATE_H +#include #include "msg/msg.h" #include "simix/simix.h" #include "xbt/fifo.h" @@ -90,11 +91,11 @@ extern MSG_Global_t msg_global; #define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val) #define PROCESS_GET_ERRNO() (MSG_process_self()->simdata->last_errno) -#define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0) +//#define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0) +#define MSG_RETURN(val) do {return(val);} while(0) /* #define CHECK_ERRNO() ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */ -#define CHECK_HOST() xbt_assert0(surf_workstation_resource->extension_public-> \ - get_state(MSG_host_self()->simdata->host)==SURF_CPU_ON,\ +#define CHECK_HOST() xbt_assert0(SIMIX_host_get_state(SIMIX_host_self())==1,\ "Host failed, you cannot call this function.") m_host_t __MSG_host_create(smx_host_t workstation, void *data); @@ -109,6 +110,9 @@ int __MSG_process_isBlocked(m_process_t process); void __MSG_display_process_status(void); +m_process_t __MSG_process_create_with_arguments(const char *name, + m_process_code_t code, void *data, + char * hostname, int argc, char **argv); #endif diff --git a/src/msg_simix/msg_simix_process.c b/src/msg_simix/msg_simix_process.c index b57bc36afb..789862babd 100644 --- a/src/msg_simix/msg_simix_process.c +++ b/src/msg_simix/msg_simix_process.c @@ -32,7 +32,17 @@ m_process_t MSG_process_create(const char *name, static void MSG_process_cleanup(void *arg) { - xbt_die("not implemented yet"); + /* arg is a pointer to a simix process, we can get the msg process with the field data */ + m_process_t proc = ((smx_process_t)arg)->data; + printf("remove MSG process %s\n", proc->name); + xbt_fifo_remove(msg_global->process_list, proc); + SIMIX_process_cleanup(arg); + free(proc->name); + proc->name = NULL; + free(proc->simdata); + proc->simdata = NULL; + free(proc); + return; } @@ -60,13 +70,23 @@ static void MSG_process_cleanup(void *arg) * \see m_process_t * \return The new corresponding object. */ + + + +m_process_t __MSG_process_create_with_arguments(const char *name, + m_process_code_t code, void *data, + char * hostname, int argc, char **argv) +{ + m_host_t host = MSG_get_host_by_name(hostname); + return MSG_process_create_with_arguments(name,code,data,host,argc,argv); +} + m_process_t MSG_process_create_with_arguments(const char *name, m_process_code_t code, void *data, m_host_t host, int argc, char **argv) { simdata_process_t simdata = xbt_new0(s_simdata_process_t,1); m_process_t process = xbt_new0(s_m_process_t,1); - xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters"); /* Simulator Data */ @@ -75,7 +95,7 @@ m_process_t MSG_process_create_with_arguments(const char *name, simdata->argc = argc; simdata->argv = argv; simdata->smx_process = SIMIX_process_create_with_arguments(name, (smx_process_code_t)code, - (void*)process, host->simdata->host, argc, argv ); + (void*)process, host->name, argc, argv, MSG_process_cleanup ); if (SIMIX_process_self()) { simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data); @@ -89,6 +109,8 @@ m_process_t MSG_process_create_with_arguments(const char *name, process->simdata = simdata; process->data = data; + xbt_fifo_unshift(msg_global->process_list, process); + return process; } @@ -99,7 +121,49 @@ m_process_t MSG_process_create_with_arguments(const char *name, */ void MSG_process_kill(m_process_t process) { - xbt_die("not implemented yet"); + + /* + int i; + simdata_process_t p_simdata = process->simdata; + simdata_host_t h_simdata= p_simdata->host->simdata; + int _cursor; + m_process_t proc = NULL; + + DEBUG3("Killing %s(%d) on %s",process->name, p_simdata->PID, p_simdata->host->name); + + for (i=0; imax_channel; i++) { + if (h_simdata->sleeping[i] == process) { + h_simdata->sleeping[i] = NULL; + break; + } + } + + if(p_simdata->waiting_task) { + xbt_dynar_foreach(p_simdata->waiting_task->simdata->sleeping,_cursor,proc) { + if(proc==process) + xbt_dynar_remove_at(p_simdata->waiting_task->simdata->sleeping,_cursor,&proc); + } + if(p_simdata->waiting_task->simdata->compute) + surf_workstation_resource->common_public-> + action_free(p_simdata->waiting_task->simdata->compute); + else if (p_simdata->waiting_task->simdata->comm) { + surf_workstation_resource->common_public-> + action_change_state(p_simdata->waiting_task->simdata->comm,SURF_ACTION_FAILED); + surf_workstation_resource->common_public-> + action_free(p_simdata->waiting_task->simdata->comm); + } else { + xbt_die("UNKNOWN STATUS. Please report this bug."); + } + } + + if ((i==msg_global->max_channel) && (process!=MSG_process_self()) && + (!p_simdata->waiting_task)) { + xbt_die("UNKNOWN STATUS. Please report this bug."); + } +*/ + xbt_fifo_remove(msg_global->process_list,process); + SIMIX_process_kill(process->simdata->smx_process); + return; } @@ -111,7 +175,7 @@ void MSG_process_kill(m_process_t process) */ MSG_error_t MSG_process_change_host(m_process_t process, m_host_t host) { - xbt_die("not implemented yet"); + xbt_die("MSG_process_change_host - not implemented yet - maybe useless function"); return MSG_OK; } @@ -168,7 +232,12 @@ m_host_t MSG_process_get_host(m_process_t process) */ m_process_t MSG_process_from_PID(int PID) { + xbt_fifo_item_t i = NULL; + m_process_t process = NULL; + xbt_fifo_foreach(msg_global->process_list,i,process,m_process_t) { + if(MSG_process_get_PID(process) == PID) return process; + } return NULL; } @@ -240,7 +309,14 @@ int MSG_process_self_PPID(void) */ m_process_t MSG_process_self(void) { - return (m_process_t)SIMIX_process_self()->data; + smx_process_t proc = SIMIX_process_self(); + if (proc != NULL) { + return (m_process_t)proc->data; + } + else { + return NULL; + } + } /** \ingroup m_process_management diff --git a/src/msg_simix/msg_simix_task.c b/src/msg_simix/msg_simix_task.c index 1aae241f89..fdbcd25375 100644 --- a/src/msg_simix/msg_simix_task.c +++ b/src/msg_simix/msg_simix_task.c @@ -39,7 +39,7 @@ m_task_t MSG_task_create(const char *name, double compute_duration, double message_size, void *data) { m_task_t task = xbt_new(s_m_task_t,1); - simdata_task_t simdata = task->simdata; + simdata_task_t simdata = xbt_new(s_simdata_task_t,1); task->simdata = simdata; /* Task structure */ task->name = xbt_strdup(name); @@ -54,6 +54,8 @@ m_task_t MSG_task_create(const char *name, double compute_duration, simdata->sender = NULL; simdata->cond = SIMIX_cond_init(); simdata->mutex = SIMIX_mutex_init(); + simdata->compute = NULL; + simdata->comm = NULL; return task; }