Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the waitany functions on semaphore and communications to return the rank of...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 20 Oct 2009 13:10:35 +0000 (13:10 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 20 Oct 2009 13:10:35 +0000 (13:10 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6811 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/include/simix/simix.h
src/simix/smx_network.c
src/simix/smx_synchro.c

index 6e9d360..82785d0 100644 (file)
@@ -148,7 +148,7 @@ XBT_PUBLIC(void) SIMIX_sem_release_forever(smx_sem_t sem);
 XBT_PUBLIC(int) SIMIX_sem_would_block(smx_sem_t sem);
 XBT_PUBLIC(void) SIMIX_sem_acquire(smx_sem_t sem);
 XBT_PUBLIC(void) SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration);
 XBT_PUBLIC(int) SIMIX_sem_would_block(smx_sem_t sem);
 XBT_PUBLIC(void) SIMIX_sem_acquire(smx_sem_t sem);
 XBT_PUBLIC(void) SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration);
-XBT_PUBLIC(smx_sem_t) SIMIX_sem_acquire_any(xbt_dynar_t sems);
+XBT_PUBLIC(unsigned int) SIMIX_sem_acquire_any(xbt_dynar_t sems);
 
 
 /************************** Action handling ************************************/
 
 
 /************************** Action handling ************************************/
@@ -218,7 +218,7 @@ XBT_PUBLIC(void) SIMIX_network_recv(smx_rdv_t rdv, double timeout, void *dst_buf
 XBT_PUBLIC(smx_comm_t) SIMIX_network_isend(smx_rdv_t rdv, double task_size, double rate,
                                            void *src_buff, size_t src_buff_size, void *data);
 XBT_PUBLIC(smx_comm_t) SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size);
 XBT_PUBLIC(smx_comm_t) SIMIX_network_isend(smx_rdv_t rdv, double task_size, double rate,
                                            void *src_buff, size_t src_buff_size, void *data);
 XBT_PUBLIC(smx_comm_t) SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size);
-XBT_PUBLIC(smx_comm_t) SIMIX_network_waitany(xbt_dynar_t comms);
+XBT_PUBLIC(unsigned int) SIMIX_network_waitany(xbt_dynar_t comms);
 XBT_PUBLIC(void) SIMIX_network_wait(smx_comm_t comm, double timeout);
 XBT_PUBLIC(int) SIMIX_network_test(smx_comm_t comm);
 
 XBT_PUBLIC(void) SIMIX_network_wait(smx_comm_t comm, double timeout);
 XBT_PUBLIC(int) SIMIX_network_test(smx_comm_t comm);
 
