Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,58 @@
|
|||
structure TTd = Thread.Thread ;
|
||||
structure TTm = Thread.Mutex ;
|
||||
|
||||
|
||||
val threadedBigPrime = fn input:IntInf.int list =>
|
||||
|
||||
let
|
||||
|
||||
(* --------------------- code from prime decomposition page ------------------- *)
|
||||
val factor = fn n :IntInf.int =>
|
||||
let
|
||||
val unfactored = fn (u,_,_) => u; val factors = fn (_,f,_) => f; val try = fn (_,_,i) => i; fun getresult t = unfactored t::(factors t);
|
||||
fun until done change x = if done x then getresult x else until done change (change x); (* iteration *)
|
||||
fun lastprime t = unfactored t < (try t)*(try t)
|
||||
fun trymore t = if unfactored t mod (try t) = 0 then (unfactored t div (try t) , try t::(factors t) , try t) else (unfactored t, factors t , try t + 1)
|
||||
in until lastprime trymore (n,[],2) end;
|
||||
(* --------------------- end of code from prime decomposition page ------------ *)
|
||||
|
||||
|
||||
val mx = TTm.mutex () ;
|
||||
val results : IntInf.int list list ref = ref [ ] ;
|
||||
val tasks : IntInf.int list list ref = ref [ ] ;
|
||||
|
||||
|
||||
val divideup = fn cores => fn inp : IntInf.int list =>
|
||||
let
|
||||
val np = (List.length inp) div cores + (cores +1) div cores (* assume length > cores to reduce code *)
|
||||
val rec divd = fn ([], outp) => ([],outp )
|
||||
| (inp,outp) => divd ( List.drop (inp,np) , (List.take (inp,np))::outp ) handle Subscript => ([],inp :: outp)
|
||||
in
|
||||
#2 ( divd (inp, [ ] ))
|
||||
end;
|
||||
|
||||
|
||||
val doTask = fn () =>
|
||||
let
|
||||
val mytask : IntInf.int list ref = ref [];
|
||||
val myres : IntInf.int list list ref = ref [];
|
||||
in
|
||||
( TTm.lock mx ; mytask := hd ( !tasks ) ; tasks:= tl (!tasks) ; TTm.unlock mx ;
|
||||
myres := List.map factor ( !mytask ) ;
|
||||
TTm.lock mx ; results := !myres @ ( !results ) ; TTm.unlock mx ;
|
||||
TTd.exit ()
|
||||
)
|
||||
end;
|
||||
|
||||
|
||||
val cores = TTd.numProcessors ();
|
||||
val tmp = tasks := divideup cores input ;
|
||||
val processes = List.tabulate ( cores , fn i => TTd.fork (doTask , []) ) ;
|
||||
val maxim = ( while ( List.exists TTd.isActive processes ) do (Posix.Process.sleep (Time.fromReal 1.0 ));
|
||||
List.foldr IntInf.max 1 ( List.map (fn i => List.last i ) (!results) ) ) (* maximal lowest prime *)
|
||||
|
||||
in
|
||||
|
||||
List.filter (fn lst => List.last lst = maxim ) (!results)
|
||||
|
||||
end ;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
> threadedBigPrime [ 62478923478923409323, 69478923478923409313, 79234790234098402349,
|
||||
33498023480920234793, 92834098234098023409, 31908234098234098243,
|
||||
92873400002348028833, 73498200234098200239, 4349023423478999243,
|
||||
13480234982340982343, 62478923478925971503, 5340823480234982007,
|
||||
134802349691098498233, 81780923490092302251, 802487292348792949 ] ;
|
||||
|
||||
val it = [[1463103844669601, 42703], [1463103844669541, 42703]]:
|
||||
|
||||
(* numbers *)
|
||||
> List.map (List.foldr IntInf.* 1 ) it ;
|
||||
val it = [62478923478925971503, 62478923478923409323]: IntInf.int list
|
||||
Loading…
Add table
Add a link
Reference in a new issue