# Problem with large number of inputs

**URL:** <https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199>\
**Category:** GNU Radio\
**Created:** [July 26, 2014, 7:50pm UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199 "2014-07-26T19:50:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [July 26, 2014, 7:50pm UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/1 "2014-07-26T19:50:44Z")

</div>

Hi all,

I’ve used to have a block with large number of inputs, say 24, but I  
think  
GNURadio has a problem with memory allocation because when I use the  
block  
it’s suddenly jump out of the program with

“The program has unexpectedly finished.”

(the above message isn’t for GNURadio)

However, when I decrease the number of inputs to 8, it’s fine and works  
properly!

This is so strange to me.

Any idea?

Best,

Mostafa

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [July 26, 2014, 8:07pm UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/2 "2014-07-26T20:07:23Z")

</div>

Hi Mostafa,

indeed, this sounds strange.  
However, with but the information you offered, it will be hard to  
determine what goes wrong.

Would you have more information, e.g. when exactly this happens, is this  
C++ or python, do you have source code, in which code line the error  
occurs (hint: [1])?

Greetings,  
Marcus

[1]  
[http://gnuradio.org/redmine/projects/gnuradio/wiki/TutorialsDebugging](http://gnuradio.org/redmine/projects/gnuradio/wiki/TutorialsDebugging),  
follow the gdb instructions

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [July 26, 2014, 9:56pm UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/3 "2014-07-26T21:56:22Z")

</div>

Hi Marcus,

You’re right. I didn’t clarify the problem.

Actually in C++, I wrote:

block\_impl::block\_impl(bool normal, int group)  
: gr::block(“phich\_grouping”,  
gr::io\_signature::make(1, group \* N\_FS(normal), sizeof  
(gr\_complex)),  
gr::io\_signature::make(1, 1, sizeof(gr\_complex))),

// N\_FS function returns 8 or 4 depends on its input.  
// in the work function :  
// d\_normal and d\_group are defined in the .h file

const gr\_complex \*in[d\_N\_phich\_group \* N\_FS\_phich(d\_normal\_cp)];  
for (int i=0; i\<d\_group \* N\_FS(d\_normal); i++)  
{  
in[i] = (const gr\_complex \*) input\_items[i];  
}

when I set the “group” value to 3, the number of input ports would be  
24.  
In this case, I want to access to one element of “in” like this:

cout \<\< " in " \<\< in[0][0] \<\< endl;

I got the aforementioned error!

But when I set “group = 1” which means 8 input ports, all things are  
fine.

any idea please,

Best

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [July 27, 2014, 1:23pm UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/4 "2014-07-27T13:23:15Z")

</div>

Having your complete general\_work function wouldn’t have hurt my  
understanding much…

I really can’t make out what you’re trying to do without doubt.

Anyway, from the code below I think “in” _must at least_ have the same  
number of entries that your for loop has iterations; did you just try  
using

d\_group \* N\_FS(d\_normal) instead of d\_N\_phich\_group \*  
N\_FS\_phich(d\_normal\_cp) when allocating your array?  
It seems to me that having two ways to determine how many inputs there  
is a likely cause for mistake. Use the size() of the input\_items to  
determine how many inputs you really have, and assert(input\_items.size()  
== number\_of\_inputs\_like\_I\_calculate\_it); to make sure things line up.

Also, the whole process seems unnecessary, since you do nothing more  
than copying the pointers from input\_items to in; the typecast is  
nothing but syntactic magic and can be done by having “in = ((const  
gr\_complex\*)\*) input\_items;”; also, I encourage you to use the C+±style  
explicit cast operators (in this case, reinterpret\_cast\<\>) for their  
clarity, but that’s more a question of personal liking 🙂

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [July 27, 2014, 7:22pm UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/5 "2014-07-27T19:22:40Z")

</div>

Thank you for your notes Marcus,

As you said this is unnecessary process to point to the input\_items in a  
for loop!!  
However, this is not the problem because I checked that I have the same  
number of iteration in the for loop as the number of input ports.

The problem is somewhere else. _Again I must mention that if I use, only  
8  
input ports, the code runs perfectly,_ however, with 24 inputs, it does  
something wrong! (perhaps pointing to somewhere in the memory which is  
not  
allocated to the input as it seemed to allocated to the input!). In  
another  
words, when I want to access the first input of the first input port, I  
can  
write:

gr\_complex \*\*in = (gr\_complex) input\_items;

// for example  
cout \<\< in[0][0] \<\< endl;

The program terminated with unexpected error!

Please help me, where is the problem?? ☹

On Sun, Jul 27, 2014 at 4:21 AM, Marcus M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [July 27, 2014, 7:42pm UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/6 "2014-07-27T19:42:10Z")

</div>

As I said, you should use the gdb debugging approach to find the  
mistake.  
gr\_complex \*\*in = (gr\_complex) input\_items; shouldn’t compile, because  
the types are incompatible.

I can’t help you any further with the information you’re offering.  
Please share at least your complete general\_work method, and the methods  
that you use to calculate the input numbers. I stand by my opininion  
that beauty lies in simplicity. If you want to make sure you don’t do  
more “for” iterations than you have inputs, iterate over the number of  
inputs (input\_items.size()) and not something you calculate yourself.  
That’s the simple approach of eliminating error sources.

Also, you’re using a gr::block. If you play around with the forecast  
method, you might trigger situations where you are asked to produce a  
number of output items on different output streams, and have zero input  
items on some input streams; I don’t see you check for that in the code  
excerpt you were sharing.  
Again, it isn’t very useful to share only a portion of your block,  
especially when you are very sure yourself that this portion is correct,  
if you want help identifying what goes wrong.

With best regards,  
Marcus M.

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [July 28, 2014, 1:40am UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/7 "2014-07-28T01:40:06Z")

</div>

I forgot to say, I’m using Qtcreator to debug my GNURadio codes I do not  
need any others!

The prgram is terminated at line in which I read from the input for the  
first time i.e. :

y\_p[i][k] = 0;  
for (int j=0; j\<N\_FS\_phich(d\_normal\_cp); j++)  
{  
y\_p[i][k] = y\_p[i][k] + in[i\*8+j][k];  
}

Best,

On Mon, Jul 28, 2014 at 4:05 AM, Mostafa A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [July 28, 2014, 1:37am UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/8 "2014-07-28T01:37:14Z")

</div>

Yes you’re right about casting between “in” and “input\_items”, however,  
I  
think this problem is somehow related to the large number input ports! I  
don’t why!

Here is the whole block:

#ifdef HAVE\_CONFIG\_H  
#include “config.h”  
#endif

#include \<gnuradio/io\_signature.h\>  
#include “phich\_grouping\_impl.h”

int N\_FS\_phich(bool normal\_cp){  
if(normal\_cp)  
return 8;  
else  
return 4;  
}

namespace gr {  
namespace my {

```
phich_grouping::sptr
phich_grouping::make(bool normal_cp, int N_phich_group)
{
  return gnuradio::get_initial_sptr
    (new phich_grouping_impl(normal_cp, N_phich_group));
}

/*
 * The private constructor
 */
phich_grouping_impl::phich_grouping_impl(bool normal_cp, int

```

N\_phich\_group)  
: gr::block(“phich\_grouping”,  
gr::io\_signature::make(N\_phich\_group \*  
N\_FS\_phich(normal\_cp), N\_phich\_group \* N\_FS\_phich(normal\_cp) ,  
sizeof(gr\_complex)),  
gr::io\_signature::make(1, 1, sizeof(gr\_complex))),  
d\_normal\_cp(normal\_cp),  
d\_N\_phich\_group(N\_phich\_group)  
{  
set\_tag\_propagation\_policy(TPP\_DONT);

```
}

/*
 * Our virtual destructor.
 */
phich_grouping_impl::~phich_grouping_impl()
{
}

void
phich_grouping_impl::forecast (int noutput_items, gr_vector_int

```

&ninput\_items\_required)  
{  
for (int i=0; i\<d\_N\_phich\_group \* N\_FS\_phich(d\_normal\_cp); i++)  
{  
ninput\_items\_required[i] = 12;  
}  
}

```
int
phich_grouping_impl::general_work (int noutput_items,
                   gr_vector_int &ninput_items,
                   gr_vector_const_void_star &input_items,
                   gr_vector_void_star &output_items)
{
    const gr_complex *in[d_N_phich_group * N_FS_phich(d_normal_cp)];
    gr_complex *out = (gr_complex *) output_items[0];

```

// in = (const gr\_complex \*) input\_items;

```
    cout << "n input " << input_items.size() << endl;
    int phich_in_len[d_N_phich_group];

    int x = 0;
    for (int i=0; i<d_N_phich_group * N_FS_phich(d_normal_cp); i++)
    {
        in[i] = (const gr_complex *) input_items[i];

        // reading tags
        vector<tag_t> tag_len;
        get_tags_in_window(tag_len,
                           0,
                           0,
                           ninput_items[0],
                           pmt::string_to_symbol("length"));
        if(tag_len.size()>0)
        {
            phich_in_len[i] = pmt::to_long(tag_len[0].value);
            x++;
        }

    }

    gr_complex y_p[d_N_phich_group][12];
    gr_complex y__p_tilt[d_N_phich_group/2][12];

```

// cout \<\< "\tin[0][0] "\<\<in[0][0] \<\< endl;

```
    if (x == d_N_phich_group * N_FS_phich(d_normal_cp)) // x ==

```

d\_N\_phich\_group) is for checking all the input tags are read  
{  
// grouping …  
for (int i=0; i\<d\_N\_phich\_group ;i++)  
{  
for (int k=0; k\<phich\_in\_len[i]; k++)  
{  
y\_p[i][k] = 0;  
for (int j=0; j\<N\_FS\_phich(d\_normal\_cp); j++)  
{  
y\_p[i][k] = y\_p[i][k] + in[i\*8+j][k];  
}  
}

```
        }

        ........

```

…  
…

```
        // adding tag
        add_item_tag(0,
                     nitems_written(0),
                     pmt::string_to_symbol("length"),
                     pmt::from_long(12));

        cout << "PHICH grouping" << endl;

        consume_each(12);

    }
    else
    { // if tags didn't read
        produce(0, 0);
        consume_each(0);
    }

    return WORK_CALLED_PRODUCE;
}

```

} /\* namespace my _/  
} /_ namespace gr \*/

Input to this block is a random source and its output is a file sink. I  
would be glad to see the comments on the code to improve it also finding  
the problem.

Best,  
Mostafa A.

On Sun, Jul 27, 2014 at 10:10 PM, Marcus M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [July 28, 2014, 6:18am UTC](https://www.ruby-forum.com/t/problem-with-large-number-of-inputs/231199/9 "2014-07-28T06:18:22Z")

</div>

Mostafa,

I do not think you have truly run the complete codes using Qtcreator,  
because that doesn’t have a gnuradio runtime (the scheduler).  
At the other hand, your problem sounds more like a c++ coding error  
rather  
than gnuradio-specific.  
The helpful approach is

1). Put up the OOT into github.  
This should be the simplest but complete OOT.

2). Provide a big picture of what you try to accomplish.  
From experience many amateur programmers write codes wrong from  
the  
ground up, and yet expect others to troubleshoot.  
When this happens, the only way to help is to start with the big  
picture of what you wish to accomplish.

From previous experience you refused to reveal the big picture but  
emphasize others to look at your existing buggy codes.  
Please be reminded that this is an open forum and nobody get paid for  
helping you.

On Mon, Jul 28, 2014 at 7:39 AM, Mostafa A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
