POV-Ray : Newsgroups : povray.general : Scripts for Parallel Rendering of Animations : Re: Scripts for Parallel Rendering of Animations Server Time
29 Jul 2024 10:30:13 EDT (-0400)
  Re: Scripts for Parallel Rendering of Animations  
From: Verklagekasper
Date: 28 Oct 2011 12:40:00
Message: <web.4eaad98df89e5a3fa72d194a0@news.povray.org>
Hi Dave,

I just figured out the equivalent of the locking mechanism in DOS. I thought it
was impossible, but then I found that the mkdir command provides feedback on its
succes through setting the "errorlevel" environment variable, which is local in
each DOS shell:

:lock
md lockdir
if errorlevel 1 (
   rem ping seems the only "sleep" command availabe on all Windows versions
   ping -n 2 127.0.0.1 >NUL
   goto lock
)
goto:eof

:unlock
rd lockdir
goto:eof

I tested it with Windows XP, Windows Vista, and Windows 7, and it works.

Here are the new versions of the builder scripts that include the lock mechanism
to prevent processes from rendering the same image file:

------------------------------------------
@rem builder.bat
@rem
@rem Variables to be defined:
@rem povray  - The path of the Povray executable.
@rem povname - The name of the scene to render, without extension.
@rem digits  - The number of digits in the index of the image files.
@rem suffix  - The extension of the image files, eg. png.
@rem s       - Number of the initial frame.
@rem e       - Number of the final frame.
@rem
@rem Author: Burkhard Reike, 2011-10-28

@echo off
setLocal EnableDelayedExpansion

set
povray="C:\Users\Burkhard\AppData\Roaming\POV-Ray\v3.6\bin\pvengine-sse2.exe"
set povname=landscape
set digits=5
set suffix=png
set s=1
set e=13741

echo Starting: %computername% %date% %time% >> render.log
set lockdir=%povname%.lck
for /L %%c in (%s%,1,%e%) do (
  set padcntr=0000000000%%c
  set filename=!povname!!padcntr:~-%digits%!
  call :Lock
  if not exist !filename!.%suffix% (
    type NUL > !filename!.%suffix%
    call :Unlock
    call :GetTime
    set starttime=!cseconds!
    start /WAIT /min "Render" %povray% -d +SF%%c +EF%%c /exit +I %povname%.ini
    call :GetTime
    set endtime=!cseconds!
    if !endtime! LSS !starttime! set /a endtime+=8640000
    set /a elapsed=!endtime!-!starttime!
    set /a elapsed/=100
    echo !filename!.%suffix% !elapsed! %computername% >> render.log
  ) else (
    call :Unlock
  )
)

echo Finished: %computername% %date% %time% >> render.log
goto:eof

:GetTime
for /f "usebackq tokens=1-4 delims=:., " %%f in (`echo.%time%`) do (
  set temp=%%f %%g %%h %%i
)
for /f "usebackq tokens=1-4" %%f in (`echo %temp: 0= %`) do (
  set /a cseconds=%%f*360000+%%g*6000+%%h*100+%%i
)
goto:eof

:Lock
md %lockdir%
if errorlevel 1 (
   rem ping seems the only "sleep" command availabe on all Windows versions
   ping -n 2 127.0.0.1 >NUL
   goto Lock
)
goto:eof

:Unlock
rd %lockdir%
goto:eof

------------------------------------------
#!/bin/bash
# builder.sh
#
# Variables to be defined:
# POVNAME - The name of the scene to render, without extension.
# DIGITS  - The number of digits in the index of the image files.
# SUFFIX  - The extension of the image files, eg. png.
# S       - Number of the initial frame.
# E       - Number of the final frame.
#
# Author: Burkhard Reike, 2011-10-28

echo "Starting: `hostname` `date`" >> render.log

POVNAME=landscape
DIGITS=5
SUFFIX=png
S=1
E=13741

LOCKDIR=$POVNAME.lck
lock() {
   while ! mkdir $LOCKDIR
   do
     sleep 1
   done
}
unlock() {
   rm -fr $LOCKDIR
}

while [ $S -le $E ]; do
    INDEX=`printf "%0"$DIGITS"d" ${S}`
    FILENAME=$POVNAME$INDEX.$SUFFIX
    lock
    if [ ! -f $FILENAME ]; then
        touch $FILENAME
        unlock
        BEFORE="$(date +%s)"
        povray +SF$S +EF$S -d +I $POVNAME.ini &> /dev/null
        AFTER="$(date +%s)"
        ELAPSED="$(expr $AFTER - $BEFORE)"
        echo "$FILENAME $ELAPSED `hostname`" >> render.log
    else
        unlock
    fi
    S=$(($S+1))
done
echo "Finished: `hostname` `date`" >> render.log
------------------------------------------

Cheers,
Burkhard


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.