Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Finding out computer's RAM memory

    Is there a good way to determine total RAM memory in the computer a Stata program is using?

    Some shell commands provide this information for specific platforms, as I find from an Internet search, but I am unsure which shell commands would work reliably across newer and older system versions (and my expertise with complex shell commands is limited).

    I am interested in doing this for Stata 11 through 14, on all platforms (Windows/Mac/Unix).

    ​My goal is to adapt program behavior if Stata is in danger of exceeding available RAM.

  • #2
    look at c(memory) (part of creturn list), as in
    Code:
    . di c(memory)
    33554432

    Comment


    • #3
      I appreciate Rich Goldstein's suggestion. However, c(memory) displays the amount of memory currently allocated by Stata, not the amount of RAM memory in the computer.

      Related is c(max_memory), which displays Stata's maximum allowable memory usage if the user set a maximum, but by default c(max_memory) is missing, i.e., infinite.

      I want to determine the physical amount of RAM in the computer (or some other measure of how much memory could be used on the computer without causing excessive virtual memory use).

      Comment


      • #4
        Rich Goldstein , I think Ken Simons wants Grand Total to make sure there is no swapping. c(memory) may report a smaller number, for example:
        Code:
                                                          bytes
        --------------------------------------------------------------------
        Details of set memory usage
            overhead (pointers)                               0        0.00%
            data                                              0        0.00%
                                                ----------------------------
            data + overhead                                   0        0.00%
            free                                     10,485,752      100.00%
                                                ----------------------------
            Total allocated                          10,485,752      100.00%
        --------------------------------------------------------------------
        Other memory usage
            set maxvar usage                          2,001,730
            set matsize usage                         1,315,200
            programs, saved results, etc.           968,000,598
                                                ---------------
            Total                                   971,317,528
        -------------------------------------------------------
        Grand total                                 981,803,280
        I think the task is fundamentally challenging, especially in multitasking, multiuser environments (shared servers, VMs, etc).
        Even if Stata is allocating less than reported physical memory, it may still be competing with other processes that you can't query with Stata's own means. The solution is likely to be platform-specific, since it should call OS-specific memory control functions for availability (which is different from standard crossplatform portable malloc() in C).

        On Windows you can do it with a user-written plugin-based -sysinfo-.

        Best, Sergiy Radyakin

        Comment


        • #5
          Thank you also to Sergiy Radyakin, whose post is helpful to determine Stata's usage. My original post should have been worded very carefully:

          In the computer a Stata program is using, is there a good way to determine total physical RAM memory?

          That is, how can one effectively determine RAM of the computer, regardless of what Stata is doing?

          Sergiy's plugin answers this question for Windows computers. That leaves Mac, Unix, and Linux computers. Also I would rather not have to make users rely on another plugin, so a shell script may be the necessary approach.
          Last edited by Ken Simons; 29 Apr 2015, 13:54.

          Comment


          • #6
            Shell commands that get the system memory are listed below for Windows and Mac. I also provide a link to a web page with Unix/Linux commands, but I lack the systems to test the commands for Unix/Linux, so I cannot confirm whether and how the Unix/Linux commands work.

            The Windows command uses the program "wmic", which sometimes requires administrator access, but seemingly (I could be wrong) does not need administrator access to get the RAM amount:
            Code:
            shell wmic memorychip get capacity > mytempfilename.txt
            The resulting file consists of one line with the text "Capacity ", followed by one line per RAM memory chip each with a number equal to the chip's capacity in bytes (some spaces may follow each number, and there is a final carriage return - line feed after the last line). The file can be read in using Stata's file open, file read, and file close commands. The command executes very quickly. I tested use of "wmic" in Windows 7 only.

            The Mac command uses the program "hostinfo", which seems to have been around since the introduction of OS X. I also used the grep command, also available on old and new versions of OS X, to extract the relevant line. Use of grep is optional, since the extraction of the relevant line could more efficiently be done in Stata. The command is:
            Code:
            shell hostinfo | grep memory > mytempfilename.txt
            The resulting file consists of one line saying, for example, "Primary memory available: 16.00 gigabytes", followed by a carriage return. Again, the file can be read in using Stata's file open, file read, and file close commands. The command required less than 1/10 second for the hostinfo command plus less than 1/10 second for the grep command on an old Power Mac running OS X 10.9.5, although on one occasion the commands seemed to take a bit over 1/2 second total on a machine running OS X 10.10.2 (perhaps because I was running too many programs).

            Unix/Linux commands, which I lack the means to try out, are suggested on this web page:
            http://wiki.scn.sap.com/wiki/display...+Linux+Systems

            Thanks again for the suggestions from Rich Goldstein and Sergiy Radyakin. Any other suggestions or test results will be much appreciated.

            Comment

            Working...
            X