+void* smpi_shared_malloc_intercept(size_t size, const char* file, int line)
+{
+ if( smpi_cfg_auto_shared_malloc_thresh() == 0 || size < smpi_cfg_auto_shared_malloc_thresh()){
+ void* ptr = xbt_malloc(size);
+ if(not smpi_cfg_trace_call_use_absolute_path())
+ simgrid::smpi::utils::account_malloc_size(size, simgrid::xbt::Path(file).get_base_name(), line, ptr);
+ else
+ simgrid::smpi::utils::account_malloc_size(size, file, line, ptr);
+ return ptr;
+ } else {
+ simgrid::smpi::utils::account_shared_size(size);
+ return smpi_shared_malloc(size, file, line);
+ }
+}
+
+void* smpi_shared_calloc_intercept(size_t num_elm, size_t elem_size, const char* file, int line)
+{
+ size_t size = elem_size * num_elm;
+ if (smpi_cfg_auto_shared_malloc_thresh() == 0 || size < smpi_cfg_auto_shared_malloc_thresh()) {
+ void* ptr = xbt_malloc0(size);
+ if(not smpi_cfg_trace_call_use_absolute_path())
+ simgrid::smpi::utils::account_malloc_size(size, simgrid::xbt::Path(file).get_base_name(), line, ptr);
+ else
+ simgrid::smpi::utils::account_malloc_size(size, file, line, ptr);
+ return ptr;
+ } else {
+ simgrid::smpi::utils::account_shared_size(size);
+ return memset(smpi_shared_malloc(size, file, line), 0, size);
+ }
+}
+
+void* smpi_shared_realloc_intercept(void* data, size_t size, const char* file, int line)
+{
+ if (size == 0) {
+ smpi_shared_free(data);
+ return nullptr;
+ }
+ if (data == nullptr)
+ return smpi_shared_malloc_intercept(size, file, line);
+
+ auto meta = allocs_metadata.find(data);
+ if (meta == allocs_metadata.end()) {
+ XBT_DEBUG("Classical realloc(%p, %zu)", data, size);
+ return xbt_realloc(data, size);
+ }
+
+ XBT_DEBUG("Shared realloc(%p, %zu) (old size: %zu)", data, size, meta->second.size);
+ void* ptr = smpi_shared_malloc_intercept(size, file, line);
+ if (ptr != data) {
+ memcpy(ptr, data, std::min(size, meta->second.size));
+ smpi_shared_free(data);
+ }
+ return ptr;
+}
+
+void* smpi_shared_malloc(size_t size, const char* file, int line)
+{
+ if (size > 0 && smpi_cfg_shared_malloc() == SharedMallocType::LOCAL) {