X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/321102577020b194dfb7ba89e48687952816849e..adbdcbddadcbd685b72259874d1ebfd9cbbcc497:/src/smpi/internals/smpi_bench.cpp diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 096049520e..542c0ee1e6 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -1,9 +1,8 @@ -/* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2023. 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 "getopt.h" #include "private.hpp" #include "simgrid/host.h" #include "simgrid/modelchecker.h" @@ -12,19 +11,18 @@ #include "smpi_comm.hpp" #include "smpi_utils.hpp" #include "src/internal_config.h" +#include "src/kernel/lmm/System.hpp" // sg_precision_timing #include "src/mc/mc_replay.hpp" -#include "src/surf/surf_interface.hpp" // sg_surf_precision #include "xbt/config.hpp" #include "xbt/file.hpp" +#include #include "src/smpi/include/smpi_actor.hpp" -#include -#ifndef WIN32 -#include -#endif #include #include +#include +#include #if HAVE_PAPI #include @@ -154,7 +152,7 @@ void smpi_bench_end() const papi_counter_t& counter_data = smpi_process()->papi_counters(); for (auto const& [counter, value] : counter_data) { - container->get_variable(counter)->set_event(simgrid::s4u::Engine::get_clock(), value); + container->get_variable(counter)->set_event(simgrid::s4u::Engine::get_clock(), static_cast(value)); } } #endif @@ -211,7 +209,7 @@ int smpi_gettimeofday(struct timeval* tv, struct timezone* tz) double secs = trunc(now); double usecs = (now - secs) * 1e6; tv->tv_sec = static_cast(secs); - tv->tv_usec = static_casttv_usec)>(usecs); // suseconds_t (or useconds_t on WIN32) + tv->tv_usec = static_casttv_usec)>(usecs); // suseconds_t } if (smpi_wtime_sleep > 0) simgrid::s4u::this_actor::sleep_for(smpi_wtime_sleep); @@ -258,13 +256,13 @@ double smpi_mpi_wtime() unsigned long long smpi_rastro_resolution () { const SmpiBenchGuard suspend_bench; - return static_cast(1.0 / sg_surf_precision); + return static_cast(1.0 / sg_precision_timing); } unsigned long long smpi_rastro_timestamp () { const SmpiBenchGuard suspend_bench; - return static_cast(simgrid::s4u::Engine::get_clock() / sg_surf_precision); + return static_cast(simgrid::s4u::Engine::get_clock() / sg_precision_timing); } /* ****************************** Functions related to the SMPI_SAMPLE_ macros ************************************/ @@ -304,7 +302,7 @@ bool LocalData::need_more_benchs() const std::unordered_map> samples; } -void smpi_sample_1(int global, const char *file, const char *tag, int iters, double threshold) +int smpi_sample_cond(int global, const char* file, const char* tag, int iters, double threshold, int iter_count) { SampleLocation loc(global, file, tag); if (not smpi_process()->sampling()) { /* Only at first call when benchmarking, skip for next ones */ @@ -323,12 +321,13 @@ void smpi_sample_1(int global, const char *file, const char *tag, int iters, dou 0, // count true // benching (if we have no data, we need at least one) }); + LocalData& data = sample->second; + if (inserted) { XBT_DEBUG("XXXXX First time ever on benched nest %s.", loc.c_str()); xbt_assert(threshold > 0 || iters > 0, "You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)"); } else { - LocalData& data = sample->second; if (data.iters != iters || data.threshold != threshold) { XBT_ERROR("Asked to bench block %s with different settings %d, %f is not %d, %f. " "How did you manage to give two numbers at the same line??", @@ -336,24 +335,14 @@ void smpi_sample_1(int global, const char *file, const char *tag, int iters, dou THROW_IMPOSSIBLE; } - // if we already have some data, check whether sample_2 should get one more bench or whether it should emulate + // if we already have some data, check whether we should get one more bench or whether we should emulate // the computation instead data.benching = data.need_more_benchs(); XBT_DEBUG("XXXX Re-entering the benched nest %s. %s", loc.c_str(), (data.benching ? "more benching needed" : "we have enough data, skip computes")); } -} - -int smpi_sample_2(int global, const char *file,const char *tag, int iter_count) -{ - SampleLocation loc(global, file, tag); - - XBT_DEBUG("sample2 %s %d", loc.c_str(), iter_count); - auto sample = samples.find(loc); - xbt_assert(sample != samples.end(), - "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); - const LocalData& data = sample->second; + XBT_DEBUG("sample cond %s %d", loc.c_str(), iter_count); if (data.benching) { // we need to run a new bench XBT_DEBUG("benchmarking: count:%d iter:%d stderr:%f thres:%f; mean:%f; total:%f", @@ -380,18 +369,16 @@ int smpi_sample_2(int global, const char *file,const char *tag, int iter_count) return 1; } -void smpi_sample_3(int global, const char *file, const char* tag) +void smpi_sample_iter(int global, const char* file, const char* tag) { SampleLocation loc(global, file, tag); - XBT_DEBUG("sample3 %s", loc.c_str()); + XBT_DEBUG("sample iter %s", loc.c_str()); auto sample = samples.find(loc); xbt_assert(sample != samples.end(), "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); LocalData& data = sample->second; - - if (not data.benching) - THROW_IMPOSSIBLE; + xbt_assert(data.benching); // ok, benchmarking this loop is over xbt_os_threadtimer_stop(smpi_process()->timer()); @@ -407,9 +394,6 @@ void smpi_sample_3(int global, const char *file, const char* tag) XBT_DEBUG("Average mean after %d steps is %f, relative standard error is %f (sample was %f)", data.count, data.mean, data.relstderr, period); - - // That's enough for now, prevent sample_2 to run the same code over and over - data.benching = false; } int smpi_sample_exit(int global, const char *file, const char* tag, int iter_count){ @@ -436,7 +420,7 @@ smpi_trace_call_location_t* smpi_trace_get_call_location() return smpi_process()->call_location(); } -void smpi_trace_set_call_location(const char* file, const int line) +void smpi_trace_set_call_location(const char* file, const int line, const char* call_name) { smpi_trace_call_location_t* loc = smpi_process()->call_location(); @@ -446,19 +430,21 @@ void smpi_trace_set_call_location(const char* file, const int line) loc->filename = simgrid::xbt::Path(file).get_base_name(); else loc->filename = file; + std::replace(loc->filename.begin(), loc->filename.end(), ' ', '_'); loc->linenumber = line; + loc->func_call = call_name; } /** Required for Fortran bindings */ -void smpi_trace_set_call_location_(const char* file, const int* line) +void smpi_trace_set_call_location_(const char* file, const int* line, const char* call_name) { - smpi_trace_set_call_location(file, *line); + smpi_trace_set_call_location(file, *line, call_name); } /** Required for Fortran if -fsecond-underscore is activated */ -void smpi_trace_set_call_location__(const char* file, const int* line) +void smpi_trace_set_call_location__(const char* file, const int* line, const char* call_name) { - smpi_trace_set_call_location(file, *line); + smpi_trace_set_call_location(file, *line, call_name); } void smpi_bench_destroy() @@ -497,3 +483,7 @@ int smpi_getopt (int argc, char *const *argv, const char *options) smpi_process()->set_optind(optind); return ret; } + +pid_t smpi_getpid(){ + return static_cast(simgrid::s4u::this_actor::get_pid()); +}