• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.82
/libs/core/runtime_configuration/src/runtime_configuration.cpp
1
//  Copyright (c) 2005-2025 Hartmut Kaiser
2
//  Copyright (c)      2011 Bryce Adelstein-Lelbach
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config/endian.hpp>
9
#include <hpx/assert.hpp>
10
#include <hpx/modules/errors.hpp>
11
#include <hpx/modules/filesystem.hpp>
12
#include <hpx/modules/format.hpp>
13
#include <hpx/modules/prefix.hpp>
14
#include <hpx/modules/preprocessor.hpp>
15
#include <hpx/modules/string_util.hpp>
16
#include <hpx/modules/util.hpp>
17
#include <hpx/runtime_configuration/agas_service_mode.hpp>
18
#include <hpx/runtime_configuration/component_registry_base.hpp>
19
#include <hpx/runtime_configuration/init_ini_data.hpp>
20
#include <hpx/runtime_configuration/plugin_registry_base.hpp>
21
#include <hpx/runtime_configuration/runtime_configuration.hpp>
22
#include <hpx/runtime_configuration/runtime_mode.hpp>
23
#include <hpx/version.hpp>
24

25
#if HPX_HAVE_ITTNOTIFY != 0 && !defined(HPX_HAVE_APEX)
26
#include <hpx/itt_notify/detail/use_ittnotify_api.hpp>
27
#include <hpx/modules/itt_notify.hpp>
28
#endif
29

30
#include <algorithm>
31
#include <cstddef>
32
#include <cstdint>
33
#include <cstdlib>
34
#include <iterator>
35
#include <limits>
36
#include <map>
37
#include <memory>
38
#include <set>
39
#include <string>
40
#include <system_error>
41
#include <utility>
42
#include <vector>
43

44
#if defined(HPX_WINDOWS)
45
#include <process.h>
46
#elif defined(HPX_HAVE_UNISTD_H)
47
#include <unistd.h>
48
#endif
49

50
#if (defined(__linux) || defined(linux) || defined(__linux__))
51
#include <arpa/inet.h>
52
#include <ifaddrs.h>
53
#include <netinet/in.h>
54
#include <sys/types.h>
55
#endif
56

57
#if !defined(HPX_WINDOWS)
58
#if defined(HPX_DEBUG)
59
#define HPX_DLL_STRING "libhpxd" HPX_SHARED_LIB_EXTENSION
60
#else
61
#define HPX_DLL_STRING "libhpx" HPX_SHARED_LIB_EXTENSION
62
#endif
63
#elif defined(HPX_DEBUG)
64
#define HPX_DLL_STRING "hpxd" HPX_SHARED_LIB_EXTENSION
65
#else
66
#define HPX_DLL_STRING "hpx" HPX_SHARED_LIB_EXTENSION
67
#endif
68

69
#include <limits>
70

