https://github.com/mozhgan-kch/TB_Model/blob/477ecca530f3267ea6532a2979cbcd354a69d89a/examples/TB_Model/src/model/functions.c#L790
This initialisation loop should be for (unsigned int i = 0; i < total; i++), in it's current state it fails to initialise order[0] and writes to a single value past the end of the array.
https://github.com/mozhgan-kch/TB_Model/blob/477ecca530f3267ea6532a2979cbcd354a69d89a/examples/TB_Model/src/model/functions.c#L946
This arrangement of 3 nested loops, assigns all of the people to housholds according to; household_capacity:household_of_capacity:person_within_household of capacity.
count is declared/initialised much much earlier, but remains 0 until this loop is reached.
The bug here is that count is being incremented before:
if (ages[count] >= 15)
{
adultcount++;
}
if (activepeople[order[count]] == 1)
{
h_household->active = 1;
}
Such that, again ages[0] and order[0] are unused, whereas there's an eventual access violation on the last iteration, whereby the index after the final element is accessed in both.
This can be fixed by moving the line till after the block of code shown above.
https://github.com/mozhgan-kch/TB_Model/blob/477ecca530f3267ea6532a2979cbcd354a69d89a/examples/TB_Model/src/model/functions.c#L194
This particular device function, never seems to exit, and I've little evidence that the loop within is actually iterating either.
This function is called like:
float u = rnd<CONTINUOUS>(rand48);
float v = rnd<CONTINUOUS>(rand48);
float w = rnd<CONTINUOUS>(rand48);
float dev = cadgamma(DELTA, u, v, w);
and presumably rnd<CONTINUOUS>(rand48) returns in the range [0.0,1.0)
I took the code away from CUDA to test how it operates, and came across some arguments which lead to infinite loops.
In this interactive demo, it's clear that some combinations of input arguments lead to an infinite loop case (without the added limit, it times out over the runtime limit), the output is the same, regardless of 10, 100, 1000 or 10000 iterations. Other combinations I tested (with all args close to 0.5 exited as fast as a single iteration). Given how quickly I was able to find an erroneous combination, it's fair to assume there are more than a few.
Adding an iteration limit to the loop within that function allows the model to execute to completion. It's one of the few not commented elements of the code, so I don't understand the maths enough to advise whether bad maths is the real issue.
https://github.com/mozhgan-kch/TB_Model/blob/477ecca530f3267ea6532a2979cbcd354a69d89a/examples/TB_Model/src/model/functions.c#L1810
This spurious printf causes a large string of digits to be output each iteration (there's no delimiter). Probably worth removing.
https://github.com/mozhgan-kch/TB_Model/blob/477ecca530f3267ea6532a2979cbcd354a69d89a/examples/TB_Model/src/model/functions.c#L790
This initialisation loop should be
for (unsigned int i = 0; i < total; i++), in it's current state it fails to initialiseorder[0]and writes to a single value past the end of the array.https://github.com/mozhgan-kch/TB_Model/blob/477ecca530f3267ea6532a2979cbcd354a69d89a/examples/TB_Model/src/model/functions.c#L946
This arrangement of 3 nested loops, assigns all of the people to housholds according to; household_capacity:household_of_capacity:person_within_household of capacity.
countis declared/initialised much much earlier, but remains0until this loop is reached.The bug here is that
countis being incremented before:Such that, again
ages[0]andorder[0]are unused, whereas there's an eventual access violation on the last iteration, whereby the index after the final element is accessed in both.This can be fixed by moving the line till after the block of code shown above.
https://github.com/mozhgan-kch/TB_Model/blob/477ecca530f3267ea6532a2979cbcd354a69d89a/examples/TB_Model/src/model/functions.c#L194
This particular device function, never seems to exit, and I've little evidence that the loop within is actually iterating either.
This function is called like:
and presumably
rnd<CONTINUOUS>(rand48)returns in the range[0.0,1.0)I took the code away from CUDA to test how it operates, and came across some arguments which lead to infinite loops.
In this interactive demo, it's clear that some combinations of input arguments lead to an infinite loop case (without the added limit, it times out over the runtime limit), the output is the same, regardless of 10, 100, 1000 or 10000 iterations. Other combinations I tested (with all args close to
0.5exited as fast as a single iteration). Given how quickly I was able to find an erroneous combination, it's fair to assume there are more than a few.Adding an iteration limit to the loop within that function allows the model to execute to completion. It's one of the few not commented elements of the code, so I don't understand the maths enough to advise whether bad maths is the real issue.
https://github.com/mozhgan-kch/TB_Model/blob/477ecca530f3267ea6532a2979cbcd354a69d89a/examples/TB_Model/src/model/functions.c#L1810
This spurious
printfcauses a large string of digits to be output each iteration (there's no delimiter). Probably worth removing.