How do the Scheduler and the flowgraph work?

I have a basic question regarding GNURadio scheduler and how the
works. I am using gr_sync_block but my question are valid for gr_block

From the online tutorial about how to write a block I read:

87 for (int i = 0; i < noutput_items; i++){
88 out[i] = in[i] * in[i];
89 }

I could print noutput_items and it is a huge number in order of
So my question is why should I create this loop? and how does it work? I
have read somewhere in this discution board that not using this loop
increase the calclation overhead but no clue why. Does my block outputs
items “bunch by bunch” or item by item.

Another question here: I saw few programs which dont return
from work or general_work so it seems that I dont have to always return
How can I determine the value I shoud return.



View this message in context:
Sent from the GnuRadio mailing list archive at

This loop does all your work. Without it your block is useless. :slight_smile:

To know how the scheduler chooses the value of items that are passed
the work() function I suggest you look into scheduler’s code. It’s a
easy to understand C++ code and most of your answers will be answered.

According to my knowledge the work() function always returns the number
items consumed by your block each time the work() function is called.
you return from work() you are basically informing the scheduler how
items were consumed so that the scheduler doesn’t discard the unused
data. Believe me I once did the same mistake of not returning and had a
troubling time knowing why my block wasn’t working as it was supposed to

On Thu, Jul 15, 2010 at 6:02 AM, Sammour [email protected] wrote:

I could print noutput_items and it is a huge number in order of thousands.


The scheduler passes chunks of data items between processing blocks.
The noutput_items is the number of items the scheduler tells you that
you can produce. You want to produce as many items at one time as the
scheduler tells you that you can. The scheduler knows how to handle
this to maximize throughput.

When we write a block that doesn’t return noutput_items, it’s usually
due to some boundary condition; making sure that the items in the
input and output buffers keep some kind of alignment. This is where
things get complicated and you need to do a lot of analysis, thinking,
and work to figure it out.