Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0f84820dc2bdcaf249621ae0118c93be0e5ba394
[simgrid.git] / src / smpi / mpi / smpi_comm.cpp
1 /* Copyright (c) 2010-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 #include "smpi_comm.hpp"
7 #include "simgrid/host.h"
8 #include "smpi_coll.hpp"
9 #include "smpi_datatype.hpp"
10 #include "smpi_info.hpp"
11 #include "smpi_request.hpp"
12 #include "smpi_win.hpp"
13 #include "src/smpi/include/smpi_actor.hpp"
14 #include "src/surf/HostImpl.hpp"
15
16 #include <limits>
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_comm, smpi, "Logging specific to SMPI (comm)");
19
20 simgrid::smpi::Comm smpi_MPI_COMM_UNINITIALIZED;
21 MPI_Comm MPI_COMM_UNINITIALIZED=&smpi_MPI_COMM_UNINITIALIZED;
22 /**
23  * Setting MPI_COMM_WORLD to MPI_COMM_UNINITIALIZED (it's a variable)
24  * is important because the implementation of MPI_Comm checks
25  * "this == MPI_COMM_UNINITIALIZED"? If yes, it uses smpi_process()->comm_world()
26  * instead of "this".
27  * This is basically how we only have one global variable but all processes have
28  * different communicators (the one their SMPI instance uses).
29  *
30  */
31 MPI_Comm MPI_COMM_WORLD = MPI_COMM_UNINITIALIZED;
32
33 /* Support for cartesian topology was added, but there are 2 other types of topology, graph et dist graph. In order to
34  * support them, we have to add a field SMPI_Topo_type, and replace the MPI_Topology field by an union. */
35
36 namespace simgrid::smpi {
37
38 std::unordered_map<int, smpi_key_elem> Comm::keyvals_;
39 int Comm::keyval_id_=0;
40
41 Comm::Comm(MPI_Group group, MPI_Topology topo, bool smp, int in_id)
42     : group_(group), topo_(topo), is_smp_comm_(smp), id_(in_id)
43 {
44   errhandler_->ref();
45   //First creation of comm is done before SIMIX_run, so only do comms for others
46   if(in_id==MPI_UNDEFINED && smp==0 && this->rank()!=MPI_UNDEFINED ){
47     this->add_f();
48     group->c2f();
49     int id;
50     if(this->rank()==0){
51       static int global_id_ = 0;
52       id=global_id_;
53       global_id_++;
54     }
55     colls::bcast(&id, 1, MPI_INT, 0, this);
56     XBT_DEBUG("Communicator %p has id %d", this, id);
57     id_=id;//only set here, as we don't want to change it in the middle of the bcast
58   }
59 }
60
61 void Comm::destroy(Comm* comm)
62 {
63   if (comm == MPI_COMM_UNINITIALIZED){
64     Comm::destroy(smpi_process()->comm_world());
65     return;
66   }
67   if (comm != MPI_COMM_WORLD && not comm->deleted()) {
68     comm->cleanup_attr<Comm>();
69     comm->mark_as_deleted();
70   }
71   Comm::unref(comm);
72 }
73
74 int Comm::dup(MPI_Comm* newcomm){
75   // we need to switch as the called function may silently touch global variables
76   smpi_switch_data_segment(s4u::Actor::self());
77
78   auto* cp     = new Group(this->group());
79   (*newcomm)   = new  Comm(cp, this->topo());
80
81   for (auto const& [key, value] : attributes()) {
82     auto elem_it = keyvals_.find(key);
83     xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Comm: %d", key);
84
85     smpi_key_elem& elem = elem_it->second;
86     int ret             = MPI_SUCCESS;
87     int flag            = 0;
88     void* value_out     = nullptr;
89     if (elem.copy_fn.comm_copy_fn == MPI_COMM_DUP_FN) {
90       value_out = value;
91       flag      = 1;
92     } else if (elem.copy_fn.comm_copy_fn != MPI_NULL_COPY_FN) {
93       ret = elem.copy_fn.comm_copy_fn(this, key, elem.extra_state, value, &value_out, &flag);
94     }
95     if (elem.copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN) {
96       value_out = xbt_new(int, 1);
97       if (*(int*)*elem.copy_fn.comm_copy_fn_fort == 1) { // MPI_COMM_DUP_FN
98         memcpy(value_out, value, sizeof(int));
99         flag = 1;
100       } else { // not null, nor dup
101         elem.copy_fn.comm_copy_fn_fort(this, key, elem.extra_state, value, value_out, &flag, &ret);
102       }
103       if (ret != MPI_SUCCESS)
104         xbt_free(value_out);
105     }
106     if (ret != MPI_SUCCESS) {
107       Comm::destroy(*newcomm);
108       *newcomm = MPI_COMM_NULL;
109       return ret;
110     }
111     if (flag) {
112       elem.refcount++;
113       (*newcomm)->attributes().try_emplace(key, value_out);
114     }
115   }
116   //duplicate info if present
117   if(info_!=MPI_INFO_NULL)
118     (*newcomm)->info_ = new simgrid::smpi::Info(info_);
119   //duplicate errhandler
120   if (errhandlers_ != nullptr)//MPI_COMM_WORLD, only grab our own
121     (*newcomm)->set_errhandler(errhandlers_[this->rank()]);
122   else
123     (*newcomm)->set_errhandler(errhandler_);
124   return MPI_SUCCESS;
125 }
126
127 int Comm::dup_with_info(MPI_Info info, MPI_Comm* newcomm){
128   int ret = dup(newcomm);
129   if(ret != MPI_SUCCESS)
130     return ret;
131   if((*newcomm)->info_!=MPI_INFO_NULL){
132     simgrid::smpi::Info::unref((*newcomm)->info_);
133     (*newcomm)->info_=MPI_INFO_NULL;
134   }
135   if(info != MPI_INFO_NULL){
136     info->ref();
137     (*newcomm)->info_=info;
138   }
139   return ret;
140 }
141
142 MPI_Group Comm::group()
143 {
144   if (this == MPI_COMM_UNINITIALIZED)
145     return smpi_process()->comm_world()->group();
146   return group_;
147 }
148
149 int Comm::size() const
150 {
151   if (this == MPI_COMM_UNINITIALIZED)
152     return smpi_process()->comm_world()->size();
153   return group_->size();
154 }
155
156 int Comm::rank() const
157 {
158   if (this == MPI_COMM_UNINITIALIZED)
159     return smpi_process()->comm_world()->rank();
160   return group_->rank(s4u::this_actor::get_pid());
161 }
162
163 int Comm::id() const
164 {
165   return id_;
166 }
167
168 void Comm::get_name(char* name, int* len) const
169 {
170   if (this == MPI_COMM_UNINITIALIZED){
171     smpi_process()->comm_world()->get_name(name, len);
172     return;
173   }
174   if(this == MPI_COMM_WORLD && name_.empty()) {
175     strncpy(name, "MPI_COMM_WORLD", 15);
176     *len = 14;
177   } else {
178     *len = snprintf(name, MPI_MAX_NAME_STRING+1, "%s", name_.c_str());
179   }
180 }
181
182 std::string Comm::name() const
183 {
184   int size;
185   std::array<char, MPI_MAX_NAME_STRING + 1> name;
186   this->get_name(name.data(), &size);
187   if (name[0]=='\0')
188     return "MPI_Comm";
189   else
190     return name.data();
191 }
192
193
194 void Comm::set_name (const char* name)
195 {
196   if (this == MPI_COMM_UNINITIALIZED){
197     smpi_process()->comm_world()->set_name(name);
198     return;
199   }
200   name_.replace (0, MPI_MAX_NAME_STRING+1, name);
201 }
202
203
204 void Comm::set_leaders_comm(MPI_Comm leaders){
205   if (this == MPI_COMM_UNINITIALIZED){
206     smpi_process()->comm_world()->set_leaders_comm(leaders);
207     return;
208   }
209   leaders_comm_=leaders;
210 }
211
212 int* Comm::get_non_uniform_map() const
213 {
214   if (this == MPI_COMM_UNINITIALIZED)
215     return smpi_process()->comm_world()->get_non_uniform_map();
216   return non_uniform_map_;
217 }
218
219 int* Comm::get_leaders_map() const
220 {
221   if (this == MPI_COMM_UNINITIALIZED)
222     return smpi_process()->comm_world()->get_leaders_map();
223   return leaders_map_;
224 }
225
226 MPI_Comm Comm::get_leaders_comm() const
227 {
228   if (this == MPI_COMM_UNINITIALIZED)
229     return smpi_process()->comm_world()->get_leaders_comm();
230   return leaders_comm_;
231 }
232
233 MPI_Comm Comm::get_intra_comm() const
234 {
235   if (this == MPI_COMM_UNINITIALIZED || this==MPI_COMM_WORLD)
236     return smpi_process()->comm_intra();
237   else return intra_comm_;
238 }
239
240 bool Comm::is_uniform() const
241 {
242   if (this == MPI_COMM_UNINITIALIZED)
243     return smpi_process()->comm_world()->is_uniform();
244   return is_uniform_;
245 }
246
247 bool Comm::is_blocked() const
248 {
249   if (this == MPI_COMM_UNINITIALIZED)
250     return smpi_process()->comm_world()->is_blocked();
251   return is_blocked_;
252 }
253
254 bool Comm::is_smp_comm() const
255 {
256   if (this == MPI_COMM_UNINITIALIZED)
257     return smpi_process()->comm_world()->is_smp_comm();
258   return is_smp_comm_;
259 }
260
261 MPI_Comm Comm::split(int color, int key)
262 {
263   if (this == MPI_COMM_UNINITIALIZED)
264     return smpi_process()->comm_world()->split(color, key);
265   int system_tag = -123;
266
267   MPI_Group group_root = nullptr;
268   MPI_Group group_out  = nullptr;
269   const Group* group   = this->group();
270   int myrank           = this->rank();
271   int size             = this->size();
272   /* Gather all colors and keys on rank 0 */
273   const std::array<int, 2> sendbuf = {{color, key}};
274   std::vector<int> recvbuf;
275   if (myrank == 0)
276     recvbuf.resize(2 * size);
277   gather__default(sendbuf.data(), 2, MPI_INT, recvbuf.data(), 2, MPI_INT, 0, this);
278   /* Do the actual job */
279   if (myrank == 0) {
280     std::vector<MPI_Group> group_snd(size);
281     std::vector<std::pair<int, int>> rankmap;
282     rankmap.reserve(size);
283     for (int i = 0; i < size; i++) {
284       if (recvbuf[2 * i] != MPI_UNDEFINED) {
285         rankmap.clear();
286         for (int j = i + 1; j < size; j++) {
287           if(recvbuf[2 * i] == recvbuf[2 * j]) {
288             recvbuf[2 * j] = MPI_UNDEFINED;
289             rankmap.emplace_back(recvbuf[2 * j + 1], j);
290           }
291         }
292         /* Add self in the group */
293         recvbuf[2 * i] = MPI_UNDEFINED;
294         rankmap.emplace_back(recvbuf[2 * i + 1], i);
295         std::sort(begin(rankmap), end(rankmap));
296         group_out = new Group(rankmap.size());
297         if (i == 0) {
298           group_root = group_out; /* Save root's group */
299         }
300         for (unsigned j = 0; j < rankmap.size(); j++) {
301           aid_t actor = group->actor(rankmap[j].second);
302           group_out->set_mapping(actor, j);
303         }
304         std::vector<MPI_Request> requests(rankmap.size());
305         int reqs              = 0;
306         for (auto const& [_, rank] : rankmap) {
307           if (rank != 0) {
308             group_snd[reqs]=new  Group(group_out);
309             requests[reqs] = Request::isend(&(group_snd[reqs]), 1, MPI_PTR, rank, system_tag, this);
310             reqs++;
311           }
312         }
313         if(i != 0 && group_out != MPI_COMM_WORLD->group() && group_out != MPI_GROUP_EMPTY)
314           Group::unref(group_out);
315
316         Request::waitall(reqs, requests.data(), MPI_STATUS_IGNORE);
317       }
318     }
319     group_out = group_root; /* exit with root's group */
320   } else {
321     if(color != MPI_UNDEFINED) {
322       Request::recv(&group_out, 1, MPI_PTR, 0, system_tag, this, MPI_STATUS_IGNORE);
323     } /* otherwise, exit with group_out == nullptr */
324   }
325   return group_out!=nullptr ? new  Comm(group_out, topo_) : MPI_COMM_NULL;
326 }
327
328 void Comm::ref(){
329   if (this == MPI_COMM_UNINITIALIZED){
330     smpi_process()->comm_world()->ref();
331     return;
332   }
333   group_->ref();
334   refcount_++;
335 }
336
337 void Comm::cleanup_smp(){
338   if (intra_comm_ != MPI_COMM_NULL)
339     Comm::unref(intra_comm_);
340   if (leaders_comm_ != MPI_COMM_NULL)
341     Comm::unref(leaders_comm_);
342   xbt_free(non_uniform_map_);
343   delete[] leaders_map_;
344 }
345
346 void Comm::unref(Comm* comm){
347   if (comm == MPI_COMM_UNINITIALIZED){
348     Comm::unref(smpi_process()->comm_world());
349     return;
350   }
351   comm->refcount_--;
352
353   if(comm->refcount_==0){
354     if(simgrid::smpi::F2C::lookup() != nullptr)
355       F2C::free_f(comm->f2c_id());
356     comm->cleanup_smp();
357     comm->cleanup_attr<Comm>();
358     if (comm->info_ != MPI_INFO_NULL)
359       simgrid::smpi::Info::unref(comm->info_);
360     if(comm->errhandlers_!=nullptr){
361       for (int i=0; i<comm->size(); i++)
362         if (comm->errhandlers_[i]!=MPI_ERRHANDLER_NULL)
363           simgrid::smpi::Errhandler::unref(comm->errhandlers_[i]);
364       delete[] comm->errhandlers_;
365     } else if (comm->errhandler_ != MPI_ERRHANDLER_NULL)
366       simgrid::smpi::Errhandler::unref(comm->errhandler_);
367   }
368   Group::unref(comm->group_);
369   if(comm->refcount_==0)
370     delete comm;
371 }
372
373 MPI_Comm Comm::find_intra_comm(int * leader){
374   //get the indices of all processes sharing the same simix host
375   int intra_comm_size     = 0;
376   aid_t min_index         = std::numeric_limits<aid_t>::max(); // the minimum index will be the leader
377   sg_host_self()->get_impl()->foreach_actor([this, &intra_comm_size, &min_index](auto& actor) {
378     aid_t index = actor.get_pid();
379     if (this->group()->rank(index) != MPI_UNDEFINED) { // Is this process in the current group?
380       intra_comm_size++;
381       if (index < min_index)
382         min_index = index;
383     }
384   });
385   XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
386   auto* group_intra = new Group(intra_comm_size);
387   int i = 0;
388   sg_host_self()->get_impl()->foreach_actor([this, group_intra, &i](auto& actor) {
389     if (this->group()->rank(actor.get_pid()) != MPI_UNDEFINED) {
390       group_intra->set_mapping(actor.get_pid(), i);
391       i++;
392     }
393   });
394   *leader=min_index;
395   return new Comm(group_intra, nullptr, true);
396 }
397
398 void Comm::init_smp(){
399   int leader = -1;
400   int i = 0;
401   if (this == MPI_COMM_UNINITIALIZED)
402     smpi_process()->comm_world()->init_smp();
403
404   int comm_size = this->size();
405
406   // If we are in replay - perform an ugly hack
407   // tell SimGrid we are not in replay for a while, because we need the buffers to be copied for the following calls
408   bool replaying = false; //cache data to set it back again after
409   if(smpi_process()->replaying()){
410     replaying = true;
411     smpi_process()->set_replaying(false);
412   }
413
414   // we need to switch as the called function may silently touch global variables
415   smpi_switch_data_segment(s4u::Actor::self());
416
417   // identify neighbors in comm
418   MPI_Comm comm_intra = find_intra_comm(&leader);
419
420   auto* leaders_map = new int[comm_size];
421   auto* leader_list = new int[comm_size];
422   std::fill_n(leaders_map, comm_size, 0);
423   std::fill_n(leader_list, comm_size, -1);
424
425   allgather__ring(&leader, 1, MPI_INT , leaders_map, 1, MPI_INT, this);
426
427   if(leaders_map_==nullptr){
428     leaders_map_= leaders_map;
429   }else{
430     delete[] leaders_map;
431   }
432   int leader_group_size = 0;
433   for(i=0; i<comm_size; i++){
434     int already_done = 0;
435     for (int j = 0; j < leader_group_size; j++) {
436       if (leaders_map_[i] == leader_list[j]) {
437         already_done = 1;
438       }
439     }
440     if (already_done == 0) {
441       leader_list[leader_group_size] = leaders_map_[i];
442       leader_group_size++;
443     }
444   }
445   xbt_assert(leader_group_size > 0);
446   std::sort(leader_list, leader_list + leader_group_size);
447
448   auto* leaders_group = new Group(leader_group_size);
449
450   MPI_Comm leader_comm = MPI_COMM_NULL;
451   if(MPI_COMM_WORLD!=MPI_COMM_UNINITIALIZED && this!=MPI_COMM_WORLD){
452     //create leader_communicator
453     for (i=0; i< leader_group_size;i++)
454       leaders_group->set_mapping(leader_list[i], i);
455     leader_comm = new Comm(leaders_group, nullptr, true);
456     this->set_leaders_comm(leader_comm);
457     this->set_intra_comm(comm_intra);
458
459     // create intracommunicator
460   }else{
461     for (i=0; i< leader_group_size;i++)
462       leaders_group->set_mapping(leader_list[i], i);
463
464     if(this->get_leaders_comm()==MPI_COMM_NULL){
465       leader_comm = new Comm(leaders_group, nullptr, true);
466       this->set_leaders_comm(leader_comm);
467     }else{
468       leader_comm=this->get_leaders_comm();
469       Group::unref(leaders_group);
470     }
471     smpi_process()->set_comm_intra(comm_intra);
472   }
473
474   // Are the nodes uniform ? = same number of process/node
475   int my_local_size=comm_intra->size();
476   int is_uniform;
477   if(comm_intra->rank()==0) {
478     is_uniform            = 1;
479     auto* non_uniform_map = xbt_new0(int, leader_group_size);
480     allgather__ring(&my_local_size, 1, MPI_INT,
481         non_uniform_map, 1, MPI_INT, leader_comm);
482     for(i=0; i < leader_group_size; i++) {
483       if(non_uniform_map[0] != non_uniform_map[i]) {
484         is_uniform = 0;
485         break;
486       }
487     }
488     if (is_uniform == 0 && this->is_uniform()) {
489       non_uniform_map_ = non_uniform_map;
490     }else{
491       xbt_free(non_uniform_map);
492     }
493   }
494   bcast__scatter_LR_allgather(&is_uniform, 1, MPI_INT, 0, comm_intra);
495   is_uniform_ = (is_uniform != 0);
496
497   // we need to switch as the called function may silently touch global variables
498   smpi_switch_data_segment(s4u::Actor::self());
499
500   // Are the ranks blocked ? = allocated contiguously on the SMP nodes
501   int is_blocked=1;
502   int prev      = this->group()->rank(comm_intra->group()->actor(0));
503   for (i = 1; i < my_local_size; i++) {
504     int that = this->group()->rank(comm_intra->group()->actor(i));
505     if (that != prev + 1) {
506       is_blocked = 0;
507       break;
508     }
509     prev = that;
510   }
511
512   int global_blocked;
513   allreduce__default(&is_blocked, &global_blocked, 1, MPI_INT, MPI_LAND, this);
514
515   if ((MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED && this != MPI_COMM_WORLD) || this->rank() == 0)
516     is_blocked_ = (global_blocked != 0);
517   delete[] leader_list;
518
519   if(replaying)
520     smpi_process()->set_replaying(true);
521 }
522
523 MPI_Comm Comm::f2c(int id) {
524   if(id == -2) {
525     return MPI_COMM_SELF;
526   } else if(id==0){
527     return MPI_COMM_WORLD;
528   } else if (F2C::lookup() != nullptr && id >= 0) {
529     const auto& lookup = F2C::lookup();
530     auto comm          = lookup->find(id);
531     return comm == lookup->end() ? MPI_COMM_NULL : static_cast<MPI_Comm>(comm->second);
532   } else {
533     return MPI_COMM_NULL;
534   }
535 }
536
537 void Comm::free_f(int id) {
538   F2C::lookup()->erase(id);
539 }
540
541 void Comm::add_rma_win(MPI_Win win){
542   rma_wins_.push_back(win);
543 }
544
545 void Comm::remove_rma_win(MPI_Win win){
546   rma_wins_.remove(win);
547 }
548
549 void Comm::finish_rma_calls() const
550 {
551   const int myrank = rank();
552   for (auto const& it : rma_wins_) {
553     if (it->rank() == myrank) { // is it ours (for MPI_COMM_WORLD)?
554       int finished = it->finish_comms();
555       XBT_DEBUG("Barrier for rank %d - Finished %d RMA calls", myrank, finished);
556     }
557   }
558 }
559
560 MPI_Info Comm::info()
561 {
562   return info_;
563 }
564
565 void Comm::set_info(MPI_Info info)
566 {
567   if (info_ != MPI_INFO_NULL)
568     simgrid::smpi::Info::unref(info);
569   info_ = info;
570   if (info_ != MPI_INFO_NULL)
571     info->ref();
572 }
573
574 MPI_Errhandler Comm::errhandler()
575 {
576   if (this != MPI_COMM_WORLD){
577     if (errhandler_ != MPI_ERRHANDLER_NULL)
578       errhandler_->ref();
579     return errhandler_;
580   } else {
581     if(errhandlers_==nullptr){
582       if (_smpi_cfg_default_errhandler_is_error)
583         return MPI_ERRORS_ARE_FATAL;
584       else
585         return MPI_ERRORS_RETURN;
586     } else {
587       if(errhandlers_[this->rank()] != MPI_ERRHANDLER_NULL)
588         errhandlers_[this->rank()]->ref();
589       return errhandlers_[this->rank()];
590     }
591   }
592 }
593
594 void Comm::set_errhandler(MPI_Errhandler errhandler)
595 {
596   if(this != MPI_COMM_WORLD){
597     if (errhandler_ != MPI_ERRHANDLER_NULL)
598       simgrid::smpi::Errhandler::unref(errhandler_);
599     errhandler_ = errhandler;
600   }else{
601     if(errhandlers_==nullptr)
602       errhandlers_= new MPI_Errhandler[this->size()]{MPI_ERRHANDLER_NULL};
603     if(errhandlers_[this->rank()] != MPI_ERRHANDLER_NULL)
604       simgrid::smpi::Errhandler::unref(errhandlers_[this->rank()]);
605     errhandlers_[this->rank()]=errhandler;
606   }
607   if (errhandler != MPI_ERRHANDLER_NULL)
608     errhandler->ref();
609 }
610
611 MPI_Comm Comm::split_type(int type, int /*key*/, const Info*)
612 {
613   //MPI_UNDEFINED can be given to some nodes... but we need them to still perform the smp part which is collective
614   if(type != MPI_COMM_TYPE_SHARED && type != MPI_UNDEFINED){
615     return MPI_COMM_NULL;
616   }
617   int leader=0;
618   MPI_Comm res= this->find_intra_comm(&leader);
619   if(type != MPI_UNDEFINED)
620     return res;
621   else{
622     xbt_assert(res->refcount_ == 1); // ensure the next call to Comm::destroy really frees the comm
623     Comm::destroy(res);
624     return MPI_COMM_NULL;
625   }
626 }
627
628 static inline std::string hash_message(int src, int dst, int tag){
629   return std::to_string(tag) + '_' + std::to_string(src) + '_' + std::to_string(dst);
630 }
631
632 unsigned int Comm::get_sent_messages_count(int src, int dst, int tag)
633 {
634   return sent_messages_[hash_message(src, dst, tag)];
635 }
636
637 void Comm::increment_sent_messages_count(int src, int dst, int tag)
638 {
639   sent_messages_[hash_message(src, dst, tag)]++;
640 }
641
642 unsigned int Comm::get_received_messages_count(int src, int dst, int tag)
643 {
644   return recv_messages_[hash_message(src, dst, tag)];
645 }
646
647 void Comm::increment_received_messages_count(int src, int dst, int tag)
648 {
649   recv_messages_[hash_message(src, dst, tag)]++;
650 }
651
652 unsigned int Comm::get_collectives_count()
653 {
654   if (this==MPI_COMM_UNINITIALIZED){
655     return smpi_process()->comm_world()->get_collectives_count();
656   }else if(this == MPI_COMM_WORLD || this == smpi_process()->comm_world()){
657     if (collectives_counts_.empty())
658       collectives_counts_.resize(this->size());
659     return collectives_counts_[this->rank()];
660   }else{
661     return collectives_count_;
662   }
663 }
664
665 void Comm::increment_collectives_count()
666 {
667    if (this==MPI_COMM_UNINITIALIZED){
668     smpi_process()->comm_world()->increment_collectives_count();
669   }else if (this == MPI_COMM_WORLD || this == smpi_process()->comm_world()){
670     if (collectives_counts_.empty())
671       collectives_counts_.resize(this->size());
672     collectives_counts_[this->rank()]++;
673   }else{
674     collectives_count_++;
675   }
676 }
677
678 } // namespace simgrid::smpi