From 3040d3f0113195a3e81c858bc4dd08884f5b62c3 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Fri, 19 Jan 2018 14:28:18 +0200 Subject: [PATCH] Code rebase, README init --- Makefile | 23 +++-- README.md | 33 +++++++ serial.c | 202 +------------------------------------------ serialDeclarations.c | 181 ++++++++++++++++++++++++++++++++++++++ serialDeclarations.h | 25 ++++++ 5 files changed, 259 insertions(+), 205 deletions(-) create mode 100644 README.md create mode 100644 serialDeclarations.c create mode 100644 serialDeclarations.h diff --git a/Makefile b/Makefile index 45ca86e..573c8a3 100755 --- a/Makefile +++ b/Makefile @@ -1,23 +1,36 @@ SHELL := /bin/bash - # ============================================ # COMMANDS CC = gcc RM = rm -f -CFLAGS=-lm +CFLAGS=-lm -O3 -Wall -I. +OBJ=serial.o serialDeclarations.o +DEPS=serialDeclarations.h # ========================================== # TARGETS - EXECUTABLES = serial +.PHONY: all clean + all: $(EXECUTABLES) -serial: serial.c - $(CC) $< -o $@ $(CFLAGS) +# ========================================== +# DEPENDENCIES (HEADERS) + +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(CFLAGS) + +.PRECIOUS: $(EXECUTABLES) $(OBJ) + +# ========================================== +# EXECUTABLE (MAIN) + +$(EXECUTABLES): $(OBJ) + $(CC) -o $@ $^ $(CFLAGS) clean: $(RM) *.o *~ $(EXECUTABLES) diff --git a/README.md b/README.md new file mode 100644 index 0000000..fb31dc3 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Mean-shift + +[Mean-shift] is a mathematical procedure, adopted in algorithms, designed in the 70's by Fukunaga and Hostetler. The algorithm is used for: + + - Cluster analysis + - Computer vision + - Image processing + +## Repository + +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. + +## Compilation + +To compile make sure all necessary packages and dependencies are installed. Then run: + +```sh +$ make +``` + +## Usage + +blah blah, arguments needed etc + + +**Free Software, Hell Yeah!** + +[//]: # (Links) + + [Mean-shift]: + [Gaussian]: \ No newline at end of file diff --git a/serial.c b/serial.c index 852c954..cc5177f 100755 --- a/serial.c +++ b/serial.c @@ -1,32 +1,12 @@ #include #include #include -#include -#include -#include -#include -#define X "data/X.bin" -#define L "data/L.bin" -#define COLUMNS 2 -#define ROWS 600 +#include "serialDeclarations.h" -struct parameters { - double epsilom; - bool verbose; - bool display; -}; struct timeval startwtime, endwtime; double seq_time; -double **alloc_2d_double(int rows, int cols); -double **duplicate(double **a, double **b, int rows, int cols); -void meanshift(double **x, int h, struct parameters *opt); -double norm(double ** m, int rows, int cols); -void multiply(double ** matrix1, double ** matrix2, double ** output); -double calculateDistance(double *, double *); -void print_matrix(double ** array, int rows, int cols); - int main(int argc, char **argv){ // if (argc<2){ @@ -88,182 +68,4 @@ int main(int argc, char **argv){ //TODO write output points to file -> plot later -} - - -void meanshift(double **x, int h, struct parameters *opt){ - - double **y; - y = alloc_2d_double(ROWS, COLUMNS); - y = duplicate(x, y, ROWS, COLUMNS); - - // mean shift vectors - double **m; - m = alloc_2d_double(ROWS, COLUMNS); - // initialize elements of m to inf - for (int i=0;iepsilom); - // TODO ITERATION - /** iterate until convergence **/ - // printf("norm : %f \n", norm(m, ROWS, COLUMNS)); - - while (norm(m, ROWS, COLUMNS) > opt->epsilom) { -// while (iter < 1){ - iter = iter +1; - // find pairwise distance matrix (inside radius) - // TODO write in C - /** allocate memory for inside iteration arrays **/ - double ** W = alloc_2d_double(ROWS, ROWS); - double * l = malloc(ROWS * sizeof(double)); - // [I, D] = rangesearch(x,y,h); - for (int i=0; i apply to non-zero elements - for (int i=0; i +#include +#include +#include + +#include "serialDeclarations.h" + +void meanshift(double **x, int h, struct parameters *opt){ + + double **y; + y = alloc_2d_double(ROWS, COLUMNS); + y = duplicate(x, y, ROWS, COLUMNS); + + // mean shift vectors + double **m; + m = alloc_2d_double(ROWS, COLUMNS); + // initialize elements of m to inf + for (int i=0;iepsilom); + // TODO ITERATION + /** iterate until convergence **/ + // printf("norm : %f \n", norm(m, ROWS, COLUMNS)); + + while (norm(m, ROWS, COLUMNS) > opt->epsilom) { +// while (iter < 1){ + iter = iter +1; + // find pairwise distance matrix (inside radius) + // TODO write in C + /** allocate memory for inside iteration arrays **/ + double ** W = alloc_2d_double(ROWS, ROWS); + double * l = malloc(ROWS * sizeof(double)); + // [I, D] = rangesearch(x,y,h); + for (int i=0; i apply to non-zero elements + for (int i=0; i + +#define X "data/X.bin" +#define L "data/L.bin" +#define COLUMNS 2 +#define ROWS 600 + +struct parameters { + double epsilom; + bool verbose; + bool display; +}; + +double **alloc_2d_double(int rows, int cols); +double **duplicate(double **a, double **b, int rows, int cols); +void meanshift(double **x, int h, struct parameters *opt); +double norm(double ** m, int rows, int cols); +void multiply(double ** matrix1, double ** matrix2, double ** output); +double calculateDistance(double *, double *); +void print_matrix(double ** array, int rows, int cols); + +#endif //SERIAL_DECLARATIONS_H \ No newline at end of file