Skip to content

Commit

Permalink
compile bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaweiZhuang committed Apr 29, 2017
1 parent 4f5c7a0 commit 0e45d12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Parallel_Algorithm/MPI/compile.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mpicc -o Kmean_mpi.out -O2 -std=c99 -lnetcdf -fopenmp -lpthread ../shared/make_2D_array.c ../shared/ncdf_util.c ../shared/math_util.c Kmean_mpi.c
mpicc -o Kmean_mpi.out -O2 -std=c99 -lm -lnetcdf -fopenmp -lpthread ../shared/make_2D_array.c ../shared/ncdf_util.c ../shared/math_util.c Kmean_mpi.c
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 -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
gcc -o Kmean_omp.out -O2 -std=c99 -lm -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
11 changes: 6 additions & 5 deletions Parallel_Algorithm/shared/math_util.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <math.h>
#include "math_util.h"

// square of the distance between x1[N_features] and x2[N_features]
Expand All @@ -11,11 +12,11 @@ float distance(int N_features,float *x1,float *x2){
float correlation(int N_features,float *x,float *y){
float xsum=0.0,ysum=0.0,xysum=0.0,xsqr_sum=0.0,ysqr_sum=0.0;
for (int j = 0; j<N_features; j++) {
xsum = xsum + x[i];
ysum = ysum + y[i];
xysum = xysum + x[i] * y[i];
xsqr_sum = xsqr_sum + x[i] * x[i];
ysqr_sum = ysqr_sum + y[i] * y[i];
xsum = xsum + x[j];
ysum = ysum + y[j];
xysum = xysum + x[j] * y[j];
xsqr_sum = xsqr_sum + x[j] * x[j];
ysqr_sum = ysqr_sum + y[j] * y[j];
}

float num = ((N_features * xysum) - (xsum * ysum));
Expand Down

0 comments on commit 0e45d12

Please sign in to comment.