Re: [eigen] Help on solving a race condition |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Help on solving a race condition
- From: Rhys Ulerich <rhys.ulerich@xxxxxxxxx>
- Date: Fri, 8 Jun 2012 11:13:28 -0500
- 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; bh=ZGBhEVHkN6doxbqPhwA+Xynv9MLBnk4FXOWkdZRR1fA=; b=cWyXppPwjXwBJh+o007Z6Djp19NSZ0kjKYFQyRm8i3AzVqHsjWKHkUYKLaaD3oT9bk ZFshk8lboMKZx3bd+FAZPqeyrIUl3t8GEvFaHNLfmCBmWzdydS1IYiOlYeiBty3h7XGK 1cJ0UF+KwO0iy4iBsrs3FT56KXUuNYJ2i6zHgEVWfvVjZCmFCHy51OBehNEBwOWFjzXj UokXsRwBO3e0IKeYAf095Wuhsixaph1Cn+pAh7az5flVuossybMrRC8PWRR5ilz0O+j2 4n/YDblCnsJ31V33I0tpct0Pthn70Mmsc29tnrUD1B6b7UEJbir45ExL/Qp7Z2o8SW+b OgSQ==
> 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?
>> 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
#elseif....
# define TLS ...
#else
# define TLS
#endif
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
#endif
Notice that no vendor-specific threadlocal keyword is used when OMP is
active because OMP is the better way to go.
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