X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/50ddfe2f5b5035e0ed9556b334d6977ee81ff83a..6e7cd3b98b151c28f744e0a778d7efb82e076c38:/src/smpi/plugins/ampi/ampi.cpp diff --git a/src/smpi/plugins/ampi/ampi.cpp b/src/smpi/plugins/ampi/ampi.cpp index 6f400b8bab..10cf2a2050 100644 --- a/src/smpi/plugins/ampi/ampi.cpp +++ b/src/smpi/plugins/ampi/ampi.cpp @@ -1,20 +1,25 @@ -#include +/* Copyright (c) 2018-2021. 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 -#include +#include #include +#include #include -#include #include +#include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(plugin_pampi, smpi, "Logging specific to the AMPI functions"); +#include "ampi.hpp" +#include static std::vector memory_size(500, 0); // FIXME cheinrich This needs to be dynamic static std::map alloc_table; // Keep track of all allocations -extern "C" XBT_PUBLIC void* _sampi_malloc(size_t); -extern "C" XBT_PUBLIC void _sampi_free(void* ptr); + extern "C" void* _sampi_malloc(size_t size) { - void* result = malloc (size); // We need the space here to prevent recursive substitution + void* result = xbt_malloc(size); alloc_table.insert({result, size}); if (not simgrid::s4u::this_actor::is_maestro()) { memory_size[simgrid::s4u::this_actor::get_pid()] += size; @@ -25,22 +30,42 @@ extern "C" void* _sampi_malloc(size_t size) extern "C" void _sampi_free(void* ptr) { size_t alloc_size = alloc_table.at(ptr); - int my_proc_id = simgrid::s4u::this_actor::get_pid(); + aid_t my_proc_id = simgrid::s4u::this_actor::get_pid(); memory_size[my_proc_id] -= alloc_size; - free(ptr); + xbt_free(ptr); +} + +extern "C" void* _sampi_calloc(size_t num_elm, size_t elem_size) +{ + void* result = xbt_malloc0(num_elm * elem_size); + 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 = xbt_realloc(ptr, size); + size_t 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 namespace simgrid { namespace smpi { namespace plugin { namespace ampi { - simgrid::xbt::signal on_iteration_in; - simgrid::xbt::signal on_iteration_out; -} -} -} -} +xbt::signal on_iteration_in; +xbt::signal on_iteration_out; +} // namespace ampi +} // namespace plugin +} // namespace smpi +} // namespace simgrid /* FIXME The following contains several times "rank() + 1". This works for one * instance, but we need to find a way to deal with this for several instances and @@ -49,26 +74,23 @@ namespace ampi { */ int APMPI_Iteration_in(MPI_Comm comm) { - smpi_bench_end(); + const SmpiBenchGuard suspend_bench; TRACE_Iteration_in(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_in")); // implemented on instr_smpi.c - smpi_bench_begin(); return 1; } int APMPI_Iteration_out(MPI_Comm comm) { - smpi_bench_end(); + const SmpiBenchGuard suspend_bench; TRACE_Iteration_out(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_out")); - smpi_bench_begin(); return 1; } void APMPI_Migrate(MPI_Comm comm) { - smpi_bench_end(); - int my_proc_id = simgrid::s4u::this_actor::get_pid(); + const SmpiBenchGuard suspend_bench; + aid_t my_proc_id = simgrid::s4u::this_actor::get_pid(); TRACE_migration_call(comm->rank() + 1, new simgrid::instr::AmpiMigrateTIData(memory_size[my_proc_id])); - smpi_bench_begin(); } int AMPI_Iteration_in(MPI_Comm comm)