Commit 0460cbfa authored by Martin Perdacher's avatar Martin Perdacher

changed int to size_t

parent 4fd07670
#include "blasmeans.h"
double blasMeans(long *members, double *x, int const D, int const K,
long const N, int const NUM_THREADS){
double blasMeans(size_t *members, double *x, size_t const D, size_t const K,
size_t const N, size_t const NUM_THREADS){
double *bigM=NULL;
double *dotyy=NULL;
double *dist=NULL;
......@@ -34,8 +34,6 @@ double blasMeans(long *members, double *x, int const D, int const K,
// // // while ( memcmp(members, membersOld, N * sizeof(int)) != 0 ){
for (int iter = 0; iter < 5; iter++) {
// printf("%d, \n", iter);
// fflush(stdout);
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans, N, K, D, 1.0, x, D, bigM, D, 0.0, dist, K);
for (int j = 0; j < K; j++){
......@@ -47,13 +45,16 @@ double blasMeans(long *members, double *x, int const D, int const K,
}
dotyy[i] = dotyy[i] * 0.5;
}
#pragma omp parallel for shared(ksum, bigM,members)
#pragma omp parallel for shared(ksum, bigM, members)
for (int par = 0; par < NUM_THREADS; par++) {
for (int i = 0; i < D * K; i++) bigM[par * D * K + i] = 0.;
for (int i = 0; i < K; i++) ksum[par * K + i] = 0;
for (int i = N * par / NUM_THREADS; i < N * (par + 1) / NUM_THREADS; i++) {
int smallestIndex = 0;
for (int i = 0; i < D * K; i++) {
bigM[par * D * K + i] = 0.;
}
for (int i = 0; i < K; i++){
ksum[par * K + i] = 0;
}
for (size_t i = N * par / NUM_THREADS; i < N * (par + 1) / NUM_THREADS; i++) {
size_t smallestIndex = 0;
double smallest = dotyy[0] - dist[i * K];
for (int j = 1; j < K; j++) {
double h = dotyy[j] - dist[i * K + j]; // ( (dot(Y,Y,2) * ones(1,n))' + dist ) with dist = -2*X*Y'
......@@ -63,12 +64,12 @@ double blasMeans(long *members, double *x, int const D, int const K,
}
}
ksum[par * K + smallestIndex]++;
for (int j = 0; j < D; j++)
for (int j = 0; j < D; j++){
bigM[par * D * K + smallestIndex * D + j] += x[i * D + j];
}
members[i] = smallestIndex;
}
}
for (int par = 1; par < NUM_THREADS; par++) {
for (int i = 0; i < K; i++) {
ksum[i] += ksum[K * par + i];
......
......@@ -13,7 +13,7 @@
#include "../util/allocation.h"
#include "../util/timer.h"
double blasMeans(long *members, double *x, int const D, int const K,
long const N, int const NUM_THREADS);
double blasMeans(size_t *members, double *x, size_t const D, size_t const K,
size_t const N, size_t const NUM_THREADS);
#endif
......@@ -10,15 +10,15 @@
int main(int argc, char** argv) {
long *members = NULL;
size_t *members = NULL;
double *x = NULL;
CUtilTimer timer;
char filename[] = "";
double elapsed=0.0;
bool isBinary = false;
int threads = 0;
int N=64, K=40, D=20;
size_t threads = 0;
size_t N=64, K=40, D=20;
parsing_args(argc,argv, &N, &K, &D, &threads, filename, isBinary);
......@@ -26,11 +26,12 @@ int main(int argc, char** argv) {
omp_set_num_threads(threads);
}
const int n = 1024 * 1024 * N ;
// const int n = 1024 * 1024 * N ;
const int n = N ;
const int d = D ;
const int k = K ;
members = (long*) ddr_alloc(sizeof (long) * n);
members = (size_t *) ddr_alloc(sizeof (size_t) * n);
x = (double*) ddr_alloc(sizeof (double)*n * d);
if ( strcmp(filename,"" ) == 0) {
......
......@@ -3,7 +3,7 @@
#include "arguments.h"
void parsing_args(int argc, char* argv[], int *n, int *k, int *d, int *threads, char *filename, bool isBinary){
void parsing_args(int argc, char* argv[], size_t *n, size_t *k, size_t *d, size_t *threads, char *filename, bool isBinary){
char c;
FILE *file;
......
......@@ -8,6 +8,6 @@
#include <string.h>
#include <ctype.h>
void parsing_args(int argc, char* argv[], int *n, int *k, int *d, int *threads, char *filename, bool isBinary);
void parsing_args(int argc, char* argv[], size_t *n, size_t *k, size_t *d, size_t *threads, char *filename, bool isBinary);
#endif //KMEANS_ARGS_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment