Parcourir la source

Add missing Cilk++ parts :)

Jean Fromentin il y a 5 ans
Parent
commit
13194c9046
3 fichiers modifiés avec 24 ajouts et 33 suppressions
  1. 3 3
      Makefile
  2. 20 29
      main.cpp
  3. 1 1
      rationnal.hpp

+ 3 - 3
Makefile

@@ -1,12 +1,12 @@
 EXE 	= test
 CPP 	= g++
-CFLAGS 	=  -mavx2 -mfma -g -O3 -DNDEBUG
-LIBS	= 
+CFLAGS 	= --std=c++11 -fcilkplus -mavx2 -mfma -g -O3 -DNDEBUG
+LIBS	= -lcilkrts
 
 %.o:%.cpp %.hpp config.hpp
 	$(CPP) $(CFLAGS) -c $< -o $@
 
-$(EXE): avx_matrix.o polygon_step.o polygon_generator.o polygon.o rationnal.o coeffs.o main.cpp
+$(EXE): results.o avx_matrix.o polygon_step.o polygon_generator.o polygon.o rationnal.o coeffs.o main.cpp
 	$(CPP) $(CFLAGS) $^ -o $@ $(LIBS)
 
 clean:

+ 20 - 29
main.cpp

@@ -1,30 +1,13 @@
 #include <iomanip>
+#include <cilk/cilk.h>
+#include <cilk/cilk_api.h>
 #include "config.hpp"
 #include "coeffs.hpp"
 #include "polygon_generator.hpp"
 #include "avx_matrix.hpp"
+#include "results.hpp"
 
-static const size_t numbers[]=
-  {
-   1,
-   2,
-   7,
-   28,
-   124,
-   588,
-   2938,
-   15268,
-   81826,
-   449572,
-   2521270,
-   14385376,
-   83290424,
-   488384528,
-   2895432660,
-   17332874364,
-   104653427012,
-   636737003384
-  };
+ResultsReducer cilk_result;
 
 void box(string str){
   size_t w=str.size();
@@ -41,8 +24,17 @@ void disp_info(){
   box("Compute Fp's series of Self Avoiding Polygon");
   cout<<endl;
   cout<<" Maximal length is "<<max_len<<endl;
+  cout<<" Workers number is "<<__cilkrts_get_nworkers()<<endl;
 }
 
+void treat(Polygon* P){
+  size_t l=P->length;
+  size_t i=l/2-1;
+  ++cilk_result.numbers(i);
+  Reel fp=P->fp();
+  cilk_result.sum_fp(i)+=fp;
+  delete P;
+}
 int main(){
   cout<<std::setprecision(20);
   disp_info();
@@ -56,23 +48,22 @@ int main(){
   }
   PolygonGenerator gen;
   size_t total=0;
-  Polygon P;
+  Polygon* P;
   while(gen.next()){
-    P=gen.get();
-    size_t l=P.length;
-    ++nb[l/2-1];
+    P=new Polygon;
+    gen.set(*P);
+    cilk_spawn treat(P);
     ++total;
-    Reel fp=P.fp();
-    res[l/2-1]+=fp;
   }
+  cilk_sync;
   Reel d=256;
   for(size_t i=1;2*i<max_len;++i){
     Reel l=2*i+2;
     cout<<endl<<"=== Length "<<l<<" ==="<<endl;
-    Reel r=res[i];
+    Reel r=cilk_result.sum_fp(i);
     Reel n=2*l;
     coeff[i]=(n*r)/d;
-    cout<<" > number : "<<nb[i]<<endl;
+    cout<<" > number : "<<cilk_result.numbers(i)<<endl;
     cout<<" >  value : "<<coeff[i]<<endl; 
     d*=16;
   }

+ 1 - 1
rationnal.hpp

@@ -127,7 +127,7 @@ Rationnal::operator Reel() const{
 
 inline void
 Rationnal::normalize(){
-  Int d=gcd(abs(num),den);
+  Int d=gcd((num<0)?-num:num,den);
   num/=d;
   den/=d;
 }