-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_sequential.c
77 lines (64 loc) · 2.13 KB
/
main_sequential.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
#include "lab1_io.h"
#include "lab1_sequential.h"
#include <omp.h>
#include <stdlib.h>
#include <time.h>
/*
Arguments:
arg1: K (no of clusters)
arg2: input filename (data points)
arg3: output filename (data points & cluster)
arg4: output filename (centroids of each iteration)
*/
int main(int argc, char const *argv[])
{
if (argc < 5){
printf("\nLess Arguments\n");
return 0;
}
if (argc > 5){
printf("\nToo many Arguments\n");
return 0;
}
//---------------------------------------------------------------------
int N; //no. of data points (input)
int K; //no. of clusters to be formed (input)
int* data_points; //data points (input)
int* cluster_points; //clustered data points (to be computed)
float* centroids; //centroids of each iteration (to be computed)
int num_iterations; //no of iterations performed by algo (to be computed)
//---------------------------------------------------------------------
double start_time, end_time;
double computation_time;
K = atoi(argv[1]);
/*
-- Pre-defined function --
reads dataset points from input file and creates array
containing data points, using 3 index per data point, ie
-----------------------------------------------
| pt1_x | pt1_y | pt1_z | pt2_x | pt2_y | pt2_z | ...
-----------------------------------------------
*/
dataset_in (argv[2], &N, &data_points);
start_time = omp_get_wtime();
// /*
// *****************************************************
// TODO -- You must implement this function
// *****************************************************
// */
kmeans_sequential(N, K, data_points, &cluster_points, ¢roids, &num_iterations);
end_time = omp_get_wtime();
// /*
// -- Pre-defined function --
// reads cluster_points and centroids and save it it appropriate files
// */
clusters_out (argv[3], N, cluster_points);
centroids_out (argv[4], K, num_iterations, centroids);
computation_time = end_time - start_time;
printf("Time Taken: %lf \n", computation_time);
char *time_file_seq = "time_seq.txt";
FILE *fout = fopen(time_file_seq, "a");
fprintf(fout, "%f\n", computation_time);
fclose(fout);
return 0;
}