# Why alignment feature work only when output\_multiple not set

**URL:** <https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331>\
**Category:** GNU Radio\
**Created:** [June 16, 2015, 3:00pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331 "2015-06-16T15:00:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [June 16, 2015, 3:00pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/1 "2015-06-16T15:00:19Z")

</div>

Hi,  
After go through the block\_executor.cc, I found alignment feature work  
only when output\_multiple not set, why them can not work at the same  
time?

–  
Thanks  
Tiankun

---

<div class="post-metadata">

**Author:** ![Tiankun\_Hu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@Tiankun\_Hu](https://www.ruby-forum.com/u/Tiankun_Hu)\
**Post date:** [June 18, 2015, 2:31pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/2 "2015-06-18T14:31:22Z")

</div>

Hi Tom,  
Thanks your reply, I have another question, in function  
“min\_available\_space” why buffer\_size/2 is best ?

??? 2015???06???16??? 21:31, Tom R. ???:

---

<div class="post-metadata">

**Author:** ![Tiankun\_Hu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@Tiankun\_Hu](https://www.ruby-forum.com/u/Tiankun_Hu)\
**Post date:** [June 16, 2015, 3:33pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/3 "2015-06-16T15:33:37Z")

</div>

On Tue, Jun 16, 2015 at 8:57 AM, Tiankun Hu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,  
> After go through the block\_executor.cc, I found alignment feature work  
> only when output\_multiple not set, why them can not work at the same time?
> 
> –  
> Thanks  
> Tiankun

Because they are competing objectives. The alignment tries to keep  
buffers  
aligned and therefore the number of items will be based on a multiple of  
the alignment requirement. If you need an output multiple that’s  
different  
than that, which one should the scheduler choose?

Note that the buffers always begin on a page and so are inherently  
aligned.  
If your output multiple is also a multiple of the alignment for the data  
type, then you’ll always be aligned.

Tom

---

<div class="post-metadata">

**Author:** ![Tiankun\_Hu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@Tiankun\_Hu](https://www.ruby-forum.com/u/Tiankun_Hu)\
**Post date:** [June 19, 2015, 4:14pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/4 "2015-06-19T16:14:19Z")

</div>

Hi Tiankun, Hi Tom,

I vaguely remember me wondering about that line. It comes from the  
single threaded scheduler; back then, wondering, I came to the  
conclusion that for the STS that it’s probably been considered useful to  
half the the “buffer usage ripple” that could occur when blocks started  
to always use the full buffer. That sounds helpful in a scheduler where,  
per iteration, you either do something or you don’t, so a buffer without  
any space left to write to might be worse than the overhead that you get  
by only being allowed to use buffer/2. Basically, back then, I had  
another problem, and just shrugged.

Now, for the thread-per-block scheduler, there’s no monolithic iteration  
over all blocks, so I guess that problem wouldn’t occur. I would have to  
try; however, it’s hard to find a single proper benchmark for this (if  
it doesn’t break anything). Tiankun, maybe you have an idea?

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![Tiankun\_Hu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@Tiankun\_Hu](https://www.ruby-forum.com/u/Tiankun_Hu)\
**Post date:** [June 19, 2015, 3:16pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/5 "2015-06-19T15:16:28Z")

</div>

On Thu, Jun 18, 2015 at 8:29 AM, Tiankun Hu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi Tom,  
> Thanks your reply, I have another question, in function  
> “min\_available\_space” why buffer\_size/2 is best ?

I’m not really sure. That’s a question for Eric.

What happens when you change it? How does it affect performance?

Tom

---

<div class="post-metadata">

**Author:** ![Tiankun\_Hu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@Tiankun\_Hu](https://www.ruby-forum.com/u/Tiankun_Hu)\
**Post date:** [June 19, 2015, 4:50pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/6 "2015-06-19T16:50:33Z")

</div>

On Fri, Jun 19, 2015 at 6:09 AM, Tom R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Thu, Jun 18, 2015 at 8:29 AM, Tiankun Hu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi Tom,  
> > Thanks your reply, I have another question, in function  
> > “min\_available\_space” why buffer\_size/2 is best ?
> 
> I’m not really sure. That’s a question for Eric.

The scheduler aims to keep the buffer no more than half full, so that in  
the steady state the producing block can write into the free half and  
the  
downstream consuming block(s) read from the filled half.

---

<div class="post-metadata">

**Author:** ![Tiankun\_Hu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@Tiankun\_Hu](https://www.ruby-forum.com/u/Tiankun_Hu)\
**Post date:** [June 20, 2015, 5:06pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/7 "2015-06-20T17:06:32Z")

</div>

> But I don’t know why do it can increase parallelism?

Assume the following situation

file\_source-\> multiply\_const → file\_sink

assume the complete file fits into the buffer, and n\_best wouldn’t be  
buffer/2, then file\_source would read the whole file, and write it to  
the buffer. Only then, multiply\_const would have something to work. It  
would also consume the whole input buffer at once, and produce the full  
output buffer. Only then, file\_sink could start to work.

so, at no time, more than one block would be active. You could that run  
on a single-core computer, and wouldn’t see any difference to a  
multi-core computer.

Even if the file is larger than the buffer, then multiply\_const couldn’t  
do anything, because it must wait for the whole time that file\_sink  
needs to write away a complete buffer.

If you restrict the maximum number of produced samples to half the  
output buffer size, the multipy\_const block would much more often be  
able to execute, whilst file\_sink is still writing away half of the  
buffer.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![Tiankun\_Hu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@Tiankun\_Hu](https://www.ruby-forum.com/u/Tiankun_Hu)\
**Post date:** [June 20, 2015, 4:44pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/8 "2015-06-20T16:44:55Z")

</div>

Hi Tom, Johnathan,  
Thanks your reply.

Hi Marcus,  
Seems your conclusion is make sense.  
I think it might relate with buffer size which was allocated in  
“flat\_flowgraph.cc / allocate\_buffer”

```
 // *2 because we're now only filling them 1/2 way in order to
 // increase the available parallelism when using the TPB scheduler.
 // (We're double buffering, where we used to single buffer)
 int nitems = s_fixed_buffer_size * 2 / item_size

```

But I don’t know why do it can increase parallelism?

??? 2015???06???19??? 22:48, Johnathan C. ???:

---

<div class="post-metadata">

**Author:** ![Tiankun\_Hu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/46a35a/32.png) [@Tiankun\_Hu](https://www.ruby-forum.com/u/Tiankun_Hu)\
**Post date:** [July 7, 2015, 3:29pm UTC](https://www.ruby-forum.com/t/why-alignment-feature-work-only-when-output-multiple-not-set/242331/9 "2015-07-07T15:29:22Z")

</div>

Hi Marcus,  
Sorry for responding lately. I got it, thanks your reply

??? 2015???06???20??? 23:05, Marcus M??ller ???:
