Exactly same code but different result

correct : CodeChef: Practical coding for everyone
TLE. : CodeChef: Practical coding for everyone
I was trying to debug my code and i was getting AC and TLE for same code . I tried to submit this same code repeatedly and was getting different answer everytime . Infact i was getting TLE for different subtasks .
Why such behaviour ? Is it because codechef server goes high and low ?

Strange!

1 Like
1 Like

thanks @ssjgz

1 Like

Having some variance in execution time is expected.

But it’s a good question whether the variance is higher than normal or not. Apparently codechef is using CPU: Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz as a judge machine (based on deciphering the information returned by the CPUID instruction). And this processor may scale its clock frequency between 2.3GHz and 3.7Ghz depending on how many CPU cores are in use simultaneously if the Turbo Boost feature is enabled. Normally it’s a good idea to have Turbo Boost enabled if the users want the best performance. But if it’s a timing sensitive competitive programming judge system, then disabling Turbo Boost may make sense to always enforce 2.3Ghz regardless of how many CPU cores are used simultaneously (during a busy contest and many concurrent submissions it’s going to run at the lowest clock frequency anyway).

2 Likes

Thanks @ssvb this information helped a lot .

Well, plot thickens. I’m using the following C++ code to retrieve the information about the judge machine:

#include <stdio.h>
#include <chrono>
#include <cpuid.h>

#define BENCHMARK_DURATION_MS 1000

const char *get_cpu_name()
{
  static unsigned int cpu_name[3 * 4 + 1] = { 0 };
  unsigned int eax, ebx, ecx, edx;
  for (int i = 0; i < 3; i++)
    __cpuid(0x80000002 + i,
            cpu_name[i * 4 + 0],
            cpu_name[i * 4 + 1],
            cpu_name[i * 4 + 2],
            cpu_name[i * 4 + 3]);
  return (const char *)&cpu_name[0];
}

void simpleloop(int cnt)
{
  asm volatile(
    "1: .rep 10000\n sub $0x1,%0\n .endr\n"
    "   jg 1b\n" : "+&r" (cnt) :: "cc");
}

double cpu_clock_freq_ghz(double time_limit_ms)
{
  double total_cycles = 0;
  double time_ms;
  auto t_start = std::chrono::high_resolution_clock::now();
  while (true) {
    int cnt = 100000000;
    simpleloop(cnt);
    total_cycles += cnt;
    auto t_cur = std::chrono::high_resolution_clock::now();
    time_ms = std::chrono::duration<double, std::milli>(t_cur - t_start).count();
    if (time_ms >= time_limit_ms)
      break;
  }

  return total_cycles / time_ms / 1000000.0;
}

int main()
{
  printf("CPUID processor name     : %s\n",
         get_cpu_name());
  printf("Measured clock frequency : %.3f GHz\n",
         cpu_clock_freq_ghz(BENCHMARK_DURATION_MS));
}

Paste it as a C++ solution for any problem in practice mode. And then press “Run” button instead of “Submit”. And for me it results in one of these two outcomes:

CPUID processor name : Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
Measured clock frequency : 2.394 GHz

CPUID processor name : Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz
Measured clock frequency : 2.934 GHz

So the codechef judge machines are apparently using at least two different processors models. And they both support turbo boost, which seems to be enabled. So their clock speed may automatically adjust depending on how many cores are used simultaneously.

Maybe codechef @admin can explain something? Do actual rated codechef contests use the same mix of different judge machines with varying clock speeds?

3 Likes

The IDE Run uses a different set of checkers than Submit, which is the critical set of checkers.
Will have to check up on the rest.

4 Likes