dx24816's blog

By dx24816, history, 6 years ago, In English

Hello,

I use to include the following code into my headers because I saw others doing the same.

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

For the most part, it has made some of my programs that previously got TLE get AC. However I recently kept getting TLE with these comments in the header of my program for a problem, and when I removed them, I got AC. So I'm wondering what do these comments do, and when should I use them? Thanks in advance!

Edit:

Here is the TLE: http://codeforces.com/contest/1009/submission/40353118

Here is the AC: http://codeforces.com/contest/1009/submission/40353105

You can check the only difference is the pragma.

-dx24816

  • Vote: I like it
  • +14
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Please give examples of removing these giving AC.

BTW, if this is for USACO, I think they will switch you to optimize level 0 if you use any of these flags. So don't try it there.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This was on Codeforces. I have added the codes.

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      http://codeforces.com/contest/1009/submission/40353472 http://codeforces.com/contest/1009/submission/40353529

      It is optimization flags issue. I remember hearing in the past that optimize levels more aggressive than 2 can actually result in slowdowns. CF uses optimize level 2 by default. Ofast is the one slowing you down the most.

      Removing the target instructions also seems to provide a speedup. I don't have any explanation for this.

      • »
        »
        »
        »
        6 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        I see your point. The problem is if I'm on an actually Codeforces contest, how would I know if pragma speeds up my code or slows it down without potentially getting a bad submission, since sometimes adding the pragma on Codeforces turns my code from TLE to AC.

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          I never use the Ofast pragma. You shouldn't either

          For the target instructions, use them when you are trying to brute force something with a lot of simple for loops (preferably over large-sized arrays, or with no arrays at all), that's where it helps the most. Otherwise I don't use them.

          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I was thinking to use these pragma comments in my code I have found about all the pragma comments from here https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html but there was not much explanation about target pragma. So Can you please give more details on GCC target pragma. Thanks

            • »
              »
              »
              »
              »
              »
              »
              5 years ago, # ^ |
                Vote: I like it +1 Vote: I do not like it

              It's stuff that targets for physical architecture and speeds up brute-force loops and such immensely, and it can be helpful sometimes. See MrDindows or dmkozyrev for more

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Can anyone say what the following line actually do?

#pragma comment(linker, "/stack:200000000")
»
2 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

https://codeforces.com/contest/1009/submission/153624213 submit it again and get AC

UPD: Sorry I didn't notice the time of this blog, I think it might be because of the judge have been update.