PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/batch/run1fsp.bat

http://josh-phd-code.googlecode.com/
Batch | 173 lines | 120 code | 20 blank | 33 comment | 10 complexity | 138da474438cfca4fab96831cfdc761f MD5 | raw file
  1. @echo off
  2. call :getsectime
  3. REM create log file if it doesn't exist already, then add a new section
  4. set run1fsplog=run1fsp.log
  5. if not exist %run1fsplog% touch %run1fsplog%
  6. echo -------------------------------------------------------------------------------- >> %run1fsplog%
  7. echo New run1fsp job starting at %time% on %date% >> %run1fsplog%
  8. if "%1"=="" goto :usage
  9. REM email address specified
  10. if "%1" == "-e" (
  11. if "%2"=="" (
  12. echo Error: missing email address!
  13. echo Error: missing email address! >> %run1fsplog%
  14. echo -------------------------------------------------------------------------------- >> %run1fsplog%
  15. echo.
  16. goto :usage
  17. )
  18. if "%3"=="" (
  19. echo Error: missing file!
  20. echo Error: missing file! >> %run1fsplog%
  21. echo arguments supplied were: >> %run1fsplog%
  22. echo %%1=%1 >> %run1fsplog%
  23. echo %%2=%2 >> %run1fsplog%
  24. echo %%3=%3 >> %run1fsplog%
  25. echo -------------------------------------------------------------------------------- >> %run1fsplog%
  26. echo.
  27. goto :usage
  28. )
  29. REM test to see if there's an @ symbol (simple check to see if it's an email address)
  30. set testval=%2
  31. REM remove anything before @
  32. set testval=%testval:*@=%
  33. REM limit testval to length 1
  34. set testval=%testval:~0,1%
  35. if not "%testval%"=="@" (
  36. echo Error: missing @ in email address!
  37. echo Error: missing @ in email address! >> %run1fsplog%
  38. echo -------------------------------------------------------------------------------- >> %run1fsplog%
  39. echo.
  40. goto :usage
  41. )
  42. REM set email to address
  43. set to=%2
  44. REM get rid of email arguments
  45. shift
  46. shift
  47. )
  48. set _params=%*
  49. call :namesetter "%_params%"
  50. REM add job-start to log
  51. echo Starting job on file %filename%, located in directory >> %run1fsplog%
  52. echo %filepath% >> %run1fsplog%
  53. REM pw for gmail account
  54. set pw=beaming2009
  55. REM username & from address for gmail account
  56. set from=masimulation1@gmail.com
  57. REM default to: address
  58. set to=jcb91@cam.ac.uk
  59. REM determines the log file name - _p0 is added because it's the log from
  60. :: process 0. I guess you could also add logs from other processes as
  61. :: attachments, but they're only necessary if something's gone very wrong
  62. :: anyway.
  63. set logfile=%filename:.fsp=%_p0.log
  64. REM server for blat. This server is the STunnel listener for encryption.
  65. set serv=127.0.0.1
  66. REM subject line for success email
  67. set successmsg=Simulation '%filename%' has completed successfully
  68. REM subject line for failure email
  69. set failmsg=Simulation '%filename%' has ended unexpectedly!
  70. REM copy file to uncompleted location
  71. :: set compfile=%date:~6,4%%date:~3,2%%date:~0,2%_completed
  72. ::if not exist "%compfile%" md "%compfile%" > NUL
  73. ::copy "%filename%" "u_%filename%" > NUL
  74. call :getsectime
  75. set /a starttime=sectime > NUL
  76. echo starting job at %time% on %date% >> %run1fsplog%
  77. echo on
  78. "C:\Program Files\Lumerical\FDTD\bin\..\mpich2\mpiexec" -channel nemesis -n 8 -binding user:4,7,6,5,0,3,2,1 "C:\Program Files\Lumerical\FDTD\bin\FDTD-par" -fullinfo -logall "'%1'"
  79. @echo off
  80. REM %errorlevel% is set by the previous command.
  81. if %errorlevel% == 0 goto :success
  82. : failure
  83. echo job failure at %time% on %date% >> %run1fsplog%
  84. echo emailing logs to %to% >> %run1fsplog%
  85. REM email failure notice with logfile, or if there's an error (probably opening
  86. :: the log), email without it.
  87. blat %logfile% -server %serv% -f %from% -u %from% -pw %pw% -to %to% -subject "%failmsg%" -q || ^
  88. blat -body "log file unavailable!" -server %serv% -f %from% -u %from% -pw %pw% -to %to% -subject "%failmsg%" >> %run1fsplog%
  89. REM exit code so a multiple-job runner knows it's failed
  90. echo exiting with error code 1 >> %run1fsplog%
  91. echo -------------------------------------------------------------------------------- >> %run1fsplog%
  92. echo.
  93. exit /B 1
  94. : success
  95. echo finished job at %time% on %date% >> %run1fsplog%
  96. REM calculate the time taken (assuming no days!)
  97. call :getsectime
  98. set /a diff=sectime-starttime > NUL
  99. call :gethrmnsctime %diff%
  100. echo job took %hr% hours, %mn% minutes and %sc% seconds
  101. REM email success notice with logfile
  102. blat %logfile% -server %serv% -f %from% -u %from% -pw %pw% -to %to% -subject "%successmsg% in %hr%:%mn%:%sc%" >> %run1fsplog%
  103. REM delete p1-7 log files, pausing first to allow them to be left alone by the fdtd-par process
  104. ping -n 3 127.0.0.1>nul
  105. del %filename:.fsp=%_p1.log
  106. del %filename:.fsp=%_p2.log
  107. del %filename:.fsp=%_p3.log
  108. del %filename:.fsp=%_p4.log
  109. del %filename:.fsp=%_p5.log
  110. del %filename:.fsp=%_p6.log
  111. del %filename:.fsp=%_p7.log
  112. REM exit code so a multiple-job runner knows it's succeeded
  113. echo exiting with 0 error code >> %run1fsplog%
  114. echo -------------------------------------------------------------------------------- >> %run1fsplog%
  115. echo.
  116. start/min mplay32 /play /close %windir%\media\ding.wav
  117. exit /B 0
  118. : usage
  119. echo This batch script will execute a single .fsp file in parallel mode on 8 cores,
  120. echo then email the result to a specified address (defaults to jcb91@cam.ac.uk).
  121. echo syntax:
  122. echo run1fsp (-e [email]) [filename]
  123. echo runs the fsp file [filename], notifying email address [email] if
  124. echo specified (otherwise default email is used). Filenames with spaces
  125. echo should be enclosed in double quotes
  126. goto :eof
  127. :namesetter
  128. :: just set names
  129. REM gets the drive letter & path
  130. set filepath=%~d1%~p1
  131. REM gets the unqualified filename
  132. set filename=%~n1%~x1
  133. goto :eof
  134. :getsectime
  135. set year=%date:~6,4%
  136. set month=%date:~3,2%
  137. set day=%date:~0,2%
  138. set hr=%time:~0,2%
  139. set mn=%time:~3,2%
  140. set sc=%time:~6,2%
  141. set /a sectime=day*86400+hr*3600+mn*60+sc > NUL
  142. goto :eof
  143. :gethrmnsctime
  144. set _var=%1
  145. echo gethrminsec %_var%
  146. set /a day=_var/86400 > NUL
  147. set /a _var=_var%86400 > NUL
  148. set /a hr=_var/3600 > NUL
  149. set /a _var=_var%3600 > NUL
  150. set /a mn=_var/60 > NUL
  151. set /a _var=_var%60 > NUL
  152. set /a sc=_var > NUL
  153. goto :eof