Commits

Lars Yencken committed 1a1b978

Parallelised rescoring loop using openmp.

Comments (0)

Files changed (2)

 # Set up the compilation environment.
 env = Environment(
         SHLIBPREFIX='',
-        LIBS=[],
+        LIBS=['gomp'],
     )
 
 environmentVars = (
     env.Append(DEBUG=True, CXXFLAGS='-O0 -g -pg -Wall', LINKFLAGS='-g -pg')
 else:
     print 'Using optimised targets'
-    env.Append(DEBUG=False, CXXFLAGS='-O3 -DNDEBUG -Wall ')
+    env.Append(DEBUG=False, CXXFLAGS='-O3 -DNDEBUG -Wall -fopenmp')
 
 # Configure the environment.
 env = checkLibraries(env)

src/tfIdfAligner.cpp

 #include <fstream>
 #include <stdexcept>
 
+#include <omp.h>
+
 //--------------------------------------------------------------------------//
 
 TfIdfAligner::TfIdfAligner(double alpha, int blockSize)
 {
     results.clear();
     // Rescore all the clouds.
-    for (vector<AlignmentCloudPtr>::iterator iter = clouds.begin();
-            iter != clouds.end(); iter++) {
-        (void) _scoreCloud(**iter);
+
+    const int nClouds = (int) clouds.size();
+
+#pragma omp parallel for
+    for (int i = 0; i < nClouds; i++) {
+        (void) _scoreCloud(*clouds[i]);
     }
 
     for (int i = 0; i < m_blockSize && clouds.size() > 0; i++) {