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

Problem using Graph interface

ashok_saravanan
Beginner
257 Views
Below is the sample code for the Graphs Interface. I have problem building this piece of code in VS2010.
I get the following errors:
error : no instance of function template "tbb::make_edge" matches the argument list
1> argument types are: (, tbb::function_node<, int>)
1> make_edge( j, summer );
1> ^

1>main.cpp(42): error : argument list for class template "tbb::buffer_node" is missing
1> buffer_node square_buffer(g);

1>main.cpp(31): error : no instance of overloaded function "std::get" matches the argument list
1> argument types are: ()
1> my_sum += std::get<0>(v) + std::get<1>(v);
1. I have placed the contents of the Update 5 in the TBB30_INSTALL_DIR.
2. In general settings of C/C++ for the project
the Additional Include Directories is $(TBB30_INSTALL_DIR)\\include
3. In general settings of linker for the project
the Additional Library Directories are $(TBB30_INSTALL_DIR)\\lib\\ia32\\vc8 and $(TBB30_INSTALL_DIR)\\lib\\ia32\\vc_mt
4. In input settings of linker for the project
the Additional Dependencies is tbb_debug.lib
5. No paths have been mentioned in Post-Build event also.
The compiler recognizes Graph object. But not the stuffs inside the tbb namespace.
I couldn't locate where the problem is. Kindly suggest a solution.
[cpp]#define TBB_PREVIEW_GRAPH 1
#include "tbb/graph.h"
#include 
using namespace tbb; 
using namespace std; 


struct square { 
  int operator()(int v) {
    printf("squaring %d\n", v);
    return v*v; 
  }
};

struct cube {
  int operator()(int v) {
    printf("cubing %d\n", v);
    return v*v*v; 
  }
};

class sum {
  int &my_sum;
public:
  sum( int &s ) : my_sum(s) {}
  int operator()( std::tuple v ) {
    printf("adding %d and %d to %d\n", std::get<0>(v), std::get<1>(v), my_sum);
    my_sum += std::get<0>(v) + std::get<1>(v);
    return my_sum;
  }
};

int main() {
  int result = 0;

  graph g;
  broadcast_node input;
  function_node squarer( g, graph::unlimited, square() );
  buffer_node square_buffer(g);
  function_node cuber( g, graph::unlimited, cube() );
  buffer_node cube_buffer(g);
  join_node j( g );
  function_node<:TUPLE> summer( g, graph::serial, sum(result) );

  make_edge( input, squarer );
  make_edge( input, cuber );
  make_edge( squarer, square_buffer );
  make_edge( square_buffer, std::get( j.inputs() ) );
  make_edge( cuber, cube_buffer );
  make_edge( cube_buffer, std::get( j.inputs() ) );
  make_edge( j, summer );

  for (int i = 1; i <= 10; ++i)
    input.try_put(i);
  g.wait_for_all();
  printf("Final result is %d\n", result);
  return 0;
}[/cpp]
0 Kudos
1 Reply
Christophe_H_Intel
257 Views
Hello, Ashok,

I would like to apologize; the Forum posting software removed the template parameters from Mike's post. If you check the updated version of the forum post ( "Using the Intel Threading Building Blocks Graph Community Preview Feature: Creating a Simple Message Graph." ) you can see the corrected code.

Please be aware that if you copy and paste the code you might get extended-chaacters for the quotes in the printf's in square, cube and sum. (It appears we haven't tamed the Forum posting software completely yet!)

I put the code in squarer.cpp, corrected the double-quotes, and used the following Makefile:

[bash]CXX = icpc
OPT = -O2 ${CXXFLAGS}

all:  clean squarer run_tests

squarer: squarer.o
        $(CXX) -o $@ $< $(OPT) -ltbb -ltbbmalloc

squarer.o: squarer.cpp
        $(CXX) -c $(OPT) -o $@ $<

clean:
        rm -f squarer *.o
[/bash]

You may have to substitute "<" for "lt;" in the Makefile; it looks like that was also substituted.

Thank you for the feedback; it is good to hear from people looking at the graph feature.

Regards,
Chris
0 Kudos
Reply