 
 // Sorts the vocabulary by frequency using word counts
 void SortVocab() {
-    int a, size;
+    int a, b, size;
     unsigned int hash;
     // Sort the vocabulary and keep </s> at the first position
     qsort(&vocab[1], vocab_size - 1, sizeof(struct vocab_word), VocabCompare);

    return -1;
}

__global__ void train_model_kernel(const long long *cache, const long long cache_length)
{
    const unsigned int thread_idx = (blockIdx.x * blockDim.x) + threadIdx.x;
    const long long cache_begin = get_fragment_begin(cache, cache_length, thread_idx);
    const long long cache_end = get_fragment_end(cache, cache_length, thread_idx);

    
    
    printf("| -- (gpu) cache_length: %lld, thread_idx = %ud, cache_begin = %lld, cache_end = %lld\n",
           cache_length, thread_idx, cache_begin, cache_end);
}

__device__ long long get_fragment_begin(const long long *cache, const long long cache_length, const unsigned int thread_idx)


struct vocab_word {
    long long cn;
    int point[MAX_CODE_LENGTH];
    char *word, code[MAX_CODE_LENGTH], codelen;
};

struct Lock {
    int *mutex;
    Lock(void) {
        int state = 0;
        cudaMalloc((void**) &mutex, sizeof(int));
        cudaMemcpy(mutex, &state, sizeof(int), cudaMemcpyHostToDevice);
    }
    ~Lock(void) {
        cudaFree(mutex);
    }
    __device__ void lock(void) {
        while(atomicCAS(mutex, 0, 1) != 0);
    }
    __device__ void unlock(void) {
        atomicExch(mutex, 0);
    }
};

char train_file[MAX_STRING], output_file[MAX_STRING];
char save_vocab_file[MAX_STRING], read_vocab_file[MAX_STRING];
struct vocab_word *vocab, *gpu_vocab;
real *gpu_expTable, *gpu_syn0, *gpu_syn1;
// int binary = 0, cbow = 1, debug_mode = 2, window = 5, min_count = 5, num_threads = 12, min_reduce = 1, cache_size = 1;
int binary = 0, cbow = 1, debug_mode = 2, min_count = 5, num_threads = 12, min_reduce = 1, cache_size = 1;
int *vocab_hash;
long long vocab_max_size = 1000, vocab_size = 0, layer1_size = 100, cache_length = 0, *cpu_cache, *gpu_cache;
//long long train_words = 0, word_count_actual = 0, iter = 5, file_size = 0, classes = 0;
long long train_words = 0, file_size = 0, classes = 0;
//real alpha = 0.025, starting_alpha, sample = 1e-3;
real *syn0, *syn1, *syn1neg, *expTable;
clock_t start;

int hs = 0, negative = 5;
const int table_size = 1e8;
int *table;

__device__ long long word_count_actual = 0;
//__device__ real alpha = 0.25;
__constant__ long long gpu_train_words = 0, iter = 5;
__constant__ real starting_alpha, sample = 1e-3;
__constant__ int window;

void paulse(void);
void profile(const char *);
