I am writing a C program where I control nested loops for, one inside the other, as follows:
for(i[0] = 0; i[0] < n[0]; i[0]++)
for(i[1] = 0; i[1] < n[1]; i[1]++)
for(i[2] = 0; i[2] < n[2]; i[2]++)
{
do_lot_of_work(i, n, 3);
}
As you can see, the above code has three nested loops for. In my program, it takes into account 3 dimensions. However, I want to make my program extensible, which can take into account any number of measurements on the fly, as the user wishes; that is, for 4 dimensions, I want to have four nested loops forand do the work like do_lot_of_work(i,n,4). Similarly, for any number of measurements.
My question is: how to make the nesting of the loops described above forextensible?
Please note that to achieve the goal, I am ready to sacrifice internal loops for, but I want to keep the first loop forto make my program parallel with OpenMP.
source
share