X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b9625f82f86db0674e911887addce45dca31b57f..3e9453209f1da7deb92fe629428e49f3528217bd:/teshsuite/xbt/parmap_test/parmap_test.cpp diff --git a/teshsuite/xbt/parmap_test/parmap_test.cpp b/teshsuite/xbt/parmap_test/parmap_test.cpp index 3da1c4a467..0e63aaa9f0 100644 --- a/teshsuite/xbt/parmap_test/parmap_test.cpp +++ b/teshsuite/xbt/parmap_test/parmap_test.cpp @@ -1,29 +1,24 @@ /* parmap_test -- test parmap */ -/* Copyright (c) 2007-2020. 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 "src/internal_config.h" // HAVE_FUTEX_H +#include "src/xbt/parmap.hpp" #include -#include -#include +#include #include +#include #include #include // std::iota -#include #include #include XBT_LOG_NEW_DEFAULT_CATEGORY(parmap_test, "Test for parmap"); -static void fun_double(unsigned* arg) -{ - *arg = 2 * *arg + 1; -} - static int test_parmap_basic(e_xbt_parmap_mode_t mode) { int ret = 0; @@ -38,7 +33,7 @@ static int test_parmap_basic(e_xbt_parmap_mode_t mode) std::iota(begin(data), end(data), &a[0]); for (unsigned i = 0; i < num; i++) - parmap.apply(fun_double, data); + parmap.apply([](unsigned* arg) { *arg = 2 * *arg + 1; }, data); for (unsigned i = 0; i < len; i++) { unsigned expected = (1U << num) * (i + 1) - 1; @@ -52,14 +47,6 @@ static int test_parmap_basic(e_xbt_parmap_mode_t mode) return ret; } -static void fun_get_id(std::string* arg) -{ - std::stringstream ss; - ss << std::this_thread::get_id(); - *arg = ss.str(); - xbt_os_sleep(0.05); -} - static int test_parmap_extended(e_xbt_parmap_mode_t mode) { int ret = 0; @@ -67,15 +54,27 @@ static int test_parmap_extended(e_xbt_parmap_mode_t mode) for (unsigned num_workers = 1; num_workers <= 16; num_workers *= 2) { const unsigned len = 2 * num_workers; - simgrid::xbt::Parmap parmap(num_workers, mode); - std::vector a(len); - std::vector data(len); + simgrid::xbt::Parmap parmap(num_workers, mode); + std::vector a(len); + std::vector data(len); std::iota(begin(data), end(data), &a[0]); - parmap.apply(fun_get_id, data); - - std::sort(begin(a), end(a)); - unsigned count = static_cast(std::distance(begin(a), std::unique(begin(a), end(a)))); + unsigned sleep_ms = 10; + unsigned count; + while (true) { + parmap.apply( + [sleep_ms](std::thread::id* arg) { + *arg = std::this_thread::get_id(); + std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms)); + }, + data); + std::sort(begin(a), end(a)); + count = static_cast(std::distance(begin(a), std::unique(begin(a), end(a)))); + if (count == num_workers || sleep_ms > 250) + break; + sleep_ms *= 2; + XBT_DEBUG("Failure. Try again with duration = %ums", sleep_ms); + } if (count != num_workers) { XBT_CRITICAL("only %u/%u threads did some work", count, num_workers); ret = 1; @@ -89,7 +88,7 @@ int main(int argc, char** argv) int status = 0; xbt_log_control_set("parmap_test.fmt:[%c/%p]%e%m%n"); simgrid::s4u::Engine e(&argc, argv); - SIMIX_context_set_nthreads(16); // dummy value > 1 + simgrid::kernel::context::Context::set_nthreads(16); // dummy value > 1 XBT_INFO("Basic testing posix"); status += test_parmap_basic(XBT_PARMAP_POSIX);