index 0f2bd0b..7008ec3 100644 (file)
@@ -446,13 +446,12 @@ int SIMIX_network_test(smx_comm_t comm) {
 
 /** @brief wait for the completion of any communication of a set
  *
 
 /** @brief wait for the completion of any communication of a set
  *
- *  @Returns the communication which finished, destroy it after identifying which one it is (not removed from the dynar)
+ *  @Returns the rank in the dynar of communication which finished; destroy it after identifying which one it is
  */
  */
-smx_comm_t SIMIX_network_waitany(xbt_dynar_t comms) {
+unsigned int SIMIX_network_waitany(xbt_dynar_t comms) {
   xbt_dynar_t sems = xbt_dynar_new(sizeof(smx_sem_t),NULL);
   xbt_dynar_t sems = xbt_dynar_new(sizeof(smx_sem_t),NULL);
-  unsigned int cursor;
+  unsigned int cursor, found_comm=-1;
   smx_comm_t comm,comm_finished=NULL;
   smx_comm_t comm,comm_finished=NULL;
-  smx_sem_t sem;
 
   xbt_dynar_foreach(comms,cursor,comm){
     xbt_dynar_push(sems,&(comm->sem));
 
   xbt_dynar_foreach(comms,cursor,comm){
     xbt_dynar_push(sems,&(comm->sem));
@@ -460,13 +459,9 @@ smx_comm_t SIMIX_network_waitany(xbt_dynar_t comms) {
 
   DEBUG1("Waiting for the completion of communication set %p", comms);
 
 
   DEBUG1("Waiting for the completion of communication set %p", comms);
 
-  sem = SIMIX_sem_acquire_any(sems);
-  xbt_dynar_foreach(comms,cursor,comm){
-    if (comm->sem == sem) {
-      comm_finished = comm;
-    }
-  }
-  xbt_assert0(comm_finished,"Cannot find which communication finished");
+  found_comm = SIMIX_sem_acquire_any(sems);
+  xbt_assert0(found_comm!=-1,"Cannot find which communication finished");
+  xbt_dynar_get_cpy(comms,found_comm,&comm_finished);
 
   DEBUG1("Communication %p complete! Let's check for errors", comm_finished);
 
 
   DEBUG1("Communication %p complete! Let's check for errors", comm_finished);
 
@@ -474,7 +469,7 @@ smx_comm_t SIMIX_network_waitany(xbt_dynar_t comms) {
    * and that nobody will ever block on it */
   SIMIX_sem_release_forever(comm_finished->sem);
 
    * and that nobody will ever block on it */
   SIMIX_sem_release_forever(comm_finished->sem);
 
-  /* Check for errors other than timeouts (they are catched above) */
+  /* Check for errors */
   if(!SIMIX_host_get_state(SIMIX_host_self())){
     if(comm_finished->rdv)
       SIMIX_rdv_remove(comm_finished->rdv, comm_finished);
   if(!SIMIX_host_get_state(SIMIX_host_self())){
     if(comm_finished->rdv)
       SIMIX_rdv_remove(comm_finished->rdv, comm_finished);
@@ -485,5 +480,5 @@ smx_comm_t SIMIX_network_waitany(xbt_dynar_t comms) {
     THROW0(network_error, 0, "Link failure");
   }
 
     THROW0(network_error, 0, "Link failure");
   }
 
-  return comm_finished;
+  return found_comm;
 }
 }
index 4b23875..42d67bc 100644 (file)
@@ -499,11 +499,11 @@ void SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration) {
  * If any of the semaphores has some more capacity, it gets decreased.
  * If not, blocks until the capacity of one of the semaphores becomes more friendly.
  *
  * If any of the semaphores has some more capacity, it gets decreased.
  * If not, blocks until the capacity of one of the semaphores becomes more friendly.
  *
- * \return the semaphore which just got locked from the set (it's not removed from the set).
+ * \return the rank in the dynar of the semaphore which just got locked from the set
  */
  */
-smx_sem_t SIMIX_sem_acquire_any(xbt_dynar_t sems) {
-  smx_sem_t sem,result=NULL;
-  unsigned int counter;
+unsigned int SIMIX_sem_acquire_any(xbt_dynar_t sems) {
+  smx_sem_t sem;
+  unsigned int counter,result=-1;
   smx_action_t act_sleep;
   smx_process_t self = SIMIX_process_self();
 
   smx_action_t act_sleep;
   smx_process_t self = SIMIX_process_self();
 
@@ -514,7 +514,7 @@ smx_sem_t SIMIX_sem_acquire_any(xbt_dynar_t sems) {
   xbt_dynar_foreach(sems,counter,sem) {
     if (!SIMIX_sem_would_block(sem))
       SIMIX_sem_acquire(sem);
   xbt_dynar_foreach(sems,counter,sem) {
     if (!SIMIX_sem_would_block(sem))
       SIMIX_sem_acquire(sem);
-    return sem;
+    return counter;
   }
 
   /* Always create an action null in case there is a host failure */
   }
 
   /* Always create an action null in case there is a host failure */
@@ -538,11 +538,11 @@ smx_sem_t SIMIX_sem_acquire_any(xbt_dynar_t sems) {
     if (xbt_swag_belongs(self,sem->sleeping))
       xbt_swag_remove(self,sem->sleeping);
     else {
     if (xbt_swag_belongs(self,sem->sleeping))
       xbt_swag_remove(self,sem->sleeping);
     else {
-      xbt_assert0(!result,"More than one semaphore unlocked us. Dunno what to do");
-      result = sem;
+      xbt_assert0(result==-1,"More than one semaphore unlocked us. Dunno what to do");
+      result = counter;
     }
   }
     }
   }
-  xbt_assert0(result,"Cannot find which semaphore unlocked me!");
+  xbt_assert0(counter!=-1,"Cannot find which semaphore unlocked me!");
 
   /* Destroy the waiting action */
   self->waiting_action = NULL;
 
   /* Destroy the waiting action */
   self->waiting_action = NULL;