0

下面代码中的行set cyclezipPPMdd=%cyclezipPPMdd!cycleCount!%没有按我的意图工作。!cycleCount!例如,它应该转换为 ,1然后转换%cyclezipPPMdd!cycleCount!%cyclezipPPMdd1并最终设置cyclezipPPMdd为等于 的cyclezipPPMdd1256m

我需要一个旋转值cyclezipPPMdd

rem @echo off
setlocal enableDelayedExpansion

: part1
set "cyclezipPPMdd0=256m 128m 64m 32m 16m 8m 4m 2m 1m"
set "memcyclezipPPMdd=258 130 66 34 18 10 6 4 3"

set /a anotherCounter=0
set tempCycle=!cyclezipPPMdd0: =^

!
for /f %%i in ("!tempCycle!") do (
  set /a anotherCounter+=1
  set cyclezipPPMdd!anotherCounter!=%%i
)
set /a cycleCount=0

: part2
set tempMem=!memcyclezipPPMdd: =^

!
for /f %%i in ("!tempMem!") do (
  set /a cycleCount+=1
  set tempMem!cycleCount!=%%i
  set cyclezipPPMdd=%cyclezipPPMdd!cycleCount!%
  set cyclezipPPMdd
  pause
)
set /a anotherCounter=0
set /a cycleCount=0

pause

最后,我对我需要做什么来实现我的目标一无所知。我根本不是程序员。这是最终目标主题:for and start commands in a batch for parallel and sequence work


编辑:太久没读过的版本

我需要一种方法来拆分cyclezipPPMdd0=256m 128m 64m 32m 16m 8m 4m 2m 1m成单个部分,如下所示:

cyclezipPPMdd0=256m 128m 64m 32m 16m 8m 4m 2m 1m
cyclezipPPMdd1=256m
cyclezipPPMdd2=128m
cyclezipPPMdd3=64m
cyclezipPPMdd4=32m
cyclezipPPMdd5=16m
cyclezipPPMdd6=8m
cyclezipPPMdd7=4m
cyclezipPPMdd8=2m
cyclezipPPMdd9=1m

这些值将直接影响 7z.exe 将使用多少内存(在另一个主题中解释),我需要一种方法来跟踪当前正在使用多少内存以确定剩余内存是否允许我是否运行另一个 7z.exe 实例。当 7z.exe 启动时,它一次只会使用其中一个值。但是,256m 是 7z.exe 的一个参数值,它是字典大小。这个参数的实际内存使用量是258,所以,关联的值是这样的:

cyclezipPPMdd1=256m <=> tempMem1=258
cyclezipPPMdd2=128m <=> tempMem2=130
cyclezipPPMdd3=64m  <=> tempMem3=66
cyclezipPPMdd4=32m  <=> tempMem4=34
cyclezipPPMdd5=16m  <=> tempMem5=18
cyclezipPPMdd6=8m   <=> tempMem6=10
cyclezipPPMdd7=4m   <=> tempMem7=6
cyclezipPPMdd8=2m   <=> tempMem8=4
cyclezipPPMdd9=1m   <=> tempMem9=3

7z.exe 目前在我的代码上设置为读取值cyclezipPPMdd(不带数字)。这个变量必须在所有可用的部分中旋转,从 拆分cyclezipPPMdd0,但始终是相同的名称,cyclezipPPMdd(仍然没有数字)。

if defined cyclezipPPMd (
  for %%x IN (%cyclezipPPMdx%) DO for %%t IN (%cyclezipPPMdt%) DO for %%d IN (%cyclezipPPMdd%) DO for %%w IN (%cyclezipPPMdw%) DO (
    set "cmd=7z.exe a teste.resultado\%%xx.ppmd.%%tt.%%dd.%%ww.zip .\teste.original\* -mx=%%x -mm=PPMd:mem=%%d:o=%%w -mmt=%%t"
    call :executeProc
  )
)

第一次 7z.exe 运行会做cyclezipPPMdd=256m,第二次运行会做cyclezipPPMdd=128m等等......像这样:

first run
cyclezipPPMdd1=256m <=> tempMem1=258  -> cyclezipPPMdd=256m
cyclezipPPMdd2=128m <=> tempMem2=130
cyclezipPPMdd3=64m  <=> tempMem3=66
cyclezipPPMdd4=32m  <=> tempMem4=34
cyclezipPPMdd5=16m  <=> tempMem5=18
cyclezipPPMdd6=8m   <=> tempMem6=10
cyclezipPPMdd7=4m   <=> tempMem7=6
cyclezipPPMdd8=2m   <=> tempMem8=4
cyclezipPPMdd9=1m   <=> tempMem9=3

