Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix: default rate (bound) for comms is -1 not 0
[simgrid.git] / src / kernel / activity / CommImpl.hpp
1 /* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_KERNEL_ACTIVITY_COMM_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_COMM_HPP
8
9 #include "src/kernel/activity/ActivityImpl.hpp"
10 #include "src/kernel/actor/ActorImpl.hpp"
11 #include "src/kernel/actor/CommObserver.hpp"
12
13 namespace simgrid {
14 namespace kernel {
15 namespace activity {
16
17 enum class CommImplType { SEND, RECEIVE };
18
19 class XBT_PUBLIC CommImpl : public ActivityImpl_T<CommImpl> {
20   ~CommImpl() override;
21   void cleanup_surf();
22
23   static void (*copy_data_callback_)(CommImpl*, void*, size_t);
24
25   double rate_       = -1.0;
26   double size_       = 0.0;
27   bool detached_     = false;   /* If detached or not */
28   bool copied_       = false;   /* whether the data were already copied */
29   MailboxImpl* mbox_ = nullptr; /* Rendez-vous where the comm is queued. nullptr once the comm is matched with both a
30                                    sender and receiver */
31   long mbox_id_      = -1;      /* ID of the rendez-vous where the comm was first queued (for MC) */
32   s4u::Host* from_   = nullptr; /* Pre-determined only for direct host-to-host communications */
33   s4u::Host* to_     = nullptr; /* Otherwise, computed at start() time from the actors */
34   CommImplType type_ = CommImplType::SEND; /* Type of the communication (SEND or RECEIVE) */
35
36 public:
37   CommImpl() = default;
38
39   static void set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t));
40
41   CommImpl& set_type(CommImplType type);
42   CommImplType get_type() const { return type_; }
43   CommImpl& set_source(s4u::Host* from);
44   s4u::Host* get_source() const { return from_; }
45   CommImpl& set_destination(s4u::Host* to);
46   s4u::Host* get_destination() const { return to_; }
47   CommImpl& set_size(double size);
48   CommImpl& set_src_buff(unsigned char* buff, size_t size);
49   CommImpl& set_dst_buff(unsigned char* buff, size_t* size);
50   CommImpl& set_rate(double rate);
51   CommImpl& set_mailbox(MailboxImpl* mbox);
52   CommImpl& detach();
53
54   double get_rate() const { return rate_; }
55   MailboxImpl* get_mailbox() const { return mbox_; }
56   long get_mailbox_id() const { return mbox_id_; }
57   bool is_detached() const { return detached_; }
58   bool is_assigned() const { return (to_ != nullptr && from_ != nullptr); }
59
60   std::vector<s4u::Link*> get_traversed_links() const;
61   void copy_data();
62
63   static ActivityImplPtr isend(actor::CommIsendSimcall* observer);
64   static ActivityImplPtr irecv(actor::CommIrecvSimcall* observer);
65
66   bool test(actor::ActorImpl* issuer) override;
67   void wait_for(actor::ActorImpl* issuer, double timeout) override;
68   static void wait_any_for(actor::ActorImpl* issuer, const std::vector<CommImpl*>& comms, double timeout);
69
70   CommImpl* start();
71   void suspend() override;
72   void resume() override;
73   void cancel() override;
74   void post() override;
75   void set_exception(actor::ActorImpl* issuer) override;
76   void finish() override;
77
78   void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
79   bool (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
80 looking if a given communication matches my needs. For that, myself must match the
81 expectations of the other side, too. See  */
82   void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr;
83
84   /* Surf action data */
85   resource::Action* src_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
86   resource::Action* dst_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
87   actor::ActorImplPtr src_actor_ = nullptr;
88   actor::ActorImplPtr dst_actor_ = nullptr;
89
90   /* Data to be transferred */
91   unsigned char* src_buff_ = nullptr;
92   unsigned char* dst_buff_ = nullptr;
93   size_t src_buff_size_    = 0;
94   size_t* dst_buff_size_   = nullptr;
95
96   void* src_data_ = nullptr; /* User data associated to the communication */
97   void* dst_data_ = nullptr;
98   static xbt::signal<void(CommImpl const&)> on_start;
99   static xbt::signal<void(CommImpl const&)> on_completion;
100 };
101 } // namespace activity
102 } // namespace kernel
103 } // namespace simgrid
104
105 #endif