On-line engine blitz tourney November

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

brianr
Posts: 536
Joined: Thu Mar 09, 2006 3:01 pm

Re: On-line engine blitz tourney November

Post by brianr »

Ras wrote: Thu Nov 26, 2020 8:35 pm
brianr wrote: Thu Nov 26, 2020 8:07 pm Is there a tourney manager that uses the higher precision timers?
I'm not on Windows anymore, but under Linux, c-chess-cli has very precise timing (via clock_gettime with monotonic clock).
Thanks, I have not tried that one yet.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: On-line engine blitz tourney November

Post by hgm »

WinBoard uses gettimeofday() to read the clock, as a first choice. (I didn't know that even was available in a MinGW compile. In Fairy-Max I have an #ifdef WIN32 to choose between GetTickCount() and gettimeofday(), and it seems I would not even need that! :shock: )

I am afraid that in MinGW gettimeofday() just ticks every 16msec, though, despite the microsec precision.

Code: Select all

/* Get the current time as a TimeMark */
void
GetTimeMark (TimeMark *tm)
{
#if HAVE_GETTIMEOFDAY

    struct timeval timeVal;
    struct timezone timeZone;

    gettimeofday(&timeVal, &timeZone);
    tm->sec = (long) timeVal.tv_sec;
    tm->ms = (int) (timeVal.tv_usec / 1000L);

#else /*!HAVE_GETTIMEOFDAY*/
#if HAVE_FTIME

// include <sys/timeb.h> / moved to just above start of function
    struct timeb timeB;

    ftime(&timeB);
    tm->sec = (long) timeB.time;
    tm->ms = (int) timeB.millitm;

#else /*!HAVE_FTIME && !HAVE_GETTIMEOFDAY*/
    tm->sec = (long) time(NULL);
    tm->ms = 0;
#endif
#endif
}
I guess I could prefix this with an #ifdef WIN32 to make QueryPerformanceCounter the first choice. How would that work? Should I also use QueryPerformanceFrequency to normalize thhe count? And is that frequency a constant, or should I do that every time (because of turbo boost)? Would this work?:

Code: Select all

#ifdef WIN32
  long long 
  int freq, ticks;
  QueryPerformanceFrequency(&freq);
  QueryPerformanceCounter(&ticks);
  ticks *= 1000000; ticks /= freq;
  tm->sec = ticks / 1000000;
  tm->ms = (ticks / 1000) % 1000;
#else
...
#endif
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: On-line engine blitz tourney November

Post by Ras »

hgm wrote: Fri Nov 27, 2020 12:07 amI am afraid that in MinGW gettimeofday() just ticks every 16msec, though, despite the microsec precision.
Try clock_gettime(), does this have the same issue?
I guess I could prefix this with an #ifdef WIN32 to make QueryPerformanceCounter the first choice.
That's what I'm doing for the Windows compile. Omitting the Windows build ifdefs:

Code: Select all

#include <windows.h>
#include <process.h>

LARGE_INTEGER clock_ticks_start, clock_ticks_freq;

/*init time acquisition, to be called on program start*/
void Init_Millisecs(void)
{
    /*QueryPerformanceFrequency doesn't change after Windows has booted*/
    QueryPerformanceFrequency(&clock_ticks_freq);
    QueryPerformanceCounter(&clock_ticks_start);
}

/*gets the absolute timestamp in milliseconds since Init_Millisecs() call*/
int64_t Get_Millisecs(void)
{
    LARGE_INTEGER clock_ticks_now, clock_ticks_elapsed, millisecs_elapsed;

    QueryPerformanceCounter(&clock_ticks_now);
    clock_ticks_elapsed.QuadPart = clock_ticks_now.QuadPart - clock_ticks_start.QuadPart;

    /*ticks to milliseconds:
      the tick counter won't overflow for a 100 years, but the milliseconds
      calculation might overflow if multiplying the tick difference by 1000
      and directly dividing by the clock frequency. That would require
      having the application open for 0.1 years, i.e. 36.5 days, which
      might be feasible.*/

    /*whole seconds*/
    millisecs_elapsed.QuadPart = clock_ticks_elapsed.QuadPart / clock_ticks_freq.QuadPart;
    /*fractional seconds in ticks*/
    clock_ticks_elapsed.QuadPart %= clock_ticks_freq.QuadPart;
    /*whole seconds to milliseconds*/
    millisecs_elapsed.QuadPart *= 1000;
    /*add fractional seconds in milliseconds, rounding downwards*/
    millisecs_elapsed.QuadPart += (clock_ticks_elapsed.QuadPart * 1000) / clock_ticks_freq.QuadPart;
    return((int64_t)millisecs_elapsed.QuadPart);
}
Rasmus Althoff
https://www.ct800.net
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: On-line engine blitz tourney November

Post by hgm »

Hmm... It seems my compiler doesn't recognize 'struct timespec' or CLOCK_REALTIME even after #including time.h. And I get a linker error for QueryPerformanceFrequency. So this will be harder than I expected.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: On-line engine blitz tourney November

Post by Ras »

hgm wrote: Fri Nov 27, 2020 12:57 pmHmm... It seems my compiler doesn't recognize 'struct timespec' or CLOCK_REALTIME even after #including time.h.
IIRC MingW uses the pthread stuff for that, which requires:

Code: Select all

#define _POSIX_C_SOURCE 200809L
#include <pthread.h>
And probably also for the compiler call: -pthread -lpthread

Further headers that I have included, for both Linux and Windows:

Code: Select all

#include <inttypes.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
And I get a linker error for QueryPerformanceFrequency.
That's strange indeed.
Rasmus Althoff
https://www.ct800.net
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: On-line engine blitz tourney November

Post by hgm »

The problem could be that I am using gcc 3.4.4 under Cygwin. (It says (C) 2004...)

Newer versions do not support the -mno-cygwin flag, though. I would need a separate MinGW compiler. I have that on my laptop (because the virus scanner removed Cygwin there), but it doesn't understand the Makefile that comes with WinBoard, so that I have to build by hand. Which is a real pain for a project as complex as WinBoard.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: On-line engine blitz tourney November

Post by Ras »

hgm wrote: Fri Nov 27, 2020 1:21 pmThe problem could be that I am using gcc 3.4.4 under Cygwin. (It says (C) 2004...)
That might be a problem. You could try one of these packages: https://sourceforge.net/projects/mingw- ... gw-builds/. Under Windows, I used x86_64-7.3.0-posix-seh-rt_v5-rev0 (64 bit) and i686-7.3.0-posix-dwarf-rt_v5-rev0 (32 bit) for static linkage.
Rasmus Althoff
https://www.ct800.net