|Re: [eigen] Help on solving a race condition|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Help on solving a race condition
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Fri, 8 Jun 2012 20:54:12 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=bHnijdz/Zn7XwhJKG8t0u0uIwfydUN4e3IVdj8PuqUA=; b=h7CxebSdsp+QImKEO1xS1PwHp7IKFyTrivET1jJyB9aenTwQQxIuUIdLFZwLPThyal kd0Ah4wV/gISR40eOWTef4rD7TQRhd6uO3eeKDTray9SbRPZIpMDYXyH301Syif/8cso ugVBqFq0z/kmnCoY86iHkHHlPvMj2hP0mkq8yTeE1zO6Rp35hNs3f3QQk3RskYlUYyB7 5h0UaR02Hj1dce26Na4NRr4in6MJY3IprjxE6Hlg4HoB5OIFtxnwgfjtIKw3ZJx1hkIs X1DRwZObyCY3FtvbXoSn7Y6UJpyYaAO3yH5r0KvWXR08E3LkD5xgmAKKlyDd2e6sdv3f iBng==
On Fri, Jun 8, 2012 at 6:13 PM, Rhys Ulerich <rhys.ulerich@xxxxxxxxx> wrote:
>> Then I guess the only safe and clean solution is to request users to
>> call a Eigen::init_parallel() or something.
> That's safe but I'd not call it clean. It's error prone. And verbose.
>> The problem with this approach, is that the cache-sizes are recomputed
>>for every thread.
> That doesn't seem terrible to me if I don't have to explicitly call
> Eigen::init_parallel() as a tradeoff. Is this a slow process?
as I said in a previous email, after some benchmarking, this approach
is not that slow: compared to the thread creation cost it's a no-op.
>>> This solution is openmp specific; what if someone wants to use pthreads or
>>> some other threading system ?
> Why not #ifdef on compiler versions to dig out the vendor-specific
> thread-local storage extension when OpenMP isn't active:
> #if defined(_OPENMP)
> # define TLS
> #elseif defined(__GNUC__) && __GNUC__ > 3
> # define TLS __thread
> # define TLS ...
> # define TLS
> static TLS std::ptrdiff_t m_l1CacheSize = 0;
> static TLS std::ptrdiff_t m_l2CacheSize = 0;
> #pragma omp threadprivate(m_l1CacheSize, m_l2CacheSize)
> #ifdef TLS
> #undef TLS
> Notice that no vendor-specific threadlocal keyword is used when OMP is
> active because OMP is the better way to go.
ah great, I did not know there existed such compiler extensions.
That's a lead to pursue.
> It's a bit ugly from the implementer's side, but it the number of
> vendor-specific thread-local keywords should be small. From the end
> user's perspective, however, it is seamless.
> - Rhys