Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.75 KB | None | 0 0
  1. module factorialp;
  2.  
  3. import pyd.pyd;
  4. import std.algorithm;
  5. import std.range;
  6. import std.bigint;
  7. import std.parallelism;
  8. import std.datetime;
  9. import std.stdio;
  10.  
  11. BigInt factorial(int base) {
  12.     auto chsize = base / totalCPUs / 4;
  13.     BigInt result;
  14.     auto starttime = Clock.currTime();
  15.     auto result =  
  16.         taskPool.reduce!"a * b"(
  17.             map!(fold!"cast(std.bigint.BigInt)a * b")
  18.                 (
  19.                     chunks(
  20.                         iota(1, base + 1),
  21.                         chsize ? chsize : 1
  22.                     )
  23.                 )
  24.         );
  25.     writefln("elapsed time = %s", Clock.currTime() - starttime);
  26.     return result;
  27. }
  28.  
  29. extern(C) void PydMain() {
  30.     def!factorial();
  31.     module_init();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement