Skip to content

Commit

Permalink
split out distance function. All shared functions are now separated.
Browse files Browse the repository at this point in the history
  • Loading branch information
EC2 Default User committed Apr 16, 2017
1 parent a751fca commit 3df024d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
*.out
*.nc
__pycache__
10 changes: 1 addition & 9 deletions Parallel_Algorithm/OpenMP/Kmean_omp.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
#include "../shared/timing.h" //for timer seconds()
#include "../shared/make_2D_array.h"
#include "../shared/ncdf_util.h"
#include "../shared/math_util.h"
#include <stdio.h>
#include <stdlib.h>
#include <float.h> //for FLT_MAX
#include <netcdf.h>

/* This is the name of the data file we will read. */
#define FILE_NAME "../test_data/Blobs_smp20000_fea30_cls8.nc"
#define TOL 0.0001
#define MAX_ITER 100

// square of the distance between x1[N_features] and x2[N_features]
float distance(int N_features,float *x1,float *x2){
float dist=0.0;
for (int j=0; j<N_features; j++)
dist += (x1[j]-x2[j])*(x1[j]-x2[j]);
return(dist);
}

int main() {

size_t N_samples,N_features,N_clusters,N_repeat;
Expand Down
2 changes: 1 addition & 1 deletion Parallel_Algorithm/OpenMP/compile.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gcc -O2 -std=c99 -lnetcdf -fopenmp -lpthread ../shared/make_2D_array.c ../shared/ncdf_util.c Kmean_omp.c -o Kmean_omp.out
gcc -o Kmean_omp.out -O2 -std=c99 -lnetcdf -fopenmp -lpthread ../shared/make_2D_array.c ../shared/ncdf_util.c ../shared/math_util.c Kmean_omp.c

#For debugging with gdb
#gcc -g -O0 -std=c99 -lnetcdf Kmean_seq.c -o Kmean_seq.out
9 changes: 9 additions & 0 deletions Parallel_Algorithm/shared/math_util.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "math_util.h"

// square of the distance between x1[N_features] and x2[N_features]
float distance(int N_features,float *x1,float *x2){
float dist=0.0;
for (int j=0; j<N_features; j++)
dist += (x1[j]-x2[j])*(x1[j]-x2[j]);
return(dist);
}
6 changes: 6 additions & 0 deletions Parallel_Algorithm/shared/math_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef MATH_UTIL_H
#define MATH_UTIL_H

float distance(int N_features,float *x1,float *x2);

#endif // MATH_UTIL_H

0 comments on commit 3df024d

Please sign in to comment.