### MikeMirzayanov's blog

By MikeMirzayanov, 20 months ago, translation, ,

Hello!

I am pleased to report that two rounds of Codeforces have gone quite well in terms of the work of Codeforces, I am very glad about it. These days nights I spent in a profiler, fixing the code, researching the settings of MariaDB.

In addition, I managed to allocate several hours on Sunday (to be honest, until Monday morning) to finish the long-planned innovation.

Meet, diagnostics of solutions in C++!

Many Codeforces visitors are already tired of the questions of less experienced participants: "Why does my solution not work on some test on the Codeforces servers, if I locally launch it and it works correctly? You have the wrong compiler/servers!" In 99% of cases this is an example of undefined behavior in a program. In other words, the program contains mistakes that, due to a number of circumstances, are not reproduced at local launch, but are reproduced at launch on the Codeforces servers.

Sometimes, it's not easy to notice such a mistake. A small overflow of the array can lead to an incorrect answer on the test and to an runtime error of the program.

In g++/clang++ there is a remarkable tools called sanitizers. It's such a way to compile a program in a special mode so that when it's working, it will check it for undefined behavior (and some other errors) and, if any, print them to stderr. The drmemory (it is similar to valgrind, but for Windows) has similar functionality, which starts the program in a special mode to detect errors. With such two diagnostic launches, the performance of the program suffers tremendously (the program is executed 5-100 times slower and requires more memory), but often it's worth it.

Now automatic diagnostics in some cases will prevent a question like "Why does not work ???", indicating the error or its appearance!

• written in C++,
• finishes with a verdict "wrong answer" or "runtime error"
• on this test worked extremely quickly and consumed a little memory,

then it will be restarted using special diagnostic compilers (clang ++ with sanitizers and g++ with drmemory). If an execution error occurs during this launch, the diagnostics log will be displayed in the test details in the "diagnostics" section. Of course, this entry will contain a technical report in English, but often it will indicate to you the error of the program. Often it contains the cause of the mistake and even the source code line. If the diagnostics are not displayed, then at least one condition above is not fulfilled or the diagnostics has not detected any errors.

Example of the diagnostics:  here it is written that there was an array out of range error in the line 78.

Thus, the diagnostics will sometimes help you to find a mistake like "out of bounds error", "signed numbers overflow", "uninitialized variable", etc. Carefully read the diagnosis and do not make such mistakes in the future!

I wish your programs did not fail. I hope the innovation will be useful!

There are big plans as it is useful to apply such diagnostics. Do not go far, wait for news, soon there will be more innovations!

P.S. Also, diagnostic compilers are simply available for use. For example, you can use them on the "Custom invocation" tab. I recall that the program runs many times slower and consumes more memory in diagnostic mode.

• +1718

 » 20 months ago, # | ← Rev. 3 →   +43 It's all good, of course. But, please, fix the issue with virtual participating in gyms and contests.UPD: Fixed
•  » » 20 months ago, # ^ |   +34 What is the issue? Please, write the details.
•  » » » 20 months ago, # ^ | ← Rev. 2 →   +46 When I register in virtual participation, it seems that contest has already started. However, there is no countdown.
•  » » » » 20 months ago, # ^ |   +87 Fixed. Thank you for information.
 » 20 months ago, # |   +4 Sometimes when we participate in a GYM contest as a team,sometimes I get a message as displayed in the photo attached but my teammates don't face that kind of error,so the problem might be on my system but I couldn't figure any solution.What might be the problem?
 » 20 months ago, # |   0 so great
•  » » 20 months ago, # ^ |   +1 I believe this will be fine if you use Mozilla browser for hacking.
•  » » » 20 months ago, # ^ |   +1 I'm realy using it.
•  » » » » 20 months ago, # ^ |   +2 try using google chrome.
•  » » » » » 20 months ago, # ^ | ← Rev. 2 →   0 I will do this, but I'm wonderring, why will the browser solve this problem? Is it the features in the browser which can do what Adobe Flash Player do?
•  » » » » » » 20 months ago, # ^ |   +2 Mozilla firefox requires flash player installation for running flash applications but google chrome comes with adobe flash player plugin.(link for reference) It solved my problem. Maybe it solve yours too. :)
•  » » » » » » » 20 months ago, # ^ |   0 OK, Thank you very much :).
•  » » » » » 20 months ago, # ^ |   0 Thank you anyway for your advice.
•  » » » 20 months ago, # ^ |   0 Thank you anyway for your advice.
•  » » 20 months ago, # ^ |   +1 same here
 » 20 months ago, # |   0 Thank you so much for this! now I can have the peace of mind when my compiler gives different result than Codeforces — there will be explained a reason why. :)
 » 20 months ago, # | ← Rev. 2 →   0 Thanks MikeMirzayanov.
 » 20 months ago, # |   +32 Great work! I see that you use -O0 for clang and gcc with diagnostics. Sanitizers work well even in release mode (at least on Linux). That's how I typically use them and stack traces always were on point as far as I remember. Is Windows different?If you got clang 5.0 to work, may be it is time to replace MSVC 2010 with Clang? Clang tries to support MSVC compiler extensions so for the most people there would be no difference. It is not as mature yet as Clang on Linux or Visual Studio though. Alternatively, upgrade MSVC to 2017, since you now have it installed anyway.
•  » » 20 months ago, # ^ | ← Rev. 2 →   0 plus to MSVC 2017
 » 20 months ago, # |   +35 So, basically this update gives an opportunity to see pretests during contest?
