What should be the most efficient way of layout out the three nested
loops?
Does not really make sense (you should spend more time before you post
asking yourself whether your posts are complete and unambiguous). What is
efficient?
The code is the fastest to execute?
The code is the easiest to maintain?
Assuming you mean CPU efficient, it should be such that the inmost loop is
going the memory references that are adjacent. That make it cache friendly
For C and C++, for multi-dimensional arrays, it is the right-most index.
for (i=0; i<10000; i++)
for (j=0; j<1000; j++)
for (k=0; k<100; k++)
array[i][j][k] = i * j * k; // Cache friendly
Also, it is possible sometime to unroll a 3 index loop into a 1-index loop
which can be faster. e.g..
for (i=0; i<10000 * 1000 * 100; i++)
array2[i]= 1;
or replace with a function call like memset() etc.
Stephen Howe