71
///////////////////////////////////////////////////////////////////////////////
72
namespace hpx::util {
73

74
    namespace detail {
75

×
76
        // CMake does not deal with explicit semicolons well, for this reason,
77
        // the paths are delimited with ':'. On Windows those need to be
78
        // converted to ';'.
79
        static std::string convert_delimiters(std::string paths)
80
        {
256✔
81
#if defined(HPX_WINDOWS)
82
            std::replace(paths.begin(), paths.end(), ':', ';');
83
#endif
84
            return paths;
85
        }
320✔
86
    }    // namespace detail
87

320✔
88
    // pre-initialize entries with compile time based values
64✔
89
    void runtime_configuration::pre_initialize_ini()
90
    {
91
        if (!need_to_call_pre_initialize)
92
            return;
93

94
        std::vector<std::string> lines = {
95
            // clang-format off
96
            // create an empty application section
97
            "[application]",
256✔
98

512✔
99
            // create system and application instance specific entries
100
            "[system]",
512✔
101
            "pid = " + std::to_string(getpid()),
102
            "prefix = " + find_prefix(),
103
#if defined(__linux) || defined(linux) || defined(__linux__)
104
            "executable_prefix = " + get_executable_prefix(argv0),
105
#else
106
            "executable_prefix = " + get_executable_prefix(),
107
#endif
108
            // create default installation location and logging settings
109
            "[hpx]",
110
            "location = ${HPX_LOCATION:$[system.prefix]}",
111
            "component_paths = ${HPX_COMPONENT_PATHS}",
256✔
112
            "component_base_paths = $[hpx.location]"    // NOLINT
113
                HPX_INI_PATH_DELIMITER "$[system.executable_prefix]",
114
            "component_path_suffixes = " +
115
                detail::convert_delimiters(HPX_DEFAULT_COMPONENT_PATH_SUFFIXES),
116
            "master_ini_path = $[hpx.location]" HPX_INI_PATH_DELIMITER
117
            "$[system.executable_prefix]/",
118
            "master_ini_path_suffixes = /share/" HPX_BASE_DIR_NAME
119
                HPX_INI_PATH_DELIMITER "/../share/" HPX_BASE_DIR_NAME,
120
#ifdef HPX_HAVE_ITTNOTIFY
121
            "use_itt_notify = ${HPX_HAVE_ITTNOTIFY:0}",
122
#endif
123
            "finalize_wait_time = ${HPX_FINALIZE_WAIT_TIME:-1.0}",
124
            "shutdown_timeout = ${HPX_SHUTDOWN_TIMEOUT:-1.0}",
125
            "shutdown_check_count = ${HPX_SHUTDOWN_CHECK_COUNT:10}",
126
#ifdef HPX_HAVE_VERIFY_LOCKS
127
#if defined(HPX_DEBUG)
128
            "lock_detection = ${HPX_LOCK_DETECTION:1}",
129
#else
130
            "lock_detection = ${HPX_LOCK_DETECTION:0}",
131
#endif
132
            "throw_on_held_lock = ${HPX_THROW_ON_HELD_LOCK:1}",
133
#endif
134
#ifdef HPX_HAVE_THREAD_MINIMAL_DEADLOCK_DETECTION
135
#ifdef HPX_DEBUG
136
            "minimal_deadlock_detection = ${HPX_MINIMAL_DEADLOCK_DETECTION:1}",
137
#else
138
            "minimal_deadlock_detection = ${HPX_MINIMAL_DEADLOCK_DETECTION:0}",
139
#endif
140
#endif
141
#ifdef HPX_HAVE_SPINLOCK_DEADLOCK_DETECTION
142
#ifdef HPX_DEBUG
143
            "spinlock_deadlock_detection = "
144
            "${HPX_SPINLOCK_DEADLOCK_DETECTION:1}",
145
#else
146
            "spinlock_deadlock_detection = "
147
            "${HPX_SPINLOCK_DEADLOCK_DETECTION:0}",
148
#endif
149
            "spinlock_deadlock_detection_limit = "
150
            "${HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT:" HPX_PP_STRINGIZE(
151
                HPX_PP_EXPAND(HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT)) "}",
152
#endif
153
            "expect_connecting_localities = "
154
            "${HPX_EXPECT_CONNECTING_LOCALITIES:0}",
155

156
            // add placeholders for keys to be added by command line handling
157
            "os_threads = ${HPX_NUM_WORKER_THREADS:cores}",
158
            "cores = all",
159
            "localities = 1",
160
            "first_pu = 0",
161
            "runtime_mode = console",
162
            "scheduler = local-priority-fifo",
163
            "affinity = core",
164
            "pu_step = 1",
165
            "pu_offset = 0",
166
            "numa_sensitive = 0",
167
            "loopback_network = 0",
168
            "max_background_threads = "
169
            "${HPX_MAX_BACKGROUND_THREADS:$[hpx.os_threads]}",
170
            "max_idle_loop_count = ${HPX_MAX_IDLE_LOOP_COUNT:" HPX_PP_STRINGIZE(
171
                HPX_PP_EXPAND(HPX_IDLE_LOOP_COUNT_MAX)) "}",
172
            "max_busy_loop_count = ${HPX_MAX_BUSY_LOOP_COUNT:" HPX_PP_STRINGIZE(
173
                HPX_PP_EXPAND(HPX_BUSY_LOOP_COUNT_MAX)) "}",
174
#if defined(HPX_HAVE_THREAD_MANAGER_IDLE_BACKOFF)
175
            "max_idle_backoff_time = "
176
            "${HPX_MAX_IDLE_BACKOFF_TIME:" HPX_PP_STRINGIZE(
177
                HPX_PP_EXPAND(HPX_IDLE_BACKOFF_TIME_MAX)) "}",
178
#endif
179
            "default_scheduler_mode = ${HPX_DEFAULT_SCHEDULER_MODE}",
180

181
        /// If HPX_HAVE_ATTACH_DEBUGGER_ON_TEST_FAILURE is set,
182
        /// then apply the test-failure value as default.
183
#if defined(HPX_HAVE_ATTACH_DEBUGGER_ON_TEST_FAILURE)
184
            "attach_debugger = ${HPX_ATTACH_DEBUGGER:test-failure}",
185
#else
186
            "attach_debugger = ${HPX_ATTACH_DEBUGGER}",
187
#endif
188
            "exception_verbosity = ${HPX_EXCEPTION_VERBOSITY:2}",
189
            "trace_depth = ${HPX_TRACE_DEPTH:" HPX_PP_STRINGIZE(
190
                HPX_PP_EXPAND(HPX_HAVE_THREAD_BACKTRACE_DEPTH)) "}",
191
            "handle_signals = ${HPX_HANDLE_SIGNALS:1}",
192
            "handle_failed_new = ${HPX_HANDLE_FAILED_NEW:1}",
193

194
            // arity for collective operations implemented in a tree fashion
195
            "[hpx.lcos.collectives]",
196
            "arity = ${HPX_LCOS_COLLECTIVES_ARITY:32}",
197
            "cut_off = ${HPX_LCOS_COLLECTIVES_CUT_OFF:-1}",
198

199
            // connect back to the given latch if specified
200
            "[hpx.on_startup]",
201
            "wait_on_latch = ${HPX_ON_STARTUP_WAIT_ON_LATCH}",
202

203
#if defined(HPX_HAVE_NETWORKING)
204
            // by default, enable networking
205
            "[hpx.parcel]",
206
            "enable = 1",
207
#endif
208

209
            "[hpx.stacks]",
210
            "small_size = ${HPX_SMALL_STACK_SIZE:" HPX_PP_STRINGIZE(
211
                HPX_PP_EXPAND(HPX_SMALL_STACK_SIZE)) "}",
212
            "medium_size = ${HPX_MEDIUM_STACK_SIZE:" HPX_PP_STRINGIZE(
213
                HPX_PP_EXPAND(HPX_MEDIUM_STACK_SIZE)) "}",
214
            "large_size = ${HPX_LARGE_STACK_SIZE:" HPX_PP_STRINGIZE(
215
                HPX_PP_EXPAND(HPX_LARGE_STACK_SIZE)) "}",
216
            "huge_size = ${HPX_HUGE_STACK_SIZE:" HPX_PP_STRINGIZE(
217
                HPX_PP_EXPAND(HPX_HUGE_STACK_SIZE)) "}",
218
#if defined(__linux) || defined(linux) || defined(__linux__) ||                \
219
    defined(__FreeBSD__)
220
            "use_guard_pages = ${HPX_USE_GUARD_PAGES:1}",
221
#endif
222

223
            "[hpx.threadpools]",
224
#if defined(HPX_HAVE_IO_POOL)
225
            "io_pool_size = ${HPX_NUM_IO_POOL_SIZE:" HPX_PP_STRINGIZE(
226
                HPX_PP_EXPAND(HPX_NUM_IO_POOL_SIZE)) "}",
227
#endif
228
#if defined(HPX_HAVE_NETWORKING)
229
            "parcel_pool_size = ${HPX_NUM_PARCEL_POOL_SIZE:" HPX_PP_STRINGIZE(
230
                HPX_PP_EXPAND(HPX_NUM_PARCEL_POOL_SIZE)) "}",
231
#endif
232
#if defined(HPX_HAVE_TIMER_POOL)
233
            "timer_pool_size = ${HPX_NUM_TIMER_POOL_SIZE:" HPX_PP_STRINGIZE(
234
                HPX_PP_EXPAND(HPX_NUM_TIMER_POOL_SIZE)) "}",
235
#endif
236

237
            "[hpx.thread_queue]",
238
            "max_thread_count = ${HPX_THREAD_QUEUE_MAX_THREAD_COUNT:" HPX_PP_STRINGIZE(
239
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MAX_THREAD_COUNT)) "}",
240
            "min_tasks_to_steal_pending = "
241
            "${HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_PENDING:" HPX_PP_STRINGIZE(
242
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_PENDING)) "}",
243
            "min_tasks_to_steal_staged = "
244
            "${HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_STAGED:" HPX_PP_STRINGIZE(
245
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MIN_TASKS_TO_STEAL_STAGED)) "}",
246
            "min_add_new_count = "
247
            "${HPX_THREAD_QUEUE_MIN_ADD_NEW_COUNT:" HPX_PP_STRINGIZE(
248
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MIN_ADD_NEW_COUNT)) "}",
249
            "max_add_new_count = "
250
            "${HPX_THREAD_QUEUE_MAX_ADD_NEW_COUNT:" HPX_PP_STRINGIZE(
251
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MAX_ADD_NEW_COUNT)) "}",
252
            "min_delete_count = "
