- comm->copied = 1;
-
- /* pimple to display the message sizes */
- {
- casted_size = comm->task_size;
- amount = xbt_dicti_get(simix_global->msg_sizes, casted_size);
- amount++;
-
- xbt_dicti_set(simix_global->msg_sizes, casted_size, amount);
- }
-}
-
-/**
- * \brief Return the user data associated to the communication
- * \param comm The communication
- * \return the user data
- */
-XBT_INLINE void *SIMIX_communication_get_data(smx_comm_t comm)
-{
- return comm->data;
-}
-
-XBT_PUBLIC(void *) SIMIX_communication_get_src_buf(smx_comm_t comm)
-{
- return comm->src_buff;
-}
-
-XBT_PUBLIC(void *) SIMIX_communication_get_dst_buf(smx_comm_t comm)
-{
- return comm->dst_buff;
-}
-
-XBT_PUBLIC(size_t) SIMIX_communication_get_src_buf_size(smx_comm_t comm)
-{
- return comm->src_buff_size;
-}
-
-XBT_PUBLIC(size_t) SIMIX_communication_get_dst_buf_size(smx_comm_t comm)
-{
- return *(comm->dst_buff_size);
-}
-
-/******************************************************************************/
-/* Synchronous Communication */
-/******************************************************************************/
-/**
- * \brief Put a send communication request in a rendez-vous point and waits for
- * its completion (blocking)
- * \param rdv The rendez-vous point
- * \param task_size The size of the communication action (for surf simulation)
- * \param rate The rate of the communication action (for surf)
- * \param timeout The timeout used for the waiting the completion
- * \param src_buff The source buffer containing the message to be sent
- * \param src_buff_size The size of the source buffer
- * \param comm_ref The communication object used for the send (useful if someone else wants to cancel this communication afterward)
- * \param data User data associated to the communication object
- * Throws:
- * - host_error if peer failed
- * - timeout_error if communication reached the timeout specified
- * - network_error if network failed or peer issued a timeout
- */
-XBT_INLINE void SIMIX_network_send(smx_rdv_t rdv, double task_size,
- double rate, double timeout,
- void *src_buff, size_t src_buff_size,
- smx_comm_t * comm_ref, void *data)
-{
- xbt_ex_t e;
- smx_comm_t comm = *comm_ref =
- SIMIX_network_isend(rdv, task_size, rate, src_buff, src_buff_size,
- data);
- TRY {
- SIMIX_network_wait(comm, timeout);
- }
- TRY_CLEANUP {
- SIMIX_communication_destroy(comm);
- }
- CATCH(e) {
- RETHROW;
- }
-}
-
-/**
- * \brief Put a receive communication request in a rendez-vous point and waits
- * for its completion (blocking)
- * \param rdv The rendez-vous point
- * \param timeout The timeout used for the waiting the completion
- * \param dst_buff The destination buffer to copy the received message
- * \param src_buff_size The size of the destination buffer
- * \param comm_ref The communication object used for the send (useful if someone else wants to cancel this communication afterward)
- * Throws:
- * - host_error if peer failed
- * - timeout_error if communication reached the timeout specified
- * - network_error if network failed or peer issued a timeout
- */
-XBT_INLINE void SIMIX_network_recv(smx_rdv_t rdv, double timeout,
- void *dst_buff, size_t * dst_buff_size,
- smx_comm_t * comm_ref)
-{
- xbt_ex_t e;
- smx_comm_t comm = *comm_ref =
- (smx_comm_t) SIMIX_network_irecv(rdv, dst_buff, dst_buff_size);
- TRY {
- SIMIX_network_wait(comm, timeout);
- }
- TRY_CLEANUP {
- SIMIX_communication_destroy(comm);
- }
- CATCH(e) {
- RETHROW;
- }
-}
-
-/******************************************************************************/
-/* Asynchronous Communication */
-/******************************************************************************/
-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)
-{
- smx_comm_t comm;
-
- /*If running in model-checking mode then intercept the communication action */
-#ifdef HAVE_MC
- if (_surf_do_model_check)
- MC_trans_intercept_isend(rdv);
-#endif
- /* Look for communication request matching our needs.
- If it is not found then create it and push it into the rendez-vous point */
- comm = SIMIX_rdv_get_request(rdv, comm_recv);
-
- if (!comm) {
- comm = SIMIX_communication_new(comm_send);
- SIMIX_rdv_push(rdv, comm);
- }
-
- /* Setup the communication request */
- comm->src_proc = SIMIX_process_self();
- comm->task_size = task_size;
- comm->rate = rate;
- comm->src_buff = src_buff;
- comm->src_buff_size = src_buff_size;
- comm->data = data;
-
- SIMIX_communication_start(comm);
- return comm;
-}
-
-smx_comm_t SIMIX_network_irecv(smx_rdv_t rdv, void *dst_buff,
- size_t * dst_buff_size)
-{
- smx_comm_t comm;
-
- /*If running in model-checking mode then intercept the communication action */
-#ifdef HAVE_MC
- if (_surf_do_model_check)
- MC_trans_intercept_irecv(rdv);
-#endif
- /* Look for communication request matching our needs.
- * If it is not found then create it and push it into the rendez-vous point
- */
- comm = SIMIX_rdv_get_request(rdv, comm_send);
-
- if (!comm) {
- comm = SIMIX_communication_new(comm_recv);
- SIMIX_rdv_push(rdv, comm);
- }
-
- /* Setup communication request */
- comm->dst_proc = SIMIX_process_self();
- comm->dst_buff = dst_buff;
- comm->dst_buff_size = dst_buff_size;
-
- SIMIX_communication_start(comm);
- return comm;
-}
-
-/** @brief blocks until the communication terminates or the timeout occurs */
-XBT_INLINE void SIMIX_network_wait(smx_comm_t comm, double timeout)
-{
- /*If running in model-checking mode then intercept the communication action */
-#ifdef HAVE_MC
- if (_surf_do_model_check)
- MC_trans_intercept_wait(comm);
-#endif
- SIMIX_communication_use(comm);
- /* Wait for communication completion */
- SIMIX_communication_wait_for_completion(comm, timeout);
-}
-
-/** @Returns whether the (asynchronous) communication is done yet or not */
-XBT_INLINE int SIMIX_network_test(smx_comm_t comm)
-{
- /*If running in model-checking mode then intercept the communication action */
-#ifdef HAVE_MC
- if (_surf_do_model_check)
- MC_trans_intercept_test(comm);
-#endif
-
- /* 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
- *
- * @Returns the rank in the dynar of communication which finished; destroy it after identifying which one it is
- */
-unsigned int SIMIX_network_waitany(xbt_dynar_t comms)
-{
- xbt_dynar_t sems = xbt_dynar_new(sizeof(smx_sem_t), NULL);
- unsigned int cursor, found_comm = -1;
- smx_comm_t comm, comm_finished = NULL;
-
- /*If running in model-checking mode then intercept the communication action */
-#ifdef HAVE_MC
- if (_surf_do_model_check)
- MC_trans_intercept_waitany(comms);
-#endif
- 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);
-
- DEBUG2("Communication %p of communication set %p finished",
- comm_finished, comms);
-
- /* let the regular code deal with the communication end (errors checking and cleanup).
- * A bit of useless work will be done, but that's good for source factorization */
- SIMIX_sem_release_forever(comm_finished->sem);
- SIMIX_communication_use(comm_finished);
- SIMIX_communication_wait_for_completion(comm_finished, -1);
- return found_comm;