Skip to content

QDiD(pl=TRUE, cores=<numeric>) silently runs serial on Windows because bootstrap ignores pl #7

@Auxes1s

Description

@Auxes1s

I noticed a cross-platform parallelization issue in qte::QDiD() while running bootstrap standard errors for a large applied QDiD analysis.
QDiD() exposes both pl and cores:

QDiD(..., se = TRUE, iters = 100, pl = FALSE, cores = NULL)

The documentation suggests that pl controls whether standard errors are computed in parallel, and cores controls the number of cores. However, internally QDiD() passes both arguments into QTEparams() and then calls:

SEobj <- bootstrap(qp, qdid, compute.QDiD)
In the installed qte 1.3.1 source, bootstrap() reads pl but does not use it:

pl <- qteparams$pl
cores <- qteparams$cores
eachIter <- pblapply(1:iters,  bootiter,  qteparams = qteparams,  func = func,  cl = cores)

As a result, actual parallel behavior is controlled by pbapply::pblapply(..., cl = cores), not by pl.

This leads to surprising behavior:

  1. On Windows, QDiD(pl = TRUE, cores = 2) silently runs serially when cores is numeric, because pbapply::pblapply() ignores numeric cl on Windows unless cl is a cluster object.
  2. On Unix-like systems, QDiD(pl = FALSE, cores = 2) may still run in parallel, because numeric cl = 2 can trigger parallel::mclapply().
  • The documented pl argument is therefore not authoritative.
  • The documented cores argument says it is a number, but on Windows parallel execution appears to require passing a PSOCK cluster object.
  • Minimal demonstration of the underlying pbapply behavior on Windows:

A possible fix would be for bootstrap() to honor pl explicitly. A more complete fix could also create a PSOCK cluster internally on Windows when pl = TRUE and cores is numeric and greater than 1, or document that cores may be a pre-created cluster object.

This would make QDiD(pl = FALSE, cores = 2) reliably serial and QDiD(pl = TRUE, cores = 2) reliably parallel across supported platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions