global $N=0 ; THE number global $ncore=0 ; nr of allocated computing units global $nth=1 ; spreading step in allocatable threads global $ndiv=0 global const $maxcpus=EnvGet("NUMBER_OF_PROCESSORS") ; nr of cpus (threads) on the machine global const $minseg=100 ; minimum segment length per cpu global $MAFF=true ; start command /affinity mask global $bigch="" if Not(SaisieOK()) then Exit Gloops() Retbuild() $ndiv=nblank($bigch) MsgBox(0, "RESULTS", $ndiv&" divisors "&$bigch) Exit func Retbuild() Local $icore=0 local $corelaunch=0 Local $kpos=0 Local $fname="" local $bigchup="" local $bigchwn="" local $file $icore=0 while $icore<$ncore $fname="Journal_"&$corelaunch&".txt" while (fileexists($fname)=0) sleep(125) wend $bigch="" $file=FileOpen($fname,0) $bigch=FileReadLine($file) FileClose($file) If StringLen($bigch)>0 then $kpos=StringInStr($bigch,"_") if $kpos>1 then $ch=StringLeft($bigch,$kpos-1) $bigchup&=$ch endif $ch=StringTrimLeft($bigch,$kpos) if stringlen($ch)>1 then $bigchwn=$ch&$bigchwn EndIf $icore=$icore+1 $corelaunch=$corelaunch+$nth wend $bigch=$bigchup&$bigchwn endfunc Func nblank($sin) $sin=StringReplace($sin," "," ") Return @extended EndFunc func Gloops() Local $candfloor=1 Local $candceiling=0 Local $finalcandceiling=0 Local $segment=0 Local $icore=0 Local $increment=0 Local $slaunch="" Local $corelaunch=0 Local $flastname="" Local $Hmask="" Local $double=false if mod($N,2)>0 then $increment=2 else $increment=1 endif $candceiling=int(sqrt($N)+0.5) $finalcandceiling=$candceiling $segment=int($candceiling/$ncore) while ($ncore>1) and ($segment<$minseg) $ncore=$ncore-1 $segment=int($candceiling/$ncore) wend if ($segment<$minseg) or ($ncore=1) then $candceiling=$finalcandceiling $ncore=1 else if $increment=2 then if mod($segment,2)>0 then $segment=$segment+1 endif $candceiling=$candfloor+$segment endif while $icore<$maxcpus $flastname="Journal_"&$icore&".txt" if FileDelete($flastname)<1 then if $double then ExitLoop $double=true else $double=false endif $icore=$icore+1 wend $icore=0 while $icore<$ncore envset("corenr",$corelaunch) envset("theN",$N) envset("candfloor",$candfloor) envset("candceiling",$candceiling) envset("increment",$increment) if $MAFF then $Hmask=Amask(($nth*$icore)) Run(@ComSpec & " /C start /affinity "&$Hmask&" loopkim.exe") else ; $slaunch="Launch.exe loopkim.exe /ap="&$corelaunch $slaunch="StartAffinity.exe loopkim.exe "&$corelaunch Run($slaunch) endif $icore=$icore+1 $corelaunch=$corelaunch+$nth $candfloor=$candceiling if $icore<$ncore then $candceiling=$candceiling+$segment else $candceiling=$finalcandceiling endif wend endfunc Func Amask($k) Local $B="" Local $H="" Local $quad="" Local $i=0 Local $delta=0 Local $nhex=0 while $i<$k $B&="0" $i+=1 wend $B&="1" $i=mod($maxcpus,4) if $i>0 then $delta=4-$i $delta=$delta+$maxcpus-StringLen($B) $i=0 while $i<$delta $B&="0" $i+=1 wend $B=StringReverse($B) $nhex=Int(StringLen($B)/4) $i=0 while $i<$nhex $quad=StringLeft($B,4) Switch $quad case "0000" $H&="0" case "0001" $H&="1" case "0010" $H&="2" case "0100" $H&="4" case "1000" $H&="8" EndSwitch $B=StringTrimLeft($B,4) $i+=1 wend $H="0x"&$H Return $H endfunc Func SaisieOK() Local $sin="" $N=0 if FileExists("StartAffinity.exe")<1 then if StringInStr(@OSVersion,"WIN_XP")>0 then MsgBox(0, "NOP","No StartAfiinity.exe found in directory") Return False endif else $MAFF=false endif if FileExists("loopkim.exe")<1 then MsgBox(0, "NOP","No loopkim.exe found in directory") Return False endif $Sin=inputbox("Integer Divisors of N","Enter N") $Sin=StringReplace($Sin," ","") $Sin=StringReplace($Sin,",","") If (StringIsDigit($Sin)>0) and (StringIsInt($Sin)>0) then $N=Number($Sin) endif if not($N>0) then MsgBox(0, "NO","A Positive Integer number is required") Return False endif if (StringLen($Sin)>15) then MsgBox(0, "NO","This number is too large !") Return False endif while $ncore=0 $Sin=inputbox("Allocatable Computing Power","How many cpus ? [ Return = "&$maxcpus&" ]") If (StringIsDigit($Sin)>0) and (StringIsInt($Sin)>0) then $ncore=Number($Sin) endif if $ncore=0 then $ncore=$maxcpus if not($ncore>0) then MsgBox(0, "NO","Positive Integer number required") $ncore=0 endif if $ncore>$maxcpus then MsgBox(0, "NO","Maximum nr of cpus on your machine = "&$maxcpus&" !") $ncore=0 endif if $ncore>=2 then $sin=inputbox("CPUs allocation method"," 1 (all) or 2 (even) ? [ Return = 1"&" ]") if Number($sin)=2 then $nth=2 $ncore=int($ncore/2)+mod($ncore,2) endif endif wend Return True EndFunc