253
            "${HPX_THREAD_QUEUE_MIN_DELETE_COUNT:" HPX_PP_STRINGIZE(
254
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MIN_DELETE_COUNT)) "}",
255
            "max_delete_count = "
256
            "${HPX_THREAD_QUEUE_MAX_DELETE_COUNT:" HPX_PP_STRINGIZE(
257
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MAX_THREAD_COUNT)) "}",
258
            "max_terminated_threads = "
259
            "${HPX_THREAD_QUEUE_MAX_TERMINATED_THREADS:" HPX_PP_STRINGIZE(
260
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_MAX_TERMINATED_THREADS)) "}",
261
            "init_threads_count = "
262
            "${HPX_THREAD_QUEUE_INIT_THREADS_COUNT:" HPX_PP_STRINGIZE(
263
                HPX_PP_EXPAND(HPX_THREAD_QUEUE_INIT_THREADS_COUNT)) "}",
264

265
            "[hpx.commandline]",
266
            // enable aliasing
267
            "aliasing = ${HPX_COMMANDLINE_ALIASING:1}",
268

269
            // allow for unknown options to be passed through
270
            "allow_unknown = ${HPX_COMMANDLINE_ALLOW_UNKNOWN:0}",
271

272
            // allow for command line options to be passed through the
273
            // environment
274
            "prepend_options = ${HPX_COMMANDLINE_OPTIONS}",
275

276
            // predefine command line aliases
277
            "[hpx.commandline.aliases]",
278
            "-a = --hpx:agas",
279
            "-c = --hpx:console",
280
            "-h = --hpx:help",
281
            "-I = --hpx:ini",
282
            "-l = --hpx:localities",
283
            "-p = --hpx:app-config",
284
            "-q = --hpx:queuing",
285
            "-r = --hpx:run-agas-server",
286
            "-t = --hpx:threads",
287
            "-v = --hpx:version",
288
            "-w = --hpx:worker",
289
            "-x = --hpx:hpx",
290
            "-0 = --hpx:node=0",
291
            "-1 = --hpx:node=1",
292
            "-2 = --hpx:node=2",
293
            "-3 = --hpx:node=3",
294
            "-4 = --hpx:node=4",
295
            "-5 = --hpx:node=5",
296
            "-6 = --hpx:node=6",
297
            "-7 = --hpx:node=7",
298
            "-8 = --hpx:node=8",
299
            "-9 = --hpx:node=9",
300

301
            "[hpx.agas]",
302
            // 'address' has deliberately no default, see
303
            // command_line_handling.cpp
304
            "address = ${HPX_AGAS_SERVER_ADDRESS}",
305
            "port = ${HPX_AGAS_SERVER_PORT:" HPX_PP_STRINGIZE(
306
                HPX_PP_EXPAND(HPX_INITIAL_IP_PORT)) "}",
307
            "max_pending_refcnt_requests = "
308
            "${HPX_AGAS_MAX_PENDING_REFCNT_REQUESTS:" HPX_PP_STRINGIZE(
309
                HPX_PP_EXPAND(
310
                    HPX_INITIAL_AGAS_MAX_PENDING_REFCNT_REQUESTS)) "}",
311
            "service_mode = hosted",
312
            "local_cache_size = ${HPX_AGAS_LOCAL_CACHE_SIZE:" HPX_PP_STRINGIZE(
313
                HPX_PP_EXPAND(HPX_AGAS_LOCAL_CACHE_SIZE)) "}",
314
            "use_range_caching = ${HPX_AGAS_USE_RANGE_CACHING:1}",
315
            "use_caching = ${HPX_AGAS_USE_CACHING:1}",
316

317
            "[hpx.components]",
318
            "load_external = ${HPX_LOAD_EXTERNAL_COMPONENTS:1}",
319

320
            "[hpx.components.barrier]",
321
            "name = hpx",
322
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
323
            "enabled = 1",
324

325
            "[hpx.components.hpx_lcos_server_latch]",
326
            "name = hpx",
327
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
328
            "enabled = 1",
329

330
            "[hpx.components.raw_counter]",
331
            "name = hpx",
332
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
333
            "enabled = 1",
334

335
            "[hpx.components.average_count_counter]",
336
            "name = hpx",
337
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
338
            "enabled = 1",
339

340
            "[hpx.components.elapsed_time_counter]",
341
            "name = hpx",
30,976✔
342
            "path = $[hpx.location]/bin/" HPX_DLL_STRING,
343
            "enabled = 1"
256✔
344
            // clang-format on
345
        };
346

347
        lines.insert(lines.end(), extra_static_ini_defs.begin(),
256✔
348
            extra_static_ini_defs.end());
349

256✔
350
        // don't overload user overrides
1,792✔
351
        this->parse("<static defaults>", lines, false, false, false);
352

256✔
353
        need_to_call_pre_initialize = false;
354
    }
355

256✔
356
    void runtime_configuration::post_initialize_ini(std::string& hpx_ini_file_,
256✔
357
        std::vector<std::string> const& cmdline_ini_defs_)
358
    {
359
        util::init_ini_data_base(*this, hpx_ini_file_);
256✔
360
        need_to_call_pre_initialize = true;
361

362
        // let the command line override the config file.
140✔
363
        if (!cmdline_ini_defs_.empty())
364
        {
140✔
365
            // do not weed out comments
366
            this->parse(
256✔
367
                "<command line definitions>", cmdline_ini_defs_, true, false);
368
            need_to_call_pre_initialize = true;
256✔
369
        }
370
    }
371

372
    void runtime_configuration::pre_initialize_logging_ini()
