int bNum=3;
int aNum=3;
for (int i = 0; i < bNum; i++)
{
for (int j = 0; j < aNum; j++)
{
b[i] += a[j];
b[i + 1] += a[j + 3];
b[i + 2] += a[j + 6];
}
}
I basically want the following to happen:
b[0]=a[0]+a[1]+a[2];
b[1]=a[3]+a[4]+a[5];
b[2]=a[6]+a[7]+a[8];
What is wrong with my logic?
HAHA! OOPS! My sleepy eyes are accounting for the dumb question. I see that at every iteration it get computed multiple times.
whatever language it is, you need to make constant index for b, variable index for a
i made the “k” loop outer to let it read the a[] as continuously as possible. You can make “k” loop innerside but it makes reads of a[] jumping from here to there then coming back here again an jumping again, which makes it slow.
this is not a vector though 😛 i just used it to fill the space