Forráskód Böngészése

k-Nearest Neighbor now supports use of multiple CPUs.

Frank Prüfer 11 éve
szülő
commit
954e8fbf8b

+ 8 - 1
regression/npregression/RegKNN.cpp

@@ -4,7 +4,12 @@
 * @author Frank Prüfer
 * @date 08/29/2013
 
-*/  
+*/
+
+#ifdef NICE_USELIB_OPENMP
+#include <omp.h>
+#endif
+
 #include <iostream>
 
 #include "vislearning/regression/npregression/RegKNN.h"
@@ -68,6 +73,7 @@ double RegKNN::predict ( const NICE::Vector & x )
 		exit(-1);
     }
 
+#pragma omp parallel for
     for(uint i = 0; i < dataSet.size(); i++){
     
       double distance = distancefunc->calculate (x,dataSet[i]);
@@ -77,6 +83,7 @@ double RegKNN::predict ( const NICE::Vector & x )
           cerr << x << endl;
           cerr << dataSet[i] << endl;
       }
+// #pragma omp critical      
       distances[i] = distance;     
     }
     

+ 5 - 0
regression/progs/testNPRegression.cpp

@@ -6,6 +6,10 @@
 
 */
 
+#ifdef NICE_USELIB_OPENMP
+#include <omp.h>
+#endif
+
 #include <sstream>
 #include <iostream>
 #include <fstream>
@@ -228,6 +232,7 @@ void testFrame (  Config conf,
     cerr << "\nGetting prediction values for all data points...";
     NICE::Vector predictionValues( testingSize );
     predictionValues.set ( 0.0 );
+#pragma omp parallel for    
     for ( int j = 0; j < testingSize; j++ )
     {
       predictionValues[j] = knn->predict( testData[j] );