373
    {
374
#if defined(HPX_HAVE_LOGGING)
375
        std::vector<std::string> const lines = {
376
        // clang-format off
377
#define HPX_TIMEFORMAT "$hh:$mm.$ss.$mili"
378
#define HPX_LOGFORMAT "(T%locality%/%hpxthread%.%hpxphase%/%hpxcomponent%) "
379

380
            // general logging
381
            "[hpx.logging]",
382
            "level = ${HPX_LOGLEVEL:0}",
383
            "destination = ${HPX_LOGDESTINATION:console}",
384
            "format = ${HPX_LOGFORMAT:" HPX_LOGFORMAT
385
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
386
                HPX_TIMEFORMAT ") [%idx%]|\\n}",
387

388
            // general console logging
389
            "[hpx.logging.console]",
390
            "level = ${HPX_LOGLEVEL:$[hpx.logging.level]}",
391
#if defined(ANDROID) || defined(__ANDROID__)
392
            "destination = ${HPX_CONSOLE_LOGDESTINATION:android_log}",
393
#else
394
            "destination = ${HPX_CONSOLE_LOGDESTINATION:"
395
                "file(hpx.$[system.pid].log)}",
396
#endif
397
            "format = ${HPX_CONSOLE_LOGFORMAT:|}",
398

399
            // logging related to timing
400
            "[hpx.logging.timing]",
401
            "level = ${HPX_TIMING_LOGLEVEL:-1}",
402
            "destination = ${HPX_TIMING_LOGDESTINATION:console}",
403
            "format = ${HPX_TIMING_LOGFORMAT:" HPX_LOGFORMAT
404
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
405
                HPX_TIMEFORMAT ") [%idx%] [TIM] |\\n}",
406

407
            // console logging related to timing
408
            "[hpx.logging.console.timing]",
409
            "level = ${HPX_TIMING_LOGLEVEL:$[hpx.logging.timing.level]}",
410
#if defined(ANDROID) || defined(__ANDROID__)
411
            "destination = ${HPX_CONSOLE_TIMING_LOGDESTINATION:android_log}",
412
#else
413
            "destination = ${HPX_CONSOLE_TIMING_LOGDESTINATION:"
414
                "file(hpx.timing.$[system.pid].log)}",
415
#endif
416
            "format = ${HPX_CONSOLE_TIMING_LOGFORMAT:|}",
417

418
            // logging related to AGAS
419
            "[hpx.logging.agas]",
420
            "level = ${HPX_AGAS_LOGLEVEL:-1}",
421
            "destination = ${HPX_AGAS_LOGDESTINATION:"
422
                "file(hpx.agas.$[system.pid].log)}",
423
            "format = ${HPX_AGAS_LOGFORMAT:" HPX_LOGFORMAT
424
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
425
                    HPX_TIMEFORMAT ") [%idx%][AGAS] |\\n}",
426

427
            // console logging related to AGAS
428
            "[hpx.logging.console.agas]",
429
            "level = ${HPX_AGAS_LOGLEVEL:$[hpx.logging.agas.level]}",
430
#if defined(ANDROID) || defined(__ANDROID__)
431
            "destination = ${HPX_CONSOLE_AGAS_LOGDESTINATION:android_log}",
432
#else
433
            "destination = ${HPX_CONSOLE_AGAS_LOGDESTINATION:"
434
                "file(hpx.agas.$[system.pid].log)}",
435
#endif
436
            "format = ${HPX_CONSOLE_AGAS_LOGFORMAT:|}",
437

438
            // logging related to the parcel transport
439
            "[hpx.logging.parcel]",
440
            "level = ${HPX_PARCEL_LOGLEVEL:-1}",
441
            "destination = ${HPX_PARCEL_LOGDESTINATION:"
442
                "file(hpx.parcel.$[system.pid].log)}",
443
            "format = ${HPX_PARCEL_LOGFORMAT:" HPX_LOGFORMAT
444
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
445
                HPX_TIMEFORMAT ") [%idx%][  PT] |\\n}",
446

447
            // console logging related to the parcel transport
448
            "[hpx.logging.console.parcel]",
449
            "level = ${HPX_PARCEL_LOGLEVEL:$[hpx.logging.parcel.level]}",
450
#if defined(ANDROID) || defined(__ANDROID__)
451
            "destination = ${HPX_CONSOLE_PARCEL_LOGDESTINATION:android_log}",
452
#else
453
            "destination = ${HPX_CONSOLE_PARCEL_LOGDESTINATION:"
454
                "file(hpx.parcel.$[system.pid].log)}",
455
#endif
456
            "format = ${HPX_CONSOLE_PARCEL_LOGFORMAT:|}",
457

458
            // logging related to applications
459
            "[hpx.logging.application]",
460
            "level = ${HPX_APP_LOGLEVEL:-1}",
461
            "destination = ${HPX_APP_LOGDESTINATION:console}",
462
            "format = ${HPX_APP_LOGFORMAT:" HPX_LOGFORMAT
463
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
464
                HPX_TIMEFORMAT ") [%idx%] [APP] |\\n}",
465

466
            // console logging related to applications
467
            "[hpx.logging.console.application]",
468
            "level = ${HPX_APP_LOGLEVEL:$[hpx.logging.application.level]}",
469
#if defined(ANDROID) || defined(__ANDROID__)
470
            "destination = ${HPX_CONSOLE_APP_LOGDESTINATION:android_log}",
471
#else
472
            "destination = ${HPX_CONSOLE_APP_LOGDESTINATION:"
473
                "file(hpx.application.$[system.pid].log)}",
474
#endif
475
            "format = ${HPX_CONSOLE_APP_LOGFORMAT:|}",
476

477
            // logging of debug channel
478
            "[hpx.logging.debuglog]",
479
            "level = ${HPX_DEB_LOGLEVEL:-1}",
480
            "destination = ${HPX_DEB_LOGDESTINATION:console}",
481
            "format = ${HPX_DEB_LOGFORMAT:" HPX_LOGFORMAT
482
                "P%parentloc%/%hpxparent%.%hpxparentphase% %time%("
483
                HPX_TIMEFORMAT ") [%idx%] [DEB] |\\n}",
484

485
            "[hpx.logging.console.debuglog]",
486
            "level = ${HPX_DEB_LOGLEVEL:$[hpx.logging.debuglog.level]}",
487
#if defined(ANDROID) || defined(__ANDROID__)
488
            "destination = ${HPX_CONSOLE_DEB_LOGDESTINATION:android_log}",
489
#else
490
            "destination = ${HPX_CONSOLE_DEB_LOGDESTINATION:"
491
                "file(hpx.debuglog.$[system.pid].log)}",
492
#endif
493
            "format = ${HPX_CONSOLE_DEB_LOGFORMAT:|}"
494

12,544✔
495
#undef HPX_TIMEFORMAT
496
#undef HPX_LOGFORMAT
497
            // clang-format on
256✔
498
        };
499

768✔
500
        // don't overload user overrides
501
        this->parse("<static logging defaults>", lines, false, false);
502
#endif
503
    }
32✔
504

505
    ///////////////////////////////////////////////////////////////////////////
506
    // load information about statically known components
507
    void runtime_configuration::load_components_static(
508
        std::vector<components::static_factory_load_data_type> const&
32✔
509
            static_modules)
32✔
510
    {
80✔
511
        std::vector<std::shared_ptr<components::component_registry_base>>
512
            registries;
513
        for (components::static_factory_load_data_type const& d :
96✔
514
            static_modules)
48✔
515
        {
516
            auto new_registries = util::load_component_factory_static(
517
                *this, d.name, d.get_factory);
48✔
518
            registries.reserve(registries.size() + new_registries.size());
519
            std::copy(new_registries.begin(), new_registries.end(),
520
                std::back_inserter(registries));
521
        }
32✔
522

523
        // read system and user ini files _again_, to allow the user to
524
        // overwrite the settings from the default component ini's.
32✔
525
        util::init_ini_data_base(*this, hpx_ini_file);
64✔
526

527
        // let the command line override the config file.
528
        if (!cmdline_ini_defs.empty())
32✔
529
            parse("<command line definitions>", cmdline_ini_defs, true, false);
530

32✔
531
        // merge all found ini files of all components
532
        util::merge_component_inis(*this);
533

32✔
534
        need_to_call_pre_initialize = true;
892✔
535

536
        // invoke last reconfigure
860✔
537
        reconfigure();
538
        for (auto const& registry : registries)
32✔
539
        {
540
            registry->register_component_type();
541
        }
542
    }
