Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define CommImpl::test().
[simgrid.git] / src / kernel / activity / CommImpl.hpp
1 /* Copyright (c) 2007-2021. 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 "surf/surf.hpp"
12
13
14 namespace simgrid {
15 namespace kernel {
16 namespace activity {
17
18 class XBT_PUBLIC CommImpl : public ActivityImpl_T<CommImpl> {
19   ~CommImpl() override;
20   void cleanup_surf();
21
22   static void (*copy_data_callback_)(CommImpl*, void*, size_t);
23
24   double rate_       = 0.0;
25   double size_       = 0.0;
26   bool detached_     = false;   /* If detached or not */
27   bool copied_       = false;   /* whether the data were already copied */
28   MailboxImpl* mbox_ = nullptr; /* Rendez-vous where the comm is queued */
29   s4u::Host* from_   = nullptr; /* Pre-determined only for direct host-to-host communications */
30   s4u::Host* to_     = nullptr; /* Otherwise, computed at start() time from the actors */
31
32 public:
33   enum class Type { SEND, RECEIVE };
34
35   static void set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t));
36
37   explicit CommImpl(Type type) : type_(type) {}
38   CommImpl(s4u::Host* from, s4u::Host* to, double bytes);
39
40   CommImpl& set_size(double size);
41   CommImpl& set_src_buff(unsigned char* buff, size_t size);
42   CommImpl& set_dst_buff(unsigned char* buff, size_t* size);
43   CommImpl& set_rate(double rate);
44   CommImpl& set_mailbox(MailboxImpl* mbox);
45   CommImpl& detach();
46
47   double get_rate() const { return rate_; }
48   MailboxImpl* get_mailbox() const { return mbox_; }
49   bool detached() const { return detached_; }
50
51   void copy_data();
52
53   bool test() override;
54
55   CommImpl* start();
56   void suspend() override;
57   void resume() override;
58   void cancel() override;
59   void post() override;
60   void finish() override;
61
62   const Type type_ = Type::SEND; /* Type of the communication (SEND or RECEIVE) */
63
64 #if SIMGRID_HAVE_MC
65   MailboxImpl* mbox_cpy = nullptr; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
66                                      (comm.mbox set to nullptr when the communication is removed from the mailbox
67                                      (used as garbage collector)) */
68 #endif
69
70   void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
71   bool (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
72 looking if a given communication matches my needs. For that, myself must match the
73 expectations of the other side, too. See  */
74   void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr;
75
76   /* Surf action data */
77   resource::Action* src_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
78   resource::Action* dst_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
79   actor::ActorImplPtr src_actor_ = nullptr;
80   actor::ActorImplPtr dst_actor_ = nullptr;
81
82   /* Data to be transferred */
83   unsigned char* src_buff_ = nullptr;
84   unsigned char* dst_buff_ = nullptr;
85   size_t src_buff_size_    = 0;
86   size_t* dst_buff_size_   = nullptr;
87
88   void* src_data_ = nullptr; /* User data associated to the communication */
89   void* dst_data_ = nullptr;
90 };
91 } // namespace activity
92 } // namespace kernel
93 } // namespace simgrid
94
95 #endif