[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Excessive copies of set elements in GMPL

From: Michael Hennebry
Subject: Re: Excessive copies of set elements in GMPL
Date: Fri, 24 Jul 2020 13:04:25 -0500 (CDT)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)

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.

"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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]