•  » » 20 months ago, # ^ |   -8 mind-blown
•  » » 20 months ago, # ^ |   0 Codeforces shows diagnostics only if you can view judgement details on tests. Am I right that during a round you can't see submission judgement details on pretests?
•  » » » 20 months ago, # ^ | ← Rev. 2 →   +24 So, the new diagnostic run will happen only in upsolving, not during a contest, right?Edit: Or some wrong answers will turn into runtime errors, but people still won't see the reason?
•  » » » » 20 months ago, # ^ |   +17 It works also during a contest but results are not available to participants. I have plans to show detailed report on example tests only.Diagnostic launches do not substitute verdict, they only add diagnostics message to report if exists.
•  » » » » » 20 months ago, # ^ |   0 >> I have plans to show detailed report on example tests only.Bad idea. Everyone should be equal. And it should be also disabled in custom tests, at least during contests.Or show me my out of bounds errors when I write in Pascal, show me my Integer == Integer or treeSet.remove(badObject) warnings when I write in Java.
•  » » » » » » 20 months ago, # ^ |   +12 Nobody forbids you switching to C++. Whining about advantages of C++ because you chose some different language is kinda not justified. C++ has such diagnostics and UB detector for already some time, this is just making it a little bit easier to use for beginners.
•  » » » » » » » 20 months ago, # ^ |   -17 Too fat. Java has PMD since ancient times, and what? Mike isn't going to enable it. C++ users will get advantage of third party tool executed on samples, and it's unfair.
•  » » » » » » 20 months ago, # ^ |   +47 Does it bother you that I write contests on Linux with C++ sanitizers switched on? I don't see any problems with detailed report for example tests — anyone can run solution locally and get the same information.There are variations in the rules at different sites each having its own definition of fairness between languages. So it is not an absolute point and we shouldn't stop trying new variations. You just need to get used to new rules and then you might call absence of sanitizers as unfair.
•  » » » » » » 20 months ago, # ^ |   +4 Java already does not have Undefined Behavior. You always get On Java a run-time error for out-of-bounds access. This update try to close the gap, not to create a new one.
•  » » » » » 20 months ago, # ^ |   +44 The feature is great, but I have a question here, you say "the program is executed 5-100 times slower and requires more memory", and you are planning to enable it during contests, wouldn't this put a greater risk in having rounds ruined by a long submission queue?
 » 20 months ago, # | ← Rev. 2 →   +54 Can I say a question that has nothing to do with the topic? Often times when I view my own code in the standings I will not be able to load it. But I found that I can successfully see the code of others. And i found this on the console.
•  » » 20 months ago, # ^ |   +3 that is generally caused by the GFW
 » 20 months ago, # | ← Rev. 4 →   +144 MikeMirzayanov Hi, I just want to request a new feature that I hope you can spend some time considering it. I think Codeforces should enable users to judge a single test (in practice of course). i.e, a test of users' choosing. I have debugged quite many problems on Codeforces, and every time that I get a WA or a TLE at a big test, after debugging, I have to resubmit and wait for my code to run through all previous tests. That is not only time-consuming for me but also put more pressure on the judging system. I just wonder why a simple feature hasn't been added to Codeforces, which will bring enormous benefit to both users and the judging system. Thank you for reading and if because of some reasons this feature can't be implemented, please just state some reasons.
 » 20 months ago, # |   +8 Ohhh this feature is amazing!
 » 20 months ago, # | ← Rev. 3 →   +2 Sorry for inconvenience in the following comment, but we always complain from this issue, and it hasn't been fixed yet.When a user opens the coach mode, all his submissions disappear from the standing. Also when he adds a gym contest to the group who is managed by him, he will face the same issue.All of us will be pleasured if you fix this bug soon.Thanks
•  » » 20 months ago, # ^ |   +10 I think these are intended.So that Problemsetters can test some submissions without polluting the standing.
 » 20 months ago, # |   +6 This would help me so much at IOI...
 » 20 months ago, # |   0 Thank you for the diagnostics. It should be quite helpful. I tried to modify an accepted solution, making it access out of band memory, in order to trigger the diagnostics output, but the diagnostic did not show anything. Here are the modified solution with no diagnostic output in 2 submissions: 32530091 using GNU G++17 Diagnostics and 32530060 using Clang++17 Diagnostics.
 » 20 months ago, # |   +20 We live in 2017 and CF is in 3082 now !
 » 20 months ago, # |   0 Can we know the exact options with which the code will be compiled to get these diagnostics? (I'm sorry if you've already published them, I couldn't find them).I believe it will be really useful when participating in official ICPC/Olympiads contests.Thank you!
•  » » 20 months ago, # ^ |   0 Just read the manual https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html https://clang.llvm.org/docs/index.html. Read Codeforces http://codeforces.com/blog/entry/15547 and don't repeat newbie mistakes http://codeforces.com/blog/entry/54610 .
•  » » » 20 months ago, # ^ | ← Rev. 2 →   0 Thank you for pointing to these links. However, the exact options for diagnostics is still relevant and Important, because: these options have bugs that vary according to platform: for example: Map Erase causes a crash on Mingw and Crash on cin or getline to empty string on MinGW gcc with Debug mode. Also not all diagnostic flags work well with each other , more sanitizers are added overtime, and it helps to know the exact compiler options as in About the Programming languages in order to replicate the results locally.