Commits

Hans-Nikolai Viessmann  committed 2b06d55

DOne

  • Participants
  • Parent commits e9ba245

Comments (0)

Files changed (2)

File cw2/Makefile

 
 hs: $(HASKBIN)
 
-sac: $(SACBIN)
+sc: $(SACBIN)
 
 $(HASKBIN): TotientRange.hs
 	ghc -O2 -rtsopts -threaded -eventlog -o $@ $<

File cw2/TotientRange.sac

 use CommandLine: all;
 use Benchmarking: all;
 use Environment: all;
+use Math: {log2};
 
 // A bit of a nasty hack, so that we actually get the result value and not the
 // complete data structure pretty-printed
     return(tod(x == 1d));
 }
 
-inline double[] euler(double[] n)
+double[] euler(double[] n)
 {
     vec = with {
         ([0] < iv < [toi(n)]) : hcf(n, tod(iv[0]));
 
 inline double[] sumTotient(int[] lower, int[] upper)
 {
+    count = 2;
     tmp = with {
         // Seems to make little difference...
         //#pragma wlcomp Ubv([5,5], [5,5], ConstSeg([0,0], [50,100], [50,0], [100,100], Default))
         
         // This is the original solution that simply goes from the first
         // index to the last index.
-        //([0] <= iv <= [upper - lower]) : euler(tod(iv[0] + lower));
+        //([0] <= [i] <= [upper - lower]) : euler(tod(i + lower));
             
         // This is the optimized version that uses pair-based computation,
         // which reduces the number of threads created and helps to more
         // evenly balance the computational load.
-        ([0] <= iv <= [(upper - lower) / 2]) : euler(tod(iv[0] + lower)) + euler(tod(upper - iv[0]));
+        //([0] <= [i] <= [(upper - lower) / 2]) : euler(tod(i + lower)) + euler(tod(upper - i));
+       
+        // Seems to provide about the same amount of speedup as the one above
+        ([0] <= [i] <= [(upper - lower) / 4]) : euler(tod(i + lower)) + euler(tod(upper - i)) + euler(tod(i + lower + 250)) + euler(tod(upper - 250 - i));
     } : fold(+, 0d);
     return(tmp);
 }
                 " SAC_PARALLEL and omit the `-mt' flag\n", argv(0));
         status = 1;
     } else {
+        // A nieve way of getting the `-mt' flag value
         if(argc() == 5){
             threads = argv(4);
         } else {
             //printf("%s\n", ExistEnv("SAC_PARALLEL") ? "true" : "false");
             threads = GetEnv("SAC_PARALLEL");
         }
+
         lower = String::toi(argv(1));
         upper = String::toi(argv(2));