Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Functions added.
authordonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 12 Apr 2007 15:23:43 +0000 (15:23 +0000)
committerdonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 12 Apr 2007 15:23:43 +0000 (15:23 +0000)
Bugs corrected.

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

src/include/simix/simix.h
src/msg_simix/msg_simix_global.c
src/msg_simix/msg_simix_gos.c
src/msg_simix/msg_simix_private.h
src/simix/smx_action.c
src/simix/smx_synchro.c

index 83c9f33..08fbfcf 100644 (file)
@@ -12,6 +12,7 @@
 #include "xbt/misc.h"
 #include "xbt/fifo.h"
 #include "simix/datatypes.h"
 #include "xbt/misc.h"
 #include "xbt/fifo.h"
 #include "simix/datatypes.h"
+#include "surf/surf.h"
 
 SG_BEGIN_DECL()
 
 
 SG_BEGIN_DECL()
 
@@ -103,6 +104,7 @@ XBT_PUBLIC(void) SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, doub
 XBT_PUBLIC(void) SIMIX_cond_broadcast(smx_cond_t cond);
 XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond);
 XBT_PUBLIC(void) SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond);
 XBT_PUBLIC(void) SIMIX_cond_broadcast(smx_cond_t cond);
 XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond);
 XBT_PUBLIC(void) SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond);
+XBT_PUBLIC(xbt_fifo_t) SIMIX_cond_get_actions(smx_cond_t cond);
 
 
 /************************** Action handling ************************************/
 
 
 /************************** Action handling ************************************/
@@ -116,6 +118,8 @@ XBT_PUBLIC(void) SIMIX_action_destroy(smx_action_t action);
 XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond);
 XBT_PUBLIC(double) SIMIX_action_get_remains(smx_action_t action);
 
 XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond);
 XBT_PUBLIC(double) SIMIX_action_get_remains(smx_action_t action);
 
+XBT_PUBLIC(e_surf_action_state_t) SIMIX_action_get_state(smx_action_t action);
+
 /*Not implemented yet */
 XBT_PUBLIC(smx_action_t) SIMIX_action_parallel_execute(char * name, 
                                                                                                                                                                                                                        int workstation_nb,      
 /*Not implemented yet */
 XBT_PUBLIC(smx_action_t) SIMIX_action_parallel_execute(char * name, 
                                                                                                                                                                                                                        int workstation_nb,      
index 0296d16..837bef4 100644 (file)
@@ -143,7 +143,7 @@ MSG_error_t MSG_main(void)
                                SIMIX_cond_broadcast(cond);
                        }
                        /* action finished, destroy it */
                                SIMIX_cond_broadcast(cond);
                        }
                        /* action finished, destroy it */
-                       SIMIX_action_destroy(smx_action);
+               //      SIMIX_action_destroy(smx_action);
                }
 
                while ( (smx_action = xbt_fifo_pop(actions_done)) ) {
                }
 
                while ( (smx_action = xbt_fifo_pop(actions_done)) ) {
@@ -153,7 +153,7 @@ MSG_error_t MSG_main(void)
                                SIMIX_cond_broadcast(cond);
                        }
                        /* action finished, destroy it */
                                SIMIX_cond_broadcast(cond);
                        }
                        /* action finished, destroy it */
-                       SIMIX_action_destroy(smx_action);
+                       //SIMIX_action_destroy(smx_action);
                }
        }
        xbt_fifo_free(actions_failed);
                }
        }
        xbt_fifo_free(actions_failed);
index f34fd64..8d3a00e 100644 (file)
@@ -58,6 +58,9 @@ static MSG_error_t __MSG_task_get_with_time_out_from_host(m_task_t * task,
                
                if(max_duration>0) {
                        if(!first_time) {
                
                if(max_duration>0) {
                        if(!first_time) {
+                               SIMIX_mutex_unlock(h->simdata->mutex);
+                               h_simdata->sleeping[channel] = NULL;
+                               SIMIX_cond_destroy(cond);
                                MSG_RETURN(MSG_TRANSFER_FAILURE);
                        }
                }
                                MSG_RETURN(MSG_TRANSFER_FAILURE);
                        }
                }
@@ -70,6 +73,9 @@ static MSG_error_t __MSG_task_get_with_time_out_from_host(m_task_t * task,
                }
                else SIMIX_cond_wait(h_simdata->sleeping[channel],h->simdata->mutex);
 
                }
                else SIMIX_cond_wait(h_simdata->sleeping[channel],h->simdata->mutex);
 
+               if(SIMIX_host_get_state(h_simdata->host)==0)
+      MSG_RETURN(MSG_HOST_FAILURE);
+
                first_time = 0;
        }
        SIMIX_mutex_unlock(h->simdata->mutex);
                first_time = 0;
        }
        SIMIX_mutex_unlock(h->simdata->mutex);
