queue_node is slow

queue_node is slow

vishketan's picture

Hi I am new to Intel TBB, and am trying to write some code which uses a flow graph. I have a reader class to read data from a file which I want to queue using a buffer (there are other classes which read data from this buffer and process it). Here is what I tried:

graph g;

  data_source the_source(g, reader(p, db, iter, cont), false);

  data_pool the_data_pool(g);
  try {

    task_scheduler_init init(p.num_threads);
    make_edge(the_source, the_data_pool);
    tick_count begin=tick_count::now();

    the_source.activate();

    g.wait_for_all();

    tick_count end=tick_count::now();

    cout << (end-begin).seconds() << "seconds " << endl;    
  } catch(std::exception& e) {

    cerr<<"error occurred. error text is :"" <
    return 1;

  }

data_pool is a queue_node. This takes about 7 seconds to read a file with 100,000 lines. The reader only takes around 3 - 3.5 seconds. I verified this by using the following code:
graph g;

  data_pool the_data_pool(g);

  reader r(p, db, iter, cont);

  size_t idx;

  while(r(idx)){   }

To confirm that it is the queing that is taking up more time I used the following code:
graph g;

  data_pool the_data_pool(g);

  reader r(p, db, iter, cont);

  size_t idx;

  while(r(idx)){

     the_data_pool.try_put(idx);

     the_data_pool.try_consume();

  }

and sure enough the time doubles. I am wondering why merely queing up data takes up so much time. Please ask if you need any other information. I am using the tbb installed by macports tbb @4.0-20120201 (devel) thanks vishy

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.