performance measurements

Each table row shows performance measurements for this C gcc program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
500,000Make Error  761   

Read the ↓ make, command line, and program output logs to see how this program was run.

Read thread-ring benchmark to see what this program should do.

 notes

gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)

 thread-ring C gcc #4 program source code

/* The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/

   Contributed by Andrew Gottemoller
*/
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>


#define LIKELY(expression)   __builtin_expect(!!(expression), 1)
#define UNLIKELY(expression) __builtin_expect(!!(expression), 0)


#define THREAD_COUNT 503
#define PASS_COUNT   1000

#define THREAD_CREATED 0x01


struct thread_data
{
   unsigned int flags;
   unsigned int id;

   sem_t pass_semaphore;

   pthread_t thread;
};


static struct thread_data passing_threads[THREAD_COUNT] = {{0}};
static unsigned int      passes_remaining           = PASS_COUNT+1;


static inline void  CreateThread (unsigned int);
static void*      PerformPass  (void*);


static inline void CreateThread (unsigned int id)
{
   struct thread_data* restrict thread;

   thread = &passing_threads[id];

   thread->id = id;

   sem_init(&thread->pass_semaphore, 0, 0);
   pthread_create(&thread->thread, NULL, &PerformPass, thread);

   __sync_fetch_and_or(&thread->flags, THREAD_CREATED);
}

static void* PerformPass (void* argument)
{
   struct thread_data* restrict thread;
   struct thread_data* restrict next_thread;
   unsigned int             id;
   unsigned int             next_id;
   unsigned int             thread_ready;

   thread = argument;

   id     = thread->id;
   next_id = (id+1)%THREAD_COUNT;

   next_thread = &passing_threads[next_id];

   sem_wait(&thread->pass_semaphore);

   passes_remaining--;
   if(LIKELY(passes_remaining != 0))
   {
      do
      {
         thread_ready = __sync_fetch_and_or(&next_thread->flags, 0);
      }while(!(thread_ready&THREAD_CREATED));

      while(1)
      {
         sem_post(&next_thread->pass_semaphore);
         sem_wait(&thread->pass_semaphore);

         passes_remaining--;
         if(UNLIKELY(passes_remaining == 0))
            break;
      }
   }

   printf("%d\n", id+1);

   exit(EXIT_SUCCESS);
}


int main (int argument_count, char** arguments)
{
   struct thread_data* restrict initial_thread;

   if(argument_count > 1)
      passes_remaining = atoi(arguments[1])+1;

   CreateThread(0);

   initial_thread = &passing_threads[0];

   sem_post(&initial_thread->pass_semaphore);

   for(unsigned int index = 1; index < THREAD_COUNT; index++)
      CreateThread(index);

   pthread_join(initial_thread->thread, NULL);

   return 0;
}

 make, command-line, and program output logs

Wed, 20 May 2015 10:12:22 GMT

MAKE:
/usr/bin/gcc -pipe -Wall -O3 -fomit-frame-pointer -march=native -pthread threadring.gcc-4.c -o threadring.gcc-4.gcc_run 
threadring.gcc-4.c: In function ‘CreateThread’:
threadring.gcc-4.c:43:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘thread’
    struct thread_data* restrict thread;
                                 ^
threadring.gcc-4.c:43:33: error: ‘thread’ undeclared (first use in this function)
threadring.gcc-4.c:43:33: note: each undeclared identifier is reported only once for each function it appears in
threadring.gcc-4.c:52:4: error: incompatible type for argument 1 of ‘__sync_fetch_and_or’
    __sync_fetch_and_or(&thread->flags, THREAD_CREATED);
    ^
threadring.gcc-4.c: In function ‘PerformPass’:
threadring.gcc-4.c:57:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘thread’
    struct thread_data* restrict thread;
                                 ^
threadring.gcc-4.c:57:33: error: ‘thread’ undeclared (first use in this function)
threadring.gcc-4.c:58:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘next_thread’
    struct thread_data* restrict next_thread;
                                 ^
threadring.gcc-4.c:58:33: error: ‘next_thread’ undeclared (first use in this function)
threadring.gcc-4.c:77:10: error: incompatible type for argument 1 of ‘__sync_fetch_and_or’
          thread_ready = __sync_fetch_and_or(&next_thread->flags, 0);
          ^
threadring.gcc-4.c: In function ‘main’:
threadring.gcc-4.c:99:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘initial_thread’
    struct thread_data* restrict initial_thread;
                                 ^
threadring.gcc-4.c:99:33: error: ‘initial_thread’ undeclared (first use in this function)
threadring.gcc-4.c:110:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
    for(unsigned int index = 1; index < THREAD_COUNT; index++)
    ^
threadring.gcc-4.c:110:4: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
/home/dunham/benchmarksgame/nanobench/makefiles/u64.programs.Makefile:54: recipe for target 'threadring.gcc-4.gcc_run' failed
make: [threadring.gcc-4.gcc_run] Error 1 (ignored)
rm threadring.gcc-4.c
0.05s to complete and log all make actions

COMMAND LINE:
./threadring.gcc-4.gcc_run 500000

MAKE ERROR 

Revised BSD license

  Home   Conclusions   License   Play