-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_omp.c
80 lines (67 loc) · 2.24 KB
/
main_omp.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
#include "lab1_io.h"
#include "lab1_omp.h"
#include <omp.h>
#include <stdlib.h>
#include <time.h>
/*
Arguments:
arg1: K (no of clusters)
arg2: no of threads
arg3: input filename (data points)
arg4: output filename (data points & cluster)
arg5: output filename (centroids of each iteration)
*/
int main(int argc, char const *argv[])
{
if (argc < 6){
printf("\nLess Arguments\n");
return 0;
}
if (argc > 6){
printf("\nTOO many Arguments\n");
return 0;
}
//---------------------------------------------------------------------
int N; //no. of data points (input)
int K; //no. of clusters to be formed (input)
int num_threads; //no. of threads to be used (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]);
num_threads = atoi(argv[2]);
/*
-- 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[3], &N, &data_points);
start_time = omp_get_wtime();
// /*
// *****************************************************
// TODO -- You must implement this function
// *****************************************************
// */
kmeans_omp(num_threads, 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[4], N, cluster_points);
centroids_out (argv[5], K, num_iterations, centroids);
computation_time = end_time - start_time;
printf("Time Taken: %lf \n", computation_time);
char *time_file_pthread = "time_openmp.txt";
FILE *fout = fopen(time_file_pthread, "a");
fprintf(fout, "%f\n", computation_time);
fclose(fout);
return 0;
}