128✔
543

544
    ///////////////////////////////////////////////////////////////////////////
545
    // collect all directories where to use for the search for plugins
546
    void runtime_configuration::load_component_path(
547
        std::vector<std::shared_ptr<plugins::plugin_registry_base>>&
548
            plugin_registries,
549
        std::vector<std::shared_ptr<components::component_registry_base>>&
550
            component_registries,
551
        std::string const& path, std::set<std::string>& component_paths,
552
        std::map<std::string, filesystem::path>& basenames)
553
    {
554
        namespace fs = filesystem;
555

128✔
556
        using plugin_list_type =
557
            std::vector<std::shared_ptr<plugins::plugin_registry_base>>;
128✔
558

559
        if (!path.empty())
560
        {
128✔
561
            fs::path const this_p(path);
128✔
562
            std::error_code fsec;
96✔
563
            fs::path canonical_p =
564
                fs::canonical(this_p, fs::initial_path(), fsec);
128✔
565
            if (fsec)
128✔
566
                canonical_p = this_p;
128✔
567

568
            if (auto const [it, ok] =
569
                    component_paths.emplace(canonical_p.string());
96✔
570
                ok)
96✔
571
            {
572
                // have all path elements, now find ini files in there...
573
                fs::path const this_path(*it);
32✔
574
                if (fs::exists(this_path, fsec) && !fsec)
32✔
575
                {
576
                    plugin_list_type tmp_regs =
577
                        util::init_ini_data_default(this_path.string(), *this,
578
                            basenames, modules_, component_registries);
32✔
579

96✔
580
                    std::copy(tmp_regs.begin(), tmp_regs.end(),
128✔
581
                        std::back_inserter(plugin_registries));
128✔
582
                }
583
            }
64✔
584
        }
585
    }
586

587
    void runtime_configuration::load_component_paths(
588
        std::vector<std::shared_ptr<plugins::plugin_registry_base>>&
589
            plugin_registries,
590
        std::vector<std::shared_ptr<components::component_registry_base>>&
591
            component_registries,
592
        std::string const& component_base_paths,
593
        std::string const& component_path_suffixes,
594
        std::set<std::string>& component_paths,
595
        std::map<std::string, filesystem::path>& basenames)
596
    {
597
        // try to build default ini structure from shared libraries in default
598
        // installation location, this allows to install simple components
599
        // without the need to install an ini file split of the separate paths
64✔
600
        // from the given path list
601
        hpx::string_util::char_separator sep(HPX_INI_PATH_DELIMITER);
602
        hpx::string_util::tokenizer tok_path(component_base_paths, sep);
603
        hpx::string_util::tokenizer tok_suffixes(component_path_suffixes, sep);
604
        auto end_path = tok_path.end();
605
        auto end_suffixes = tok_suffixes.end();
96✔
606

607
        for (auto it = tok_path.begin(); it != end_path; ++it)
608
        {
32✔
609
            std::string const& path = *it;
610
            if (tok_suffixes.begin() != tok_suffixes.end())
160✔
611
            {
612
                for (auto jt = tok_suffixes.begin(); jt != end_suffixes; ++jt)
613
                {
614
                    std::string p = path;
128✔
615
                    p += *jt;
616
                    load_component_path(plugin_registries, component_registries,
32✔
617
                        p, component_paths, basenames);
618
                }
619
            }
620
            else
×
621
            {
622
                load_component_path(plugin_registries, component_registries,
623
                    path, component_paths, basenames);
64✔
624
            }
128✔
625
        }
626
    }
627

628
    // load information about dynamically discovered plugins
32✔
629
    std::vector<std::shared_ptr<plugins::plugin_registry_base>>
630
    runtime_configuration::load_modules(
631
        std::vector<std::shared_ptr<components::component_registry_base>>&
632
            component_registries)
633
    {
634
        typedef std::vector<std::shared_ptr<plugins::plugin_registry_base>>
635
            plugin_list_type;
636

637
        // protect against duplicate paths
638
        std::set<std::string> component_paths;
639

640
        // list of base names avoiding loading a module more than once
641
        std::map<std::string, filesystem::path> basenames;
642

32✔
643
        // plugin registry object
644
        plugin_list_type plugin_registries;
645

646
        // load plugin paths from component_base_paths and suffixes
96✔
647
        std::string const component_base_paths(
648
            get_entry("hpx.component_base_paths", HPX_DEFAULT_COMPONENT_PATH));
32✔
649
        std::string const component_path_suffixes(
650
            get_entry("hpx.component_path_suffixes", "/lib/hpx"));
32✔
651

652
        load_component_paths(plugin_registries, component_registries,
653
            component_base_paths, component_path_suffixes, component_paths,
654
            basenames);
655

32✔
656
        // load additional explicit plugin paths from plugin_paths key
32✔
657
        std::string const plugin_paths(get_entry("hpx.component_paths", ""));
658
        load_component_paths(plugin_registries, component_registries,
659
            plugin_paths, "", component_paths, basenames);
660

661
        // read system and user ini files _again_, to allow the user to
32✔
662
        // overwrite the settings from the default component ini's.
663
        util::init_ini_data_base(*this, hpx_ini_file);
664

32✔
665
        // let the command line override the config file.
42✔
666
        if (!cmdline_ini_defs.empty())
667
            parse("<command line definitions>", cmdline_ini_defs, true, false);
668

32✔
669
        // merge all found ini files of all components
670
        util::merge_component_inis(*this);
32✔
671

672
        need_to_call_pre_initialize = true;
673

32✔
674
        // invoke reconfigure
675
        reconfigure();
32✔
676

×
677
        return plugin_registries;
678
    }
679

64✔
680
    ///////////////////////////////////////////////////////////////////////////
64✔
681
    runtime_configuration::runtime_configuration(char const* argv0_,
64✔
682
        runtime_mode const mode,
64✔
683
        std::vector<std::string> extra_static_ini_defs_)
64✔
684
      : extra_static_ini_defs(HPX_MOVE(extra_static_ini_defs_))
64✔
685
      , mode_(mode)
64✔
686
      , num_localities(0)
64✔
687
      , num_os_threads(0)
64✔
688
      , small_stacksize(HPX_SMALL_STACK_SIZE)
64✔
689
      , medium_stacksize(HPX_MEDIUM_STACK_SIZE)