second run
cyclezipPPMdd1=256m <=> tempMem1=258
cyclezipPPMdd2=128m <=> tempMem2=130  -> cyclezipPPMdd=128m
cyclezipPPMdd3=64m  <=> tempMem3=66
cyclezipPPMdd4=32m  <=> tempMem4=34
cyclezipPPMdd5=16m  <=> tempMem5=18
cyclezipPPMdd6=8m   <=> tempMem6=10
cyclezipPPMdd7=4m   <=> tempMem7=6
cyclezipPPMdd8=2m   <=> tempMem8=4
cyclezipPPMdd9=1m   <=> tempMem9=3

third run
cyclezipPPMdd1=256m <=> tempMem1=258
cyclezipPPMdd2=128m <=> tempMem2=130
cyclezipPPMdd3=64m  <=> tempMem3=66   -> cyclezipPPMdd=64m
cyclezipPPMdd4=32m  <=> tempMem4=34
cyclezipPPMdd5=16m  <=> tempMem5=18
cyclezipPPMdd6=8m   <=> tempMem6=10
cyclezipPPMdd7=4m   <=> tempMem7=6
cyclezipPPMdd8=2m   <=> tempMem8=4
cyclezipPPMdd9=1m   <=> tempMem9=3
etc...

然而,这还不是全部。还有另一个 7z.exe 参数不仅会影响将使用多少内存,还会影响将使用多少线程。我的脚本中没有准备好这部分,我仍在试图弄清楚如何实现它。

first cycle <=> cyclezipPPMdt1=1 <=> tempProc1=8
first run
cyclezipPPMdd1=256m <=> tempMem1=258  -> cyclezipPPMdd=256m
cyclezipPPMdd2=128m <=> tempMem2=130
second run
cyclezipPPMdd1=256m <=> tempMem1=258
cyclezipPPMdd2=128m <=> tempMem2=130  -> cyclezipPPMdd=128m
etc...

second cycle <=> cyclezipPPMdt2=2 <=> tempProc2=4
first run
cyclezipPPMdd1=256m <=> tempMem1=580 -> cyclezipPPMdd=256m
cyclezipPPMdd2=128m <=> tempMem2=324
second run
cyclezipPPMdd1=256m <=> tempMem1=580
cyclezipPPMdd2=128m <=> tempMem2=324 -> cyclezipPPMdd=128m
etc...

下表显示了 zipPPMd 算法的内存使用、线程使用和压缩强度之间的关系。

@echo off
echo mem=1m 2m 4m 8m 16m 32m 64m 128m 256m
echo o=2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
echo mt=1 2 3 4 5 6 7 8
echo x=1 3 5 7 9
echo 256m 9x 7x 5x 3x 1x 8t - 2320 MB, 7t - 2030 MB, 6t - 1740 MB, 5t - 1450 MB, 4t - 1160 MB, 3t - 870 MB, 2t - 580 MB, 1t - 258 MB
echo 128m 9x 7x 5x 3x 1x 8t - 1296 MB, 7t - 1134 MB, 6t -  972 MB, 5t -  810 MB, 4t -  648 MB, 3t - 486 MB, 2t - 324 MB, 1t - 130 MB
echo  64m 9x 7x 5x 3x 1x 8t -  784 MB, 7t -  686 MB, 6t -  588 MB, 5t -  490 MB, 4t -  392 MB, 3t - 294 MB, 2t - 196 MB, 1t -  66 MB
echo  32m 9x 7x 5x 3x 1x 8t -  528 MB, 7t -  462 MB, 6t -  396 MB, 5t -  330 MB, 4t -  264 MB, 3t - 198 MB, 2t - 132 MB, 1t -  34 MB
echo  16m 9x 7x 5x 3x 1x 8t -  400 MB, 7t -  350 MB, 6t -  300 MB, 5t -  250 MB, 4t -  200 MB, 3t - 150 MB, 2t - 100 MB, 1t -  18 MB
echo   8m 9x 7x 5x 3x 1x 8t -  336 MB, 7t -  294 MB, 6t -  252 MB, 5t -  210 MB, 4t -  168 MB, 3t - 126 MB, 2t -  84 MB, 1t -  10 MB
echo   4m 9x 7x 5x 3x 1x 8t -  304 MB, 7t -  266 MB, 6t -  228 MB, 5t -  190 MB, 4t -  152 MB, 3t - 114 MB, 2t -  76 MB, 1t -   6 MB
echo   2m 9x 7x 5x 3x 1x 8t -  288 MB, 7t -  252 MB, 6t -  216 MB, 5t -  180 MB, 4t -  144 MB, 3t - 108 MB, 2t -  72 MB, 1t -   4 MB
echo   1m 9x 7x 5x 3x 1x 8t -  280 MB, 7t -  245 MB, 6t -  210 MB, 5t -  175 MB, 4t -  140 MB, 3t - 105 MB, 2t -  70 MB, 1t -   3 MB

