Re: Self-abort/protective code for bootstrapping
Shelley,
You can pass control to the operation system that will do it. Below is the part of code that I use in Windows OS. R is continuously looking for a number of processes of nonmem.exe program. It starts the next run only if this number is below the number of CPUs. It also checks for the run time of each process, and kills it if it is too large.
sleepTime maxRunTimeChar nCPU parameters should be defined earlier.
Leonid
wait <- F
nruns <- nCPU+1
while(nruns >= nCPU) {
Sys.sleep(sleepTime)
SystemCommand <- paste('tasklist /fi "CPUtime gt "', maxRunTimeChar,'"',sep="")
LongTasklist <- data.frame(full= system(SystemCommand,intern=T))
LongTasklist$name <- substring(LongTasklist$full,1,6)
LongTasklist$pid <- as.double(substring(LongTasklist$full,27,33))
LongTasklist <- LongTasklist[!is.na(LongTasklist$pid) &
LongTasklist$name == "nonmem",]
if(length(LongTasklist$pid) > 0) for( pid in LongTasklist$pid) {
killCommand <- paste("taskkill /F /PID",pid)
system(paste("taskkill /F /PID",pid))
}
tasklist <- data.frame(full=system("tasklist",intern=T))
tasklist$name <- substring(tasklist$full,1,6)
tasklist$pid <- as.double(substring(tasklist$full,27,33))
tasklist <- tasklist[!is.na(tasklist$pid) & tasklist$name == "nonmem",]
nruns <- sum(tasklist$name == "nonmem")
}
nonmemCommand <- paste("perl BatchNM7.p ",BootstrapDir,"Temp.boot/ ",runNumber,sep="")
system(nonmemCommand,wait=wait)
--------------------------------------
Leonid Gibiansky, Ph.D.
President, QuantPharm LLC
web: www.quantpharm.com
e-mail: LGibiansky at quantpharm.com
tel: (301) 767 5566
Quoted reply history
On 7/28/2011 7:08 AM, Xiao Hu wrote:
> Dear NMusers,
>
> I’m running an automated sequential PK/PD bootstrapping in R. Generally,
> it takes 15 minutes for each run. However Run #195 has taken over 10
> hours and been stuck between Iterations NO 5 and NO 10. Is there a way
> to code NONMEM for self-abort if it gets stuck, so that R can start the
> next run?
>
> Best regards,
>
> Shelley
>
> =============================================
>
> Xiao Hu (Shelley)
>
> Senior Scientist
>
> Clinical Pharmacology and Pharmacometrics
>
> Department of Translational Medicine
>
> Biogen Idec,
>
> 14 Cambridge Center, Cambridge, MA 02142