Explorar el Código

Optimized calcPiTau

Konstantin Ladutenko hace 10 años
padre
commit
a238488774
Se han modificado 2 ficheros con 20 adiciones y 42 borrados
  1. 12 12
      go.sh
  2. 8 30
      nmie-wrapper.cc

+ 12 - 12
go.sh

@@ -3,8 +3,8 @@ echo Compile with gcc -O2
 rm -f *.bin
 rm -f ../scattnlay
 g++ -Ofast -std=c++11 compare.cc nmie.cc nmie-wrapper.cc -lm -lrt -o scattnlay.bin -static
-g++ -Ofast -std=c++11 compare.cc nmie.cc nmie-wrapper.cc -lm -lrt -o scattnlay-pg.bin -static -pg
-# clang++ -g -O1 -fsanitize=address  -fno-optimize-sibling-calls -fno-omit-frame-pointer -std=c++11 compare.cc nmie.cc nmie-wrapper.cc -lm -lrt -o scattnlay.bin
+# g++ -Ofast -std=c++11 compare.cc nmie.cc nmie-wrapper.cc -lm -lrt -o scattnlay-pg.bin -static -pg
+#clang++ -g -O1 -fsanitize=address  -fno-optimize-sibling-calls -fno-omit-frame-pointer -std=c++11 compare.cc nmie.cc nmie-wrapper.cc -lm -lrt -o scattnlay.bin
 
 cp scattnlay.bin ../scattnlay
 cp scattnlay-pg.bin ../scattnlay-pg
@@ -19,17 +19,17 @@ cd tests/shell
 # time ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4 
 time $PROGRAM -l 5 0.4642 1.8000 1.7000 0.7114 0.8000 0.7000 0.7393 1.2000 0.0900 0.9168 2.8000 0.2000 1.0000 1.5000 0.4000  -t 0.0 90.0 5 -c test01
 
-# echo valgring
-# valgrind --tool=callgrind $PROGRAM -l 5 0.4642 1.8000 1.7000 0.7114 0.8000 0.7000 0.7393 1.2000 0.0900 0.9168 2.8000 0.2000 1.0000 1.5000 0.4000  -t 0.0 90.0 5 -c test01
-# ./gprof2dot.py --output=out.dot --format=callgrind callgrind.out.*
-# mv callgrind.out.* callgrind
-# dot -Tsvg out.dot -o graph.svg
+echo valgring
+valgrind --tool=callgrind $PROGRAM -l 5 0.4642 1.8000 1.7000 0.7114 0.8000 0.7000 0.7393 1.2000 0.0900 0.9168 2.8000 0.2000 1.0000 1.5000 0.4000  -t 0.0 90.0 5 -c test01
+./gprof2dot.py --output=out.dot --format=callgrind callgrind.out.*
+mv callgrind.out.* callgrind
+dot -Tsvg out.dot -o graph.svg
 
-rm gmon.out
-rm analysis.txt
-PROGRAM='../../../scattnlay-pg'
-time $PROGRAM -l 5 0.4642 1.8000 1.7000 0.7114 0.8000 0.7000 0.7393 1.2000 0.0900 0.9168 2.8000 0.2000 1.0000 1.5000 0.4000  -t 0.0 90.0 5 -c test01
-gprof $PROGRAM gmon.out > analysis.txt
+# rm gmon.out
+# rm analysis.txt
+# PROGRAM='../../../scattnlay-pg'
+# time $PROGRAM -l 5 0.4642 1.8000 1.7000 0.7114 0.8000 0.7000 0.7393 1.2000 0.0900 0.9168 2.8000 0.2000 1.0000 1.5000 0.4000  -t 0.0 90.0 5 -c test01
+# gprof $PROGRAM gmon.out > analysis.txt
 
 # repeats=30
 # echo Run test for $repeats times

+ 8 - 30
nmie-wrapper.cc

@@ -549,44 +549,22 @@ namespace nmie {
     //****************************************************//
     // Equations (26a) - (26c)                            //
     //****************************************************//
-    // // // Assume nmax_ > 0;
-    // // int n = 0;
-
-    // // double Pin, Pinm1, Pinm2;
-    // // Pi[n] = 1.0;
-    // // Pinm2 = 1.0;
-    // // Tau[n] = (n + 1)*cos(Theta);    
-    // // if (nmax_ == 1) return;
-    // // n = 1;
-    // // Pinm1 = (n + n + 1)*cos(Theta)*Pi[n - 1]/n;
-    // // Pi[n] = Pinm1;
-    // // Tau[n] = (n + 1)*cos(Theta)*Pi[n] - (n + 2)*Pi[n - 1];
-    // // if (nmax_ == 2) return;
-    // // double nf = 2.0, cosTheta = std::cos(Theta);
-    // // for (n = 2; n < nmax_; n++) {      
-    // //   // Calculate the actual values
-    // //   //Pin =  ((nf + nf + 1.0)*cosTheta*Pinm1 - (nf + 1)*Pinm2)/nf;
-    // //   Pi[n] =  ((nf + nf + 1.0)*std::cos(Theta)*Pi[n - 1] - (nf + 1)*Pi[n - 2])/nf;
-    // //   // Pi[n] = Pin;
-    // //   Tau[n] = (nf + 1.0)*cosTheta*Pin - (nf + 2)*Pinm1;
-    // //   // Tau[n] = (nf + 1.0)*cos(Theta)*Pi[n] - (nf + 2)*Pi[n - 1];
-    // //   nf+=1.0;
-    // //   // Pinm2 = Pinm1;
-    // //   // Pinm1 = Pin;
-    // // }
-    // Unoptimized
+    std::vector<double> costheta(theta_.size(), 0.0);
+    for (int t = 0; t < theta_.size(); t++) {	
+      costheta[t] = cos(theta_[t]);
+    }
     for (int n = 0; n < nmax_; n++) {
       for (int t = 0; t < theta_.size(); t++) {	
 	if (n == 0) {
 	  // Initialize Pi and Tau
 	  Pi[n][t] = 1.0;
-	  Tau[n][t] = (n + 1)*cos(theta_[t]);
+	  Tau[n][t] = (n + 1)*costheta[t]; 
 	} else {
 	  // Calculate the actual values
-	  Pi[n][t] = ((n == 1) ? ((n + n + 1)*cos(theta_[t])*Pi[n - 1][t]/n)
-		   : (((n + n + 1)*cos(theta_[t])*Pi[n - 1][t]
+	  Pi[n][t] = ((n == 1) ? ((n + n + 1)*costheta[t]*Pi[n - 1][t]/n)
+		   : (((n + n + 1)*costheta[t]*Pi[n - 1][t]
 		       - (n + 1)*Pi[n - 2][t])/n));
-	  Tau[n][t] = (n + 1)*cos(theta_[t])*Pi[n][t] - (n + 2)*Pi[n - 1][t];
+	  Tau[n][t] = (n + 1)*costheta[t]*Pi[n][t] - (n + 2)*Pi[n - 1][t];
 	}
       }
     }