+static void (*SIMIX_network_copy_data_callback)(smx_comm_t, size_t) = &SIMIX_network_copy_pointer_callback;
+
+void SIMIX_network_set_copy_data_callback(void (*callback)(smx_comm_t, size_t)) {
+ SIMIX_network_copy_data_callback = callback;
+}
+
+void SIMIX_network_copy_pointer_callback(smx_comm_t comm, size_t buff_size) {
+ xbt_assert1((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)",buff_size);
+ *(void**)(comm->dst_buff) = comm->src_buff;
+}
+
+void SIMIX_network_copy_buffer_callback(smx_comm_t comm, size_t buff_size) {
+ memcpy(comm->dst_buff, comm->src_buff, buff_size);
+}
+
+/**
+ * \brief Copy the communication data from the sender's buffer to the receiver's one
+ * \param comm The communication
+ */
+void SIMIX_network_copy_data(smx_comm_t comm)
+{
+ size_t buff_size = comm->src_buff_size;
+ uintptr_t casted_size = 0;
+ uintptr_t amount = 0;
+ /* If there is no data to be copy then return */
+ if(!comm->src_buff || !comm->dst_buff || comm->copied == 1)
+ 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);
+
+ /* 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));
+
+ /* Update the receiver's buffer size to the copied amount */
+ if (comm->dst_buff_size)
+ *comm->dst_buff_size = buff_size;
+
+ if(buff_size == 0)
+ return;
+ (*SIMIX_network_copy_data_callback)(comm, buff_size);
+
+ /* Set the copied flag so we copy data only once */
+ /* (this function might be called from both communication ends)*/
+ comm->copied = 1;
+
+ /* pimple to display the message sizes */
+ {
+ if (msg_sizes == NULL)
+ msg_sizes = xbt_dict_new();
+ casted_size = comm->task_size;
+ amount = xbt_dicti_get(msg_sizes, casted_size);
+ amount++;
+
+ xbt_dicti_set(msg_sizes,casted_size, amount);
+ }
+}
+#include "xbt.h"
+/* pimple to display the message sizes */
+void SIMIX_message_sizes_output(const char *filename) {
+ uintptr_t key = 0;
+ uintptr_t data = 0;
+ xbt_dict_cursor_t cursor;
+ FILE * out = NULL;
+ out = fopen(filename,"w");
+ xbt_assert1(out,"Cannot open file %s",filename);
+
+ xbt_dict_foreach(msg_sizes,cursor,key,data) {
+ fprintf(out,"%zu %zu\n",key,data);
+ }
+ fclose(out);
+}