Can dense container elements be reference parameters?

Can dense container elements be reference parameters?

I'm trying to code up a GCD algorithm. Given two dense containers, num and sum, I want to reduce corresponding elements to lowest terms (as if they were a ratio). One version of my GCD code that works is...

[c++]void find_gcd(dense &gcDiv, dense num, dense sum) { _for (usize i = 0, i < num.length(), ++i) { i32 t, u = num[i], v = sum[i]; _while (v != 0) { t = u % v; u = v; v = t; } _end_while; gcDiv[i] = u; } _end_for; }[/c++]

Trying to put the _while loop into another function that is called through a for-loop doesn't yield any results.

[c++]void arbb_gcd(i32 &d, i32 n, i32 s) { i32 t, u = n, v = s; _while (v != 0) { t = u % v; u = v; v = t; } _end_while; d = u; } void find_gcd(dense &gcDiv, dense num, dense sum) { _for (usize i = 0, i < num.length(), ++i) { call(arbb_gcd)(gcDiv[i], num[i], sum[i]); } _end_for; }[/c++]

But, if I add a dummy variable to take the return variable in find_gcd(), it all works fine.

[c++]void find_gcd(dense &gcDiv, dense num, densesum) { _for (usize i = 0, i < num.length(), ++i) { i32 d; call(arbb_gcd)(d, num[i], sum[i]); gcDiv[i] = d; } _end_for; }[/c++]

Can I not send a singleelement from a dense container as a reference parameter to an ArBB function? Or am Idoing something obviously wrong?

--clay

(Ultimately, I'm hoping to use arbb_gcd() as a map function, but that's another question.)

2 post / 0 new
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

This does look like a bug in the ArBB's C++ frontend. However, it's not a good ArBB programming practice anyway. This code does not express any parallelism. There is no point updating individual elements of a dense container using a _for loop when these updates can be done in parallel. You should use a map function here.