From b56acfcdcaf55547becd55fa8391b3ad8c51afc8 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sun, 21 Jan 2018 00:53:03 +0200 Subject: [PATCH] Code clean-up, vars rename, loops merge, matrix saving function --- README.md | 2 +- serial.c | 8 +- serialDeclarations.c | 172 ++++++++++++++++++++----------------------- serialDeclarations.h | 9 ++- 4 files changed, 89 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index fb31dc3..f370845 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This repository provides a serial implementation of the algorithm in C language, as well as the parallel equivalent in CUDA. The project was undertaken as part of the "Parallel and distributed systems" course of AUTH university. -A [Gaussian] kernel was used for the weighting function. The code was tested for different data sets and information regarding the execution time and correctness were extracted. In addition, two versions of the parallel algorithm was tested and compared, with and without the usage of shared memory respectively. +A [Gaussian] kernel was used for the weighting function. The code was tested for different data sets and information regarding the execution time and correctness were extracted. In addition, two versions of the parallel algorithm were tested and compared, with and without the usage of shared memory respectively. ## Compilation diff --git a/serial.c b/serial.c index 2cb5705..faafbc2 100755 --- a/serial.c +++ b/serial.c @@ -30,8 +30,8 @@ int main(int argc, char **argv){ for (int i=0; i #include #include +#include #include "serialDeclarations.h" -void meanshift(double **x, int h, struct parameters *opt){ +void meanshift(double **originalPoints, int h, parameters *opt){ double **y; y = alloc_2d_double(ROWS, COLUMNS); - y = duplicate(x, y, ROWS, COLUMNS); + y = duplicate(originalPoints, y, ROWS, COLUMNS); - // mean shift vectors - double **m; - m = alloc_2d_double(ROWS, COLUMNS); - // initialize elements of m to inf + // mean shift vector + double **meanShiftVector; + meanShiftVector = alloc_2d_double(ROWS, COLUMNS); + // initialize elements of meanShiftVector to inf for (int i=0;iepsilon); - double ** W = alloc_2d_double(ROWS, ROWS); - double * l = malloc(ROWS * sizeof(double)); + double ** kernelMatrix = alloc_2d_double(ROWS, ROWS); + double *denominator = malloc(ROWS * sizeof(double)); /** iterate until convergence **/ // printf("norm : %f \n", norm(m, ROWS, COLUMNS)); - - while (norm(m, ROWS, COLUMNS) > opt->epsilon) { + while (norm(meanShiftVector, ROWS, COLUMNS) > opt->epsilon) { iter = iter +1; // find pairwise distance matrix (inside radius) - /** allocate memory for inside iteration arrays **/ - // [I, D] = rangesearch(x,y,h); for (int i=0; i apply to non-zero elements - for (int i=0; i