64✔
690
      , large_stacksize(HPX_LARGE_STACK_SIZE)
691
      , huge_stacksize(HPX_HUGE_STACK_SIZE)
64✔
692
      , need_to_call_pre_initialize(true)
693
#if defined(__linux) || defined(linux) || defined(__linux__)
694
      , argv0(argv0_)
695
#endif
696
    {
64✔
697
        (void) argv0_;
698

699
        pre_initialize_ini();
700

701
        // set global config options
702
#if HPX_HAVE_ITTNOTIFY != 0
703
        use_ittnotify_api = get_itt_notify_mode();
704
#endif
64✔
705
        HPX_ASSERT(init_small_stack_size() >= HPX_SMALL_STACK_SIZE);
64✔
706

64✔
707
        small_stacksize = init_small_stack_size();
708
        medium_stacksize = init_medium_stack_size();
64✔
709
        large_stacksize = init_large_stack_size();
64✔
710
        HPX_ASSERT(init_huge_stack_size() <= HPX_HUGE_STACK_SIZE);
711
        huge_stacksize = init_huge_stack_size();
712
    }
64✔
713

714
    ///////////////////////////////////////////////////////////////////////////
64✔
715
    void runtime_configuration::reconfigure(std::string ini_file)
64✔
716
    {
64✔
717
        hpx_ini_file = HPX_MOVE(ini_file);
718
        reconfigure();
128✔
719
    }
720

128✔
721
    void runtime_configuration::reconfigure(std::vector<std::string> ini_defs)
128✔
722
    {
128✔
723
        cmdline_ini_defs = HPX_MOVE(ini_defs);
724
        reconfigure();
256✔
725
    }
726

256✔
727
    void runtime_configuration::reconfigure()
256✔
728
    {
256✔
729
        pre_initialize_ini();
730
        pre_initialize_logging_ini();
731
        post_initialize_ini(hpx_ini_file, cmdline_ini_defs);
732

733
        // set global config options
734
#if HPX_HAVE_ITTNOTIFY != 0
735
        use_ittnotify_api = get_itt_notify_mode();
736
#endif
256✔
737
        HPX_ASSERT(init_small_stack_size() >= HPX_SMALL_STACK_SIZE);
256✔
738

256✔
739
        small_stacksize = init_small_stack_size();
256✔
740
        medium_stacksize = init_medium_stack_size();
256✔
741
        large_stacksize = init_large_stack_size();
742
        huge_stacksize = init_huge_stack_size();
×
743
    }
744

×
745
    std::size_t runtime_configuration::get_ipc_data_buffer_cache_size() const
746
    {
747
        if (util::section const* sec = get_section("hpx.parcel.ipc");
×
748
            nullptr != sec)
749
        {
×
750
            return hpx::util::get_entry_as<std::size_t>(*sec,
751
                "data_buffer_cache_size",
752
                HPX_PARCEL_IPC_DATA_BUFFER_CACHE_SIZE);
753
        }
754
        return HPX_PARCEL_IPC_DATA_BUFFER_CACHE_SIZE;
96✔
755
    }
756

757
    agas::service_mode runtime_configuration::get_agas_service_mode() const
192✔
758
    {
759
        // load all components as described in the configuration information
192✔
760
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
761
        {
96✔
762
            std::string const m = sec->get_entry("service_mode", "hosted");
763

764
            if (m == "hosted")
765
            {
87✔
766
                return agas::service_mode::hosted;
767
            }
768
            else if (m == "bootstrap")
769
            {
770
                return agas::service_mode::bootstrap;
771
            }
772
            else
×
773
            {
774
                // REVIEW: exception type is overused
775
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
776
                    "runtime_configuration::get_agas_service_mode",
777
                    "invalid AGAS router mode \"{}\"", m);
778
            }
779
        }
780
        return agas::service_mode::hosted;
561✔
781
    }
782

561✔
783
    std::uint32_t runtime_configuration::get_num_localities() const
784
    {
58✔
785
        if (num_localities == 0)
786
        {
29✔
787
            if (util::section const* sec = get_section("hpx"); nullptr != sec)
58✔
788
            {
789
                num_localities = hpx::util::get_entry_as<std::uint32_t>(
790
                    *sec, "localities", 1);
791
            }
792
        }
561✔
793

794
        HPX_ASSERT(num_localities != 0);
795
        return num_localities;
3✔
796
    }
797

798
    void runtime_configuration::set_num_localities(
799
        std::uint32_t const num_localities_)
800
    {
3✔
801
        // this function should not be called on the AGAS server
802
        HPX_ASSERT(agas::service_mode::bootstrap != get_agas_service_mode());
6✔
803
        num_localities = num_localities_;
804

6✔
805
        if (util::section* sec = get_section("hpx"); nullptr != sec)
806
        {
3✔
807
            sec->add_entry("localities", std::to_string(num_localities));
808
        }
809
    }
224✔
810

811
    // this function should figure out whether networking has to be enabled.
812
    bool runtime_configuration::enable_networking() const
448✔
813
    {
814
#if defined(HPX_HAVE_NETWORKING)
815
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
448✔
816
        {
817
            // get the number of initial localities
818
            if (hpx::util::get_entry_as<std::uint32_t>(*sec, "localities", 1) >
819
                1)
820
            {
821
                return true;
822
            }
823

376✔
824
            // on localities other than locality zero the number of
825
            // localities might not have been initialized yet
826
            if (hpx::util::get_entry_as<std::int32_t>(*sec, "node", -1) > 0)
827
            {
828
                return true;
829
            }
188✔
830

376✔
831
            // get whether localities are expected to connect
832
            if (hpx::util::get_entry_as<std::int32_t>(
833
                    *sec, "expect_connecting_localities", 0) != 0)
834
            {
835
                return true;
836
            }
837

376✔
838
            // for any runtime mode except 'console' networking should be
839
            // enabled as well
840
            if (hpx::util::get_entry_as<std::string>(
841
                    *sec, "runtime_mode", "") != "console")
842
            {
843
                return true;
844
            }
188✔
845

376✔
846
            // whether the user has explicitly asked for network enabled
847
            if (hpx::util::get_entry_as<std::int32_t>(
848
                    *sec, "loopback_network", 0) != 0)
849
            {
850
                return true;
851
            }
852
        }
853
#endif
854
        return false;
67✔
855
    }
856

134✔
857
    std::uint32_t runtime_configuration::get_first_used_core() const
858
    {
67✔
859
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
134✔
860
        {
861
            return hpx::util::get_entry_as<std::uint32_t>(
862
                *sec, "first_used_core", 0);
863
        }
864
        return 0;
32✔
865
    }
866

867
    void runtime_configuration::set_first_used_core(
64✔
868
        std::uint32_t const first_used_core)
