Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merging changes done by Steven, Samuel and Luka, regarding simulation of StarPU-MPI
[simgrid.git] / include / simgrid / s4u / comm.hpp
1 /* Copyright (c) 2006-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_S4U_COMM_HPP
8 #define SIMGRID_S4U_COMM_HPP
9
10 #include <xbt/base.h>
11 #include <simgrid/s4u/async.hpp>
12 #include <simgrid/s4u/mailbox.hpp>
13
14 namespace simgrid {
15 namespace s4u {
16
17 class Mailbox;
18
19 /** @brief Communication async
20  *
21  * Represents all asynchronous communications, that you can test or wait onto.
22  */
23 XBT_PUBLIC_CLASS Comm : public Async {
24         Comm() : Async() {}
25 public:
26         virtual ~Comm();
27
28 public:
29         /** Creates (but don't start) an async send to the mailbox #dest */
30         static Comm &send_init(Actor *sender, Mailbox &dest);
31         /** Creates and start an async send to the mailbox #dest */
32         static Comm &send_async(s4u::Actor *sender, Mailbox &dest, void *data, int simulatedByteAmount);
33     /** Creates (but don't start) an async recv onto the mailbox #from */
34         static Comm &recv_init(s4u::Actor *receiver, Mailbox &from);
35         /** Creates and start an async recv to the mailbox #from */
36         static Comm &recv_async(s4u::Actor *receiver, Mailbox &from, void **data);
37
38         void start() override;
39         void wait() override;
40         void wait(double timeout) override;
41
42 private:
43         double p_rate=-1;
44 public:
45         /** Sets the maximal communication rate (in byte/sec). Must be done before start */
46         void setRate(double rate);
47
48 private:
49         void *p_dstBuff = NULL;
50         size_t p_dstBuffSize = 0;
51         void *p_srcBuff = NULL;
52         size_t p_srcBuffSize = sizeof(void*);
53 public:
54         /** Specify the data to send */
55         void setSrcData(void * buff);
56         /** Specify the size of the data to send */
57         void setSrcDataSize(size_t size);
58         /** Specify the data to send and its size */
59         void setSrcData(void * buff, size_t size);
60
61         /** Specify where to receive the data */
62         void setDstData(void ** buff);
63         /** Specify the buffer in which the data should be received */
64         void setDstData(void ** buff, size_t size);
65         /** Retrieve the size of the received data */
66         size_t getDstDataSize();
67
68
69 private: /* FIXME: expose these elements in the API */
70         int p_detached = 0;
71     int (*p_matchFunction)(void *, void *, smx_synchro_t) = NULL;
72     void (*p_cleanFunction)(void *) = NULL;
73     void (*p_copyDataFunction)(smx_synchro_t, void*, size_t) = NULL;
74
75 private:
76         Actor *p_sender = NULL;
77         Actor *p_receiver = NULL;
78         Mailbox *p_mailbox = NULL;
79 };
80
81 }} // namespace simgrid::s4u
82
83 #endif /* SIMGRID_S4U_COMM_HPP */