Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / src / smpi / plugins / ampi / ampi.cpp
index d2780de..e823b32 100644 (file)
@@ -1,3 +1,8 @@
+/* Copyright (c) 2018-2019. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
 #include <simgrid/plugins/load_balancer.h>
 #include <simgrid/s4u/Actor.hpp>
 #include <src/smpi/include/smpi_comm.hpp>
@@ -10,8 +15,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(plugin_pampi, smpi, "Logging specific to the AMP
 
 static std::vector<size_t> memory_size(500, 0); // FIXME cheinrich This needs to be dynamic
 static std::map</*address*/ void*, size_t> alloc_table; // Keep track of all allocations
-extern "C" XBT_PUBLIC void* _sampi_malloc(size_t);
+extern "C" XBT_PUBLIC void* _sampi_malloc(size_t); // FIXME Use declarations from sampi.h instead
 extern "C" XBT_PUBLIC void _sampi_free(void* ptr);
+extern "C" XBT_PUBLIC void* _sampi_calloc(size_t num_elm, size_t elem_size);
+extern "C" XBT_PUBLIC void* _sampi_realloc(void* ptr, size_t size);
 extern "C" void* _sampi_malloc(size_t size)
 {
   void* result = malloc (size); // We need the space here to prevent recursive substitution
@@ -30,6 +37,27 @@ extern "C" void _sampi_free(void* ptr)
   free(ptr);
 }
 
+extern "C" void* _sampi_calloc(size_t num_elm, size_t elem_size)
+{
+  void* result = calloc (num_elm, elem_size); // We need the space here to prevent recursive substitution
+  alloc_table.insert({result, num_elm * elem_size});
+  if (not simgrid::s4u::this_actor::is_maestro()) {
+    memory_size[simgrid::s4u::this_actor::get_pid()] += num_elm * elem_size;
+  }
+  return result;
+}
+extern "C" void* _sampi_realloc(void* ptr, size_t size)
+{
+  void* result = realloc (ptr, size); // We need the space here to prevent recursive substitution
+  int old_size = alloc_table.at(ptr);
+  alloc_table.erase(ptr);
+  alloc_table.insert({result, size});
+  if (not simgrid::s4u::this_actor::is_maestro()) {
+    memory_size[simgrid::s4u::this_actor::get_pid()] += size - old_size;
+  }
+  return result;
+}
+
 #include "ampi.hpp"
 #include <smpi/sampi.h>
 namespace simgrid {