@@ -108,13 +114,32 @@ static MSG_error_t __MSG_task_get_with_time_out_from_host(m_task_t * task,
        if (t->simdata->sender) {
                t->simdata->sender->simdata->waiting_task = NULL;
                /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
        if (t->simdata->sender) {
                t->simdata->sender->simdata->waiting_task = NULL;
                /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
-               t->simdata->comm = NULL;
-               t->simdata->compute = NULL;
+               //t->simdata->comm = NULL;
+               //t->simdata->compute = NULL;
        }
        /* for this process, don't need to change in get function*/
        t->simdata->receiver = NULL;
        SIMIX_mutex_unlock(t_simdata->mutex);
        }
        /* for this process, don't need to change in get function*/
        t->simdata->receiver = NULL;
        SIMIX_mutex_unlock(t_simdata->mutex);
-       MSG_RETURN(MSG_OK);
+
+
+       DEBUG0("GET FREE ACTION");
+       if(SIMIX_action_get_state(t_simdata->comm) == SURF_ACTION_DONE) {
+               //t_simdata->comm = NULL;
+               SIMIX_action_destroy(t_simdata->comm);
+               t_simdata->comm = NULL;
+    MSG_RETURN(MSG_OK);
+       } else if (SIMIX_host_get_state(h_simdata->host)==0) {
+               //t_simdata->comm = NULL;
+               SIMIX_action_destroy(t_simdata->comm);
+               t_simdata->comm = NULL;
+    MSG_RETURN(MSG_HOST_FAILURE);
+  } else { 
+               //t_simdata->comm = NULL;
+               SIMIX_action_destroy(t_simdata->comm);
+               t_simdata->comm = NULL;
+    MSG_RETURN(MSG_TRANSFER_FAILURE);
+  }
+
 }
        
 /** \ingroup msg_gos_functions
 }
        
 /** \ingroup msg_gos_functions
@@ -416,10 +441,22 @@ MSG_error_t MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
        process->simdata->waiting_task = task;
        if (max_duration >0) {
                SIMIX_cond_wait_timeout(task->simdata->cond,task->simdata->mutex,max_duration);
        process->simdata->waiting_task = task;
        if (max_duration >0) {
                SIMIX_cond_wait_timeout(task->simdata->cond,task->simdata->mutex,max_duration);
+               /* verify if the timeout happened and the communication didn't started yet */
+               if (task->simdata->comm==NULL) {
+                       task->simdata->using--;
+                       process->simdata->waiting_task = NULL;
+                       if (task->simdata->receiver) {
+                               task->simdata->receiver->simdata->waiting_task = NULL;
+                       }
+                       task->simdata->sender = NULL;
+                       SIMIX_mutex_unlock(task->simdata->mutex);
+                       MSG_RETURN(MSG_TRANSFER_FAILURE);
+               }
        }
        else {
                SIMIX_cond_wait(task->simdata->cond,task->simdata->mutex);
        }
        }
        else {
                SIMIX_cond_wait(task->simdata->cond,task->simdata->mutex);
        }
+
        DEBUG1("Action terminated %s",task->name);    
        task->simdata->using--;
        process->simdata->waiting_task = NULL;
        DEBUG1("Action terminated %s",task->name);    
        task->simdata->using--;
        process->simdata->waiting_task = NULL;
@@ -427,15 +464,19 @@ MSG_error_t MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
        if (task->simdata->receiver) {
                task->simdata->receiver->simdata->waiting_task = NULL;
                /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
        if (task->simdata->receiver) {
                task->simdata->receiver->simdata->waiting_task = NULL;
                /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
-               task->simdata->comm = NULL;
-               task->simdata->compute = NULL;
+       //      task->simdata->comm = NULL;
+               //task->simdata->compute = NULL;
        }
        }
-       /* for this process, don't need to change in get function*/
        task->simdata->sender = NULL;
        SIMIX_mutex_unlock(task->simdata->mutex);
 
        task->simdata->sender = NULL;
        SIMIX_mutex_unlock(task->simdata->mutex);
 
