From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>,
Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [RFC][gdbsupport] Add PARALLEL_FOR_EACH_DEBUG
Date: Mon, 18 Jul 2022 05:40:40 +0200 [thread overview]
Message-ID: <b4a6a2de-5bc3-cb9c-183d-6507d32569fd@suse.de> (raw)
In-Reply-To: <8735f2nqto.fsf@tromey.com>
[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]
On 7/15/22 21:01, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Tom> +#define PARALLEL_FOR_EACH_DEBUG 0
>
> Probably needs a short comment.
>
Done.
Also changed this into a const variable.
> Tom> +#if PARALLEL_FOR_EACH_DEBUG
> Tom> + fprintf (stderr, "Parallel for: n_elements: %zu\n", n_elements);
> Tom> + fprintf (stderr, "Parallel for: minimum elements per thread: %u\n", n);
>
> I'm meh on this kind of logging but if it helped you it seems fine.
>
I've reworked the output to the slightly more clear:
...
Parallel for: n_elements: 7271
Parallel for: minimum elements per thread: 10
Parallel for: elts_per_thread: 1817
Parallel for: elements on worker thread 0 : 1817
Parallel for: elements on worker thread 1 : 1817
Parallel for: elements on worker thread 2 : 1817
Parallel for: elements on worker thread 3 : 0
Parallel for: elements on main thread : 1820
...
It was a surprise for me to find that worker thread 3 is idle, so I
think the information is useful enough.
Committed as attached.
Thanks,
- Tom
[-- Attachment #2: 0001-gdbsupport-Add-parallel_for_each_debug.patch --]
[-- Type: text/x-patch, Size: 2972 bytes --]
[gdbsupport] Add parallel_for_each_debug
Add a parallel_for_each_debug variable, set to false by default.
With an a.out compiled from hello world, we get with
parallel_for_each_debug == true:
...
$ gdb -q -batch a.out -ex start
...
Parallel for: n_elements: 7271
Parallel for: minimum elements per thread: 10
Parallel for: elts_per_thread: 1817
Parallel for: elements on worker thread 0 : 1817
Parallel for: elements on worker thread 1 : 1817
Parallel for: elements on worker thread 2 : 1817
Parallel for: elements on worker thread 3 : 0
Parallel for: elements on main thread : 1820
Temporary breakpoint 1, main () at /home/vries/hello.c:6
6 printf ("hello\n");
...
Tested on x86_64-linux.
---
gdbsupport/parallel-for.h | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h
index a614fc35766..cfe8a6e4f09 100644
--- a/gdbsupport/parallel-for.h
+++ b/gdbsupport/parallel-for.h
@@ -139,7 +139,12 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
using result_type
= typename std::result_of<RangeFunction (RandomIt, RandomIt)>::type;
- size_t n_threads = thread_pool::g_thread_pool->thread_count ();
+ /* If enabled, print debug info about how the work is distributed across
+ the threads. */
+ const int parallel_for_each_debug = false;
+
+ size_t n_worker_threads = thread_pool::g_thread_pool->thread_count ();
+ size_t n_threads = n_worker_threads;
size_t n_elements = last - first;
size_t elts_per_thread = 0;
if (n_threads > 1)
@@ -155,9 +160,19 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
size_t count = n_threads == 0 ? 0 : n_threads - 1;
gdb::detail::par_for_accumulator<result_type> results (count);
+ if (parallel_for_each_debug)
+ {
+ debug_printf (_("Parallel for: n_elements: %zu\n"), n_elements);
+ debug_printf (_("Parallel for: minimum elements per thread: %u\n"), n);
+ debug_printf (_("Parallel for: elts_per_thread: %zu\n"), elts_per_thread);
+ }
+
for (int i = 0; i < count; ++i)
{
RandomIt end = first + elts_per_thread;
+ if (parallel_for_each_debug)
+ debug_printf (_("Parallel for: elements on worker thread %i\t: %zu\n"),
+ i, (size_t)(end - first));
results.post (i, [=] ()
{
return callback (first, end);
@@ -165,7 +180,14 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
first = end;
}
+ for (int i = count; i < n_worker_threads; ++i)
+ if (parallel_for_each_debug)
+ debug_printf (_("Parallel for: elements on worker thread %i\t: 0\n"), i);
+
/* Process all the remaining elements in the main thread. */
+ if (parallel_for_each_debug)
+ debug_printf (_("Parallel for: elements on main thread\t\t: %zu\n"),
+ (size_t)(last - first));
return results.finish ([=] ()
{
return callback (first, last);
prev parent reply other threads:[~2022-07-18 3:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-14 22:18 Tom de Vries
2022-07-15 19:01 ` Tom Tromey
2022-07-18 3:40 ` Tom de Vries [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b4a6a2de-5bc3-cb9c-183d-6507d32569fd@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).