Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

graph example from reference manual not compiling

gajendra_g_
Beginner
532 Views

Hi, I tried to compile the graph example as it is in the reference manual but it gives me an error.

Here is the code

#include <cstdio>
#include <iostream>
#include "tbb/flow_graph.h"

using namespace tbb::flow;
using namespace tbb;
struct body
{
    std::string m_name;
    body(const char *name) : m_name(name) {}
    void operator() (continue_msg) const
    {
        std::cout << m_name.c_str() << "\n";
    }

};

int main()
{
    graph g;
    broadcast_node <continue_msg> start;
    continue_node<continue_msg> a (g, body("A"));
    continue_node<continue_msg> b (g, body("B"));
    continue_node<continue_msg> c (g, body("C"));
    continue_node<continue_msg> d (g, body("D"));
    continue_node<continue_msg> e (g, body("E"));

    make_edge(start, a);
    make_edge(start, b);
    make_edge(a,c);
    make_edge(b,c);
    make_edge(c,d);
    make_edge(a,e);

    for(int i=0; i<3; ++i)
    {
        start.try_put(continue_msg() );
        g.wait_for_all();
    }

    return 0;
}

and here is the error.

In file included from ./firstExample.cpp:3:0:
/usr/include/tbb/flow_graph.h:1578:5: note: candidate: tbb::flow::interface8::broadcast_node<T>::broadcast_node(const tbb::flow::interface8::broadcast_node<T>&) [with T = tbb::flow::interface8::continue_msg]
     broadcast_node( const broadcast_node& src ) :
     ^
/usr/include/tbb/flow_graph.h:1578:5: note:   candidate expects 1 argument, 0 provided
/usr/include/tbb/flow_graph.h:1571:5: note: candidate: tbb::flow::interface8::broadcast_node<T>::broadcast_node(tbb::flow::interface8::graph&) [with T = tbb::flow::interface8::continue_msg]
     broadcast_node(graph& g) : graph_node(g) {
     ^
/usr/include/tbb/flow_graph.h:1571:5: note:   candidate expects 1 argument, 0 provided


It will be great to have clarification on the error.

 

Thanks in advance

0 Kudos
1 Solution
Alexei_K_Intel
Employee
532 Views

Thank you for the report. We will try to improve the example in one of the future releases.

I suppose the problem is that tbb::flow::broadcast_node always expects a graph reference to be passed to its constructor. Try to replace the line

broadcast_node <continue_msg> start;

with

broadcast_node <continue_msg> start(g);

Regards,
Alex

View solution in original post

0 Kudos
4 Replies
Alexei_K_Intel
Employee
533 Views

Thank you for the report. We will try to improve the example in one of the future releases.

I suppose the problem is that tbb::flow::broadcast_node always expects a graph reference to be passed to its constructor. Try to replace the line

broadcast_node <continue_msg> start;

with

broadcast_node <continue_msg> start(g);

Regards,
Alex

0 Kudos
gajendra_g_
Beginner
532 Views

Dear Alex,

Thanks for the prompt reply even on a sunday. It will be really great to have examples in manual that compile when copied as such. My past experience with tbb has shown that the manual is not sufficient to learn, especially without the support from this forum.

Without good examples the learning curve becomes very steep.

But I hope to benefit from this forum and spread my knowledge on the fly as well.

Best

Gajendra

0 Kudos
Alexei_K_Intel
Employee
532 Views

gajendra g. wrote:

My past experience with tbb has shown that the manual is not sufficient to learn, especially without the support from this forum.

Could you share what examples/functionality caused the learning/understanding problems, please? Your input can help us improve the documentation.

Regards,
Alex

0 Kudos
gajendra_g_
Beginner
532 Views

Hi Alex,

Missed this post. Sorry for delay in reply. I shared another example in another post which doesn't compile. To be very honest, I am new to TBB and am scourging the tutorials and reference manuals to get things straight.

without the corrections that you suggested in this post, I would never be able to compile my code unless I know the reference manual and each class member function of TBB. However with the corrections you suggested in this post , i still get an error in another example in the reference manual which apparently points to another object join of type join_node in the flow graph example 2 from the reference manual page 167

When i compile this example, compiler complains that object join doesn't have member function join_node::inputs()  . In this case i looked up the reference manual to check if indeed this was the case and it isn't true . There's a member function called inputs() (page 236) that returns reference to input_port_types.

I am not sure then what error am I making in my code. But it's consuming too much time to figure out  the error every time i try to compile examples :(

Best Gajendra

0 Kudos
Reply