main.cpp 2.08 KB
Newer Older
martinp16cs's avatar
martinp16cs committed
1

Martin Perdacher's avatar
Martin Perdacher committed
2 3
// main method for self-join
// for a two-set join see mainJoin.cpp
4

martinp16cs's avatar
martinp16cs committed
5 6 7
#include <stdio.h>
#include <omp.h>

Martin Perdacher's avatar
Martin Perdacher committed
8 9 10 11
#ifndef COUNT_ONLY
    #include <boost/lockfree/queue.hpp>
    #include <boost/atomic.hpp>
#endif
12

Martin Perdacher's avatar
Martin Perdacher committed
13
#include "measure/timer.h"
martinp16cs's avatar
martinp16cs committed
14 15 16 17
#include "util/allocation.h"
#include "util/arguments.h"
#include "util/dataIo.h"
#include "blasJoin/blasJoin.h"
18

Martin Perdacher's avatar
Martin Perdacher committed
19 20 21 22 23 24 25 26
#ifndef COUNT_ONLY
size_t consumer_count;

int consumer(boost::lockfree::queue<join_pair> &queue)
{
    join_pair jp;
    while (queue.pop(jp)){
        #pragma omp atomic write
Martin Perdacher's avatar
Martin Perdacher committed
27
            consumer_count = consumer_count + 1;
Martin Perdacher's avatar
Martin Perdacher committed
28 29 30 31
        // printf("%lu-%lu\n", jp.p1, jp.p2);
    }
}
#endif
martinp16cs's avatar
martinp16cs committed
32 33

int main(int argc, char** argv) {
Martin Perdacher's avatar
Martin Perdacher committed
34
    char filename[255] = "";
35
    double watthours=0.0;
martinp16cs's avatar
martinp16cs committed
36
    bool isBinary = false;
37
    double *x = NULL;
martinp16cs's avatar
martinp16cs committed
38 39
    size_t threads = 64;
    size_t N=200, D=20;
Martin Perdacher's avatar
Martin Perdacher committed
40
    size_t M=200;
41
    size_t blocksize=4000, joinCounts=0;
martinp16cs's avatar
martinp16cs committed
42
    double EPS=0.2;
Martin Perdacher's avatar
Martin Perdacher committed
43
    CUtilTimer timer;
martinp16cs's avatar
martinp16cs committed
44

45
    parsing_args(argc, argv, &N, &EPS, &D, &threads, &blocksize, filename, &isBinary);
martinp16cs's avatar
martinp16cs committed
46 47 48 49 50

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

Martin Perdacher's avatar
Martin Perdacher committed
51
#ifndef COUNT_ONLY
52
    boost::lockfree::queue<join_pair> queue(10000);
Martin Perdacher's avatar
Martin Perdacher committed
53
#endif
54 55

    x = (double*) ddr_alloc(sizeof (double)* N * D);
56

martinp16cs's avatar
martinp16cs committed
57
    if ( strcmp(filename,"" ) == 0) {
58
        // printf("random_init\n");
59
        random_init_unif(x,N,D);
martinp16cs's avatar
martinp16cs committed
60
    }else{
61
        // printf("read_file\n");
martinp16cs's avatar
martinp16cs committed
62 63 64
        read_file(x, N, D, filename, isBinary);
    }

Martin Perdacher's avatar
Martin Perdacher committed
65
    timer.start();
Martin Perdacher's avatar
Martin Perdacher committed
66
#ifdef COUNT_ONLY
Martin Perdacher's avatar
Martin Perdacher committed
67
    blasSelfJoinCountOnly( x, N, D, EPS, threads, blocksize, &joinCounts);
Martin Perdacher's avatar
Martin Perdacher committed
68
#else
Martin Perdacher's avatar
Martin Perdacher committed
69
    blasSelfJoinStoreResults( x, N, D, EPS, threads, blocksize, &joinCounts, queue);
Martin Perdacher's avatar
Martin Perdacher committed
70
#endif
Martin Perdacher's avatar
Martin Perdacher committed
71
    timer.stop();
72

Martin Perdacher's avatar
Martin Perdacher committed
73 74 75 76 77 78 79 80
#ifndef COUNT_ONLY
    // if we materialize with a non-blocking linked list, then joincounts are zero
    #pragma omp parallel for
    for ( int i = 0 ; i < threads ; i++ ){
        consumer(queue);
    }
    joinCounts = consumer_count;
#endif
martinp16cs's avatar
martinp16cs committed
81

martinp16cs's avatar
martinp16cs committed
82 83 84
#pragma omp parallel
{
    if (  omp_get_thread_num() == 0 ){
Martin Perdacher's avatar
Martin Perdacher committed
85
        printf("%ld;%ld;%2.12f;%ld;%d;%f;%lu\n", N, D, EPS, blocksize, omp_get_num_threads(), timer.get_time(), joinCounts);
martinp16cs's avatar
martinp16cs committed
86 87
    }
}
martinp16cs's avatar
martinp16cs committed
88 89 90 91 92

    ddr_free(x);

    return 0;
}