Browse Source

memory allocation outside while-loop

master
anapt 7 years ago
parent
commit
6d0caf2a02
  1. 5
      mean-shift.cu
  2. 18
      serial.c
  3. 10
      serialDeclarations.c
  4. 2
      serialDeclarations.h

5
mean-shift.c → mean-shift.cu

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <sys/time.h>
#include <stdbool.h>
#include <math.h>
#define X "data/X.bin"
#define L "data/L.bin"
@ -113,6 +114,8 @@ void meanshift(double **x, int h, struct parameters *opt){
/** iterate until convergence **/
// printf("norm : %f \n", norm(m, ROWS, COLUMNS));
while (norm(m, ROWS, COLUMNS) > opt->epsilon) {
iter = iter +1;
// find pairwise distance matrix (inside radius)
@ -258,3 +261,5 @@ void print_matrix(double ** array, int rows, int cols){
printf("\n");
}
}
__global__ void

18
serial.c

@ -17,13 +17,13 @@ int main(int argc, char **argv){
FILE *f;
f = fopen(X, "rb");
fseek(f, 0L, SEEK_END);
long int pos = ftell(f);
fclose(f);
int elements = pos / sizeof(double); // number of total elements (points*dimension)
int points = elements/COLUMNS;
//printf("points : %d \n", points);
// f = fopen(X, "rb");
// fseek(f, 0L, SEEK_END);
// long int pos = ftell(f);
// fclose(f);
// int elements = pos / sizeof(double); // number of total elements (points*dimension)
// int points = elements/COLUMNS;
// //printf("points : %d \n", points);
f = fopen(X, "rb");
double ** vectors;
vectors = alloc_2d_double(ROWS, COLUMNS);
@ -38,7 +38,7 @@ int main(int argc, char **argv){
// NOTE : Labels were classified as <class 'numpy.uint8'>
// variables of type uint8 are stored as 1-byte (8-bit) unsigned integers
fseek(f, 0L, SEEK_END);
pos = ftell(f);
long int pos = ftell(f);
rewind(f);
//printf("position : %ld \n", pos);
int label_elements = pos/ sizeof(char);
@ -50,7 +50,7 @@ int main(int argc, char **argv){
// MEAN SHIFT OPTIONS
int h = 1;
struct parameters params;
params.epsilom = 0.0001;
params.epsilon = 0.0001;
params.verbose = false;
params.display = false;
struct parameters *opt;

10
serialDeclarations.c

@ -24,17 +24,19 @@ void meanshift(double **x, int h, struct parameters *opt){
// initialize iteration counter
int iter = 0;
// printf("%f \n", opt->epsilom);
// printf("%f \n", opt->epsilon);
double ** W = alloc_2d_double(ROWS, ROWS);
double * l = malloc(ROWS * sizeof(double));
/** iterate until convergence **/
// printf("norm : %f \n", norm(m, ROWS, COLUMNS));
while (norm(m, ROWS, COLUMNS) > opt->epsilom) {
while (norm(m, ROWS, COLUMNS) > opt->epsilon) {
iter = iter +1;
// find pairwise distance matrix (inside radius)
/** 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<ROWS; i++){
for (int j=0; j<ROWS; j++){

2
serialDeclarations.h

@ -9,7 +9,7 @@
#define ROWS 600
struct parameters {
double epsilom;
double epsilon;
bool verbose;
bool display;
};

Loading…
Cancel
Save