Page 1 of 1

Loops in external functions

Posted: Fri Feb 18, 2011 11:11 am
by yobiman
Given that it is necessary to specify the number of loops in an external function. Is there a limit to the number of loops that an external function can have?

Many thanks
Phil

Re: Loops in external functions

Posted: Fri Feb 18, 2011 3:16 pm
by Administrator
You don't specify the loops the function has, you specify how many subscript ranges it is going to be responsible for calculating. In C/C++ you can do anything you want to.

For example, if you have
x[sub] = SOMEFUNCTION_EG_COS(a[sub])

SOMEFUNCTION_EG_COS is computing COS, the function needs to be called for each element in the "SUB" subscript range.

Now if you have written an allocation function, you might want to allocate to all elements in "SUB" at the same time. You don't need to call the function once for each element in "SUB" as you want to allocate across all elements at the same time. This function would have 1 user managed loop.
allocation[sub] = SOME_ALLOC(DEMAND[sub], amount available)
SOME_ALLOC would only be called once, and in the function you would fill in all the values for "SUB".

If your function allocated to say store and region, your function might have 2 user managed loops. This would fill in the 2d table for [region,store] (the function would only get called once).
allocation[region,store] = SOME_ALLOC(DEMAND[region,store], amount available)

I hope this makes sense. It's kind of tricky to explain.

Re: Loops in external functions

Posted: Fri Feb 18, 2011 8:28 pm
by yobiman
Got it.. That makes sense

Thanks
Phil