runtime array size

runtime array size

Is it possible to set the size of an arbb::array at runtime?
int Dim = x*y;
array foo;

I just seem to get
test4.cpp:476:12: error: Dim cannot appear in a constant-expression

Also, this program just segfaults

# include

using namespace arbb;
typedef arbb::array<:f32> UDT2;

int main() {

dense result(2);


Is this a heap (or maybe i mean stack) size issue ? Works OK (if very slowly) if you reduce by a factor 0f 10 . . .

Also, in a map(ed) function is there a way if accessing elements of an array using any of the arbb types like
usize or i32 as and index variable ?
array foo;
i32 x = 0;

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


arbb::array is a fixed-size array type. The size cannot be set dynamically. arbb::array is a specialization of the C++0x std::array template. See here for more info about std::array.

The second template parameter of arbb::array is of std::size_t type. According to C99 standard, the limit of size_t (SIZE_MAX) is 65535. Therefore, you have specified a too big size for your array. Most likely this is why there was a segfault.

Because the size of an array has to be std::size_t type, you cannot use arbb::usize or arbb::i32 to index into an array.

Actually, all the problems you have with arbb::array can be avoided if you use arbb::dense, which can be dynamically sized and can be indexed using arbb::usize or arbb::i32.


Hi Zhang,

Once again, thanks for your reply. I have of course looked at using dense but unfortunately arbb does
not support what I am trying to achieve using this data type.


Can you tell us a bit more about what you are trying to achieve? A high-level description is fine. I'm just curious what your situation is that cannot be expressed with ArBB code.

By the way, there's no reason why an array<...> should not be indexable by ArBB integer types directly. Unfortunately, it's just something that's not implemented yet. This functionality is something that could be easily added.
Note: outside of executing a kernel, you can always use i32::value() to index the array although this is obviously not ideal.
Edwin Vane
Software Developer
Array Building Blocks

my problem is to generate a sequence of numbers in a 1D array where each number is in some way
based on the production of the preceeding number. Doesn't sound too parallel. However, it is possible to
compute numbers ahead in the sequence using a more expensive computation. The technique for parallelising
this is to compute a number of points in the 1D array a uniform distance apart and then, in parallel, complete
the shorter sequences from each intermediate point. The solution that shows the best performance is, in a loop,
bind a 2d dense object as a sliding window over the results array and comput a set of results, then move the
window and compute the next set etc. This leaves an array with out of sequence numbers but it is straight
forward to re-sort them into the right order. The problem is that its not that quick, in fact on 24 cores its slower
than serial.

My hope was to create a 1D dense object (A) whose elements themselves were 1D dense objects(B). These elements
(B) would be the 'short sequences' as described above. The object A would be passed as the return value to a function
invoked using call and then passed as the argument that is to be split into elemets in a function to be invoked using map.
Now each element (of A) to the mapped function would be a unique dense object (B) and the mapped functions, operating
independently in parallel, could compute their short sequence.

Howevere, it is not possible to consider dense as a suitable element to a mapped function.

What would really help would be if a.row(i) (where a is dense<...>) could return a modifiable refeence to a row.
This could then be passed into a function to mapped into scalars without the overhead of copying.

It would be usefull if array<...> could be indexed by arbb scalars, but i don't think that ultimately it will solve my current
problem. It is annoying tho having to re-write things with arrays into dense when you realise the loop will be an i32.

I am aware of the value function but for some reason its not allowed in a mapped function so doens't help.


Leave a Comment

Please sign in to add a comment. Not a member? Join today