-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.c
82 lines (62 loc) · 1.96 KB
/
tester.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*!
\file tester.c
\brief Validate kNN ring implementation.
\author Dimitris Floros
\date 2019-11-13
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <assert.h>
#include "knnring.h"
#include "tester_helper.h"
struct timeval startwtime, endwtime;
double p_time;
int main(int argc, char *argv[])
{
int n, d, k;
if(argc > 1)
{
n = atoi(argv[1]); // # corpus
d = atoi(argv[2]); // # dimensions
k = atoi(argv[3]); // # neighbors
}else
{
n = 1000; // # corpus elements per process
d = 10; // # dimensions
k = 5; // # neighbors
}
int m = n; // query
double * corpus = (double * ) malloc( n*d * sizeof(double) );
double * query = (double * ) malloc( m*d * sizeof(double) );
for (int i=0;i<n*d;i++)
corpus[i] = ( (double) (rand()) ) / (double) RAND_MAX;
for (int i=0;i<m*d;i++)
query[i] = corpus[i];
//! ========= START POINT =========
gettimeofday (&startwtime, NULL);
knnresult knnres = kNN( corpus, query, n, m, d, k );
//! ========= END POINT =========
gettimeofday (&endwtime, NULL);
p_time = (double)((endwtime.tv_usec - startwtime.tv_usec)/1.0e6
+ endwtime.tv_sec - startwtime.tv_sec);
int isValidC = validateResult( knnres, corpus, query, n, m, d, k, COLMAJOR );
// int isValidR = validateResult( knnres, corpus, query, n, m, d, k, ROWMAJOR );
printf("Tester validation: %s\n", STR_CORRECT_WRONG[isValidC]);
printf(YELLOW "===== n: %d, d: %d, k: %d =====\n" RESET_COLOR, n, d, k);
printf(RED "Real Time: %f\n", p_time);
//! Uncoment next line to write output in a text file
// FILE *f = fopen("seq.txt", "a");
// if (f == NULL)
// {
// printf("Error opening file!\n");
// exit(1);
// }
//
// fprintf(f, "%d, %d, %d, %f\n", n, d, k, p_time);
// fclose(f);
free( corpus );
free( query );
return 0;
}