Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
get/set for CommImpl::type
[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_       = 0.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   static void set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t));
38
39   CommImpl() = default;
40   CommImpl(s4u::Host* from, s4u::Host* to, double bytes);
41
42   CommImpl& set_type(CommImplType type);
43   CommImplType get_type() const { return type_; }
44   CommImpl& set_size(double size);
45   CommImpl& set_src_buff(unsigned char* buff, size_t size);
46   CommImpl& set_dst_buff(unsigned char* buff, size_t* size);
47   CommImpl& set_rate(double rate);
48   CommImpl& set_mailbox(MailboxImpl* mbox);
49   CommImpl& detach();
50
51   double get_rate() const { return rate_; }
52   MailboxImpl* get_mailbox() const { return mbox_; }
53   long get_mailbox_id() const { return mbox_id_; }
54   bool detached() const { return detached_; }
55
56   std::vector<s4u::Link*> get_traversed_links() const;
57   void copy_data();
58
59   static ActivityImplPtr isend(actor::CommIsendSimcall* observer);
60   static ActivityImplPtr irecv(actor::CommIrecvSimcall* observer);
61
62   bool test(actor::ActorImpl* issuer) override;
63   void wait_for(actor::ActorImpl* issuer, double timeout) override;
64   static void wait_any_for(actor::ActorImpl* issuer, const std::vector<CommImpl*>& comms, double timeout);
65
66   CommImpl* start();
67   void suspend() override;
68   void resume() override;
69   void cancel() override;
70   void post() override;
71   void set_exception(actor::ActorImpl* issuer) override;
72   void finish() override;
73
74
75 #if SIMGRID_HAVE_MC
76   MailboxImpl* mbox_cpy = nullptr; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
77                                      (comm.mbox set to nullptr when the communication is removed from the mailbox
78                                      (used as garbage collector)) */
79 #endif
80
81   void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
82   bool (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
83 looking if a given communication matches my needs. For that, myself must match the
84 expectations of the other side, too. See  */
85   void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr;
86
87   /* Surf action data */
88   resource::Action* src_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
89   resource::Action* dst_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
90   actor::ActorImplPtr src_actor_ = nullptr;
91   actor::ActorImplPtr dst_actor_ = nullptr;
92
93   /* Data to be transferred */
94   unsigned char* src_buff_ = nullptr;
95   unsigned char* dst_buff_ = nullptr;
96   size_t src_buff_size_    = 0;
97   size_t* dst_buff_size_   = nullptr;
98
99   void* src_data_ = nullptr; /* User data associated to the communication */
100   void* dst_data_ = nullptr;
101   static xbt::signal<void(CommImpl const&)> on_start;
102   static xbt::signal<void(CommImpl const&)> on_completion;
103 };
104 } // namespace activity
105 } // namespace kernel
106 } // namespace simgrid
107
108 #endif