From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 32BD03858D33 for ; Sat, 7 Jan 2023 11:19:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32BD03858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x330.google.com with SMTP id m3so2732110wmq.0 for ; Sat, 07 Jan 2023 03:19:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rk0CwTLUPPxvEvdlFhv6OFNmpV4uwXHS0y//12bu0ss=; b=X4tWBg4EEsoDoBE7m4p6TNEAPJfQyyoNu8QCwOv+kTPdjZjinvvfmRM2d3BaXkLBKi +Gs2TpB74JiIi/K/rTubUQMViKhsaFMdZKcD3Rohpu2iZcnCbY0XDXahBPhhMgn5zCEI p4G2YQvgoY/72vBYqiIAjF3WS0NU8fqz7cftSUdsp4dLgljOmOO39rGYvbnVPxUYXYLE ZR0tgIn51o293TVoWgo3fsLhvVc4xwFvaIRgyWPPNU5p3ngkcxCL8owSE6IyyEEvMf2i cA/RLzimf9Rq6e8BbDfHR47qqWxv1l+GjGlfajImd5O4298LlZLVs9yETjabTQKGI5a3 eoTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rk0CwTLUPPxvEvdlFhv6OFNmpV4uwXHS0y//12bu0ss=; b=Qaurz2QvhemGTotmYK1b8VtHkk+pnq488w2tt9g2IrqcMJlEkWt/2Nk593JHFI6+2y jdYLR6q0f9SJk1N12o5lOXRIB03sEcrcWwUT2KObadrpJqXMe0hKs1JgZs+6ttf25Emb i7B3e0xKEpon5aAllIHt8DZzszsDqHD0iJ02MgZQyHDqfN7+YrIfUzWpLq0bJc0jwqTE T1kwAXvwwPgrEc5V5A/DjH8seoQnVu/hq0Os5RA5yt0tCCXyszfdH3uMdzVkpCyytTrQ T8/6my+ceOkeMgyAA09ilZJunyX3SlYyzq+NtCrdCib+nHU7J9UAZURKWPTa3WZWkM25 Bjkw== X-Gm-Message-State: AFqh2kqgzUsa5LM6BMmUkVfqe52GD3B76xOQ8ca5lkdXBoaYEW+we9je lfLEn8HJCvi+y9d5e+K2/azi X-Google-Smtp-Source: AMrXdXuGTOdk3I9lret4tTx1SoE/fsyuUTo/FddP15atRsqostOLcWzMV318UZvsRuNN0PxvbF4BNA== X-Received: by 2002:a05:600c:3b0c:b0:3d9:e922:b417 with SMTP id m12-20020a05600c3b0c00b003d9e922b417mr6857wms.41.1673090383888; Sat, 07 Jan 2023 03:19:43 -0800 (PST) Received: from takamaka.gnat.com ([2a01:cb22:1d5:1100:ca82:1b83:d813:c72b]) by smtp.gmail.com with ESMTPSA id bh13-20020a05600c3d0d00b003d358beab9dsm4884193wmb.47.2023.01.07.03.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 03:19:43 -0800 (PST) Received: by takamaka.gnat.com (Postfix, from userid 1000) id 3065B8288F; Sat, 7 Jan 2023 15:19:41 +0400 (+04) Date: Sat, 7 Jan 2023 15:19:41 +0400 From: Joel Brobecker To: Tom Tromey via Gdb-patches Cc: Tom Tromey , Joel Brobecker Subject: Re: [PATCH 1/4] Avoid submitting empty tasks in parallel_for_each Message-ID: References: <20221215190759.2494095-1-tromey@adacore.com> <20221215190759.2494095-2-tromey@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221215190759.2494095-2-tromey@adacore.com> X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Tom, On Thu, Dec 15, 2022 at 12:07:56PM -0700, Tom Tromey via Gdb-patches wrote: > I found that parallel_for_each would submit empty tasks to the thread > pool. For example, this can happen if the number of tasks is smaller > than the number of available threads. In the DWARF reader, this > resulted in the cooked index containing empty sub-indices. This patch > arranges to instead shrink the result vector and process the trailing > entries in the calling thread. This patch looks good to me. If I'm allowed to nitpick... > --- > gdbsupport/parallel-for.h | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h > index acd9137efbd..ed460f31f63 100644 > --- a/gdbsupport/parallel-for.h > +++ b/gdbsupport/parallel-for.h > @@ -70,6 +70,12 @@ struct par_for_accumulator > return result; > } > > + /* Resize the results to N. */ > + void resize (size_t n) > + { > + m_futures.resize (n); > + } > + > private: > > /* A vector of futures coming from the tasks run in the > @@ -108,6 +114,12 @@ struct par_for_accumulator > } > } > > + /* Resize the results to N. */ > + void resize (size_t n) > + { > + m_futures.resize (n); > + } > + > private: > > std::vector> m_futures; > @@ -232,6 +244,17 @@ parallel_for_each (unsigned n, RandomIt first, RandomIt last, > end = j; > remaining_size -= chunk_size; > } > + > + if (end == last) > + { > + /* We're about to dispatch the last batch of elements, which > + we normally process in the main thread. So just truncate > + the result list here. */ ... I'd expand the last sentence to explain that this is to avoid submitting empty tasks to the thread pool. But I'll leave it up to you do decide whether that's a useful suggestion or not ;-). Thanks for that patch! > + count = i; > + results.resize (count); > + break; > + } > + > if (parallel_for_each_debug) > { > debug_printf (_("Parallel for: elements on worker thread %i\t: %zu"), > -- > 2.34.3 > -- Joel