无论压缩强度(x在这个表中定义,和%cyclezipPPMdx%在脚本中定义),当字典(mem在表中,%cyclezipPPMdd%在脚本中)设置为例如256m时,对应的实际内存使用量(tempMem#在脚本中)将为取决于定义了多少线程(mt在表中,%cyclezipPPMdt%在脚本中)。

该序列set "memcyclezipPPMdd=258 130 66 34 18 10 6 4 3"来自该表的最后一列。

4

2 回答 2

1
CALL set cyclezipPPMdd=%%cyclezipPPMdd!cycleCount!%%

代替你set cyclezipPPMdd=...似乎做你想做的事。

说明要解决的问题可能会更好,因为您的解决方案似乎过于复杂。我想你有理由不想把warandpeace写成变量名......

@ECHO OFF
setlocal enableDelayedExpansion

: part1
set "cyclezipPPMdd0=256m 128m 64m 32m 16m 8m 4m 2m 1m"
set "memcyclezipPPMdd=258 130 66 34 18 10 6 4 3"

set /a anotherCounter=0
for %%i in (%cyclezipPPMdd0%) do (
  set /a anotherCounter+=1
  set cyclezipPPMdd!anotherCounter!=%%i
)
set /a cycleCount=0

: part2
for %%i in (%memcyclezipPPMdd%) do (
  set /a cycleCount+=1
  set tempMem!cycleCount!=%%i
  CALL set cyclezipPPMdd=%%cyclezipPPMdd!cycleCount!%%
  set cyclezipPPMdd
  pause
)
SET cyclecount
SET anothercounter
pause
set /a anotherCounter=0
set /a cycleCount=0

GOTO :EOF

似乎会产生相同的结果。请注意,!var!= %var%outside of forloops whenenabledelayedexpansion生效。

这也将cyclecount和设置anothercounter为有用的值 - 变量中的元素数。

逐节进行,下面的演示应该向您展示一些技术:

首先,按照您的要求提取到cyclezipPPMdd。

然后是 cyclezipPPMdd 和cyclezipPPMdd#,其中包含 中的相应条目tempmem,您似乎没有在代码中使用这些条目。

然后从两个列表中获取不同的条目。

请注意,替换序列很关键。首先替换元变量(%%x用于主动循环控制和 %n 用于参数编号)!

@ECHO OFF
setlocal enableDelayedExpansion

: part1
set "cyclezipPPMdd0=256m 128m 64m 32m 16m 8m 4m 2m 1m"
set "memcyclezipPPMdd=258 130 66 34 18 10 6 4 3"

set /a anotherCounter=0
for %%i in (%cyclezipPPMdd0%) do (
  set /a anotherCounter+=1
  set cyclezipPPMdd!anotherCounter!=%%i
)
set /a cycleCount=0

: part2
for %%i in (%memcyclezipPPMdd%) do (
  set /a cycleCount+=1
  set tempMem!cycleCount!=%%i
)
for /l %%i in (1,1,%cyclecount%) do (
  CALL set cyclezipPPMdd=%%cyclezipPPMdd%%i%%
  set cyclezipPPMdd
  pause
)
for %%i in (1,7,4,2) do (
  CALL set cyclezipPPMdd=%%cyclezipPPMdd%%i%%
  CALL set cyclezipPPMdd#=%%tempMem%%i%%
  set cyclezipPPMdd
  pause
)
for %%i in (1,7,4,2) do (
 FOR %%j IN (2 6) DO (
  CALL :setz %%i %%j
  SET z
  PAUSE
 )
)
SET cyclecount
SET anothercounter
pause
set /a anotherCounter=0
set /a cycleCount=0

GOTO :EOF

:setz
CALL set zcyclezipPPMdd=%%cyclezipPPMdd%1%% [%1]
CALL set ztempmem=%%tempMem%2%% [%2]
GOTO :eof
于 2013-11-04T02:06:03.223 回答
0

我能够做到!目前完整的脚本如下所示:

@echo off
setlocal enableDelayedExpansion

set "maxMem=8192"
set "maxThreads=!NUMBER_OF_PROCESSORS!"
set "memSum=0"
set "memRem="
if not defined memRem set "memRem=!maxMem!"

set "cycle7zBZip2="
set "cyclezipBZip2="
set "cyclezipDeflate64="
set "cyclezipDeflate="
set "cyclezipPPMd="
set "cycle7zLZMA="
set "cycle7zLZMA2="
set "cycle7zPPMd="
set "cyclezipLZMA="

set "maxProc="
set /a "maxProc=maxThreads"

:7zBZip2
set "cycle7zBZip2=1"
set "cycle7zBZip2x=9"
set "cycle7zBZip2t=1"
set /a "tempProc=maxThreads/cycle7zBZip2t"
set "cycle7zBZip2d=900k"
set "tempMem1=39"
set "cycle7zBZip2s=on"
set /a "cycleCount=1"
call :prepareCycle
set "cycle7zBZip2="

:zipBZip2
set "cyclezipBZip2=1"
set "cyclezipBZip2x=9"
set "cyclezipBZip2t=1"
set /a "tempProc=maxThreads/cyclezipBZip2t"
set "cyclezipBZip2d=900k"
set "tempMem1=10"
set /a "cycleCount=1"
call :prepareCycle
set "cyclezipBZip2="

:zipDeflate64
set "cyclezipDeflate64=1"
set "cyclezipDeflate64x=9"
set "cyclezipDeflate64t=1"
set /a "tempProc=maxThreads/cyclezipDeflate64t"
set "cyclezipDeflate64w=257 256 192 128 96 64 48 32 24 16 12 8"
set "tempMem1=4"
set /a "cycleCount=1"
call :prepareCycle
set "cyclezipDeflate64="

:zipDeflate
set "cyclezipDeflate=1"
set "cyclezipDeflatex=9"
set "cyclezipDeflatet=1"
set /a "tempProc=maxThreads/cyclezipDeflatet"
set "cyclezipDeflatew=258 256 192 128 96 64 48 32 24 16 12 8"
set "tempMem1=4"
set /a "cycleCount=1"
call :prepareCycle
set "cyclezipDeflate="

:zipPPMd
set "cyclezipPPMd=1"
set "cyclezipPPMdx=9"
set "cyclezipPPMdt=1"
set /a "tempProc=maxThreads/cyclezipPPMdt"
set "cyclezipPPMdd0=256m 128m 64m 32m 16m 8m 4m 2m 1m"
set /a "anotherCounter=0"
set tempCycle=!cyclezipPPMdd0: =^

!
for /f %%i in ("!tempCycle!") do (
  set /a anotherCounter+=1
  set tempCycle!anotherCounter!=%%i
)
set /a "anotherCounter=0"
set "cyclezipPPMdw=16 15 14 13 12 11 10 9 8 7 6 5 4 3 2"
set "memcyclezipPPMdd=258 130 66 34 18 10 6 4 3"
set tempMem=!memcyclezipPPMdd: =^

!
for /f %%i in ("!tempMem!") do (
  set /a cycleCount+=1
  set tempMem!cycleCount!=%%i
)
call :prepareCycle
set "cyclezipPPMd="

:7zLZMA
set "cycle7zLZMA=1"
set "cycle7zLZMAx=9"
set "cycle7zLZMAt=1"
set /a "tempProc=maxThreads/cycle7zLZMAt"
set "cycle7zLZMAd=512m"
set "cycle7zLZMAw=273 256 192 128 96 64 48 32 24 16 12 8"
set "cycle7zLZMAs=on"
set "tempMem1=5407"
set /a "cycleCount=1"
call :prepareCycle
set "cycle7zLZMA="

:7zLZMA2
set "cycle7zLZMA2=1"
set "cycle7zLZMA2x=9"
set "cycle7zLZMA2t=1"
set /a "tempProc=maxThreads/cycle7zLZMA2t"
set "cycle7zLZMA2d=512m"
set "cycle7zLZMA2w=273 256 192 128 96 64 48 32 24 16 12 8"
set "cycle7zLZMA2s=on"
set "tempMem1=5407"
set /a "cycleCount=1"
call :prepareCycle
set "cycle7zLZMA2="

:7zPPMd
set "cycle7zPPMd=1"
set "cycle7zPPMdx=9"
set /a "tempProc=maxThreads/1"
set "cycle7zPPMdd0=1024m 768m 512m 384m 256m 192m 128m 96m 64m 48m 32m 24m 16m 12m 8m 6m 4m 3m 2m 1m"
set /a "anotherCounter=0"
set tempCycle=!cycle7zPPMdd0: =^

!
for /f %%i in ("!tempCycle!") do (
  set /a anotherCounter+=1
  set tempCycle!anotherCounter!=%%i
)
set /a "anotherCounter=0"
set "cycle7zPPMdw=32 28 24 20 16 14 12 10 8 7 6 5 4 3 2"
set "cycle7zPPMds=on"
set "memcycle7zPPMdd=1055 799 543 415 287 223 159 127 95 79 63 55 47 43 39 37 35 34 33 32"
set tempMem=!memcycle7zPPMdd: =^

!
for /f %%i in ("!tempMem!") do (
  set /a cycleCount+=1
  set tempMem!cycleCount!=%%i
)
call :prepareCycle
set "cycle7zPPMd="

:zipLZMA
set "cyclezipLZMA=1"
set "cyclezipLZMAx=9"
set "cyclezipLZMAt=1"
set /a "tempProc=maxThreads/cyclezipLZMAt"
set "cyclezipLZMAd=512m"
set "cyclezipLZMAw=273 256 192 128 96 64 48 32 24 16 12 8"
set "tempMem1=5378"
set /a "cycleCount=1"
call :prepareCycle
set "cyclezipLZMA="

goto :fim

:prepareCycle
for /l %%N in (1 1 %cycleCount%) DO (set "tempProc%%N=")
for /l %%N in (1 1 %cycleCount%) DO (
  if defined cycle7zBZip2 echo something
  if defined cyclezipBZip2 echo something
  if defined cyclezipDeflate64 echo something
  if defined cyclezipDeflate echo something
  if defined cyclezipPPMd set "cyclezipPPMdd=!tempCycle%%N!"
  if defined cycle7zLZMA echo something
  if defined cycle7zLZMA2 echo something
  if defined cycle7zPPMd set "cycle7zPPMdd=!tempCycle%%N!"
  if defined cyclezipLZMA echo something
  set /a "tempProc%%N=%memRem%/tempMem%%N"
  if !tempProc%%N! gtr %maxProc% set "tempProc%%N=%maxProc%"
  set /a "memSum+=tempMem%%N*tempProc%%N"
  set /a "memRem-=tempMem%%N*tempProc%%N"
  set tempProc=!tempProc%%N!
  call :prepareProc
  set /a "memRem+=tempMem%%N*tempProc%%N"
  set /a "memSum-=tempMem%%N*tempProc%%N"
)
set /a "cycleCount=0"
exit /b

:prepareProc
    set "lock=lock_%random%_"
    set /a "startCount=0, endCount=0"
    for /l %%N in (1 1 %tempProc%) DO set "endProc%%N="
    set launch=1
    if defined cycle7zBZip2 (
      for %%x IN (%cycle7zBZip2x%) DO for %%t IN (%cycle7zBZip2t%) DO for %%d IN (%cycle7zBZip2d%) DO for %%s IN (%cycle7zBZip2s%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.bzip2.%%tt.%%dd.%%ss.7z .\teste.original\* -mx=%%x -ms=%%s -m0=BZip2:d=%%d:mt=%%t"
        call :executeProc
      )
     )
    if defined cyclezipBzip2 (
      for %%x IN (%cyclezipBZip2x%) DO for %%t IN (%cyclezipBZip2t%) DO for %%d IN (%cyclezipBZip2d%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.bzip2.%%tt.%%dd.zip .\teste.original\* -mx=%%x -mm=BZip2:d=%%d -mmt=%%t"
        call :executeProc
      )
    )
    if defined cyclezipDeflate64 (
      for %%x IN (%cyclezipDeflate64x%) DO for %%t IN (%cyclezipDeflate64t%) DO for %%w IN (%cyclezipDeflate64w%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.deflate64.%%tt.%%ww.zip .\teste.original\* -mx=%%x -mm=deflate64:fb=%%w -mmt=%%t"
        call :executeProc
      )
    )
    if defined cyclezipDeflate (
      for %%x IN (%cyclezipDeflatex%) DO for %%t IN (%cyclezipDeflatet%) DO for %%w IN (%cyclezipDeflatew%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.deflate.%%tt.%%ww.zip .\teste.original\* -mx=%%x -mm=deflate:fb=%%w -mmt=%%t"
        call :executeProc
      )
    )
    if defined cyclezipPPMd (
      for %%x IN (%cyclezipPPMdx%) DO for %%t IN (%cyclezipPPMdt%) DO for %%d IN (%cyclezipPPMdd%) DO for %%w IN (%cyclezipPPMdw%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.ppmd.%%tt.%%dd.%%ww.zip .\teste.original\* -mx=%%x -mm=PPMd:mem=%%d:o=%%w -mmt=%%t"
        call :executeProc
      )
    )
    if defined cycle7zLZMA (
      for %%x IN (%cycle7zLZMAx%) DO for %%t IN (%cycle7zLZMAt%) DO for %%d IN (%cycle7zLZMAd%) DO for %%w IN (%cycle7zLZMAw%) DO for %%s IN (%cycle7zLZMAs%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.lzma.%%tt.%%dd.%%ww.%%ss.7z .\teste.original\* -mx=%%x -ms=%%s -m0=LZMA:d=%%d:fb=%%w -mmt=%%t"
        call :executeProc
      )
    )
    if defined cycle7zLZMA2 (
      for %%x IN (%cycle7zLZMA2x%) DO for %%t IN (%cycle7zLZMA2t%) DO for %%d IN (%cycle7zLZMA2d%) DO for %%w IN (%cycle7zLZMA2w%) DO for %%s IN (%cycle7zLZMA2s%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.lzma2.%%tt.%%dd.%%ww.%%ss.7z .\teste.original\* -mx=%%x -ms=%%s -m0=lzma2:d=%%d:fb=%%w -mmt=%%t"
        call :executeProc
      )
    )
    if defined cycle7zPPMd (
      for %%x IN (%cycle7zPPMdx%) DO for %%d IN (%cycle7zPPMdd%) DO for %%w IN (%cycle7zPPMdw%) DO for %%s IN (%cycle7zPPMds%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.ppmd.%%dd.%%ww.%%ss.7z .\teste.original\* -mx=%%x -m0=PPMd:mem=%%d:o=%%w -ms=%%s"
        call :executeProc
      )
    )
    if defined cyclezipLZMA (
      for %%x IN (%cyclezipLZMAx%) DO for %%t IN (%cyclezipLZMAt%) DO for %%d IN (%cyclezipLZMAd%) DO for %%w IN (%cyclezipLZMAw%) DO (
        set "cmd=7z.exe a teste.resultado\%%xx.lzma.%%tt.%%dd.%%ww.zip .\teste.original\* -mx=%%x -mm=lzma:d=%%d:fb=%%w -mmt=%%t"
        call :executeProc
      )
    )
    set "launch="
    goto :wait

:executeProc
        if !startCount! lss %tempProc%  (
          set /a "startCount+=1, nextProc=startCount"
        ) else (
          call :wait
        )
        set cmd!nextProc!=!cmd!
        echo !time! - proc!nextProc!: starting !cmd!
        2>nul del %lock%!nextProc!
        start /b /low cmd /c !cmd!>"%lock%!nextProc!"
        exit /b

:wait
          for /l %%N in (1 1 %startCount%) do (
            if not defined endProc%%N if exist "%lock%%%N" (
              echo !time! - proc%%N: finished !cmd%%N!
              if defined launch (
                set nextProc=%%N
                exit /b
              )
              set /a "endCount+=1, endProc%%N=1"
            ) 9>>"%lock%%%N"
          ) 2>nul
          if %endCount% lss %startCount% (
            rem 1>nul 2>nul ping /n 2 ::1
            goto :wait
          )
          2>nul del %lock%*
          echo ===
          echo Thats all folks!
          exit /b

:fim
echo fim
pause
exit

此示例可以正常工作!与本主题的特定问题有关的部分位于:zipPPMd。我使用了%cycleCount%to set cyclezipPPMdd。它位于:prepareCycle部分。这是使它起作用的那一行:if defined cyclezipPPMd set "cyclezipPPMdd=!tempCycle%%N!"

但这还远远没有结束。有些变量现在可能没有意义,因为它正在进行中。我已将此示例的所有算法上的线程使用率强制为 1,但我真正想要的是设置为所有这些,从 1 到 8。再说一次,我仍然不知道如何检查脚本是否可以运行另一个在一个或几个其他人正在运行时循环并决定何时运行它们。它需要跟踪当前正在使用的线程数和内存来决定。

于 2013-11-05T01:37:48.327 回答