Compiler flags within source code

Write here if you have problems with your C source code

Moderator: Board moderators

Compiler flags within source code

Postby erdos » Sat Jul 06, 2002 9:44 pm

Hi,

I would like to know if there's someway to turn on some compiler flags (like -O3) within C source code.

In Delphi or C++ Builder the compiler flags are turned on with {$O+} for instance.
In gcc what's the way to do it ?
Does the online judge allows we to do that ?
(Even if it doesn't what's the way do that in a normal program?)

Regards,
erdos
New poster
 
Posts: 32
Joined: Sat Jul 06, 2002 9:38 pm
Location: Lisbon

Postby Picard » Sun Jul 07, 2002 12:21 am

i was searching for this kind of option too but with no success. i think it's not possible to turn on optimalizations during preprocessing.

probably the admins had good reason to turn off optimalizations (much more CPU power to compile! runtime error bugs are harder to find? ) currently if i want something to be fast, i use the 'register' keyword, and have a look at the assemby code generated (at home with cygwin GCC 2.95.3-5)
Picard
Learning poster
 
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary

Postby erdos » Sun Jul 07, 2002 3:24 am

Yes, you pointed out good reasons to not allow optimization during preprocessing.
But at "home" we could do that.Do you know what's the flag ?

By the way, I noticed that you have excellent times in lots of problems. What are your tricks for faster times other than precalc (when it's possible?).

Could you try doing problem 10282 ? I would like to know how much time would you be able to do on that one:-)

Regards,
erdos
New poster
 
Posts: 32
Joined: Sat Jul 06, 2002 9:38 pm
Location: Lisbon

Postby Picard » Sun Jul 07, 2002 10:38 am

at home why can't you use the command line options? i think there is no possibility changing the optimalizations of gcc during compiling.

as i told you, i use 'register' keyword before variables and have a look at the compiled binary (at home). hopefully the judge's gcc generates same or very similar binary :)

i'am always interested in a speed challange (if i can solve the problem. but i won't use assembly, the source is ugly enough already)
P10282: 0.230 sec
Picard
Learning poster
 
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary

Postby erdos » Sun Jul 07, 2002 1:32 pm

At home I can use the command line options, of course.(And I can even set them in the source if if compile the source with Delphi or C++ Builder).

Does the register keyword do such miracles ?
Also for input/output, what's the fastest ? puts and scanf ?

You did an amazing time in 10282! Why was your source was in C++ ?
What features did you use ?
And when you passed from 0.230s to 0.180s what did you changed ?
(BTW: I implemented an hash table using what seems to be a great hash function I picked from the net.What was your hash function?).You used so much memory because you made the hashtable bigger than needed or used other auxiliary structures ?

Regards,
erdos
New poster
 
Posts: 32
Joined: Sat Jul 06, 2002 9:38 pm
Location: Lisbon

Postby Picard » Sun Jul 07, 2002 2:03 pm

without optimalization turned on, all variables is loaded/saved in memory at every access. register keyword can be important for local variables which is used many times in small part of the code.

i don't know if it's the fastest or not, but for high speed program versions i use manual i/o processing (no scanf, printf or what ever). reading all input in one huge buffer and buffering all output in another big buffer. for example in my integer/double read/write routines it's crucial to use register keyword.

i use C++ not because of STL classes or virtual methods. i think it's just easier as C, you have more freedom and compiler warnings.

10282: what features did i use? only two function calls: one read() at begining and one write() at the end. i'am using lexical tree search (i'am not sure this is the right name) using the 'a'..'z' charachter range in every level. the speed "boost" from 0.230 to 0.180 was because i reduced the memory need with eliminating the last nodes in the tree (if possible), so i have pointers with two possible types: point to another node or to directly to an english string (which is the English translation of current path)
Picard
Learning poster
 
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary

Postby Ivor » Sun Jul 07, 2002 7:40 pm

you wanted a speed chllenge picard? your turn on 10282 8)

Ivor
Ivor
Experienced poster
 
Posts: 147
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Postby Picard » Sun Jul 07, 2002 8:14 pm

it's geting tight. i waited a bit for lower server load.

ps: i try to keep my submission count <= 2 * solved problems
Picard
Learning poster
 
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary

Postby Caesum » Thu Jul 11, 2002 11:44 pm

I managed to get it down to 0.14 in pure C with many changes to my original program. As C goes its looking good although there are some possible optimisations nothing seems to make a big difference. In order to get to 0.09 have you used asm ?
Caesum
Experienced poster
 
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK

Postby Picard » Fri Jul 12, 2002 12:13 am

no asm. but played a lot with "register" keyword. memory handling is another important issue. for example my 0.090sec version got PE and tunned very much for possible judge input. yeah i hate to "sacrifice" a general good solution, but the ranklist is about what the judge say.
Picard
Learning poster
 
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary

Postby Caesum » Fri Jul 12, 2002 7:16 pm

if you fancy optimising another one, 10290 is nice :)
Caesum
Experienced poster
 
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK

Postby Picard » Sat Jul 13, 2002 2:02 am

yeah i checked it. there is a huge gap between first two and other solutions. actually this problem first needs a good mathematical algorithm (prime factorization) which i don't have :( i searched the web, but it's too complicated for me. it would need me too much time. i give up.
Picard
Learning poster
 
Posts: 96
Joined: Mon Jun 24, 2002 1:22 pm
Location: Hungary


Return to C

Who is online

Users browsing this forum: No registered users and 0 guests