Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Functions implemented, task_execute tested with a small example.
authordonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 27 Mar 2007 13:09:37 +0000 (13:09 +0000)
committerdonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 27 Mar 2007 13:09:37 +0000 (13:09 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3364 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/msg_simix/msg_simix_deployment.c
src/msg_simix/msg_simix_global.c
src/msg_simix/msg_simix_gos.c
src/msg_simix/msg_simix_private.h
src/msg_simix/msg_simix_process.c
src/msg_simix/msg_simix_task.c

index b7e14f4..6f5487a 100644 (file)
  */
 void MSG_launch_application(const char *file) 
 {
  */
 void MSG_launch_application(const char *file) 
 {
+
   xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_launch_application.");
   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;
        SIMIX_launch_application(file);
 
        return;
index 1a46780..b7a7664 100644 (file)
@@ -170,8 +170,20 @@ MSG_error_t MSG_main(void)
  */
 int MSG_process_killall(int reset_PIDs)
 {
  */
 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
 }
 
 /** \ingroup msg_simulation
index 3f6cc38..583266b 100644 (file)
@@ -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_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)
 }
 
 void __MSG_task_execute(m_process_t process, m_task_t task)
index 069086b..dbc1a64 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef METASIMGRID_PRIVATE_H
 #define METASIMGRID_PRIVATE_H
 
 #ifndef METASIMGRID_PRIVATE_H
 #define METASIMGRID_PRIVATE_H
 
+#include <stdio.h>
 #include "msg/msg.h"
 #include "simix/simix.h"
 #include "xbt/fifo.h"
 #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 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_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);
                                   "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);
 
 
 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
 
 
 #endif
index b57bc36..789862b 100644 (file)
@@ -32,7 +32,17 @@ m_process_t MSG_process_create(const char *name,
 
 static void MSG_process_cleanup(void *arg)
 {
 
 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;
 }
 
        return;
 }
 
@@ -60,13 +70,23 @@ static void MSG_process_cleanup(void *arg)
  * \see m_process_t
  * \return The new corresponding object.
  */
  * \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);
 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 */
   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,
   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);
 
        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;
 
   process->simdata = simdata;
   process->data = data;
 
+       xbt_fifo_unshift(msg_global->process_list, process); 
+
   return 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)
 {
  */
 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; i<msg_global->max_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;
 }
 
        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)
 {
  */
 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;
 }
 
   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)
 {
  */
 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;
 }
 
   return NULL;
 }
 
@@ -240,7 +309,14 @@ int MSG_process_self_PPID(void)
  */
 m_process_t MSG_process_self(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
 }
 
 /** \ingroup m_process_management
index 1aae241..fdbcd25 100644 (file)
@@ -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);
                         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);
   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->sender = NULL;
        simdata->cond = SIMIX_cond_init();
        simdata->mutex = SIMIX_mutex_init();
+       simdata->compute = NULL;
+       simdata->comm = NULL;
 
   return task;
 }
 
   return task;
 }