Use ArBB types in C + + statements

Use ArBB types in C + + statements


I am trying to parallel a function and this is the code (I only include map function):

[cpp]void mymap(f32 x, f32& density, boolean exist){
using namespace arbb;
array coord;
i32 ck =;
i32 cj =;
i32 cioriginal =;
i32 ci = cioriginal/16;
i32 index;
index = (ck*ny + cj)*nx + ci)*16+cioriginal%16;

_for(i32 C = 0, C = 0 && ii = 0 && jj = 0 && kk

the function position I need to use ArBBtypes (it cannot be used
the function value) and the statements _if and _for . However, the
operations are independent ones to each other so therefore, it would be
better to introduce statements for and if. With the code shown I obtain worse results than the serial version, any suggestion?


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

Hi, have you taken a look at our knowledge base? We have a few articles about how to use the map() function properly. The reason why your code is slower than serial right now is that your ArBB function is not really expressing any parallelism.Any ArBB command that has an underscore _ such as _if and _for are evaluated as serial single core. But don't worry. We have an excellent article which I will link you to hereabouthow to do "for loop style" computations in ArBB step by step with a code example.After reading through that article and the other relevant KBs, let me know if there's anything else I can do to help you.



Thanks for your replying. I read the suggested articles but I have a question. How could I parallelize this sample?

	float* in,out;

	bool* validPosition;

	int max = 100;

	//initialize arrays

	for(int i = 0; i 

Before I can set the result, I need to check the position of array, the position of the neighbor and the result obtained .


> [...] it would be
better to introduce statements for and if

Yes, your code looks like a 25-point 3d stencil ("27") where a cross pattern ("stencil") is completely pre-determined. The term "pre-determined" actually helps you to rely on a C++ for loop to generate the neighbor's index positions. This leads to a great advantage of run-time code generation - the stencil pattern can be hard-coded into the elemental function's code but still rely on your applications advice ("generate a 25-point stencil").

What I suggest you is to cleanup the neighbor index calculation. Use something like:
// pseudo code below!
// result = x
for (int d = 0; d for (int r = 1; r // a[d] = my_position[d] - r
// b[d] = my_position[d] + r
// left = neighbor(a)
// right = neighbor(b)
// result += left + right

Try to minimize the amount of ArBB operations inside the C++ double-for to only the necessary operations. Using _if inside the double-for will essentially replicate these branches 3x4 times. On the other hand the _if (in contrast to "cond") is able to avoid the neighbor look-up if the index is out of bounds (OOB). Usually it is even possible to avoid these _if statements by processing the inner part of the grid separately. Also, dealing with OOB values or shift_sticky is a try. Anyhow, you need the _if statements anyways since you check against a grid of Booleans that determine an arbitrary shape.

Leave a Comment

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