-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cu
64 lines (56 loc) · 1.87 KB
/
main.cu
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
#include <stdio.h>
#include <stdlib.h>
#include "seq_kmeans.c"
#include "kmeans.h"
//#include "cuda_kmeans.cu"
//#include "timer.cu"
void random_data(float ** array, int m, int n) {
for(int i=0; i<m ; i++) {
for(int j=0; j<n; j++){
array[i][j] = (float)rand()/(float)RAND_MAX;
}
}
}
int main()
{
int K = 64, D = 1000, N = 51200;
float threshold = 0.001;
int *membership;
float **data;
float **center;
double timing, sequential_timing, cuda_timing;
int num_iterations;
printf("numofdatas = %d\n", N);
printf("dimension = %d\n", D);
printf("numClusters = %d\n", K);
printf("threshold = %.4f\n", threshold);
malloc2D(data, N,D);
malloc2D(center,K,D);
random_data(data, N, D);
membership = (int*) malloc(N * sizeof(int));
timing = wtime();
sequential_timing = timing;
/* start the timer for the core computation -----------------------------*/
center = seq_kmeans(data, D, N, K, threshold,membership, &num_iterations);
timing = wtime();
sequential_timing = timing - sequential_timing;
printf("Seq Computation timing = %10.4f sec\n", sequential_timing);
printf("Loop iterations = %d\n", num_iterations);
//free(membership);
//membership = (int*) malloc(N * sizeof(int));
num_iterations=0;
timing = wtime();
cuda_timing = timing;
center = cuda_kmeans(data, D, N, K, threshold,membership, &num_iterations);
timing = wtime();
cuda_timing = timing - cuda_timing;
printf("Cuda Computation timing = %10.4f sec\n", cuda_timing);
printf("Loop iterations = %d\n", num_iterations);
printf("speed up = %.4f\n", sequential_timing/cuda_timing);
free(membership);
free(center[0]);
free(center);
free(data[0]);
free(data);
return(0);
}