I am on a shared Unix server and I want to run several Stata jobs in batch mode. I have a loop that generates these batch jobs and executes them. The problem is that all the Stata batch processes are executed simultaneously, overloading the server and depriving my colleagues of much needed memory.
I want to find out how much memory the Unix system has at a given time, then execute if there's enough memory available. I wrote this piece of code to handle that, using Stata-MP 13.1 on Unix
is there another command to get the available memory in a Unix system within Stata?
If it doesn't exist, I will submit this simple program to SSC. Could anyone help with a solution for my freemem program that uses file read instead of using preserve and import delimited to read the vmstat output?
Thank you.
I want to find out how much memory the Unix system has at a given time, then execute if there's enough memory available. I wrote this piece of code to handle that, using Stata-MP 13.1 on Unix
Code:
clear * Program to determine amount of free memory cap program drop freemem program define freemem, rclass preserve quietly { cap erase free.txt - Vmstat gives available memory shell (vmstat)>free.txt clear import delimited free.txt, delimiters("whitespace") rowrange(3:3) varnames(nonames) keep v1 split v1 keep v14 li loc fmem = v14[1] loc fmem = `fmem'/1e6 noi di "`fmem'" return local fmem=`fmem' restore } end * Test; Run regression only if memory exceeds a value loc exceed=164.7 foreach i in a b c d{ loc run=0 while `run'==0 { freemem loc fm=r(fmem) if `fm'>`exceed' { di "Available mem = `fm' - clear to run" sysuse auto, clear reg price mpg loc run=1 } else { di "Memory not available, waiting ..." pause 1000 } } }
If it doesn't exist, I will submit this simple program to SSC. Could anyone help with a solution for my freemem program that uses file read instead of using preserve and import delimited to read the vmstat output?
Thank you.
Comment