X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/053352ba13737467be4fc66c9a1c92bd84118bee..8f47d235ddc4c9e9d4ca548fc157fbf28f93a7a9:/src/simix/smx_network.c diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index 465fba78cd..573cabd16b 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -310,6 +310,9 @@ static inline void SIMIX_communication_wait_for_completion(smx_comm_t comm, doub THROW0(network_error, 0, "Remote peer failed"); } + /* Copy network data */ + SIMIX_network_copy_data(comm); + SIMIX_communication_destroy(comm); } @@ -358,16 +361,16 @@ void SIMIX_network_copy_data(smx_comm_t comm) { size_t buff_size = comm->src_buff_size; + /* If there is no data to be copy then return */ + if(!comm->src_buff || !comm->dst_buff) + return; + DEBUG6("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", comm, comm->src_proc->smx_host->name, comm->src_buff, comm->dst_proc->smx_host->name, comm->dst_buff, buff_size); - /* If there is no data to be copy then return */ - if(!comm->src_buff || !comm->dst_buff) - return; - /* Copy at most dst_buff_size bytes of the message to receiver's buffer */ if (comm->dst_buff_size) buff_size = MIN(buff_size,*(comm->dst_buff_size)); @@ -380,6 +383,11 @@ void SIMIX_network_copy_data(smx_comm_t comm) return; (*SIMIX_network_copy_data_callback)(comm, buff_size); + /* Set the buffers to null so we copy data only once */ + /* (this function might be called from both communication ends)*/ + comm->src_buff = NULL; + comm->dst_buff = NULL; + /* pimple to display the message sizes */ { if (msg_sizes == NULL) @@ -551,7 +559,14 @@ XBT_INLINE int SIMIX_network_test(smx_comm_t comm) { MC_create_transition(mc_test, SIMIX_process_self(), comm->rdv, comm); SIMIX_process_yield(); } - return comm->sem?SIMIX_sem_would_block(comm->sem):0; + + /* Copy data if the communication is done */ + if(comm->sem && !SIMIX_sem_would_block(comm->sem)){ + /* Copy network data */ + SIMIX_network_copy_data(comm); + return TRUE; + } + return FALSE; } /** @brief wait for the completion of any communication of a set @@ -569,33 +584,17 @@ unsigned int SIMIX_network_waitany(xbt_dynar_t comms) { SIMIX_process_yield(); } - xbt_dynar_foreach(comms,cursor,comm){ + xbt_dynar_foreach(comms,cursor,comm) xbt_dynar_push(sems,&(comm->sem)); - } DEBUG1("Waiting for the completion of communication set %p", comms); found_comm = SIMIX_sem_acquire_any(sems); + xbt_dynar_free_container(&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); - - /* Make sure that everyone sleeping on that semaphore is awake, - * and that nobody will ever block on it */ - SIMIX_sem_release_forever(comm_finished->sem); - - /* Check for errors */ - if(!SIMIX_host_get_state(SIMIX_host_self())){ - if(comm_finished->rdv) - SIMIX_rdv_remove(comm_finished->rdv, comm_finished); - SIMIX_communication_destroy(comm_finished); - THROW0(host_error, 0, "Host failed"); - } else if (SIMIX_action_get_state(comm_finished->act) == SURF_ACTION_FAILED){ - SIMIX_communication_destroy(comm_finished); - THROW0(network_error, 0, "Link failure"); - } - SIMIX_communication_destroy(comm_finished); - + /* Check for errors and cleanup the comm */ + SIMIX_communication_wait_for_completion(comm_finished,-1); return found_comm; }