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

18
serial.c

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

10
serialDeclarations.c

@ -24,17 +24,19 @@ void meanshift(double **x, int h, struct parameters *opt){
// initialize iteration counter // initialize iteration counter
int iter = 0; 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 **/ /** iterate until convergence **/
// printf("norm : %f \n", norm(m, ROWS, COLUMNS)); // 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; iter = iter +1;
// find pairwise distance matrix (inside radius) // find pairwise distance matrix (inside radius)
/** allocate memory for inside iteration arrays **/ /** 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); // [I, D] = rangesearch(x,y,h);
for (int i=0; i<ROWS; i++){ for (int i=0; i<ROWS; i++){
for (int j=0; j<ROWS; j++){ for (int j=0; j<ROWS; j++){

2
serialDeclarations.h

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

Loading…
Cancel
Save