869
    {
64✔
870
        if (util::section* sec = get_section("hpx"); nullptr != sec)
871
        {
32✔
872
            sec->add_entry("first_used_core", std::to_string(first_used_core));
873
        }
32✔
874
    }
875

876
    std::size_t runtime_configuration::get_agas_local_cache_size(
32✔
877
        std::size_t const dflt) const
878
    {
64✔
879
        std::size_t cache_size = dflt;
880

32✔
881
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
882
        {
883
            cache_size = hpx::util::get_entry_as<std::size_t>(
884
                *sec, "local_cache_size", cache_size);
32✔
885
        }
886

887
        if (cache_size != ~static_cast<std::size_t>(0) && cache_size < 16ul)
×
888
        {
889
            cache_size = 16;    // limit lower bound
32✔
890
        }
891
        return cache_size;
892
    }
32✔
893

894
    bool runtime_configuration::get_agas_caching_mode() const
64✔
895
    {
896
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
32✔
897
        {
898
            return hpx::util::get_entry_as<int>(*sec, "use_caching", 1) != 0;
899
        }
900
        return false;
901
    }
32✔
902

903
    bool runtime_configuration::get_agas_range_caching_mode() const
64✔
904
    {
905
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
64✔
906
        {
32✔
907
            return hpx::util::get_entry_as<int>(*sec, "use_range_caching", 1) !=
908
                0;
909
        }
910
        return false;
911
    }
32✔
912

913
    std::size_t runtime_configuration::get_agas_max_pending_refcnt_requests()
914
        const
64✔
915
    {
916
        if (util::section const* sec = get_section("hpx.agas"); nullptr != sec)
32✔
917
        {
918
            return hpx::util::get_entry_as<std::size_t>(*sec,
64✔
919
                "max_pending_refcnt_requests",
920
                HPX_INITIAL_AGAS_MAX_PENDING_REFCNT_REQUESTS);
921
        }
922
        return HPX_INITIAL_AGAS_MAX_PENDING_REFCNT_REQUESTS;
923
    }
×
924

925
    bool runtime_configuration::get_itt_notify_mode() const
926
    {
927
#if HPX_HAVE_ITTNOTIFY != 0
928
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
929
        {
930
            return hpx::util::get_entry_as<int>(*sec, "use_itt_notify", 0) != 0;
931
        }
×
932
#endif
933
        return false;
934
    }
935

×
936
    // Enable lock detection during suspension
937
    bool runtime_configuration::enable_lock_detection() const
938
    {
939
#ifdef HPX_HAVE_VERIFY_LOCKS
940
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
941
        {
942
            return hpx::util::get_entry_as<int>(*sec, "lock_detection", 0) != 0;
943
        }
×
944
#endif
945
        return false;
946
    }
947

×
948
    // Enable minimal deadlock detection for HPX threads
949
    bool runtime_configuration::enable_minimal_deadlock_detection() const
950
    {
951
#ifdef HPX_HAVE_THREAD_MINIMAL_DEADLOCK_DETECTION
952
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
953
        {
954
#ifdef HPX_DEBUG
955
            return hpx::util::get_entry_as<int>(
956
                       *sec, "minimal_deadlock_detection", 1) != 0;
957
#else
958
            return hpx::util::get_entry_as<int>(
959
                       *sec, "minimal_deadlock_detection", 0) != 0;
960
#endif
961
        }
962

963
#ifdef HPX_DEBUG
964
        return true;
965
#else
966
        return false;
967
#endif
968

×
969
#else
970
        return false;
971
#endif
972
    }
973

×
974
    ///////////////////////////////////////////////////////////////////////////
975
    bool runtime_configuration::enable_spinlock_deadlock_detection() const
976
    {
977
#ifdef HPX_HAVE_SPINLOCK_DEADLOCK_DETECTION
978
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
979
        {
980
#ifdef HPX_DEBUG
981
            return hpx::util::get_entry_as<int>(
982
                       *sec, "spinlock_deadlock_detection", 1) != 0;
983
#else
984
            return hpx::util::get_entry_as<int>(
985
                       *sec, "spinlock_deadlock_detection", 0) != 0;
986
#endif
987
        }
988

989
#ifdef HPX_DEBUG
990
        return true;
991
#else
992
        return false;
993
#endif
994

×
995
#else
996
        return false;
997
#endif
998
    }
999

×
1000
    ///////////////////////////////////////////////////////////////////////////
1001
    std::size_t runtime_configuration::get_spinlock_deadlock_detection_limit()
1002
        const
1003
    {
1004
#ifdef HPX_HAVE_SPINLOCK_DEADLOCK_DETECTION
1005
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
1006
        {
1007
            return hpx::util::get_entry_as<std::size_t>(*sec,
1008
                "spinlock_deadlock_detection_limit",
1009
                HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT);
1010
        }
1011
        return HPX_SPINLOCK_DEADLOCK_DETECTION_LIMIT;
×
1012
#else
1013
        return static_cast<std::size_t>(-1);
1014
#endif
1015
    }
×
1016

1017
    std::size_t runtime_configuration::trace_depth() const
×
1018
    {
1019
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
×
1020
        {
×
1021
            return hpx::util::get_entry_as<std::size_t>(
1022
                *sec, "trace_depth", HPX_HAVE_THREAD_BACKTRACE_DEPTH);
1023
        }
1024
        return HPX_HAVE_THREAD_BACKTRACE_DEPTH;
1025
    }
5✔
1026

1027
    std::size_t runtime_configuration::get_os_thread_count() const
5✔
1028
    {
1029
        if (num_os_threads == 0)
5✔
1030
        {
10✔
1031
            if (util::section const* sec = get_section("hpx"); nullptr != sec)
1032
            {
5✔
1033
                num_os_threads = hpx::util::get_entry_as<std::uint32_t>(
10✔
1034
                    *sec, "os_threads", 1);
1035
            }
1036
            else
5✔
1037
            {
1038
                num_os_threads = 1;
1039
            }
×
1040
        }
1041
        return static_cast<std::size_t>(num_os_threads);
×
1042
    }
1043

×
1044
    std::string runtime_configuration::get_cmd_line() const
1045
    {
×
1046
        if (util::section const* sec = get_section("hpx"); nullptr != sec)
1047
        {
1048
            return sec->get_entry("cmd_line", "");
1049
        }
128✔
1050
        return "";
1051
    }
1052

256✔
1053
    // Return the configured sizes of the known thread pools
1054
    std::size_t runtime_configuration::get_thread_pool_size(
1055
        char const* poolname) const
128✔
1056
    {
256✔
1057
        if (util::section const* sec = get_section("hpx.threadpools");
1058
            nullptr != sec)
1059
        {
1060
            return hpx::util::get_entry_as<std::size_t>(
1061
                *sec, std::string(poolname) + "_size", 2);
1062
        }
×
1063
        return 2;    // the default size for all pools is 2
1064
    }
