Skip to content
GitLab
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
    Projects Groups Topics Snippets
  • Register
  • Sign in
  • eigen eigen
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 684
    • Issues 684
    • List
    • Boards
    • Service Desk
    • Milestones
    • Requirements
  • Custom issue tracker
    • Custom issue tracker
  • Merge requests 21
    • Merge requests 21
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • libeigenlibeigen
  • eigeneigen
  • Issues
  • #1169
Closed
Open
Issue created Dec 04, 2019 by Eigen Bugzilla@eigenbzReporter

thread local storage for the Eigen thread count

Submitted by fabien chêne

Assigned to Nobody

Link to original bugzilla bug (#1169)
Version: 3.3 (current stable)

Description

Created attachment 654
testcase

The current way to set the number of threads in Eigen is not flexible enough, consider the following example, on a machine with 8 cores:

void f()
{
Eigen::setNbThreads( 1 );

#pragma omp parallel for num_threads( 4 )  
for( int i = 0; i < 100; ++i )  
{  
    #pragma omp parallel for num_threads( 2 )  
    for( int j = 0; j < 20; j++ )  
    {  
        // do some matrix computation  
    }  

    // sequential part:  
    Eigen::setNbThreads( 2 );  
    // do some matrix computation using eigen's parallelism.  

    Eigen::setNbThreads( 1 );  
    #pragma omp paralell for num_threads( 2 )  
    for( int j = 0; j < 20; j++ )  
    {  
        // do some matrix computation  
    }  
}  

}

The problem is that the thread count acts as a global variable (with static storage duration), and therefore it is not guarantee that the sequential part be performed with 2 threads in Eigen, and the parallel parts be performed with 1 thread in Eigen.

Would it be possible to provide a way to achieve that goal ?
The obvious answer would be to make the thread count thread local. I guess that it is not possible for compatibility reasons, and on platforms that perhaps do not have TLS support. Hence the idea would be to add a new function to set the thread count per thread:
void Eigen::setNbThreadsInThisThread( int nbThreads );

What do you think ?

testcase attached.

Attachment 654, "testcase":
TestEigen.cc

Edited Dec 05, 2019 by Eigen Bugzilla
Assignee
Assign to
Time tracking