Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trying to use C++17 parallel algorithms with Qt
QtWS25 Last Chance

Trying to use C++17 parallel algorithms with Qt

Scheduled Pinned Locked Moved Solved General and Desktop
c++17tbb
9 Posts 3 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eukaryote
    wrote on 31 Dec 2020, 00:01 last edited by
    #1

    Hi
    I'm trying to use C++17 parallel algorithms with Qt5.15. I'm using GCC9.3 on CentOS 7.0
    I've installed oneapi-tbb-2021.1.1,
    added

    export CPATH=<tbb_install_path>/oneapi-tbb-2021.1.1/include:<tbb_install_path>/oneapi-tbb-2021.1.1/include/oneapi:<tbb_install_path>/oneapi-tbb-2021.1.1/include/oneapi/tbb
    export LD_LIBRARY_PATH=<tbb_install_path>/oneapi-tbb-2021.1.1/lib/intel64/gcc4.8:$LD_LIBRARY_PATH
    

    When I'm trying to compile cpp file with #include <execution> has error:

    <tbb_install_path>/oneapi-tbb-2021.1.1/include/oneapi/tbb/profiling.h:231:22: error: expected unqualified-id before 'const'
      231 |     static void emit(const std::string &) { }
          |                      ^~~~~
    <tbb_install_path>/oneapi-tbb-2021.1.1/include/oneapi/tbb/profiling.h:231:22: error: expected ')' before 'const'
      231 |     static void emit(const std::string &) { }
          |                     ~^~~~~
          |                      )
    

    I suspect this is caused by "emit" name clashing with Qt emit. How can I solve this issue?
    Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 31 Dec 2020, 06:25 last edited by
      #2

      Use CONFIG+=no_keywords in your qmake file: doc.

      (Z(:^

      1 Reply Last reply
      2
      • E Offline
        E Offline
        Eukaryote
        wrote on 31 Dec 2020, 06:48 last edited by
        #3

        @sierdzio said in Trying to use C++17 parallel algorithms with Qt:

        no_keywords

        Thank you very much for your reply.
        From my understanding, this will require to change occurrences of signals to Q_SIGNALS and slots to Q_SLOTS in all of Qt code?
        Is there a way to have some sort of "ignore list" for specific files?

        I'll try this "fix-it" https://github.com/KDE/clazy/blob/master/docs/checks/README-qt-keywords.md see how that goes.

        Thank you again

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 31 Dec 2020, 06:57 last edited by
          #4

          Yes, no_keywords will work globally for the whole project.

          Locally I think you can just remove emit per file like this:

          // in c++ code:
          #undef emit
          

          (Z(:^

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Eukaryote
            wrote on 31 Dec 2020, 09:57 last edited by
            #5

            Thank you very much again

            Our build system doesn't use qmake and calls "moc" directly. I don't know where I can add CONFIG += no_keywords. How can I add this switch to "moc" without make?
            I added indef as you suggested.
            Now I'm getting the following error:

            In file included from <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/parallel_backend.h:14,
                             from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/algorithm_impl.h:25,
                             from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/glue_execution_defs.h:52,
                             from  <install_dir>//gcc/v9.3.0/include/c++/9.3.0/execution:32,
                             from policies.hpp:21,
                             from bench_t.cpp:27:
             <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/parallel_backend_tbb.h: In function 'void __pstl::__par_backend::__cancel_execution()':
             <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/parallel_backend_tbb.h:70:10: error: 'tbb::task' has not been declared
               70 |     tbb::task::self().group()->cancel_group_execution();
                  |          ^~~~
            In file included from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/parallel_backend.h:14,
                             from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/algorithm_impl.h:25,
                             from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/glue_execution_defs.h:52,
                             from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/execution:32,
            

            Is "task" some sort of special keyword too or it can't find correct headers?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 31 Dec 2020, 10:11 last edited by
              #6

              I don't think task is a keyword.

              Our build system doesn't use qmake and calls "moc" directly. I don't know where I can add CONFIG += no_keywords. How can I add this switch to "moc" without make?

              Add QT_NO_KEYWORDS to compiler defines (-DQT_NO_KEYWORDS). This has nothing to do with moc.

              (Z(:^

              E 1 Reply Last reply 31 Dec 2020, 11:09
              3
              • S sierdzio
                31 Dec 2020, 10:11

                I don't think task is a keyword.

                Our build system doesn't use qmake and calls "moc" directly. I don't know where I can add CONFIG += no_keywords. How can I add this switch to "moc" without make?

                Add QT_NO_KEYWORDS to compiler defines (-DQT_NO_KEYWORDS). This has nothing to do with moc.

                E Offline
                E Offline
                Eukaryote
                wrote on 31 Dec 2020, 11:09 last edited by
                #7

                @sierdzio said in Trying to use C++17 parallel algorithms with Qt:

                QT_NO_KEYWORDS

                From your link to the docs: "CONFIG += no_keywords tells Qt not to define the moc keywords signals, slots, and emit, because these names will be used by a 3rd party library," so I assumed it's moc command.
                Isn't it moc that translates all connection/slot related logic to C++ ?

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 31 Dec 2020, 11:22 last edited by
                  #8

                  @Eukaryote said in Trying to use C++17 parallel algorithms with Qt:

                  Isn't it moc that translates all connection/slot related logic to C++ ?

                  It is, but the compiler generates the machine code.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    Eukaryote
                    wrote on 31 Dec 2020, 14:40 last edited by
                    #9

                    Just to summerise the issue in case anyone else will be encounter something similar.

                    1. I want to use <execution> header from C++17 with GCC9
                    2. That requires Intel's TBB library and includes
                    3. Both Qt and TBB use emit that is replaced by Qt. To solve this locally, I've undefined "emit" before using <execution> header. The general solution is to use -DQT_NO_KEYWORDS and replace emit/signal with Q_SIGNALS/ Q_SLOTS
                    4. gcc9 uses task class from TBB that was deprecated in 2020. The solution is to use TBB 2019 or a newer GCC.
                    1 Reply Last reply
                    5

                    4/9

                    31 Dec 2020, 06:57

                    • Login

                    • Login or register to search.
                    4 out of 9
                    • First post
                      4/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved