public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFC][gdbsupport] Add PARALLEL_FOR_EACH_DEBUG
Date: Fri, 15 Jul 2022 00:18:31 +0200	[thread overview]
Message-ID: <20220714221829.GA31924@delia.home> (raw)

Hi,

Add a PARALLEL_FOR_EACH_DEBUG macro, set to 0 by default.

With an a.out compiled from hello world, we get with
PARALLEL_FOR_EACH_DEBUG == 1:
...
$ 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: worker threads: 4
Parallel for: worker threads used: 3
Parallel for: elements 0-1816 on thread 0: 1817
Parallel for: elements 1817-3633 on thread 1: 1817
Parallel for: elements 3634-5450 on thread 2: 1817
Parallel for: elements 5451-7270 on main thread: 1820

Temporary breakpoint 1, main () at /home/vries/hello.c:6
6         printf ("hello\n");
...

Note that thread usage isn't ideal.  We end up using only three out of four
worker threads here.

Any comments?

Thanks,
- Tom

[gdbsupport] Add PARALLEL_FOR_EACH_DEBUG

---
 gdbsupport/parallel-for.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h
index a614fc35766..358ed9e8f7f 100644
--- a/gdbsupport/parallel-for.h
+++ b/gdbsupport/parallel-for.h
@@ -113,6 +113,8 @@ struct par_for_accumulator<void>
 
 }
 
+#define PARALLEL_FOR_EACH_DEBUG 0
+
 /* A very simple "parallel for".  This splits the range of iterators
    into subranges, and then passes each subrange to the callback.  The
    work may or may not be done in separate threads.
@@ -139,6 +141,10 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
   using result_type
     = typename std::result_of<RangeFunction (RandomIt, RandomIt)>::type;
 
+#if PARALLEL_FOR_EACH_DEBUG
+  RandomIt orig_first = first;
+#endif
+
   size_t n_threads = thread_pool::g_thread_pool->thread_count ();
   size_t n_elements = last - first;
   size_t elts_per_thread = 0;
@@ -155,9 +161,25 @@ 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
+  fprintf (stderr, "Parallel for: n_elements: %zu\n", n_elements);
+  fprintf (stderr, "Parallel for: minimum elements per thread: %u\n", n);
+  fprintf (stderr, "Parallel for: elts_per_thread: %zu\n", elts_per_thread);
+  fprintf (stderr, "Parallel for: worker threads: %zu\n",
+	   thread_pool::g_thread_pool->thread_count ());
+  fprintf (stderr, "Parallel for: worker threads used: %zu\n", count);
+#endif
+
   for (int i = 0; i < count; ++i)
     {
       RandomIt end = first + elts_per_thread;
+#if PARALLEL_FOR_EACH_DEBUG
+      fprintf (stderr, "Parallel for: elements %u-%u on thread %d: %u\n",
+	       (unsigned)(first - orig_first),
+	       (unsigned)(end - 1 - orig_first),
+	       i,
+	       (unsigned)(end - first));
+#endif
       results.post (i, [=] ()
         {
 	  return callback (first, end);
@@ -166,6 +188,12 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last,
     }
 
   /* Process all the remaining elements in the main thread.  */
+#if PARALLEL_FOR_EACH_DEBUG
+      fprintf (stderr, "Parallel for: elements %u-%u on main thread: %u\n",
+	       (unsigned)(first - orig_first),
+	       (unsigned)(last - 1 - orig_first),
+	       (unsigned)(last - first));
+#endif
   return results.finish ([=] ()
     {
       return callback (first, last);

             reply	other threads:[~2022-07-14 22:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14 22:18 Tom de Vries [this message]
2022-07-15 19:01 ` Tom Tromey
2022-07-18  3:40   ` Tom de Vries

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=20220714221829.GA31924@delia.home \
    --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).