-
-       MSG_RETURN(MSG_OK);
+       if(SIMIX_action_get_state(task->simdata->comm) == SURF_ACTION_DONE) {
+    MSG_RETURN(MSG_OK);
+       } else if (SIMIX_host_get_state(local_host->simdata->host)==0) {
+    MSG_RETURN(MSG_HOST_FAILURE);
+  } else { 
+    MSG_RETURN(MSG_TRANSFER_FAILURE);
+  }
 }
 
 /** \ingroup msg_gos_functions
 }
 
 /** \ingroup msg_gos_functions
@@ -518,13 +559,29 @@ MSG_error_t MSG_task_execute(m_task_t task)
        SIMIX_cond_wait(simdata->cond, simdata->mutex);
        self->simdata->waiting_task = NULL;
 
        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--;
        SIMIX_mutex_unlock(simdata->mutex);
   simdata->using--;
-       MSG_RETURN(MSG_OK);
+
+       if(SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) {
+               /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+               SIMIX_action_destroy(task->simdata->compute);
+               simdata->computation_amount = 0.0;
+               simdata->comm = NULL;
+               simdata->compute = NULL;
+    MSG_RETURN(MSG_OK);
+       } else if (SIMIX_host_get_state(SIMIX_host_self())==0) {
+               /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+               SIMIX_action_destroy(task->simdata->compute);
+               simdata->comm = NULL;
+               simdata->compute = NULL;
+    MSG_RETURN(MSG_HOST_FAILURE);
+  } else { 
+               /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+               SIMIX_action_destroy(task->simdata->compute);
+               simdata->comm = NULL;
+               simdata->compute = NULL;
+    MSG_RETURN(MSG_TASK_CANCELLED);
+  }
 }
 
 
 }
 
 
@@ -589,11 +646,6 @@ m_task_t MSG_parallel_task_create(const char *name,
 }
 
 
 }
 
 
-static void __MSG_parallel_task_execute(m_process_t process, m_task_t task)
-{
-       return;
-}
-
 MSG_error_t MSG_parallel_task_execute(m_task_t task)
 {
        simdata_task_t simdata = NULL;
 MSG_error_t MSG_parallel_task_execute(m_task_t task)
 {
        simdata_task_t simdata = NULL;
@@ -617,15 +669,31 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task)
        SIMIX_cond_wait(simdata->cond, simdata->mutex);
        self->simdata->waiting_task = NULL;
 
        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--;
 
        SIMIX_mutex_unlock(simdata->mutex);
   simdata->using--;
-       MSG_RETURN(MSG_OK);
-       xbt_die("not implemented yet");
-  return MSG_OK;  
+
+       if(SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) {
+               /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+               SIMIX_action_destroy(task->simdata->compute);
+               simdata->computation_amount = 0.0;
+               simdata->comm = NULL;
+               simdata->compute = NULL;
+    MSG_RETURN(MSG_OK);
+       } else if (SIMIX_host_get_state(SIMIX_host_self())==0) {
+               /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+               SIMIX_action_destroy(task->simdata->compute);
+               simdata->comm = NULL;
+               simdata->compute = NULL;
+    MSG_RETURN(MSG_HOST_FAILURE);
+  } else { 
+               /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
+               SIMIX_action_destroy(task->simdata->compute);
+               simdata->comm = NULL;
+               simdata->compute = NULL;
+    MSG_RETURN(MSG_TASK_CANCELLED);
+  }    
+
 }
 
 
 }
 
 
@@ -659,6 +727,18 @@ MSG_error_t MSG_process_sleep(double nb_sec)
        SIMIX_cond_destroy(cond);
        SIMIX_mutex_destroy(mutex);
 
        SIMIX_cond_destroy(cond);
        SIMIX_mutex_destroy(mutex);
 
+  if(SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) {
+    if(SIMIX_host_get_state(SIMIX_host_self()) == SURF_CPU_OFF) {
+                       SIMIX_action_destroy(act_sleep);
+      MSG_RETURN(MSG_HOST_FAILURE);
+    }
+  }
+       else {
+               SIMIX_action_destroy(act_sleep);
+               MSG_RETURN(MSG_HOST_FAILURE);
+       }
+
+
        MSG_RETURN(MSG_OK);
 }
 
        MSG_RETURN(MSG_OK);
 }
 
index 897daf7..4054b06 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include "msg/msg.h"
 #include "simix/simix.h"
 #include <stdio.h>
 #include "msg/msg.h"
 #include "simix/simix.h"
+#include "surf/surf.h"
 #include "xbt/fifo.h"
 #include "xbt/dynar.h"
 #include "xbt/swag.h"
 #include "xbt/fifo.h"
 #include "xbt/dynar.h"
 #include "xbt/swag.h"
index d20336a..8e7124a 100644 (file)
@@ -225,3 +225,9 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int workstation_nb, void
        return act;
 }
 
        return act;
 }
 
+e_surf_action_state_t SIMIX_action_get_state(smx_action_t action)
+{
+  xbt_assert0((action != NULL), "Invalid parameter");
+       return surf_workstation_resource->common_public->action_get_state(action->simdata->surf_action);
+
+}
index f2feb6b..4e71510 100644 (file)
@@ -199,6 +199,11 @@ void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex)
        return;
 }
 
        return;
 }
 
+xbt_fifo_t SIMIX_cond_get_actions(smx_cond_t cond)
+{
+       xbt_assert0((cond != NULL), "Invalid parameters");
+       return cond->actions;
+}
 
 void __SIMIX_cond_wait(smx_cond_t cond)
 {
 
 void __SIMIX_cond_wait(smx_cond_t cond)
 {
@@ -238,8 +243,12 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_durat
                act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration);
                SIMIX_register_action_to_condition(act_sleep,cond);
                SIMIX_register_condition_to_action(act_sleep,cond);
                act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration);
                SIMIX_register_action_to_condition(act_sleep,cond);
                SIMIX_register_condition_to_action(act_sleep,cond);
+               __SIMIX_cond_wait(cond);
+               xbt_fifo_remove(act_sleep->cond_list,cond);
+               SIMIX_action_destroy(act_sleep);
        }
        }
-       __SIMIX_cond_wait(cond);
+       else
+               __SIMIX_cond_wait(cond);
 
        /* get the mutex again */
        SIMIX_mutex_lock(cond->mutex);
 
        /* get the mutex again */
        SIMIX_mutex_lock(cond->mutex);