public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aran Nokan <nokanaran@gmail.com>
To: David Brown <david@westcontrol.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: GCC Optimization Levels - Seeking Insights
Date: Fri, 22 Dec 2023 11:44:06 +0100	[thread overview]
Message-ID: <CAKHt_YY_+uueTL1_-bZOVnBwdyf9i-k=5NNjVGc6uVk+PTpp7g@mail.gmail.com> (raw)
In-Reply-To: <um3kk0$kf6$1@ciao.gmane.io>

[-- Attachment #1: Type: text/plain, Size: 3288 bytes --]

Hi,

Thank you. I noticed that it is not working with the following error:

No rule to make target 'test.0',


So I changed it to this:

$(PROGS): test.% : $(SRC) $(DEPS)
>         $(CC) -o $@ $(CFLAGS) $(LDLAGS) -O$* $(SRC)


But now another problem:

make: *** No rule to make target 'levmarg.c', needed by 'test.0'.  Stop.
>

Do you have any idea how to fix it?

Sincerely,
Aran

On Fri, Dec 22, 2023 at 10:26 AM David Brown via Gcc-help <
gcc-help@gcc.gnu.org> wrote:

> On 21/12/2023 20:57, Jonathan Wakely via Gcc-help wrote:
> > On Thu, 21 Dec 2023, 19:33 Aran Nokan via Gcc-help, <
> gcc-help@gcc.gnu.org>
> > wrote:
> >
> >> Hello GCC Community,
> >>
> >> I recently conducted an experiment where I tested the impact of
> different
> >> GCC optimization levels on the performance of a code
> >> <https://github.com/leechwort/levenberg-maquardt-example>. I observed
> that
> >> higher optimization levels didn't necessarily result in faster code
> >> execution.
> >>
> >> Is it correct or I have made a mistake? Do we have any other parameters
> for
> >> optimization?
> >>
> >
> > There is no guarantee that optimization make code faster, except that -O0
> > will invariably be slower.
> >
> >
> > However, I suspect the problem is that your makefile only builds the .o
> > objects once, for the first target that needs them. That means they will
> be
> > optimized (or not optimized) according to the CFLAGS set when building
> that
> > first target.
> >
> > Unless you do 'make clean' before building each target, you weren't
> > actually testing what you intend to test.
> >
> >
>
> For this test, since there are not many source files, I'd put them all
> on the same gcc line :
>
>
> default: all
> .PHONY: all
>
>
> OPTS = 0 1 2 3 g fast
>
> PROGS = $(foreach opt, $(OPTS), test.$(opt))
> all: $(PROGS)
>
> CC = gcc
> CFLAGS_COMMON = -I.
> LDLAGS = -lm
> DEPS = levmarq.h makefile
> SRC = main.c levmarg.c
>
> test.% : $(SRC) $(DEPS)
>         gcc -o $@ $(CFLAGS) $(LDLAGS) -O$* $(SRC)
>
> clean:
>         rm -f $(PROGS)
>
>
>
> (I haven't tried the makefile at all, but it might be a starting point
> for the OP.)
>
>
> >>
> >> My make file was as follows:
> >>
> >>
> >> CC=gcc
> >>> CFLAGS_COMMON=-I.
> >>> LDLAGS=-lm
> >>> DEPS = levmarq.h
> >>> OBJ = main.o levmarq.o
> >>>
> >>> %.o: %.c $(DEPS)
> >>>          $(CC) -c -o $@ $< $(CFLAGS) $(LDLAGS)
> >>>
> >>> main: $(OBJ)
> >>>          gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
> >>>
> >>> # No optimization
> >>> main_no_opt: CFLAGS += -O0
> >>> main_no_opt: $(OBJ)
> >>>          gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
> >>>
> >>> # Basic optimization
> >>> main_opt1: CFLAGS += -O1
> >>> main_opt1: $(OBJ)
> >>>          gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
> >>>
> >>> # Moderate optimization
> >>> main_opt2: CFLAGS += -O2
> >>> main_opt2: $(OBJ)
> >>>          gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
> >>>
> >>> # High optimization
> >>> main_opt3: CFLAGS += -O3
> >>> main_opt3: $(OBJ)
> >>>          gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
> >>>
> >>> # Clean rule
> >>> clean:
> >>>          rm -f *.o main main_no_opt main_opt2 main_opt3
> >>>
> >>
> >> Best regards,
> >> Aran
> >>
> >
>
>
>

  reply	other threads:[~2023-12-22 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21 19:32 Aran Nokan
2023-12-21 19:57 ` Jonathan Wakely
2023-12-22  9:24   ` David Brown
2023-12-22 10:44     ` Aran Nokan [this message]
2023-12-22 11:25       ` David Brown
2023-12-22 11:51       ` Jonathan Wakely
2023-12-22 11:52         ` Jonathan Wakely
2023-12-25 16:21     ` NightStrike
2023-12-26 18:46       ` Segher Boessenkool
2023-12-24 13:54 ` Peter0x44

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKHt_YY_+uueTL1_-bZOVnBwdyf9i-k=5NNjVGc6uVk+PTpp7g@mail.gmail.com' \
    --to=nokanaran@gmail.com \
    --cc=david@westcontrol.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).