main.cpp 1.4 KB
Newer Older
perdacherMartin's avatar
perdacherMartin committed
1 2 3 4 5 6

#include <string.h>
#include <stdio.h>
#include <omp.h>

#include "util/allocation.h"
perdacherMartin's avatar
perdacherMartin committed
7
#include "util/dataIo.h"
perdacherMartin's avatar
perdacherMartin committed
8 9 10 11 12 13 14 15
#include "util/timer.h"
#include "util/arguments.h"
#include "mckm/mckm.h"

int main(int argc, char** argv) {
    double *means = NULL;
    double *dmatrix = NULL;
    CUtilTimer timer;
perdacherMartin's avatar
perdacherMartin committed
16
    bool isBinary = false;
perdacherMartin's avatar
perdacherMartin committed
17
    char filename[MAX_LINE_LENGTH] = "";
perdacherMartin's avatar
perdacherMartin committed
18 19

    int threads = 0;
perdacherMartin's avatar
perdacherMartin committed
20
    size_t N=64, K=40, D=20;
perdacherMartin's avatar
perdacherMartin committed
21

perdacherMartin's avatar
perdacherMartin committed
22
    #ifndef __AVX__
perdacherMartin's avatar
typo  
perdacherMartin committed
23
        fprintf (stderr, "Unfortunately your CPU does not support AVX intrinsics. \nExit.\n");
perdacherMartin's avatar
perdacherMartin committed
24 25 26
        exit(1);
    #endif

perdacherMartin's avatar
perdacherMartin committed
27
    parsing_args(argc,argv, &N, &K, &D, &threads, filename, isBinary);
perdacherMartin's avatar
perdacherMartin committed
28 29 30 31 32 33

    if ( threads != 0 ){
        omp_set_num_threads(threads);
    }

    const int n = 1024 * 1024 * N ;
perdacherMartin's avatar
perdacherMartin committed
34
    // const int n = 10000 ;
perdacherMartin's avatar
perdacherMartin committed
35 36 37 38 39 40
    const int d = D ;
    const int k = K ;

    means = (double*) ddr_alloc((k + 3)/4*4 * d * sizeof (double));
    dmatrix = (double*) ddr_alloc(n * d * sizeof (double));

perdacherMartin's avatar
perdacherMartin committed
41
    if ( strcmp(filename,"") == 0 ) {
perdacherMartin's avatar
perdacherMartin committed
42 43 44 45
        random_init(dmatrix,n,d);
    }else{
        read_file(dmatrix, n, d, filename, isBinary);
    }
perdacherMartin's avatar
perdacherMartin committed
46

perdacherMartin's avatar
perdacherMartin committed
47 48 49 50
    // use first k points for means
    memcpy(means, dmatrix, k * d * sizeof (double));

    timer.start();
perdacherMartin's avatar
perdacherMartin committed
51
    block_km_final_omp( n, k, d, threads, means, dmatrix, 5); // perform MCKM with 5 iterations
perdacherMartin's avatar
perdacherMartin committed
52 53 54 55 56 57 58 59 60
    timer.stop();

    printf("%d; %d; %d; %f\n", n,d,k,timer.get_time());

    ddr_free(dmatrix);
    ddr_free(means);

    return 0;
}