Repository navigation
Conversation
tholden
force-pushed
the
taskloop-2level-parallel
branch
2 times, most recently
from
November 5, 2026 16:48
041a180 to
aedc5c8
Compare
tholden
added a commit
to tholden/fixest
that referenced
this pull request
Nov 5, 2026
tholden
added a commit
to tholden/fixest
that referenced
this pull request
Nov 7, 2026
…lelize group/output loops
…tive tail taskloop in compute_fe_coef_internal & Irons-Tuck inner products
tholden
force-pushed
the
taskloop-2level-parallel
branch
from
November 26, 2026 16:06
c4942a8 to
e3fcc47
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOTE: This pull request is entirely AI generated. It seems reasonable, but as always with AI, particular care should be taken before merging it.
Summary
This PR enables two-level nested parallelism in the fixed-effect demeaning routine (
cpp_demean) and fuses observation-level and group-level inner passes to minimize memory bandwidth and OpenMP task barrier overhead:#pragma omp task) instead of static loop partitioning.#pragma omp taskloop num_tasks(omp_num_tasks(n))for observation-level and group-level operations, plus#pragma omp parallel forfor final residual subtraction.Motivation & Problem
In$V$ variables and $N$ observations was previously parallelized solely across variables using:
fixest, demeaning across#pragma omp parallel for num_threads(nthreads_current) schedule(static, 1)While this works well when$V \gg \text{nthreads}$ , it suffers from two major bottlenecks:
Design of this PR
cpp_demean,#pragma omp parallel num_threads(nthreads)is opened once. Using#pragma omp master, thread 0 spawns outer tasks for variables1 .. n_vars - 1and directly executes variable0(guaranteeing that whenn_vars == 1, thread 0 runsdemean_acc_gnland checks user interrupts while worker threads execute innertaskloopchunks).taskloopwith Bounded Grain Size:omp_num_tasks(n, min_grain = 32768)bounds the task count tomin(4 * omp_get_num_threads(), n / min_grain)so large arrays divide intomy_fe_coef[m] /= my_SW[m]) and independent per-cluster forward/backward Cholesky triangular solves for varying slopes (c = 0 .. nb_id - 1) are also parallelized via#pragma omp taskloopwhennb_clusteris large.compute_sum_other_means,add_all_fe_coef_to_mu,add_2_fe_coef_to_mu):compute_fe_gnlzeroedsum_other_means(anadd_fe_coef_to_mupasses overtaskloopbarriers per sweep.FEClass::compute_sum_other_meansfuses the clearing and accumulation across allsum_other_meansDRAM traffic bytaskloopbarriers fromadd_all_fe_coef_to_muandadd_2_fe_coef_to_mufuse post-iteration mean reconstruction into a single pass overcompute_ssr,compute_2_fe_ssr):demean_acc_gnlanddemean_acc_2, a freshvector<double> mu_current(n_obs, 0)was heap-allocated (VirtualAlloc/mmap+ page faults) and freed to check whether SSR had plateaued. On large datasets (e.g.,compute_ssrandcompute_2_fe_ssrcompute the residual sum of squares directly on the fly in a singletaskloop reduction(+:ssr)pass with zero heap allocations.simple_mat_with_idfor Thread-Safe Varying-Slope Gather Passes:simple_mat_with_id::operator()computespx0[n_total * id + i + nrow * j]directly without mutable cached state, making concurrent varying-slope reads completely thread-safe and branch-free.X_demeanandy_demean(input - output) at the end ofcpp_demeanis parallelized with#pragma omp parallel for.