Giter Club home page Giter Club logo

parallel's Introduction

parallel

PARALLEL: Stata module for parallel computing

Parallel lets you run Stata faster, sometimes faster than MP itself. By organizing your job in several Stata instances, parallel allows you to work with out-of-the-box parallel computing. Using the the parallel prefix, you can get faster simulations, bootstrapping, reshaping big data, etc. without having to know a thing about parallel computing. With no need of having Stata/MP installed on your computer, parallel has showed to dramatically speedup computations up to two, four, or more times depending on how many processors your computer has.

See the HTML version of the program help file for more info. Other resources include the Stata 2017 conference presentation and the SSC page at Boston College (though the SSC version is a bit out-of-date, see below).

  1. Installation
  2. Minimal examples
  3. Authors

Citation

When using parallel, please include the following:

Vega Yon GG, Quistorff B. parallel: A command for parallel computing. The Stata Journal. 2019;19(3):667-684. doi:10.1177/1536867X19874242

Or use the following bibtex entry:

@article{
  VegaYon2019,
  author = {George G. {Vega Yon} and Brian Quistorff},
  title ={parallel: A command for parallel computing},
  journal = {The Stata Journal},
  volume = {19},
  number = {3},
  pages = {667-684},
  year = {2019},
  doi = {10.1177/1536867X19874242},
  URL = {https://doi.org/10.1177/1536867X19874242},
  eprint = {https://doi.org/10.1177/1536867X19874242}
}

Installation

If you have a previous installation of parallel installed from a different source (SSC, specific folder, specific URL) you should uninstall that first (ado uninstall parallel). Once installed it is suggested to restart Stata.

GitHub

Stable Version

Stata version >=13 can install the latest stable version using a GitHub URL,

net install parallel, from(https://raw.github.com/gvegayon/parallel/stable/) replace
mata mata mlib index

For Stata version <13, download as zip, unzip, and then replace the above URL with the full local path to the files.

Latest Version

To install the latest version (master branch):

net install parallel, from(https://raw.github.com/gvegayon/parallel/master/) replace
mata mata mlib index

To get a zip, go to https://raw.github.com/gvegayon/parallel/master/, click the "Clone or download" button and choose zip.

Older releases

Go to the Releases Page. You can use the release tag to in the URL (e.g., https://raw.github.com/gvegayon/parallel/v1.15.8.19/). See also the associated zip download option.

SSC

An older version is available from the SSC. It does not have all the bug fixes so it is not recommended to install it. If it is required, however, use

ssc install parallel, replace
mata mata mlib index

Minimal examples

The following minimal examples have been written to introduce how to use the module. Please notice that the only examples actually designed to show potential speed gains are parfor and bootstrap.

The examples have been executed on a Dell Vostro 3300 notebook running Ubuntu 14.04 with an Intel Core i5 CPU M 560 (2 physical cores) with 8Gb of RAM, using Stata/IC 12.1 for Unix (Linux 64-bit x86-64).

For more examples and details please refer to the module's help file or the wiki Gallery page.

Simple parallelization of egen

When conducted over groups, parallelizing egen can be useful. In the following example we show how to use parallel with by: egen.

. parallel initialize 2, f
N Clusters: 2
Stata dir:  /usr/local/stata13/stata

. sysuse auto
(1978 Automobile Data)

. parallel, by(foreign): egen maxp = max(price)
-------------------------------------------------------------------------------
Parallel Computing with Stata
Clusters   : 2
pll_id     : m61jt2abc1
Running at : /home/vegayon/Dropbox/repos/parallel
Randtype   : datetime

Waiting for the clusters to finish...
cluster 0001 has exited without error...
cluster 0002 has exited without error...
-------------------------------------------------------------------------------
Enter -parallel printlog #- to checkout logfiles.
-------------------------------------------------------------------------------

. tab maxp

       maxp |      Freq.     Percent        Cum.
------------+-----------------------------------
      12990 |         22       29.73       29.73
      15906 |         52       70.27      100.00
------------+-----------------------------------
      Total |         74      100.00

Which is the ``parallel'' way to do:

. sysuse auto
(1978 Automobile Data)

. bysort foreign: egen maxp = max(price)

. tab maxp

       maxp |      Freq.     Percent        Cum.
------------+-----------------------------------
      12990 |         22       29.73       29.73
      15906 |         52       70.27      100.00
------------+-----------------------------------
      Total |         74      100.00

Bootstrapping

In this example we'll evaluate a regression model using bootstrapping which, together with simulations, is one of the best ways to use parallel

. sysuse auto, clear
(1978 Automobile Data)

. parallel initialize 4, f
N Clusters: 4
Stata dir:  /usr/local/stata13/stata

. timer on 1

. parallel bs, reps(5000): reg price c.weig##c.weigh foreign rep
-------------------------------------------------------------------------------
Parallel Computing with Stata
Clusters   : 4
pll_id     : m61jt2abc1
Running at : /home/vegayon/Dropbox/repos/parallel
Randtype   : datetime

Waiting for the clusters to finish...
cluster 0001 has exited without error...
cluster 0002 has exited without error...
cluster 0003 has exited without error...
cluster 0004 has exited without error...
-------------------------------------------------------------------------------
Enter -parallel printlog #- to checkout logfiles.
-------------------------------------------------------------------------------

parallel bootstrapping                          Number of obs      =        69
                                                Replications       =      5000

      command:  regress price c.weig##c.weigh foreign rep

------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |  -4.317581   3.033419    -1.42   0.155    -10.26297    1.627811
             |
    c.weight#|
    c.weight |   .0012192   .0004827     2.53   0.012     .0002732    .0021653
             |
     foreign |   3155.969   890.4385     3.54   0.000     1410.742    4901.197
       rep78 |  -30.11387   327.7725    -0.09   0.927    -672.5361    612.3084
       _cons |   6415.187   5047.099     1.27   0.204    -3476.945    16307.32
------------------------------------------------------------------------------

. timer off 1

. timer list
   1:     10.59 /        1 =      10.5930
  97:      0.07 /        2 =       0.0340
  98:      0.00 /        1 =       0.0030
  99:     10.52 /        1 =      10.5190

Which is the ``parallel way'' to do:

. sysuse auto, clear
(1978 Automobile Data)

. timer on 2

. bs, reps(5000) nodots: reg price c.weig##c.weigh foreign rep

Linear regression                               Number of obs      =        69
                                                Replications       =      5000
                                                Wald chi2(4)       =     51.13
                                                Prob > chi2        =    0.0000
                                                R-squared          =    0.5622
                                                Adj R-squared      =    0.5348
                                                Root MSE           = 1986.4039

------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
       price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |  -4.317581   3.110807    -1.39   0.165    -10.41465    1.779489
             |
    c.weight#|
    c.weight |   .0012192   .0004951     2.46   0.014     .0002489    .0021896
             |
     foreign |   3155.969   863.9629     3.65   0.000     1462.633    4849.305
       rep78 |  -30.11387   323.6419    -0.09   0.926    -664.4404    604.2127
       _cons |   6415.187    5162.58     1.24   0.214    -3703.285    16533.66
------------------------------------------------------------------------------

. timer off 2

. timer list
   2:     17.78 /        1 =      17.7810

Simulation

From the simulate stata command:

. parallel initialize 2, f
N Clusters: 2
Stata dir:  /usr/local/stata13/stata

. program define lnsim, rclass
  1.   version 12.1
  2.   syntax [, obs(integer 1) mu(real 0) sigma(real 1) ]
  3.   drop _all
  4.   set obs `obs'
  5.   tempvar z
  6.   gen `z' = exp(rnormal(`mu',`sigma'))
  7.   summarize `z'
  8.   return scalar mean = r(mean)
  9.   return scalar Var  = r(Var)
 10. end

. parallel sim, expr(mean=r(mean) var=r(Var)) reps(10000): lnsim, obs(100)
Warning: No data loaded.
-------------------------------------------------------------------------------
> -
Exporting the following program(s): lnsim

lnsim, rclass:
  1.   version 12.1
  2.   syntax [, obs(integer 1) mu(real 0) sigma(real 1) ]
  3.   drop _all
  4.   set obs `obs'
  5.   tempvar z
  6.   gen `z' = exp(rnormal(`mu',`sigma'))
  7.   summarize `z'
  8.   return scalar mean = r(mean)
  9.   return scalar Var = r(Var)
-------------------------------------------------------------------------------
> -
-------------------------------------------------------------------------------
Parallel Computing with Stata
Clusters   : 2
pll_id     : 93mwp9vps1
Running at : /home/vegayon/Dropbox/repos/parallel
Randtype   : datetime

Waiting for the clusters to finish...
cluster 0001 has exited without error...
cluster 0002 has exited without error...
-------------------------------------------------------------------------------
Enter -parallel printlog #- to checkout logfiles.
-------------------------------------------------------------------------------

. 
. summ

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        mean |     10000    1.648843    .2165041   1.021977   2.907977
         var |     10000    4.650656    4.218584   .6159253   133.9232

which is the parallel way to do

. program define lnsim, rclass
  1.   version 12.1
  2.   syntax [, obs(integer 1) mu(real 0) sigma(real 1) ]
  3.   drop _all
  4.   set obs `obs'
  5.   tempvar z
  6.   gen `z' = exp(rnormal(`mu',`sigma'))
  7.   summarize `z'
  8.   return scalar mean = r(mean)
  9.   return scalar Var  = r(Var)
 10. end

. simulate mean=r(mean) var=r(Var), reps(10000) nodots: lnsim, obs(100)

      command:  lnsim, obs(100)
         mean:  r(mean)
          var:  r(V. 
. summ

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        mean |     10000    1.644006    .2133008   1.061809   2.991108
         var |     10000    4.568202    3.984818   .6348574    110.893

parfor

In this example we create a short program (parfor) which is intended to work as a parfor program, this is, looping through 1/N in a parallel fashion

. // Cleaning working space
. clear all

. timer clear

. 
. // Set up
. set seed 123

. local n = 5e6

. set obs `n'
obs was 0, now 5000000

. gen x = runiform()

. gen y_pll = .
(5000000 missing values generated)

. clonevar y_ser = y_pll
(5000000 missing values generated)

. 
. // Loop replacement function
. prog def parfor
  1.         args var
  2.         forval i=1/`=_N' {
  3.                 qui replace `var' = sqrt(x) in `i'
  4.         }
  5. end

. 
. // Running the algorithm in parallel fashion
. timer on 1

. parallel initialize 4, f
N Clusters: 4
Stata dir:  /usr/local/stata13/stata

. parallel, prog(parfor): parfor y_pll
-------------------------------------------------------------------------------
> -
Exporting the following program(s): parfor

parfor:
  1.         args var
  2.         forval i=1/`=_N' {
  3.                 qui replace `var' = sqrt(x) in `i'
  4.         }
-------------------------------------------------------------------------------
> -
-------------------------------------------------------------------------------
Parallel Computing with Stata
Clusters   : 4
pll_id     : wrusvgqb91
Running at : /home/vegayon/Dropbox/repos/parallel
Randtype   : datetime

Waiting for the clusters to finish...
cluster 0001 has exited without error...
cluster 0002 has exited without error...
cluster 0003 has exited without error...
cluster 0004 has exited without error...
-------------------------------------------------------------------------------
Enter -parallel printlog #- to checkout logfiles.
-------------------------------------------------------------------------------

. timer off 1

. 
. // Running the algorithm in a serial way
. timer on 2

. parfor y_ser

. timer off 2

. 
. // Is there any difference?
. list in 1/10

     +--------------------------------+
     |        x      y_pll      y_ser |
     |--------------------------------|
  1. |  .912044   .9550099   .9550099 |
  2. | .0075452   .0868631   .0868631 |
  3. | .2808588   .5299612   .5299612 |
  4. | .4602787   .6784384   .6784384 |
  5. | .5601059   .7484022   .7484022 |
     |--------------------------------|
  6. | .6731906    .820482    .820482 |
  7. | .6177611   .7859778   .7859778 |
  8. | .8656877   .9304234   .9304234 |
  9. | 9.57e-06   .0030943   .0030943 |
 10. | .4090917   .6396028   .6396028 |
     +--------------------------------+

. gen diff = y_pll != y_ser

. tab diff

       diff |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |  5,000,000      100.00      100.00
------------+-----------------------------------
      Total |  5,000,000      100.00

. 
. // Comparing time
. timer list
   1:      8.93 /        1 =       8.9260
   2:     16.06 /        1 =      16.0580
  97:      0.42 /        1 =       0.4240
  98:      0.32 /        1 =       0.3150
  99:      8.17 /        1 =       8.1740

. di "Parallel is `=round(r(t2)/r(t1),.1)' times faster"
Parallel is 1.8 times faster

. 

Building

If you need to use parallel on an older version of Stata than what we build here, you can build and install the package locally.

You will need to install Stata devtools to build the package and log2html to build the html version of the help.

Then you can go to ado/ and either do compile.do or do compile_and_install.do depending on whether you want to just build the package (.mlib) or also install. There are also several build build checks in the makefile that can easily be run from Linux.

The Windows plugins can be built using Visual Studio Community Edition (tested on 2019), which is freee, with the C++ build tools and Windows SDK.

Authors

George G. Vega [aut,cre] g.vegayon %at% gmail

Brian Quistorff [aut] brian-work %at% quistorff . com

parallel's People

Contributors

bquistorff avatar droodman avatar epkugelmass avatar gvegayon avatar leitec avatar reallinfo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parallel's Issues

Tempvar counter

Stata's handling of tempvars is a bit simplistic. We currently don't take this into account and it can cause errors. For instance if a cluster has data with a tempvar __000000 and it tries to create a tempvar (or calls a program that does) no one (Stata nor parallel) remembers the parent counter so Stata starts over and gives out the name __000000 to be created which causes an error. Having datasets with temporary variables is common if the caller of parallel is itself a program (and we want to facilitate other programs using parallel!). I have a local patch that solves this by having parallel get the tempname counter and then incrementing that counter in the child processes. I'll post after testing.

In diagnosing this error I examined the behavior for Stata's tempvar handling. I'm recording it here in case it's of use later. Stata has a global tempname counter (for both tempname and tempvar) that increments with each call (and then decrements at the end of each program). At the end of a program, if any variable was created in the program that looks like a temporary variable (name __*) then all variables that have names that were given out by tempvar/tempname will be deleted. This is true even if tempvars were made for one dataset and then another was loaded that had the same name. That is, Stata doesn't keep track of which dataset has the specific tempvar (which, admittedly, would be difficult).

connection error -601- (timeout) when c(pwd) has spaces

Expected behavior and actual behavior

When using parallel from a c(pwd) with spaces you get error r(601) (connection). It should be the case that having a c(pwd) with spaces doesn't matters.

Steps to reproduce the problem

clear all
set more off
set trace off

// Creating dir with space
!mkdir "spa ce"
cd "spa ce"

parallel setclusters 2
parallel, t(2): di 1 // connection error -601-

// To clean
cd ..
!rm -r "spa ce"

Please provide with code to reproduce the issue

System information

This happens in OSX and UNIX

This bug was referenced by Rebecca Nemec

Parsing: Auto set by() option

-parallel- should automatically recognize when a command contains the -by- prefix. This can also apply to commands such as -collapse-, -reshape- and -compress-.

if ("`by'" == "") {
    if (regexm(`"`cmd'"',"^by ([a-zA-Z0-9_ ]+)") {
        local by = regexs(1)
    }
}

possible bug when when using capture or quietly prefix

Dear George,
Thanks indeed for this brilliant suite which really does speed up my work.
I am coding to get some bootstrapped standard errors for an estimator and I find that when I prefix my "parallel bs" command with either "capture" or "quietly" it fails but if I just run it "noisily" then it completes without error.
I have observed this error on Stata 14 on Windows and Unix.
I attach an example do-file and it's log-file with the errors (note I have had to give both files an extra .txt extension so GitHub allows me to upload them).

Best wishes
Tom Palmer

parallel_example.log.txt
parallel_example.do.txt

Provide information on likely setcluster #

It would be nice if we could give a guess to the user as to what to number to put for -parallel setclusters-. That way if they type an empty -parallel setclusters- (with no number) or they try to use parallel without setting the cluster we can suggest a number and even print a command that they could click on. We could query the c(processors_mach) and have our guess be something like 75% of clusters until we max out at 8 (and if there are 2-3 processors then we guess 2).

Error cutting data when using by()

The following produces an error on both current (master) and old (ssc) versions

. sysuse auto, clear
. sort rep78
. parallel setclusters 6
. parallel, by(rep78): egen max_rep78 = max(rep78)
Insufficient number of groups:
Can not divide the dataset into -6- clusters.

Even though there are 6 groups of rep78, the code in parallel_divide_index.mata can't correctly assign the groups to clusters. The code tries to make the cluster workloads about even in size, but it can't deal with the fact that the first two groups are smaller than what the average workload should be (_N/$PLL_CLUSTERS) and it can't correct itself after assigning two groups to the first cluster.

This dividing task is a general version of the classic "partition problem" which is hard to solve (NP-hard). Therefore I don't think we should try for optimality, but for simplicity and reasonableness. I propose we replace the by-splitting code with the following solution.

egen _`parallelid'grp = group(`xtstructure'), missing //identify groups. xtstructure holds by-vars
preserve
keep _`parallelid'grp
contract _`parallelid'grp //determine their sizes
sort _freq
gen _`parallelid'cut = mod(_n, ${PLL_CLUSTERS}) + 1 //assign them in a round-robin way
tempfile grp_to_cut_map
qui save `grp_to_cut_map'
restore
qui merge m:1 _`parallelid'grp using `grp_to_cut_map', keepusing(_`parallelid'cut) nogenerate
drop _`parallelid'grp

Does this seem like it will work? I've coded it up and it passes the tests fine.

Could not create temporary directory in Mac OS X

Dear George Vega,
Congratulations for this very useful software : )
I'm trying to run simple commands using parallel and I received the error message below.
I'm running Stata/MP 13.1 in a Mac OS X 10.9.5 (aka Mavericks).
I have skills using terminal, and unix commands. Please, let me know if you need more info. I will be very pleased to help on debugging.
Best,
Marcelo Magalhaes


. parallel setclusters 2
N Clusters: 2
Stata dir: /Applications/Stata/StataMP.app/Contents/MacOS/StataMP

. parallel: gen id = _n


Parallel Computing with Stata (by GVY)
Clusters : 2
pll_id : zcmiyildp1
Running at : /Users/marcelo/Projects/pos-doc-ucr-2014/dados/climate
Randtype : datetime
Waiting for the clusters to finish...
cluster 0002 has exited without error...
could not create directory /var/folders/74/g_km5htd7ls5b179h_zh6flm0000gn/T//__pllzcmiyildp1_tmpdir0002/
rmdir(): 693 could not remove directory
parallel_finito(): - function returned error
parallel_run(): - function returned error
: - function returned error
r(693);

Use preserve to auto-recover from errors

Currently, in places like parallel_do, parallel_bs, parallel_sim, when there are errors we try to reload the dataset. This is both cumbersome (we need capture error, load dta, then delete temporary variables) and can cause small errors (I remember that depending on the error, we'd drop the sortedby). I think we should make use of the preserve as this will do the recovery automatically. I think once we've put together the results from the children we can cancel the preserved data with restore, not

Allowing execution across machines

On computer clusters that share a file system (e.g. NFS) and that allow key-based ssh, it should be possible to distribute work across different nodes in the cluster. Commands can be sent via ssh immediately (no password). This would be a bit of work, but I thought I'd outline it here in case anyone wanted to implement. The steps as I see them are:

  1. Allow a mechanism to list hostnames for each child process.
  2. Update the processor execution function to execute the command via ssh on the appropriate hostname.
  3. Update the processor waiting function to determine if a child process is still running.
  4. Update the processor kill function in case the parent wants to stop processing.
  5. Update numprocessor when hostnames are specified.

parallel do with large dataset

I am running a large number of rolling panel regressions (unbalanced panel) and I am specifically collecting RMSE's from those regressions in a large dataset, and this nice package of course extremely expedites this process.
So, I wrote a loop in a do file so that I can call it using parallel do loop.do
parallel runs fine with no errors but I noticed that calling parallel to execute the loop returns different number of RMSE point estimates depending on the number of clusters I set. This is not the case when I run the loop sequentially without using this package. When I restrict the sample from 400,000 obs to 2,000 obs this no longer happens.
The number of point estimates I get back is consistent when running the loop sequentially, but when executing using parallel I get different numbers depending on the cluster size, and the smaller the clusters the higher the number of point estimates and they almost converge when I set the cluster size to 2. Right now I am running 48 clusters on the server.
Any clues as to why this is happening?
I am using the latest version of parallel available here, along with Stata 13 MP. I've tried this with a number of different operating systems, school servers, etc. with similar results.

My loop.do file has the following form

levelsof lvls, local(lvls)
foreach l of local lvls {
    forvalues t = 1952(1)2015 {  
      capture xtreg y x1 x2 if lvls == `l' & inlist(yr,`t',`t'-1,`t'-2) , fe
      capture replace z1 = `e(rmse)' if lvls == `l' & yr==`t'
}
    forvalues t = 1954(1)2015 {   
      capture xtreg y x3 x4 if lvls == `l' & inlist(yr,`t',`t'-1,`t'-2,`t'-3,`t'-4) , fe
      capture replace z2 = `e(rmse)' if lvls == `l' & yr==`t'
} 
}

Kindly let me know if I've missed anything from my problem explanation.
Thanks!

possible use of runmlwin_qshell instead of winexec on Windows

Dear George

I wondered if you're aware of the runmlwin_qshell program which comes with another user-written command -runmlwin- (which is on SSC for running the software MLwiN from Stata)? runmlwin_qshell is their own version of Stata's shell command but prevents the pop-up DOS prompt.

Calling Stata with it (from within Stata on Windows) is as follows:
ssc install runmlwin
runmlwin_qshell "C:\Program Files (x86)\Stata14\StataSE-64.exe" /e do test.do

The author of runmlwin Chris Charlton at the University of Bristol is very helpful and I'm sure would help if you have any questions.

Best wishes
Tom

Continuous-integration

It would be nice if there was continuous integration (CI) to automatically check changes for test errors. Though I am not a lawyer, reading the single-user license terms it seems that as one can put Stata on the CI server in a way that it can't be shared with other users, that it can count as one of the three machines allowed.

The most common CI services are Travis (for Linux) and Appveyor (for Windows). One could setup a personal server with the Stata install files that are only accessible with a secret username/password. Travis could have the login info encrypted and stored so that for tests, Stata could be installed from the personal server. Appveyor has similar functionality.

Any thoughts?

Change log

It would be nice if we had a change log. See keep a changelog. They are helpful to both users and maintainers (helpful for history and for easily understanding changes by others). It would require a bit more work to (a) think about what are "releases" compared to just commits (SSC releases obviously qualify, but we'd likely include others as well), and (b) write up and summarize changes. Anyone have thoughts on this trade-off?

Recover from killed child Stata processes

If a child Stata process is terminated (such as because of an out-of-memory situation noted http://www.stata.com/manuals13/dmemory.pdf), then Stata won't create the finito file noting that the child process is done. This can cause a hung setup.

I had a few hung setups a while ago so on my old fork I had a branch where I outputed the process IDs when they were spawned so I could check the logs to see if the OOM problem was happening to me. But I think a better solution is have the scripts written in parallel_run.mata to check if a finito file exists after the Stata process finish, and write one if not.

Incorporate memory tracking into scheduler

We might want to query how much RAM is left on the machine before we launch new instances. There is memory, but I'm not sure if that reports exactly what we want from the current processes usage. We'll probably have to query the underlying system to check for free memory. There might be user-quotas as well that we might want to query.

Trouble with reshaping

I just ran across parallel and I'm trying to use it to speed up some reshaping. But I keep getting the following error:
parallel setclusters 4
N Clusters: 4
Stata dir: C:\Program Files (x86)\Stata13/StataSE-64.exe
parallel, by(Emplid) force: reshape long Q, i(Emplid) j(Question) string
file __pllv1erujp610_dataset.dta could not be opened
r(603);
I'm running Stata13 on a windows pc.
Any advice? Thanks!!

OMP abort

I am running a parallelized loop that grab some JSON data from an API. This works fine for about 1 million calls, but when I crank up the numbers of calls, I get this strange error in the nohup.out file:

OMP abort: Initializing libguide.a, but found libguide.a already initialized.
This may cause performance degradation and correctness issues.
Set environment variable KMP_DUPLICATE_LIB_OK=TRUE to ignore
this problem and force the program to continue anyway.
Please note that the use of KMP_DUPLICATE_LIB_OK is unsupported
and using it may cause undefined behavior.
For more information, please contact Intel(R) Premier Support.

I tried setting this variable, but that did not seem to help. Any advice in how I can diagnose what's wrong?

Error when number of tasks is less than the number of clusters

In the default setup (where the dataset is divided amongst the clusters) there is an error when there are fewer observations than clusters. Ideally, we'd temporarily lower the number of clusters used. Other ways of using parallel might suffer similar problems, I haven't checked.

Allow commenting in the parallelized do-file

Here's a toy example illustrating the problem.

There are three files:

  1. The main file pdo.do :
  2. Two versions of a loop mydofile.do, run by pdo.do in parallel

The cr delimited one works, while the #delimited one does not. It seems to get stuck at waiting for the clusters to finish forever.

mydofile1.do (cr delimited):
set more off
parallel break
levelsof id, local(g)
foreach v of local g {
preserve
keep if id==v' save "group_v'.dta", replace
restore
}

mydofile1.do (# delimited):

delimit;

set more off;
parallel break;
levelsof id, local(g);
foreach v of local g {;
preserve;
keep if id==v'; save "group_v'.dta", replace;
restore;
};

pdo.do (main do file):

delimit;

clear;
set more off;
!rm group__.dta;
set obs 4;
gen id = n;
expand 2 if mod(n,2)==1 ;
gen x = uniform();
sort id x;
parallel setclusters 2;
parallel do "mydofile1.do", processors(8);
/ *parallel do "mydofile2.do", processors(8); */
list, clean noobs;
clear;
fs "group
.dta";
append using `r(files)';
sort id x;
list, clean noobs;
ls;

Issue with getting started

Hi,

I'm just trying out -parallel- and am probably running into a basic issue. I'm trying "Example 1" in your minimal examples and am getting the following. Is there something I'm missing?

Thanks,
Dave

. sysuse bplong.dta
(fictional blood-pressure data)
. sort patient
. parallel setclusters 2
N Clusters: 2
Stata dir: /Applications/Stata/StataMP.app/Contents/MacOS/StataMP

. parallel, by(patient): by patient: egen max_bp = max(bp)

Parallel Computing with Stata (by GVY)
Clusters : 2
pll_id : 14un3xm8o1
Running at : /Users/davidchan/Dropbox/Research/ED peer effects/Data
Randtype : datetime
Waiting for the clusters to finish...
cluster 0001 has finished with a connection error -601- (timeout) (see more)...
cluster 0002 has finished with a connection error -601- (timeout) (see more)...

Here are the results of creturn list:

. creturn list

System values

--------------------------------------------------------------------------------------------------------------------
    c(current_date) = "22 Jan 2016"
    c(current_time) = "11:51:39"
       c(rmsg_time) = 0                          (seconds, from set rmsg)
--------------------------------------------------------------------------------------------------------------------
   c(stata_version) = 14.1
         c(version) = 14.1                       (version)
     c(userversion) = 14.1                       (version)
--------------------------------------------------------------------------------------------------------------------
       c(born_date) = "01 Dec 2015"
          c(flavor) = "IC"
             c(bit) = 64
              c(SE) = 1
              c(MP) = 1
      c(processors) = 4                          (Stata/MP, set processors)
  c(processors_lic) = 8
 c(processors_mach) = 4
  c(processors_max) = 4
            c(mode) = ""
         c(console) = ""
--------------------------------------------------------------------------------------------------------------------
              c(os) = "MacOSX"
           c(osdtl) = "10.11.3"
        c(hostname) = "DN0a22e56a.SUNet"
    c(machine_type) = "Macintosh (Intel .."
       c(byteorder) = "lohi"
        c(username) = "davidchan"
--------------------------------------------------------------------------------------------------------------------

Directories and paths

--------------------------------------------------------------------------------------------------------------------
    c(sysdir_stata) = "/Applications/Sta.."      (sysdir)
     c(sysdir_base) = "/Applications/Sta.."      (sysdir)
     c(sysdir_site) = "/Applications/Sta.."      (sysdir)
     c(sysdir_plus) = "~/Library/Applica.."      (sysdir)
 c(sysdir_personal) = "~/Library/Applica.."      (sysdir)
 c(sysdir_oldplace) = "~/ado/"                   (sysdir)
          c(tmpdir) = "/var/folders/zt/2.."
--------------------------------------------------------------------------------------------------------------------
         c(adopath) = "BASE;SITE;.;PERSO.."      (adopath)
             c(pwd) = "/Users/davidchan/.."      (cd)
          c(dirsep) = "/"
--------------------------------------------------------------------------------------------------------------------

System limits

--------------------------------------------------------------------------------------------------------------------
    c(max_N_theory) = 281474976710655
    c(max_k_theory) = 5000                       (set maxvar)
c(max_width_theory) = 1048576                    (set maxvar)
--------------------------------------------------------------------------------------------------------------------
     c(max_matsize) = 11000
     c(min_matsize) = 10
--------------------------------------------------------------------------------------------------------------------
    c(max_macrolen) = 4227143
        c(macrolen) = 645200                     (set maxvar)
         c(charlen) = 67783
      c(max_cmdlen) = 4227159
          c(cmdlen) = 645216                     (set maxvar)
     c(namelenbyte) = 128
     c(namelenchar) = 32
           c(eqlen) = 1337
--------------------------------------------------------------------------------------------------------------------

Numerical and string limits

--------------------------------------------------------------------------------------------------------------------
       c(mindouble) = -8.9884656743e+307
       c(maxdouble) = 8.9884656743e+307
       c(epsdouble) = 2.22044604925e-16
  c(smallestdouble) = 2.2250738585e-308
--------------------------------------------------------------------------------------------------------------------
        c(minfloat) = -1.70141173319e+38
        c(maxfloat) = 1.70141173319e+38
        c(epsfloat) = 1.19209289551e-07
--------------------------------------------------------------------------------------------------------------------
         c(minlong) = -2147483647
         c(maxlong) = 2147483620
--------------------------------------------------------------------------------------------------------------------
          c(minint) = -32767
          c(maxint) = 32740
--------------------------------------------------------------------------------------------------------------------
         c(minbyte) = -127
         c(maxbyte) = 100
--------------------------------------------------------------------------------------------------------------------
    c(maxstrvarlen) = 2045
   c(maxstrlvarlen) = 2000000000
    c(maxvlabellen) = 32000
--------------------------------------------------------------------------------------------------------------------

Current dataset

--------------------------------------------------------------------------------------------------------------------
               c(N) = 240
               c(k) = 5
           c(width) = 7
         c(changed) = 0
        c(filename) = "/Applications/Sta.."
        c(filedate) = "22 Jan 2016 11:47"
--------------------------------------------------------------------------------------------------------------------

Memory settings

--------------------------------------------------------------------------------------------------------------------
          c(memory) = 33554432
          c(maxvar) = 5000                       (set maxvar)
         c(matsize) = 400                        (set matsize)
        c(niceness) = 5                          (set min_memory)
      c(min_memory) = 0                          (set min_memory)
      c(max_memory) = .                          (set max_memory)
     c(segmentsize) = 33554432                   (set segmentsize)
--------------------------------------------------------------------------------------------------------------------

Output settings

--------------------------------------------------------------------------------------------------------------------
            c(more) = "on"                       (set more)
            c(rmsg) = "off"                      (set rmsg)
              c(dp) = "period"                   (set dp)
        c(linesize) = 120                        (set linesize)
        c(pagesize) = 28                         (set pagesize)
         c(logtype) = "smcl"                     (set logtype)
         c(noisily) = 1
         c(eolchar) = "unix"                     (set eolchar)
      c(notifyuser) = "on"                       (set notifyuser)
         c(playsnd) = "off"                      (set playsnd)
  c(include_bitmap) = "on"                       (set include_bitmap)
--------------------------------------------------------------------------------------------------------------------
           c(level) = 95                         (set level)
          c(clevel) = 95                         (set clevel)
--------------------------------------------------------------------------------------------------------------------
  c(showbaselevels) = ""                         (set showbaselevels)
  c(showemptycells) = ""                         (set showemptycells)
     c(showomitted) = ""                         (set showomitted)
         c(fvlabel) = "on"                       (set fvlabel)
          c(fvwrap) = 1                          (set fvwrap)
        c(fvwrapon) = "word"                     (set fvwrapon)
        c(lstretch) = ""                         (set lstretch)
--------------------------------------------------------------------------------------------------------------------
         c(cformat) = ""                         (set cformat)
         c(sformat) = ""                         (set sformat)
         c(pformat) = ""                         (set pformat)
--------------------------------------------------------------------------------------------------------------------
  c(coeftabresults) = "on"                       (set coeftabresults)

Interface settings

--------------------------------------------------------------------------------------------------------------------
      c(reventries) = 5000                       (set reventries)
     c(revkeyboard) = "on"                       (set revkeyboard)
     c(varkeyboard) = "on"                       (set varkeyboard)
     c(smoothfonts) = "on"                       (set smoothfonts)
         c(linegap) = 1                          (set linegap)
   c(scrollbufsize) = 204800                     (set scrollbufsize)
           c(maxdb) = 50                         (set maxdb)
--------------------------------------------------------------------------------------------------------------------

Graphics settings

--------------------------------------------------------------------------------------------------------------------
        c(graphics) = "on"                       (set graphics)
          c(scheme) = "s2color"                  (set scheme)
      c(printcolor) = "automatic"                (set printcolor)
       c(copycolor) = "automatic"                (set copycolor)
--------------------------------------------------------------------------------------------------------------------

Efficiency settings

--------------------------------------------------------------------------------------------------------------------
         c(adosize) = 1000                       (set adosize)
--------------------------------------------------------------------------------------------------------------------

Network settings

--------------------------------------------------------------------------------------------------------------------
        c(checksum) = "off"                      (set checksum)
        c(timeout1) = 30                         (set timeout1)
        c(timeout2) = 180                        (set timeout2)
--------------------------------------------------------------------------------------------------------------------
       c(httpproxy) = "off"                      (set httpproxy)
   c(httpproxyhost) = ""                         (set httpproxyhost)
   c(httpproxyport) = 80                         (set httpproxyport)
--------------------------------------------------------------------------------------------------------------------
   c(httpproxyauth) = "off"                      (set httpproxyauth)
   c(httpproxyuser) = ""                         (set httpproxyuser)
     c(httpproxypw) = ""                         (set httpproxypw)
--------------------------------------------------------------------------------------------------------------------

Update settings

--------------------------------------------------------------------------------------------------------------------
    c(update_query) = "on"                       (set update_query)
 c(update_interval) = 7                          (set update_interval)
   c(update_prompt) = "on"                       (set update_prompt)
--------------------------------------------------------------------------------------------------------------------

Trace (program debugging) settings

--------------------------------------------------------------------------------------------------------------------
           c(trace) = "off"                      (set trace)
      c(tracedepth) = 32000                      (set tracedepth)
        c(tracesep) = "on"                       (set tracesep)
     c(traceindent) = "on"                       (set traceindent)
     c(traceexpand) = "on"                       (set traceexpand)
     c(tracenumber) = "off"                      (set tracenumber)
     c(tracehilite) = ""                         (set tracehilite)
--------------------------------------------------------------------------------------------------------------------

Mata settings

--------------------------------------------------------------------------------------------------------------------
      c(matastrict) = "off"                      (set matastrict)
        c(matalnum) = "off"                      (set matalnum)
    c(mataoptimize) = "on"                       (set mataoptimize)
       c(matafavor) = "space"                    (set matafavor)
       c(matacache) = 2000                       (set matacache)
        c(matalibs) = "lmatabase;lmataad.."      (set matalibs)
     c(matamofirst) = "off"                      (set matamofirst)
--------------------------------------------------------------------------------------------------------------------

Unicode settings

--------------------------------------------------------------------------------------------------------------------
       c(locale_ui) = "en_US"                    (set locale_ui)
c(locale_functions) = "en_US"                    (set locale_functions)
  c(locale_icudflt) = "en_US"                    (unicode locale)
--------------------------------------------------------------------------------------------------------------------

Other settings

--------------------------------------------------------------------------------------------------------------------
            c(type) = "float"                    (set type)
         c(maxiter) = 16000                      (set maxiter)
   c(searchdefault) = "all"                      (set searchdefault)
             c(rng) = "default"                  (set rng)
     c(rng_current) = "mt64"
        c(rngstate) = "XAAe85dd500d27408.."      (set rngstate)
       c(varabbrev) = "on"                       (set varabbrev)
      c(emptycells) = "keep"                     (set emptycells)
         c(odbcmgr) = "iodbc"                    (set odbcmgr)
      c(odbcdriver) = "unicode"                  (set odbcdriver)
--------------------------------------------------------------------------------------------------------------------

Other

--------------------------------------------------------------------------------------------------------------------
              c(pi) = 3.141592653589793
           c(alpha) = "a b c d e f g h i.."
           c(ALPHA) = "A B C D E F G H I.."
            c(Mons) = "Jan Feb Mar Apr M.."
          c(Months) = "January February .."
           c(Wdays) = "Sun Mon Tue Wed T.."
        c(Weekdays) = "Sunday Monday Tue.."
              c(rc) = 0                          (capture)
--------------------------------------------------------------------------------------------------------------------

parallel_setclusters() not found

Hello,

I installed parallel through ssc yesterday and it appeared to have installed properly, but I haven't been able to use it yet. When I run -- parallel setclusters 2 -- I get the following error:
< istm t>: 3499 parallel_setclusters() not found

I'm using Stata 13.1 on a Windows machine and this occurs both on a computer with 3 cores and one with 24 cores. I'm not a computer expert, so please let me know if I'm missing something obvious or what additional information is needed. Thanks in advance for any guidance.

-Mitch

Note: This issue was also posted on the Statalist Forum on 13 August:
http://www.statalist.org/forums/forum/general-stata-discussion/general/1306137-parallel-package-problem-parallel_setclusters-not-found

Working Directory needs to be in S_ADO if using saved Mata functions

When saving mata functions, parallel makes an mlib file in the current working directory. If "." is not part of the ado-path then this file won't be found by the child processes. See this example program

clear all

//get parallel
sysdir set PERSONAL "code/ado" //change this for your own system
global S_ADO "BASE;PERSONAL;."
mata: mata mlib index
parallel setclusters 2

//define the dummy task
mata:
void dummy_func(){
    printf("Hi\n")
}
end
program dummy_prog
    mata: dummy_func()
end

parallel, keep mata programs(dummy_prog): dummy_prog
_assert r(pll_errs)==0 //works

global S_ADO "BASE;PERSONAL"
parallel, keep  mata programs(dummy_prog): dummy_prog
_assert r(pll_errs)==2 //doesn't work

The user can work around the error by adding "." to the ado-path (either S_ADO or with an include() file) or moving the mata code to an mlib.

I can't think of a perfect solution on the package side. Any changing of the ado-path might cause the programs to work differently (they might have ados in "." that override other programs) or the user might change S_ADO in the child process negating the fix. I suggest that we issue a warning and let the user deal with it. This situation is likely not very common so it would be little burden to users. We can check for a likely error by doing cap which l__pllparallelid'_mlib.mliband checking_rc(the user could work around the issue with aninclude()` or changing S_ADO in their child process so it's no necessarily an error).

parallel not running on university server

Hello,
I am having issues running any command or instance with parallel in my university server with StataMP 13.
Everything runs fine on my personal computer. But I would like to utilize the power of the server to dramatically increase the speed of my work.

Here are the symptoms of the problem:
when I run the command in my personal computer, I see new cmd and stata windows equal to the number of clusters pop up and then close when the parallel command is successfully done with execution.
When I run the same command in the server, also StataMP 13, I see the same cmd and stata instances pop up but close two seconds later and the command stalls without giving errors, as if its running in an infinite loop even for primitive operations that should execute in micro seconds.

This led me to believe that maybe the fact that I dont have admin privileges on the server is causing this issue so I pointed all stata directiories (ala sysdir and adopath) to be on a network drive that has a dropbox directory where I have full read/write privileges, but again the problem persists. Other user-written commands that warrant a read/write like "savesome" work fine on the server, so maybe this is not an admin write privileges issue, I don't know.

It must also be noted that when I run my work from my personal computer, I also point everything to the same dropbox folder (on the local pc hard-drive, not a network directory) and its running fine.

Any clues what is going on?

Thanks!
Saad

parallel. prog() syntax does not recognize spaces in path

I have a predefined program that loops over text files, coded as nmfp (x) to parse them and save them into string variables. At the end of my program, each file will be a distinct observation.
I have a lot of files so I'd like to parallelize the process..
The program runs fine when calling it (to run sequentially).. but when I use the parallel syntax, I get the following error which seems to indicate that spaces in Stata installation path is causing the error:

. parallel, prog(parfor): parfor 1 1
invalid 'Customer' 
                 stata():  3598  Stata returned error
parallel_export_programs():     -  function returned error
     parallel_write_do():     -  function returned error
                 <istmt>:     -  function returned error
r(3598);

end of do-file

r(3598);

Customer above refers to the path where Stata is installed, which in my case is
"C:\Users\Valued Customer\Dropbox\Software\Stata 13\Installed/StataMP-64.exe"

Here is my code, the predefined program along with how I am calling the parallel process:

prog def parfor
	args linenum filenum
		forvalues n=1/`=_N' {
			capture file open myfile using "nmfp (`n').txt", read text
			capture file read myfile line
			while r(eof)==0 {
				capture replace line_`linenum' = "`line'" if _n==`filenum'
				capture file read myfile line
				capture local linenum = `linenum' + 1
				}
			capture local linenum = 1
			capture local filenum = `filenum' + 1
			capture file close myfile
			}
		end

When I call it sequentiall, say parfor 1 1 then it runs fine.. but when I do the following:

parallel, prog(parfor): parfor 1 1

then it gives the above error

Any clues?

  • OS: Windows 10
  • Stata version: 13 MP-64
  • Parallel version: 1.15.8.19

Include citation information

It'd be nice to show how to cite the software. We could include a plain-text cite or a raw bibtex entry in the help.

typo line 20 parallel.sthlp

Line 20 should be as follows (i.e. change "caveates" to "caveats" to match marker and title on lines 446 and 447):

{p2col: 5. {help parallel##caveats:Caveats}}Things to consider before using parallel.{p_end}

Best wishes
Tom

Create help files for debugging ('How to debug')

These could be sthlp files with common FAQs about what to do when things go wrong (basically when there's a problem in some of the clusters' code or when Stata shuts down).

This will be mainly a guide for novice experts on how to: (1) Track errors on Stata using parallel; (2) Kill processes in the different OSs. The second part, as Brian suggested, can be aided providing a command to list Stata processes that are currently running and that may have something to do with parallel. In linux can be something like

ps -aux | grep -regexp '__pll[a-z0-9]+_do'

Read that into stata, parse it using regexp and then return the processes names/pids and a link to run the command in bash 'kill 00000'.

Make guidelines for contributing

We might want to have some guidelines for contributing, specifically issue templates for standardizing reports. See GitHub's documentation. We might also want to have the other documents too.

Copy over scalars and Stata matrices

This could be added to the export globals file and just looping through different categories for st_dir. The matrices could be stored in a -mata mosave- file. The scalars could be in there too or exported to a text file like the global macros.

Show code example where results do not depend on the number of clusters

I think it would be good to show a code example of a routine where each repetition involves randomness (simulate or bs) and where the outcome doesn't change depending on the number of clusters. The existing ones vary by number of clusters as they set the seed per cluster rather than by repetition.

The way I do this is to generate a list of RNG states, one for each repetition. Then make a program, say gen_bs that takes as an argument the filename of the original data and where the data coming in is a list RNG state strings (seeds). It then loops over the RNG states, for each, setting the current RNG state to that, loading the data, drawing the new bs sample, computing the statistic, and saving the result (either in a post file or matrix). At the end you replace the dataset with the results. Then when you parallel : gen_bs using orig_data.dta it doesn't matter how many ways the full RNG state list was split, the results will always be the same.

Maybe in the future we could make this kind of technique optional for the bs or simulate subcommands.

Edit: Stata14 now uses strLs to store the RNG state which is pain to work with (lots of space, can't merge on them, etc.). So I think it's easier to generate a list of longs for each rep and do set seed <long>.

Dealing with Stata 12 string expression length limit

Stata 11/12 has a limit of 244 characters for string "expressions". This means that, for instance, when we parse long commands from the user, regexr() will truncate the string silently! I noticed this because the truncated string had unbalanced parantheses so got an ) required error, but things might pass through and just be wrong. We could check and warn for this, or switch the functions to mata (we'd have to trace all the parts that work with user input), or just say that newer versions are better (Stata 13/14 has a limit of 2,000,000,000!).

Removing log messages in tmpdir

In parallel_recursively_rm.mata, it does not "remove logfiles in tmpdir". I understand wanting to keep them around so the user can scrutinize them. But we should delete them at some point because (a) that's correct usage of temp files (otherwise they should be normal files in one of the user's main directories), and (b) they can, in aggregate, take up lots of space (especially if trace is on).

I definitely think -parallel clean, all- should delete them by default. Normal usage shouldn't shouldn't create clutter. One option then is to consider them like the other files during normal operation (delete, keep, or keeplast) unless there is an error. If so we could (a) copy them out to pwd before treating them like the other files, or (b) leave in tmpdir (they could inspect them, copy them out, or disregard) and require the user to -parallel clean-.

We could have an option in setclusters to enable the current behavior and then provide another option to -parallel clean- to delete the normally kept logs.

What do you think?

include(path or cmd) option

In order allow the user to run commands before parallel starts, like setting the adopath, running an algorithm, etc.

Parallel on Windows does not respect STATATMP environmental variable

parallel does not respect the STATATMP variable, which takes precedence over TEMP when it exists.

http://www.stata.com/support/faqs/data-management/statatmp-environment-variable/

Walkthrough:

  1. System environment variable STATATMP is D:\temp
  2. Parallel writes batch file with set TEMP... instead of set STATATMP
  3. Stata ignores the new TEMP because STATATMP exists.

Solution:
https://github.com/gvegayon/parallel/blob/master/ado/parallel_run.mata#L85
Replace TEMP= with STATATMP=

This will always work.

Can I submit a patch?

Parallel does not execute profile.do

Stata allows the creation of a profile.do that will run every time Stata is initialized.
http://www.stata.com/manuals13/gswb.pdf#B.3ExecutingcommandseverytimeStataisstarted

This is useful because it allows users to override system preferences. This is particularly important when the ADOPATH is solely composed of write-restricted system directories. Parallel should include an option for each cluster to call profile.do. When this is not done, Parallel might not be found by the clusters.

For example:

  • ADOPATH is C:/ado/
  • User profile do: sysdir set personal C:/Users/jim/Stata
  • User installs parallel (to personal part of ADOPATH)
  • User calls parallel, parallel creates batch file
  • Batch file calls 'Stata do ...'. Profile.do is not run.
  • Call to parallel fails because cluster-do files fail: parallel mata library is not found

Tests should show error more explicitly

Right now, the user has to manual check all_tests_results.txt for errors. (I think by searching for with error and ^r\(). It would be nice if this was somehow automatic. We could:

  • have make automatically search through the output for errors
  • have the stata run return appropriate error codes. We would explicitly error out of Stata on parallel errors by adding _assert(...), msg(...) after the calls to parallel in the test files. Stata doesn't set its return code properly on error, so this wouldn't get automatically propagated back to make, but we could have a stata executable wrapper that does this on it own like this (I've made and used updated versions of this).

In parallel bs: 'invalid something: unmatched close parenthesis or bracket'

Reported by Michael Lacy, Colorado State (Thanks again!):

While

. parallel bs,  reps(1000) saving(c:/temp/crud.dta) : ///
>     regress price mpg length foreign
invalid something: unmatched close parenthesis or bracket

throws error, this does not:

parallel bs,  reps(1000) saving("c:/temp/crud.dta") : ///
    regress price mpg length foreign

Connection issues on OSX with Stata MP 13.1

Expected behavior and actual behavior

"[C]annot even run the examples you provide in your help file. The clusters never report back; the program just keeps running forever and I have to hit Break to stop it. I have of course specified the number of cores before I run anything." (Reported by Belinda Foster)

Steps to reproduce the problem

Examples

System information

dual core Mac running Stata MP 13.1

Output from creturn list:

System values
    -------------------------------------------------------------------------------------------------------
       c(stata_version) = 13.1
             c(version) = 13.1                       (version)
    -------------------------------------------------------------------------------------------------------
           c(born_date) = "09 Dec 2015"
              c(flavor) = "IC"
                 c(bit) = 64
                  c(SE) = 1
                  c(MP) = 1
          c(processors) = 2                          (Stata/MP, set processors)
      c(processors_lic) = 8
     c(processors_mach) = 2
      c(processors_max) = 2
                c(mode) = ""
             c(console) = ""
    -------------------------------------------------------------------------------------------------------
                  c(os) = "MacOSX"
               c(osdtl) = "10.6.8"
            c(hostname) = "iMac.local"
        c(machine_type) = "Macintosh (Intel .."
           c(byteorder) = "lohi"
    
    -------------------------------------------------------------------------------------------------------

Directories and paths

    -------------------------------------------------------------------------------------------------------
        c(sysdir_stata) = "/Applications/Sta.."      (sysdir)
         c(sysdir_base) = "/Applications/Sta.."      (sysdir)
         c(sysdir_site) = "/Applications/Sta.."      (sysdir)
         c(sysdir_plus) = "~/Library/Applica.."      (sysdir)
     c(sysdir_personal) = "~/Library/Applica.."      (sysdir)
     c(sysdir_oldplace) = "~/ado/"                   (sysdir)
              c(tmpdir) = "/var/folders/4j/4.."
    -------------------------------------------------------------------------------------------------------
             c(adopath) = "BASE;SITE;.;PERSO.."      (adopath)
              c(dirsep) = "/"
    -------------------------------------------------------------------------------------------------------

System limits

    -------------------------------------------------------------------------------------------------------
        c(max_N_theory) = 2147483647
        c(max_k_theory) = 5000                       (set maxvar)
    c(max_width_theory) = 1048576                    (set maxvar)
    -------------------------------------------------------------------------------------------------------
         c(max_matsize) = 11000
         c(min_matsize) = 10
    -------------------------------------------------------------------------------------------------------
        c(max_macrolen) = 1081511
            c(macrolen) = 165200                     (set maxvar)
          c(max_cmdlen) = 1081527
              c(cmdlen) = 165216                     (set maxvar)
             c(namelen) = 32
               c(eqlen) = 399
    -------------------------------------------------------------------------------------------------------

Numerical and string limits

    -------------------------------------------------------------------------------------------------------
           c(mindouble) = -8.9884656743e+307
           c(maxdouble) = 8.9884656743e+307
           c(epsdouble) = 2.22044604925e-16
      c(smallestdouble) = 2.2250738585e-308
    -------------------------------------------------------------------------------------------------------
            c(minfloat) = -1.70141173319e+38
            c(maxfloat) = 1.70141173319e+38
            c(epsfloat) = 1.19209289551e-07
    -------------------------------------------------------------------------------------------------------
             c(minlong) = -2147483647
             c(maxlong) = 2147483620
    -------------------------------------------------------------------------------------------------------
              c(minint) = -32767
              c(maxint) = 32740
    -------------------------------------------------------------------------------------------------------
             c(minbyte) = -127
             c(maxbyte) = 100
    -------------------------------------------------------------------------------------------------------
        c(maxstrvarlen) = 2045
       c(maxstrlvarlen) = 2000000000
        c(maxvlabellen) = 32000
    -------------------------------------------------------------------------------------------------------

Current dataset

    -------------------------------------------------------------------------------------------------------
                   c(N) = 74
                   c(k) = 12
               c(width) = 43
             c(changed) = 0
            c(filename) = "/Applications/Sta.."
            c(filedate) = "13 Apr 2013 17:45"
    -------------------------------------------------------------------------------------------------------

Memory settings

    -------------------------------------------------------------------------------------------------------
              c(memory) = 33554432
              c(maxvar) = 5000                       (set maxvar)
             c(matsize) = 400                        (set matsize)
            c(niceness) = 5                          (set min_memory)
          c(min_memory) = 0                          (set min_memory)
          c(max_memory) = .                          (set max_memory)
         c(segmentsize) = 33554432                   (set segmentsize)
    -------------------------------------------------------------------------------------------------------

Output settings

    -------------------------------------------------------------------------------------------------------
                c(more) = "off"                      (set more)
                c(rmsg) = "off"                      (set rmsg)
                  c(dp) = "period"                   (set dp)
            c(linesize) = 107                        (set linesize)
            c(pagesize) = 18                         (set pagesize)
             c(logtype) = "smcl"                     (set logtype)
             c(noisily) = 1
             c(charset) = "mac"                      (set charset)
             c(eolchar) = "unix"                     (set eolchar)
          c(notifyuser) = "on"                       (set notifyuser)
             c(playsnd) = "off"                      (set playsnd)
      c(include_bitmap) = "on"                       (set include_bitmap)
    -------------------------------------------------------------------------------------------------------
               c(level) = 95                         (set level)
    -------------------------------------------------------------------------------------------------------
      c(showbaselevels) = ""                         (set showbaselevels)
      c(showemptycells) = ""                         (set showemptycells)
         c(showomitted) = ""                         (set showomitted)
             c(fvlabel) = "on"                       (set fvlabel)
              c(fvwrap) = 1                          (set fvwrap)
            c(fvwrapon) = "word"                     (set fvwrapon)
            c(lstretch) = ""                         (set lstretch)
    -------------------------------------------------------------------------------------------------------
             c(cformat) = ""                         (set cformat)
             c(sformat) = ""                         (set sformat)
             c(pformat) = ""                         (set pformat)
    -------------------------------------------------------------------------------------------------------
      c(coeftabresults) = "on"                       (set coeftabresults)

Interface settings

    -------------------------------------------------------------------------------------------------------
          c(reventries) = 5000                       (set reventries)
         c(revkeyboard) = "on"                       (set revkeyboard)
         c(varkeyboard) = "on"                       (set varkeyboard)
         c(smoothfonts) = "on"                       (set smoothfonts)
             c(linegap) = 1                          (set linegap)
       c(scrollbufsize) = 204800                     (set scrollbufsize)
               c(maxdb) = 50                         (set maxdb)
    -------------------------------------------------------------------------------------------------------

Graphics settings

    -------------------------------------------------------------------------------------------------------
            c(graphics) = "on"                       (set graphics)
              c(scheme) = "s2color"                   (set scheme)
          c(printcolor) = "automatic"                (set printcolor)
           c(copycolor) = "automatic"                (set copycolor)
    -------------------------------------------------------------------------------------------------------

Efficiency settings

    -------------------------------------------------------------------------------------------------------
             c(adosize) = 1000                       (set adosize)
    -------------------------------------------------------------------------------------------------------

Network settings

    -------------------------------------------------------------------------------------------------------
            c(checksum) = "off"                      (set checksum)
            c(timeout1) = 30                         (set timeout1)
            c(timeout2) = 180                        (set timeout2)
    -------------------------------------------------------------------------------------------------------
           c(httpproxy) = "off"                      (set httpproxy)
       c(httpproxyhost) = ""                         (set httpproxyhost)
       c(httpproxyport) = 80                         (set httpproxyport)
    -------------------------------------------------------------------------------------------------------
       c(httpproxyauth) = "off"                      (set httpproxyauth)
       c(httpproxyuser) = ""                         (set httpproxyuser)
         c(httpproxypw) = ""                         (set httpproxypw)
    -------------------------------------------------------------------------------------------------------

Update settings

    -------------------------------------------------------------------------------------------------------
        c(update_query) = "off"                      (set update_query)
     c(update_interval) = 7                          (set update_interval)
       c(update_prompt) = "off"                      (set update_prompt)
    -------------------------------------------------------------------------------------------------------

Trace (program debugging) settings

    -------------------------------------------------------------------------------------------------------
               c(trace) = "off"                      (set trace)
          c(tracedepth) = 32000                      (set tracedepth)
            c(tracesep) = "on"                       (set tracesep)
         c(traceindent) = "on"                       (set traceindent)
         c(traceexpand) = "on"                       (set traceexpand)
         c(tracenumber) = "off"                      (set tracenumber)
         c(tracehilite) = ""                         (set tracehilite)
    -------------------------------------------------------------------------------------------------------

Mata settings

    -------------------------------------------------------------------------------------------------------
          c(matastrict) = "off"                      (set matastrict)
            c(matalnum) = "off"                      (set matalnum)
        c(mataoptimize) = "on"                       (set mataoptimize)
           c(matafavor) = "space"                    (set matafavor)
           c(matacache) = 400                        (set matacache)
            c(matalibs) = "lmatabase;lmataad.."      (set matalibs)
         c(matamofirst) = "off"                      (set matamofirst)
    -------------------------------------------------------------------------------------------------------

Other settings

    -------------------------------------------------------------------------------------------------------
                c(type) = "float"                    (set type)
             c(maxiter) = 16000                      (set maxiter)
       c(searchdefault) = "all"                      (set searchdefault)
                c(seed) = "X075bcd151f1.."      (set seed)
         c(version_rng) = 12.1
           c(varabbrev) = "on"                       (set varabbrev)
          c(emptycells) = "keep"                     (set emptycells)
             c(odbcmgr) = "iodbc"                    (set odbcmgr)
    -------------------------------------------------------------------------------------------------------

Other

    -------------------------------------------------------------------------------------------------------
                  c(pi) = 3.141592653589793
               c(alpha) = "a b c d e f g h i.."
               c(ALPHA) = "A B C D E F G H I.."
                c(Mons) = "Jan Feb Mar Apr M.."
              c(Months) = "January February .."
               c(Wdays) = "Sun Mon Tue Wed T.."
            c(Weekdays) = "Sunday Monday Tue.."
                  c(rc) = 0                          (capture)
    -------------------------------------------------------------------------------------------------------

In parallel bs: 'option expression() not allowed'

Reported by Michael Lacy, Colorado State (Thanks!):

Works Fine

sysuse auto, clear
parallel setclusters 4
 parallel bs,  reps(1000) :  ///
    regress price mpg length foreign

Stops with error

parallel bs, expression(_b[mpg] _b[length]) reps(1000) : ///
    regress price mpg length foreign
Parallel Computing with Stata (by GVY)
Clusters   : 4
pll_id     : g7548y2913
Running at : C:
Randtype   : datetime
Waiting for the clusters to finish...
cluster 0001 Exited with error -198- while executing the command (view log)...
cluster 0002 Exited with error -198- while executing the command (view log)...
cluster 0003 Exited with error -198- while executing the command (view log)...
cluster 0004 Exited with error -198- while executing the command (view log)...

Allow parent Stata process to terminate child Stata processes

One way that we can make parallelizing existing code easier is by having break work like it does in the normal setup. I think we should allow the parent process to forcefully terminate child processes without having users add parallel break commands to their code (they might not even be able to find locations where they can make it responsive). We would have to keep track of the child process IDs, but there's already some code to do this.

In fact I think this should be the default response to a user break, but we can deal with that once the feature is implemented. The details will differ across platforms so we might want to keep around the existing system as a fall-back.

Memory error issues when working with large dataset

Hi there,

I am working with Stata SE 13.1 on a large dataset (15 gigabyte) on a 64 bit machine with 32gb RAM. When I tried to run parallel over the four cores of my computer I received an error message

--------------------------------------------------------------------------------
Parallel Computing with Stata (by GVY)
Clusters   : 4
pll_id     : 2uctinfg15
Running at : C:\Users\wwa594\Documents\Promotion\Projects\Dualholding\Work\Do-Files
Randtype   : datetime
Waiting for the clusters to finish...
cluster 0004 Exited with error -198- while setting memory (view log)...
cluster 0001 Exited with error -198- while setting memory (view log)...
cluster 0002 Exited with error -198- while setting memory (view log)...
cluster 0003 Exited with error -198- while setting memory (view log)...
--------------------------------------------------------------------------------
Enter -parallel printlog #- to checkout logfiles.
--------------------------------------------------------------------------------

The code I tried looks like this:

encode manager, gen(managerdum) // Convert string into numeric variable

capture program drop myloop
program define myloop

//walk through each lead and find amount with this lead if lead is in of the lead* variables
forvalues i = 1/12 {
    gen leadamt`i' = .
    levelsof lead`i', local(leads)  
    foreach l of local leads {
        bysort managerdum obsq: egen hlpvar = total(principalUSD) if (lead1 == "`l'" | lead2 == "`l'" | lead3 == "`l'" | lead4 == "`l'" | lead5 == "`l'" | ///
         lead6 == "`l'" | lead7 == "`l'" | lead8 == "`l'" | lead9 == "`l'" | lead10 == "`l'" | lead11 == "`l'" | lead12 == "`l'") & obsdate == mindate
        bysort managerdum obsq: egen totamt = min(hlpvar)
        replace leadamt`i' = totamt if lead`i' == "`l'" & leadamt`i' == .
        drop totamt hlpvar
    }
}
end

capture parallel clean
cd "C:\Users\wwa594\Documents\"
parallel setclusters 4
sort managerdum
parallel, by(managerdum) programs(myloop): myloop

I discussed this issue on the Statalist before but the problem remains unsolved: http://www.statalist.org/forums/forum/general-stata-discussion/general/1352049-parallel-computing-with-stata-se-13-1-and-parallel-package-error-198-while-setting-memory

I am unable to replicate the error message with a publicly available dataset. But expanding the auto dataset and trying a simple task on indicates that the size of the dataset might cause the problem:

. sysuse auto, clear
(1978 Automobile Data)

. tab rep78, miss

     Repair |
Record 1978 |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |          2        2.70        2.70
          2 |          8       10.81       13.51
          3 |         30       40.54       54.05
          4 |         18       24.32       78.38
          5 |         11       14.86       93.24
          . |          5        6.76      100.00
------------+-----------------------------------
      Total |         74      100.00

. expand 2000000
(147999926 observations created)

.
. capture program drop myloop

. program define myloop
  1.   levelsof rep78, local(reps)
  2.         foreach r of local reps {
  3.                         sum mpg if rep78==`r'    
  4.                         gen newvar`r' = r(sum)
  5.   }
  6. end

.
. cd "C:\Users\wwa594\Documents"
C:\Users\wwa594\Documents

. sort rep78

. parallel setclusters 4
N Clusters: 4
Stata dir:  C:\Program Files (x86)\Stata13/StataSE-64.exe

. parallel, by(rep78) programs(myloop): myloop
--------------------------------------------------------------------------------
Exporting the following program(s): myloop

myloop:
  1.   levelsof rep78, local(reps)
  2.         foreach r of local reps {
  3.                         sum mpg if rep78==`r'
  4.                         gen newvar`r' = r(sum)
  5.   }
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Parallel Computing with Stata (by GVY)
Clusters   : 4
pll_id     : 1mdx8agr10
Running at : C:\Users\wwa594\Documents
Randtype   : datetime
Waiting for the clusters to finish...
  0
cluster 0001 has exited without error...
  0
cluster 0004 has exited without error...
  -3621
cluster 0003 has exited without error...
  -3621
cluster 0002 has exited without error...
--------------------------------------------------------------------------------
Enter -parallel printlog #- to checkout logfiles.
--------------------------------------------------------------------------------

. parallel clean

. tab rep78, miss

     Repair |
Record 1978 |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |  4,000,000        4.55        4.55
          2 | 16,000,000       18.18       22.73
          4 | 36,000,000       40.91       63.64
          5 | 22,000,000       25.00       88.64
          . | 10,000,000       11.36      100.00
------------+-----------------------------------
      Total | 88,000,000      100.00

rep78 now has only four categories instead of five in the original dataset and the resulting dataset is 60 million observations short: 2 mio * 74 - 88 mio = 60 mio.

Do you have an idea what might have gone wrong here?

Providing notifications for releases

Do we want to provide notification for releases or instructions on how to do that? See options here. We could steup a dedicated issue that's bumped when we release, or we could tell people to follow the RSS feed from the releases page.

Including preference file

We only copy over a few of the possible preferences to the child cluster processes. Someone might want their code to run with the appropriate version/matsize/matafavor etc. I think we should allow an option like include_file(string) and we include that file in each cluster before we start the target do or program. That way those pieces of code would be more like to be able to be run unaltered.

Default behavior on error

I wanted to discuss the possibility of changing the behavior of parallel when there is an error in the clusters. Currently a message is displayed and a value is returned in r(). Most commands, however, exit with an error when not being able to run. Why is it that parallel doesn't display a message and then throw an error?

display R-squared on bootstrap

Hello,
is there a way to display or extract out (outreg or esttab) the R-Squared when running a "parallel bs" routine?
I'm running a basic regression of the form
parallel bs, reps(1000): reg y x1 x2
All I'm getting on the results screen is the number of obs and replications..

Help or future implementation of this is appreciated..

Thanks,
Saad

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.