
// Kernel invocation: tournament <<<N_BLOCK,BLOCK_LENGTH>>> (fitgpu, randomgpu,winnergpu); 
// N_BLOCK: number of blocks, such that N_BLOCK * BLOCK_LENGTH = POP_SIZE.
// BLOCK_LENGTH: length of each block, such that N_BLOCK * BLOCK_LENGTH = POP_SIZE.
// fitgpu: pointer to global memory that stores the fitness values.
// randomgpu: pointer to global memory that stores the random numbers for the tournament (2*POP_SIZE).
// winnergpu: pointer to global memory that stores the positions of the winners of the tournaments.

__global__ void tournament(int * fit, int * random, int * win) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    int nro1 = random[2*idx];
    int nro2 = random[2*idx+1];
    int pos;
    
    if (fit[nro1] > fit[nro2]) {
	pos = nro1;
    } else {
	pos = nro2;
    }

    win[idx] = pos;
}