×
1065

1066
    // Return the endianness to be used for out-serialization
1067
    std::string runtime_configuration::get_endian_out() const
×
1068
    {
×
1069
        if (util::section const* sec = get_section("hpx.parcel");
1070
            nullptr != sec)
×
1071
        {
1072
            return sec->get_entry(
1073
                "endian_out", endian::native == endian::big ? "big" : "little");
1074
        }
1,280✔
1075
        return endian::native == endian::big ? "big" : "little";
1076
    }
1077

2,560✔
1078
    // Will return the stack size to use for all HPX-threads.
1079
    std::ptrdiff_t runtime_configuration::init_stack_size(char const* entryname,
1080
        char const* defaultvaluestr, std::ptrdiff_t const defaultvalue) const
1081
    {
1,280✔
1082
        if (util::section const* sec = get_section("hpx.stacks");
1,280✔
1083
            nullptr != sec)
1084
        {
1,280✔
1085
            std::string const entry =
1,280✔
1086
                sec->get_entry(entryname, defaultvaluestr);
1087
            char* endptr = nullptr;
1088
            std::ptrdiff_t const val =
1089
                std::strtoll(entry.c_str(), &endptr, /*base:*/ 0);
1090
            return endptr != entry.c_str() ? val : defaultvalue;
1091
        }
1092
        return defaultvalue;
64✔
1093
    }
1094

128✔
1095
#if defined(__linux) || defined(linux) || defined(__linux__) ||                \
1096
    defined(__FreeBSD__)
1097
    bool runtime_configuration::use_stack_guard_pages() const
128✔
1098
    {
64✔
1099
        if (util::section const* sec = get_section("hpx.stacks");
1100
            nullptr != sec)
1101
        {
1102
            return hpx::util::get_entry_as<int>(*sec, "use_guard_pages", 1) !=
1103
                0;
1104
        }
320✔
1105
        return true;    // default is true
1106
    }
320✔
1107
#endif
320✔
1108

1109
    std::ptrdiff_t runtime_configuration::init_small_stack_size() const
1110
    {
320✔
1111
        return init_stack_size("small_size",
1112
            HPX_PP_STRINGIZE(HPX_SMALL_STACK_SIZE), HPX_SMALL_STACK_SIZE);
320✔
1113
    }
320✔
1114

1115
    std::ptrdiff_t runtime_configuration::init_medium_stack_size() const
1116
    {
320✔
1117
        return init_stack_size("medium_size",
1118
            HPX_PP_STRINGIZE(HPX_MEDIUM_STACK_SIZE), HPX_MEDIUM_STACK_SIZE);
320✔
1119
    }
320✔
1120

1121
    std::ptrdiff_t runtime_configuration::init_large_stack_size() const
1122
    {
320✔
1123
        return init_stack_size("large_size",
1124
            HPX_PP_STRINGIZE(HPX_LARGE_STACK_SIZE), HPX_LARGE_STACK_SIZE);
320✔
1125
    }
320✔
1126

1127
    std::ptrdiff_t runtime_configuration::init_huge_stack_size() const
1128
    {
1129
        return init_stack_size("huge_size",
1130
            HPX_PP_STRINGIZE(HPX_HUGE_STACK_SIZE), HPX_HUGE_STACK_SIZE);
18✔
1131
    }
1132

36✔
1133
    ///////////////////////////////////////////////////////////////////////////
1134
    // Return maximally allowed message size (zero for unlimited)
1135
    std::uint64_t runtime_configuration::get_max_inbound_message_size(
18✔
1136
        std::string const& type) const
18✔
1137
    {
36✔
1138
        if (util::section const* sec = get_section("hpx.parcel." + type);
1139
            nullptr != sec)
1140
        {
1141
            return hpx::util::get_entry_as<std::uint64_t>(
1142
                *sec, "max_message_size", HPX_PARCEL_MAX_MESSAGE_SIZE);
1143
        }
1144
        return HPX_PARCEL_MAX_MESSAGE_SIZE;    // default is 1GByte
1145
    }
1146

18✔
1147
    std::uint64_t runtime_configuration::get_max_outbound_message_size(
1148
        std::string const& type) const
36✔
1149
    {
1150
        if (util::section const* sec = get_section("hpx.parcel." + type);
1151
            nullptr != sec)
18✔
1152
        {
18✔
1153
            if (std::uint64_t const maxsize =
1154
                    hpx::util::get_entry_as<std::uint64_t>(*sec,
36✔
1155
                        "max_outbound_message_size",
1156
                        HPX_PARCEL_MAX_OUTBOUND_MESSAGE_SIZE);
1157
                maxsize > 0)
1158
            {
1159
                return maxsize;
1160
            }
1161
        }
1162
        return HPX_PARCEL_MAX_OUTBOUND_MESSAGE_SIZE;    // default is 1GByte
1163
    }
1164

×
1165
    ///////////////////////////////////////////////////////////////////////////
1166
    bool runtime_configuration::load_application_configuration(
1167
        char const* filename, error_code& ec)
1168
    {
1169
        try
×
1170
        {
×
1171
            section appcfg(filename);
×
1172
            section applroot;
×
1173
            applroot.add_section("application", appcfg);
×
1174
            this->section::merge(applroot);
×
1175
        }
1176
        catch (hpx::exception const& e)
1177
        {
×
1178
            // file doesn't exist or is ill-formed
×
1179
            if (&ec == &throws)
×
1180
                throw;
×
1181
            ec = make_error_code(
1182
                e.get_error(), e.what(), hpx::throwmode::rethrow);
×
1183
            return false;
×
1184
        }
1185
        return true;
1186
    }
1187

42,011✔
1188
    ///////////////////////////////////////////////////////////////////////////
1189
    std::ptrdiff_t runtime_configuration::get_stack_size(
1190
        threads::thread_stacksize const stacksize) const
42,011✔
1191
    {
1192
        switch (stacksize)
198✔
1193
        {
198✔
1194
        case threads::thread_stacksize::medium:
1195
            return medium_stacksize;
98✔
1196

98✔
1197
        case threads::thread_stacksize::large:
1198
            return large_stacksize;
64✔
1199

64✔
1200
        case threads::thread_stacksize::huge:
1201
            return huge_stacksize;
1202

1203
        case threads::thread_stacksize::nostack:
1204
            return (std::numeric_limits<std::ptrdiff_t>::max)();
1205

1206
        case threads::thread_stacksize::unknown:
1207
        case threads::thread_stacksize::current:
1208
        default:
1209
            [[fallthrough]];
1210
        case threads::thread_stacksize::small_:
1211
            break;
41,651✔
1212
        }
1213
        return small_stacksize;
1214
    }
1215
}    // namespace hpx::util
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc