A tool that suggests optimized logic for a piece ofcode/module/function

T

toby

I thought you were claiming Unix uniquely had some sort of VHLL.

Compared to C, bash *is* a VHLL. Rewrite this in C:

grep -i blah.log |cut -d ' ' -f 4,7 |cut -c 2-12,23-36 |sort |uniq -c -
i

Apart
from the weird embedded ones, don't *all* OSs have a way to run the
programs that are installed on them?

Wasn't jongware suggesting something even more magical? The VHLL that
can create appications that aren't stored on the machine?
My point was that the "primitives" provided by a shell (the programs
installed on the system) give a pretty good approximation to
[Jongware]'s suggestion of "type 'word processor' and get a word
processor".
 
T

toby

Hi,
There are certain editors that highlight
the syntax/color for datatypes/variables
or comments etc.

Similarly,
Is there a tool for C language that
could suggest an optimized/alternate
programming logic for the function that
is written ?

IMHO the most effective output it could make is: "Are you really sure
the best tool for this task is C?"
 
K

karthikbalaguru

IMHO the most effective output it could make is: "Are you really sure
the best tool for this task is C?"

My query is 'A tool that suggests
optimized logic for a piece of
code/module/function' . I am
looking for a tool that suggests
optimized logic for various
modules/functions written in
C language.
The tool can be made of any
language.
- Show quoted text -

Karthik Balaguru
 
N

Nick Keighley

My query is 'A tool that suggests
optimized logic for a piece of
code/module/function' .

we can read
I am
looking for a tool that suggests
optimized logic for various
modules/functions written in
C language.

and I am doubtful that such a tool can exist
The tool can be made of any
language.

or none

BTW: are your lines so short so your posts look like poetry?
 
J

Josef Moellers

karthikbalaguru said:
My query is 'A tool that suggests
optimized logic for a piece of
code/module/function' . I am

Define "optimized"!

Optimized for speed, optimized for memory requirement, optimized to
handle extreme situations, optimized to handle easy situations?

You can try explaining "optimized" to a human being. Then try to eplain
that to a computer program.

Josef
 
K

karthikbalaguru

Define "optimized"!

Optimized for speed, optimized for memory requirement, optimized to
handle extreme situations, optimized to handle easy situations?

Exactly !
The tool should support
for memory based optimization
that greatly helps in memory/
cost constraint systems,
speed based optimization that
greatly decides the performance
in certain projects, perfect
algorithm/logic required for a
particular scenario, and other
optimization techniques applicable.
It should probably have an option
that could decide the type of
optimization required for the user
for the particular module. May
be there can be an option called
'general optimization' that would
apply all optimization techniques
to a certain level only in a
balanced manner.

If the user is particular about
certain particular optimization,
Once the type of optimization
is got as input from the user,
even the level of optimization can
be got from the user by having
some flags/options for defining
different levels of optimization .

It could also tell the bottlenecks
in the code and that would greatly
help in optimizing the right piece
of code. Maybe a profiler should
also be part of it. The tool can
also display graphs that could
give comparitive analysis of
speed improvement vs memory
usage vs various levels of various
kinds of optimization techniques.

It can also suggest the best
possible number of threads
required, message queues
required for a particular
logic and define that logic.
It can remove off redundant
threads, interrupts or timers
etc and add if required for
an efficient logic that it
could suggest to the user.

Maybe, it can also suggest
various processors and the
relative performance w.r.t
memory, speed and cost
for those .
It could also suggest if
we need to go in for a
multicore and if so , it
can suggest the number
of cores and the kind of
processor !

Karthik Balaguru
 
J

Jonathan de Boyne Pollard

BTW: are your lines so short so your posts look like poetry?
Poetry? Xe is aiming for poetry here? All right. I choose ... erm ...
English haiku.

Making programs good
involves human programmers.
You pay them money.

I tried for a limerick, but I became stuck after "A poster to Usenet
named Karthik ...".
 
A

André Gillibert

toby said:
IMHO the most effective output it could make is: "Are you really sure
the best tool for this task is C?"

That's called an "optimizer" and is built into any good C compiler...
It doesn't even need to suggest a change. It just does it
internally, without modifying the source code.

PS:
Cross-posting to 5 newsgroup is evil.
Follow-up to comp.lang.c.
 
J

John Gordon

In said:
That's called an "optimizer" and is built into any good C compiler...
It doesn't even need to suggest a change. It just does it
internally, without modifying the source code.

The OP was asking for much more than an optimizing compiler.

To give just one example, he wants something which can recognize that
you're using a bubble-sort routine and can automatically rewrite the
source code into a quicksort.
 
S

Stefan Ram

John Gordon said:
The OP was asking for much more than an optimizing compiler.
To give just one example, he wants something which can recognize that
you're using a bubble-sort routine and can automatically rewrite the
source code into a quicksort.

When a compiler would do such a thing, why could this
compiler not also be called »an optimizing compiler«?

There is at least one automated optimization technique
capable to do this: It tries all sequences of machine
instructions until it finds one that has the behavior wanted
(or the behavior of a given program).

Of course, this is too slow for real-world programs today,
but I believe it has indeed been used for some small programs.
I just forget the name of this technique.
 
K

Keith Thompson

When a compiler would do such a thing, why could this
compiler not also be called »an optimizing compiler«?

There is at least one automated optimization technique
capable to do this: It tries all sequences of machine
instructions until it finds one that has the behavior wanted
(or the behavior of a given program).

Of course, this is too slow for real-world programs today,
but I believe it has indeed been used for some small programs.
I just forget the name of this technique.

It's called "superoptimization". I think it's been used to generate
optimal code sequences that can then be hardwired into a compiler (so
the expensive superoptimization occurs during compiler development,
not during each compilation).
 
K

Keith Thompson

John Gordon said:
The OP was asking for much more than an optimizing compiler.

To give just one example, he wants something which can recognize that
you're using a bubble-sort routine and can automatically rewrite the
source code into a quicksort.

So he wants a really clever optimizing compiler.
 
W

Walter Banks

Stefan said:
There is at least one automated optimization technique
capable to do this: It tries all sequences of machine
instructions until it finds one that has the behavior wanted
(or the behavior of a given program).

Of course, this is too slow for real-world programs today,
but I believe it has indeed been used for some small programs.
I just forget the name of this technique.

It comes under a number of names "superoptimizer" is one.
There two problems,

1) it as you say it can be slow. A 5 or 6 instruction search
can take up to a day.

2) Anything other than simple examples are surprisingly
hard to write correct execution criterion for.

It is however a technique that be useful for compiler writers
and those interested in coding algorithms.

Regards,


w..
 
R

Richard Bos

Keith Thompson said:
So he wants a really clever optimizing compiler.

No, he wants a read-my-mind magic optimising compiler. That is a
fundamentally different thing from a merely really clever one.

Richard
 
K

Keith Thompson

No, he wants a read-my-mind magic optimising compiler. That is a
fundamentally different thing from a merely really clever one.

I don't think so. It would require some of what one might call
artificial intelligence, but the boundary between AI and merely
clever programming has always been fuzzy.

An optimizer that's able to recognize bubble sort and replace it
with quicksort should be entirely feasible, if it's handled as a
special case. (It's probably not worth doing, since it's easier
for the programmer to just use quicksort in the first place.)

And it wouldn't read the programmer's mind; the whole point is that
the programmer didn't think of using quicksort.
 
W

Walter Banks

Keith said:
An optimizer that's able to recognize bubble sort and replace it
with quicksort should be entirely feasible, if it's handled as a
special case.

And it wouldn't read the programmer's mind; the whole point is that
the programmer didn't think of using quicksort.

The optimizer difficulty in C is recognizing the bubble sort then
determining that if it were replaced with a quicksort there
would be a benefit.

If a language represented objectives rather than implementations
it would be then possible for the compiler to simply make
choices in the code it generates.

To some extent this happens in C compilers now. For example
when a compiler sees a multiply "*" in source code it makes a
lot of choices when selecting what code to generate. The final
choice is based on data size, multiply by a constant or multiply
to constants (constant folding) and the appropriate code is
generated.

Telling the compiler ins some way what the objective is would
be the first step would be in determining what code should be
included in the application.

Regards,


Walter..
 
R

Richard Tobin

It would have to be a bit clever than that. Bubble sort is stable,
and quicksort implementations typically are't. It would have to
either use a stable version of quicksort, or determine that the
difference didn't affect the rest of the program.

Which is another example of this:
If a language represented objectives rather than implementations
it would be then possible for the compiler to simply make
choices in the code it generates.
To some extent this happens in C compilers now. For example
when a compiler sees a multiply "*" in source code it makes a
lot of choices when selecting what code to generate.

And of course one way C does this is by providing the library. Using
qsort() instead of writing a sort algorithm expresses clearly that you
want the data sorted. And it would be better if it provided both
a sort() and a stable-sort(), so you could express whether you
cared.

-- Richard
 
S

Stefan Ram

It would have to be a bit clever than that. Bubble sort is stable,
and quicksort implementations typically are't. It would have to
either use a stable version of quicksort, or determine that the
difference didn't affect the rest of the program.

What one might want is to provide a list of input-output
pairs and get a generated program to implement a mapping
via a rule that is as simple (small) as possible and then
can be generalized to other inputs as well.

An example of a program to do this is

http://ccsl.mae.cornell.edu/sites/default/files/Science09_Schmidt.pdf

. A copy of Eureqa can be downloaded at

http://ccsl.mae.cornell.edu/eureqa_download
http://ccsl.mae.cornell.edu/eureqa

. So, to generate a program to map x to f(x), you would
provide pairs of x and f(x) to Eureqa, and then copy the
formula it gives you into your source code. To »optimize«
another program, let it first generator such pairs and
then feed these pairs to Eureqa.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top