+
+void print_current_handle(){
+ if(current_handle){
+ if(current_handle->call_location().empty())
+ XBT_INFO("To get handle location information, pass -trace-call-location flag to smpicc/f90 as well");
+ else
+ XBT_INFO("Handle %s was allocated by a call at %s", current_handle->name().c_str(),
+ (char*)(current_handle->call_location().c_str()));
+ }
+}
+
+void set_current_buffer(int i, const char* name, const void* buf){
+ //clear previous one
+ if(i==1){
+ if(not current_buffer1.name.empty()){
+ current_buffer1.name="";
+ }
+ if(not current_buffer2.name.empty()){
+ current_buffer2.name="";
+ }
+ }
+ auto meta = allocs.find(buf);
+ if (meta == allocs.end()) {
+ XBT_DEBUG("Buffer %p was not allocated with malloc/calloc", buf);
+ return;
+ }
+ if(i==1){
+ current_buffer1.alloc = meta->second;
+ current_buffer1.name = name;
+ }else{
+ current_buffer2.alloc=meta->second;
+ current_buffer2.name=name;
+ }
+}
+
+void print_buffer_info()
+{
+ if (not current_buffer1.name.empty())
+ XBT_INFO("Buffer %s was allocated from %s line %d, with size %zu", current_buffer1.name.c_str(),
+ current_buffer1.alloc.file.c_str(), current_buffer1.alloc.line, current_buffer1.alloc.size);
+ if (not current_buffer2.name.empty())
+ XBT_INFO("Buffer %s was allocated from %s line %d, with size %zu", current_buffer2.name.c_str(),
+ current_buffer2.alloc.file.c_str(), current_buffer2.alloc.line, current_buffer2.alloc.size);
+}
+
+size_t get_buffer_size(const void* buf){
+ auto meta = allocs.find(buf);
+ if (meta == allocs.end()) {
+ //we don't know this buffer (on stack or feature disabled), assume it's fine.
+ return std::numeric_limits<std::size_t>::max();
+ }
+ return meta->second.size;
+}
+
+void account_free(const void* ptr){
+ if (smpi_cfg_display_alloc()) {
+ allocs.erase(ptr);
+ }
+}
+
+int check_collectives_ordering(MPI_Comm comm, const std::string& call)
+{
+ unsigned int count = comm->get_collectives_count();
+ comm->increment_collectives_count();
+ if (auto vec = collective_calls.find(comm->id()); vec == collective_calls.end()) {
+ collective_calls.try_emplace(comm->id(), std::vector<std::string>{call});
+ } else {
+ // are we the first ? add the call
+ if (vec->second.size() == count) {
+ vec->second.emplace_back(call);
+ } else if (vec->second.size() > count) {
+ if (vec->second[count] != call) {
+ XBT_WARN("Collective operation mismatch. For process %ld, expected %s, got %s",
+ simgrid::s4u::this_actor::get_pid(), vec->second[count].c_str(), call.c_str());
+ return MPI_ERR_OTHER;
+ }
+ } else {
+ THROW_IMPOSSIBLE;
+ }
+ }
+ return MPI_SUCCESS;