Skip to content

Commit

Permalink
OpenMP working for E-step
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamovar committed Oct 23, 2014
1 parent 5026077 commit d8e13e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
21 changes: 13 additions & 8 deletions klustakwik.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,8 @@ void KK::EStep()
integer p, c, cc, i;
integer nSkipped;
scalar LogRootDet; // log of square root of covariance determinant
scalar Mahal; // Mahalanobis distance of point from cluster center
scalar correction_factor = (scalar)1; // for partial correction in distributional step
scalar InverseClusterNorm;
//scalar InverseClusterNorm;
vector<scalar> Chol(nDims2); // to store choleski decomposition
vector<scalar> Vec2Mean(nDims); // stores data point minus class mean
vector<scalar> Root(nDims); // stores result of Chol*Root = Vec
Expand Down Expand Up @@ -749,16 +748,18 @@ void KK::EStep()
}
}

for(p=0; p<nPoints; p++)
#pragma omp parallel for schedule(dynamic) firstprivate(Vec2Mean, Root) default(shared)
for(integer p=0; p<nPoints; p++)
{
// to save time -- only recalculate if the last one was close
// to save time -- only recalculate if the last one was close
if (
!FullStep
&& (Class[p] == OldClass[p])
&& (LogP[p*MaxPossibleClusters+c] - LogP[p*MaxPossibleClusters+Class[p]] > DistThresh)
)
{
nSkipped++;
#pragma omp atomic
nSkipped++;
continue;
}

Expand Down Expand Up @@ -791,13 +792,17 @@ void KK::EStep()
//dotprod *= InverseClusterNorm;
if (dotprod < MinMaskOverlap)
{
#pragma omp atomic
nSkipped++;
continue;
}
}

SafeArray<scalar> safeVec2Mean(Vec2Mean, "safeVec2Mean");
SafeArray<scalar> safeRoot(Root, "safeRoot");

// Compute Mahalanobis distance
Mahal = 0;
scalar Mahal = 0;

// calculate data minus class mean
//for (i = 0; i<nDims; i++)
Expand All @@ -821,8 +826,8 @@ void KK::EStep()
// if distributional E step, add correction term
if (UseDistributional)
{
scalar * __restrict ctp = &(CorrectionTerm[p*nDims]);
scalar * __restrict icd = &(InvCovDiag[0]);
const scalar * __restrict ctp = &(CorrectionTerm[p*nDims]);
const scalar * __restrict icd = &(InvCovDiag[0]);
scalar subMahal = 0.0;
for (i = 0; i < nDims; i++)
subMahal += ctp[i] * icd[i];
Expand Down
1 change: 1 addition & 0 deletions klustakwik.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<FloatingPointModel>Fast</FloatingPointModel>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OpenMPSupport>true</OpenMPSupport>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ CC = g++
DEBUG = -g
PROFILE = -pg
OPTIMISATIONS = -O3 -ffast-math -march=native
CFLAGS = -Wall -c -Wno-write-strings $(OPTIMISATIONS)
LFLAGS = -Wall
CFLAGS = -Wall -c -Wno-write-strings $(OPTIMISATIONS) -fopenmp
LFLAGS = -Wall -fopenmp

all: executable

Expand Down

0 comments on commit d8e13e6

Please sign in to comment.