Re: Excessive copies of set elements in GMPL
Michael Hennebry <[email protected]> Fri, 24 Jul 2020 13:04:25 -0500 (CDT)
| Newsgroups | gmane.comp.gnu.glpk |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 24 Jul 2020, Andrew Makhorin wrote: > The issue can be illustrated by the following example: > > for (i = 0; i < 1000000; i++) > for (j = 0; j < 1000000; j++) > for (k = 0; k < 1000000; k++) > if (j == i+1 && j == j+2) > foo(i, j, k); > > Would you expect the C compiler to optimize this fragment in order not > to perform obvious excessive computations? My recollection is that gcc does make that kind of optimization for linear constraints. At the very least, most optimizing compilers would hoist the j==i+1 test ouside the k loop. That might be just enough to allow it to run in a practical amount of time: a few trillion cycles plus whatever foo requires. That said, the coder can, as noted, provide equivalent code that requires no optimization. -- Michael [email protected] "Sorry but your password must contain an uppercase letter, a number, a haiku, a gang sign, a heiroglyph, and the blood of a virgin." -- someeecards