From patchwork Mon Jul 3 22:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Rodgers X-Patchwork-Id: 115503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp820350vqx; Mon, 3 Jul 2023 15:14:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlE7MbxvuL62YFPv9abKJjzJfBrwNvy68+TmbBTrVwtK+I3hctikQoqScwSbFmlPon7ODBGa X-Received: by 2002:a17:906:a88b:b0:988:4a48:6ff3 with SMTP id ha11-20020a170906a88b00b009884a486ff3mr8140920ejb.30.1688422487912; Mon, 03 Jul 2023 15:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688422487; cv=none; d=google.com; s=arc-20160816; b=TbVyU7cmXri1fNj5Y1GW5VEc/rp/Tvr22bOI7D+NfSaOZiFY3UuUZZ9naX55zQPqWJ 2E2RdbMFJMjBNfCHCy+/TcR4J5Rq7uzeJkRnREAktCKq3aDqIi9acVZjlin3dPG40GWu /rO4DLqzgkjio+PaGOVkVjopFUKrgnUdm/TSSGHap7J4oV+RtNaoXv4sBiSFvqwcsFlw V+EhXOHuUuIOnNMegzsuToslm+4DJKZIzYsFtpsEW71wJzHvOsmzF6q46IL4QLiU0oan 6qLk/GnA2XEdfp30V/6U2Da9tXgz6ozmonno11bil7Jh4ae9jvb7TB//fxDoN9JqTKlt VvsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=2cnCRBLnpUs/fjlohKqB2CJxrutC7DGR3eRien4oXo8=; fh=8DnVA9EzZmHhMRck0lF/C2uxPFaNkqwUIcgDzp/eYaE=; b=sINXsAj3tVtl7M+7u6JI0ZGrbnU1NlPTgm0x/9sZ/uAWSy95DBwZuWua9j401690Ge RM0s8r5QX91sCkXQ2nUsbOB9Y57lqF3BTkqxWX5n3L6cvsuk0siXKVTJMXvrQJJOAcSN Hbw4esJhp9yWwhhFEyrHQwF34v5uS3WO4WJDsfr2iQONjMf3pNOXZDAVqBXSYqHwzDXy WINSb/bdsHO995oeDKtJ4Pv62CUsRtkQAlNhcj/Njt/4mdewqNR+50qbGh/F4FJmnQmm i8ugG6MT+YYB3O16cK0HuAfkCgz8tTlluX4vBp8HK5TBHv5T6TT0yfK7eVit+Jwe68CR 2t7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sR5kVGAk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id lf13-20020a170907174d00b0098e15152095si11135025ejc.331.2023.07.03.15.14.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 15:14:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sR5kVGAk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B120385772B for ; Mon, 3 Jul 2023 22:14:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B120385772B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688422448; bh=2cnCRBLnpUs/fjlohKqB2CJxrutC7DGR3eRien4oXo8=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=sR5kVGAkXVj2dq+cOi2qPmBR7BLpYiZMLpRVxVv/AFLx8MFQZDpD8KlMI3ZDsrEW2 qBJte+Dl9K0s2NE0/9ChLBP2aImCdjjWq6KQOciezC+HCqfh22Zk7BVOQnwqJJ9rm3 n0xk4W4ljdksCq9kNTStWleJ0Wy+I4jaxNHPmWwU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 55DEA385734A for ; Mon, 3 Jul 2023 22:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55DEA385734A Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-41-Q3C58e8ROM6tbavJlKv3OA-1; Mon, 03 Jul 2023 18:13:17 -0400 X-MC-Unique: Q3C58e8ROM6tbavJlKv3OA-1 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-262d69faef9so4935675a91.3 for ; Mon, 03 Jul 2023 15:13:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688422397; x=1691014397; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jlPfrTknACvPG7J2XoT7LoJunagIKX5S4xtGHCyslj8=; b=VY0uSlzCjaQ6aBbegmyxsSETy6iJba/zROtyHl879GSh9CTw/OmiXI7LxY3FkutDFg Q7x2FN9WA3lDn5eJjdUIxXPiqr/zehGeEp+44h12iRlKZHLKAVuKq/z2JRgBQT8JHkWC Svq3rzq5QGwn7LxwrZMTKkDRXjzVyuJCVok7Rgi8WUFR9EWaL1V8jOSqnFdJayhiK+/c qjj15oLvUoRQyJmiueVIQyRQndoDcv0qK/8FVIUTl7ECNWuW77g45Z0JmCrIDKRscCjQ 1Gsd28/XB5RQS5F88JATxxXwe2uG65Y3z24D19QPOC8332xGQSbTFN/97NEcbOPcyRZW g+xA== X-Gm-Message-State: ABy/qLagNt/nRL4k2pLnHGFOYPQmrrCMicu9ltAs/IolVYFOZqMNJ5AS UaY/ioRe/Gvn+g2WccBEtUNS4Ax4Vl3gWcKF/t7odJMlbsXE4J2GNjGywMMfhXf7eOJ8Bqinm9s o+ZnQY2VPx6dVU1OXr+AU6suuS2blzBHVXA== X-Received: by 2002:a17:90a:f0d7:b0:263:5702:d4c5 with SMTP id fa23-20020a17090af0d700b002635702d4c5mr9781207pjb.19.1688422396849; Mon, 03 Jul 2023 15:13:16 -0700 (PDT) X-Received: by 2002:a17:90a:f0d7:b0:263:5702:d4c5 with SMTP id fa23-20020a17090af0d700b002635702d4c5mr9781185pjb.19.1688422396394; Mon, 03 Jul 2023 15:13:16 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 3 Jul 2023 15:13:05 -0700 Message-ID: Subject: [PATCH] libstdc++: Split up pstl/set.cc testcase To: "libstdc++" , gcc Patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thomas Rodgers via Gcc-patches From: Thomas Rodgers Reply-To: Thomas Rodgers Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770439298475519923?= X-GMAIL-MSGID: =?utf-8?q?1770439298475519923?= This testcase is causing some timeout issues. This patch splits the testcase up by individual set algorithm. From 857359b72f8886b6e90db3b596d04f08559d2b51 Mon Sep 17 00:00:00 2001 From: Thomas Rodgers Date: Mon, 3 Jul 2023 15:04:45 -0700 Subject: [PATCH] libstdc++: Split up pstl/set.cc testcase This testcase is causing some timeout issues. This patch splits the testcase up by individual set algorithm. libstdc++-v3:/ChangeLog: * testsuite/25_algorithms/pstl/alg_sorting/set.cc: Delete file. * testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc: New file. * testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_union.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_util.h: Likewise. --- .../25_algorithms/pstl/alg_sorting/set.cc | 289 ------------------ .../pstl/alg_sorting/set_difference.cc | 90 ++++++ .../pstl/alg_sorting/set_intersection.cc | 91 ++++++ .../alg_sorting/set_symmetric_difference.cc | 92 ++++++ .../pstl/alg_sorting/set_union.cc | 90 ++++++ .../25_algorithms/pstl/alg_sorting/set_util.h | 72 +++++ 6 files changed, 435 insertions(+), 289 deletions(-) delete mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc deleted file mode 100644 index 0343739dfd1..00000000000 --- a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc +++ /dev/null @@ -1,289 +0,0 @@ -// -*- C++ -*- -// { dg-options "-ltbb" } -// { dg-do run { target c++17 } } -// { dg-timeout-factor 3 } -// { dg-require-effective-target tbb_backend } - -//===-- set.pass.cpp ------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "pstl/pstl_test_config.h" - -#ifdef PSTL_STANDALONE_TESTS - -#include -#include - -#include "pstl/execution" -#include "pstl/algorithm" -#else -#include -#include -#endif // PSTL_STANDALONE_TESTS - -#include "pstl/test_utils.h" - -using namespace TestUtils; - -template -struct Num -{ - T val; - - Num() : val{} {} - Num(const T& v) : val(v) {} - - //for "includes" checks - template - bool - operator<(const Num& v1) const - { - return val < v1.val; - } - - //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them - template - operator Num() const - { - return Num((T1)val); - } - - friend bool - operator==(const Num& v1, const Num& v2) - { - return v1.val == v2.val; - } -}; - -template -struct test_set_union -{ - template - typename std::enable_if::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence expect(n); - Sequence out(n); - - auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect"); - } - - template - typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template -struct test_set_intersection -{ - template - typename std::enable_if::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence expect(n); - Sequence out(n); - - auto expect_res = std::set_intersection(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_intersection(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_intersection"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_intersection effect"); - } - - template - typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template -struct test_set_difference -{ - template - typename std::enable_if::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence expect(n); - Sequence out(n); - - auto expect_res = std::set_difference(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_difference(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_difference"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_difference effect"); - } - - template - typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template -struct test_set_symmetric_difference -{ - template - typename std::enable_if::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence expect(n); - Sequence out(n); - - auto expect_res = std::set_symmetric_difference(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_symmetric_difference(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_symmetric_difference"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), - "wrong set_symmetric_difference effect"); - } - - template - typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template -void -test_set(Compare compare) -{ - - const std::size_t n_max = 100000; - - // The rand()%(2*n+1) encourages generation of some duplicates. - std::srand(4200); - - for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n)) - { - for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m)) - { - //prepare the input ranges - Sequence in1(n, [](std::size_t k) { return rand() % (2 * k + 1); }); - Sequence in2(m, [m](std::size_t k) { return (m % 2) * rand() + rand() % (k + 1); }); - - std::sort(in1.begin(), in1.end(), compare); - std::sort(in2.begin(), in2.end(), compare); - - invoke_on_all_policies(test_set_union(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_intersection(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_difference(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_symmetric_difference(), in1.begin(), in1.end(), in2.cbegin(), - in2.cend(), compare); - } - } -} - -template -struct test_non_const_set_difference -{ - template - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); - } -}; - -template -struct test_non_const_set_intersection -{ - template - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_intersection(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); - } -}; - -template -struct test_non_const_set_symmetric_difference -{ - template - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, - non_const(std::less())); - } -}; - -template -struct test_non_const_set_union -{ - template - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_union(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); - } -}; - -int -main() -{ - - test_set(std::less<>()); - test_set, Num>([](const Num& x, const Num& y) { return x < y; }); - - test_set([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { - return val1.value() < val2.value(); - }); - EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); - EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); - - test_algo_basic_double(run_for_rnd_fw>()); - - test_algo_basic_double(run_for_rnd_fw>()); - - test_algo_basic_double(run_for_rnd_fw>()); - - test_algo_basic_double(run_for_rnd_fw>()); - - std::cout << done() << std::endl; - - return 0; -} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc new file mode 100644 index 00000000000..13db9550e71 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc @@ -0,0 +1,90 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include +#include + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include +#include +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template +struct test_set_difference +{ + template + typename std::enable_if::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence expect(n); + Sequence out(n); + + auto expect_res = std::set_difference(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_difference(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_difference"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_difference effect"); + } + + template + typename std::enable_if::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template +struct test_non_const_set_difference +{ + template + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); + } +}; + +int +main() +{ + test_set_op, float64_t, float64_t>(std::less<>()); + test_set_op>, Num, Num>([](const Num& x, const Num& y) { return x < y; }); + test_set_op, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double(run_for_rnd_fw>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc new file mode 100644 index 00000000000..a4d4fd244b0 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc @@ -0,0 +1,91 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include +#include + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include +#include +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template +struct test_set_intersection +{ + template + typename std::enable_if::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence expect(n); + Sequence out(n); + + auto expect_res = std::set_intersection(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_intersection(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_intersection"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_intersection effect"); + } + + template + typename std::enable_if::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template +struct test_non_const_set_intersection +{ + template + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_intersection(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); + } +}; + +int +main() +{ + test_set_op, float64_t, float64_t>(std::less<>()); + test_set_op>, Num, Num>([](const Num& x, const Num& y) { return x < y; }); + + test_set_op, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + std::cout << done() << std::endl; + + test_algo_basic_double(run_for_rnd_fw>()); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc new file mode 100644 index 00000000000..2996c75bdd4 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc @@ -0,0 +1,92 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include +#include + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include +#include +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template +struct test_set_symmetric_difference +{ + template + typename std::enable_if::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence expect(n); + Sequence out(n); + + auto expect_res = std::set_symmetric_difference(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_symmetric_difference(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_symmetric_difference"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), + "wrong set_symmetric_difference effect"); + } + + template + typename std::enable_if::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template +struct test_non_const_set_symmetric_difference +{ + template + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, + non_const(std::less())); + } +}; + +int +main() +{ + test_set_op, float64_t, float64_t>(std::less<>()); + test_set_op>, Num, Num>([](const Num& x, const Num& y) { return x < y; }); + test_set_op, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double(run_for_rnd_fw>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc new file mode 100644 index 00000000000..b552ab6778a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc @@ -0,0 +1,90 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include +#include + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include +#include +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template +struct test_set_union +{ + template + typename std::enable_if::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence expect(n); + Sequence out(n); + + auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect"); + } + + template + typename std::enable_if::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template +struct test_non_const_set_union +{ + template + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_union(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less())); + } +}; + +int +main() +{ + test_set_op, float64_t, float64_t>(std::less<>()); + test_set_op>, Num, Num>([](const Num& x, const Num& y) { return x < y; }); + test_set_op, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double(run_for_rnd_fw>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h new file mode 100644 index 00000000000..90e37c23e9f --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h @@ -0,0 +1,72 @@ +// -*- C++ -*- + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef __PSTL_TEST_SET_UTIL_H +#define __PSTL_TEST_SET_UTIL_H + +namespace TestUtils +{ + template + struct Num + { + T val; + + Num() : val{} {} + Num(const T& v) : val(v) {} + + //for "includes" checks + template + bool + operator<(const Num& v1) const + { + return val < v1.val; + } + + //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them + template + operator Num() const + { + return Num((T1)val); + } + + friend bool + operator==(const Num& v1, const Num& v2) + { + return v1.val == v2.val; + } + }; + + template + void + test_set_op(Compare compare) + { + const std::size_t n_max = 100000; + + // The rand()%(2*n+1) encourages generation of some duplicates. + std::srand(4200); + + for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n)) + { + for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m)) + { + //prepare the input ranges + Sequence in1(n, [](std::size_t k) { return rand() % (2 * k + 1); }); + Sequence in2(m, [m](std::size_t k) { return (m % 2) * rand() + rand() % (k + 1); }); + + std::sort(in1.begin(), in1.end(), compare); + std::sort(in2.begin(), in2.end(), compare); + + invoke_on_all_policies(Operation(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), + compare); + } + } + } +} // namespace TestUtils +#endif // __PSTL_TEST_SET_UTIL_H -- 2.40.1