Ok, here we go...
If you want that your script
run on multi-processes you may use the same method explained in my answer to Magialisk's topic and placed below "The Batch code below is an example of this method; it may be used as general format for any application that follows this scheme"; indeed, I used it as a guideline to convert your program. However, in this case there are not
input records to process, just output records represented by the lines in the screen. I slightly modified the method so each parallel process run on its own set of screen lines interleaved by the same number of processes, that is, if there are 3 processes the first one generate lines 1, 4, 7, etc. until line 34; the second one the lines 2, 5, 8..33; and 3,6,9..32 for the last one.
Code: Select all
@echo off & setlocal EnableDelayedExpansion
rem Multi-process dispatcher:
set "param=%~1"
if "!param:~0,1!" equ ":" (
shift
goto !param:~1!
)
REM set /A N=NUMBER_OF_PROCESSORS-1
set N=3
set /a cols=34, lines=38
mode con cols=%cols% lines=%lines%
set /a lines-=4, nchar=cols*lines, angle=0
rem Values used in parallel processes
set /A linesPerProc=lines/N, missingLines=lines%%N, Nminus1=N-1
set t0=%time%
For /L %%. in (1,1,100) do (
cls
rem rotate two degree at second
for /F "tokens=1-8 delims=:.," %%a in ("!t0: =0!:!time: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, angle=(a*20000/100)%%450000"
call :INT_SinD_CosD !angle! sin cos
set /a "cos=cos/100000, sin=sin/100000" & rem echo t=!a! angle=!angle! sin=!sin! cos=!cos!
rem Set the initial output turn
del processActive.* 2>NUL
del outputTurn.* 2>NUL
echo X >outputTurn.0
rem Start the parallel processes
set /A startLine=1, missing=missingLines, carry=1
for /L %%p in (0,1,!Nminus1!) do (
if !missing! equ 0 set carry=0
set /A "endLine=startLine+N*(linesPerProc-1+carry)"
echo X > processActive.%%p
start "" /B "%~F0" :ShowInterleavedLines %%p !startLine! %N% !endLine!
set /A startLine+=1, missing-=1
)
rem Wait for parallel processes to end
call :waitForActiveProcesses
)
goto :eof
:waitForActiveProcesses
if exist processActive.* goto waitForActiveProcesses
exit /B
:ShowInterleavedLines turn startLine interleave endLine
for /L %%y in (%2,%3,%4) do (
set "line="
for /L %%x in (1,1,%cols%) do (
set /a "x=(%%x-cols/2)*100/8, y=(%%y-lines/2)*100/8"
rem rotate x,y
set /a "x1=x*cos/100-y*sin/100, y=x*sin/100+y*cos/100, x=x1"
set /a "c1=(x*x/100+y*y/100), c2=c1*c1/100*c1/100*c1/100*c1/100, c3=((x*x/100-y*y/100)*8*x/100*y/100), c4=c3*c3/100, c=(c2-c4)"
if !c! lss 0 (set "line=!line!*") else set "line=!line!."
)
if not exist outputTurn.%1 call :waitMyTurn %1
set /P "=!line!" < nul
set /A "nextTurn=(%1+1) %% N"
ren outputTurn.%1 outputTurn.!nextTurn!
)
del processActive.%1
exit
:waitMyTurn
if not exist outputTurn.%1 goto waitMyTurn
exit /B
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:INT_SinD_CosD Angle SinResultVAR CosResultVAR
::
:: -- Return the sine and cosine for the specified angle in 100*micro-degrees.
:: ie. 10000 is one degree.
::
:: Call :INT_sinD_CosD Angle sin cos
::
:: -- Angle [in] in 100 micro-Degree is an integer in [-449999,449999]
::
:: -- SinResultVAR [out] var reference to return value of sine [-100000000,100000000]
::
:: -- CosResultVAR [out] var reference to return value of cosine [-100000000,100000000]
::
::
:: Version history
::
:: 0.1 16/9/2013
::
:: First version Beta! Internal 27bit used
::
:: From Francesco Poscetti aka Einstein1969
::
:: NOTE: This Function allow you to calculate almost all other common
:: trigonometric function. Use the CORDIC modified algorithm.
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SetLocal EnableDelayedExpansion
set /a "a=%~1"
if %a% lss -449999 echo Not implemented. Exit. & goto :eof
if %a% gtr 449999 echo Not implemented. Exit. & goto :eof
set /a size=-1
For %%a in (450000000 265650512 140362435 71250163 35763344 17899106
8951737 4476142 2238105 1119057 559529 279765 139882 69941 34971 17485
8743 4371 2186 1093 546 273 137 68 34 17 9 4 2 1) do (set /a "size+=1" & set "at!size!=%%a")
if %a% geq 0 ( set /a x=607252935, angle=!a!*10*10*10, angle-=!at0!, y=x
) else set /a x=607252935, angle=!a!*10*10*10, angle+=!at0!, y=-x
For /L %%# in (1,1,!size!) do (
rem echo [%1] %%# angle:!angle! x:!x! y:!y! at%%#=!at%%#! size:!size!
if !angle! lss 0 (set /a "angle+=!at%%#!, dx=x/(1<<%%#), x+=y/(1<<%%#), y-=dx"
) else if !angle! gtr 0 (set /a "angle-=!at%%#!, dx=x/(1<<%%#), x-=y/(1<<%%#), y+=dx")
)
endlocal & set /a %2=(%y%+55)/100, %3=(%x%+55)/100
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
On the other hand, if you would want that
your script run faster, then there are several modifications that may help to do that. For example, the simple modification required in the multi-process method of store the output characters in a line and then display the line with one SET /P command, instead of show
every character via individual SET /P commands, cause that the program run 21% faster. Another simple modification, although it run just 16% faster, allows to display the result of the whole screen in a single operation, so in this case the waiting time between screen frames doesn't matter to much.
I am pretty sure that a slightly larger modification in the method to calculate Sin and Cos values will result in additional time gains in the single process mode; of course, this modification may be combined with the multi-process one. However, I was confused by the values that your INT_SinD_CosD routine use.
In my previous posts I tried to explain you that having a better knowledge about a problem will conduce to better solutions, and asked you for additional information; however, it seems that you are not interested in such better solutions and just wanted to "parallelize your script". I have presented my solution here that allows your script to run on multi-processes, as you requested... I would have liked to complete and show you the other modifications that allows to decrease the execution time, but those modifications have absolutely no relation with the multi-process method and I have spent too much time in this matter!
Antonio