Announcement

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

  • Running multiple instances of Stata from the same do-file

    I'm trying to loop through many different items. I understand that, computer power permitting, two Stata windows running half of the loop separately and simultaneously would run quicker than a single instance of Stata (this is based on other posts I have seen on this forum, please correct me if I'm wrong). Since the results are not dependent on each other, these could theoretically be separate do-files, one for each part of the loop.

    I was wondering if it was possible to run multiple instances of Stata from the same do-file, essentially running two different do-files from the same master do-file simultaneously in different windows.

  • #2
    1. Yes, it is possible. You can start a different Stata session from your do file, just like starting any other executable, and you can pass a dofilename to execute in a command line.
    2. For your particular use scenario, solutions have been developed to facilitate parallel execution of Stata code, such as -parallel- by George Vega Yon.
    Best, Sergiy Radyakin

    Comment


    • #3
      Hi Sergiy, I have found that even using the shell command to run a do-file does not enable it to move on until the current do-file is complete. Do you which command will run these separate do-files simulatenously?

      Comment


      • #4
        Hi,

        You can indeed use parallel for such task (running several do-files simultaneously), take the following example, assuming that I have dofiles called mydofile1.do to mydofile3.do

        Code:
        clear all
        set more off
        set trace off
        
        parallel setclusters 3
        
        program def myprogram
            if ($pll_instance == 1) do "mydofile1.do"
            else if ($pll_instance == 2) do "mydofile2.do"
            else if ($pll_instance == 3) do "mydofile3.do"
        end
        
        parallel, nodata prog(myprogram): myprogram
        If you run this code asis (without having the mentioned do files) you get this:

        Code:
        . parallel, nodata prog(myprogram): myprogram
        --------------------------------------------------------------------------------
        Exporting the following program(s): myprogram
        
        myprogram:
          1.     if ($pll_instance == 1) do "mydofile1.do"
          2.     else if ($pll_instance == 2) do "mydofile2.do"
          3.     else if ($pll_instance == 3) do "mydofile3.do"
        --------------------------------------------------------------------------------
        --------------------------------------------------------------------------------
        Parallel Computing with Stata (by GVY)
        Clusters   : 3
        pll_id     : k3z1z3qry5
        Running at : /home/george
        Randtype   : datetime
        
        Waiting for the clusters to finish...
        cluster 0001 Exited with error -601- while running the command/dofile (view log)...
        cluster 0002 Exited with error -601- while running the command/dofile (view log)...
        cluster 0003 Exited with error -601- while running the command/dofile (view log)...
        --------------------------------------------------------------------------------
        Enter -parallel printlog #- to checkout logfiles.
        --------------------------------------------------------------------------------
        3 child processes encountered errors. Throwing last error.
        file not found
        r(601);
        Since I have no files called like that in my folder.

        HIH

        George

        Comment


        • #5
          George Vega does parallel work on unix servers? I tired but I'm getting an error message which I can't understand so I assume it doesn't. I just wanted to make sure!

          Comment


          • #6
            Originally posted by Trevor Andrew View Post
            George Vega does parallel work on unix servers? I tired but I'm getting an error message which I can't understand so I assume it doesn't. I just wanted to make sure!
            Certainly, I only use Unix systems

            PS: Thanks for your patience!

            Comment

            Working...
            X