- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I am trying to parallelize a subroutine which populates content of a double vector using parallel_for
Due to nature of population, racing condition will certainly occur so I need to somehow guard against that.
The vector is beging defined/allocated as a double v
What's the correct way of passing this vector to the operator() so I can use tbb::atomic.
I was thinking of doing something like this and wanted to know if this is enough
to make sure that [cpp]my_v += some_new_value;[/cpp] is atomic.
[cpp]
double *v = new double
tbb:atomic<double *> va = v;
parallel_for(tbb::blocked_range<size_t>(0,N), Foo(va))
[/cpp]
where Foo is defined as:
[cpp]
class Foo {
double *my_v;
public:
void operator()(tbb:blocked_range<size_t>& r) const {
for (size_t i=r.begin(); i<r.end(); ++r) {
size_t idx = _compute_index(i);
my_v[idx] += some_new_value;
}
}
Foo(double *in_v) : my_v(in_v) { }
};
[/cpp]
(Line 6 above can produce identical values of 'idx' on different threads so I have to make sure line 7 is atomic.)
thanks in advance for any help/input.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Raf Schietekat wrote:Thanks for your reply Raf. Since the subroutine is supposed to return that array to the calling function in a double result
You should define an array of atomics, not an atomic pointer to a non-atomic array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Raf Schietekat wrote:oh, yes you are right. This parallelization won't be as easy as I thought it would be... maybe scope locking?
But wait, isn't += unimplemented for atomic double?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
JimDempseyAtTheCove wrote:Jim, thanks for your help. I am not completely following the logic here. Aren't the 'non-intersecting portions of boundaries' already taken care of in the first step when we parallelize interior of partitions.
(join)
of shared boundaries, identify cells that intersect (cross points of tile boundaries)
parallel-ize non-intersecting portion of boundaries
(join)
JimDempseyAtTheCove wrote:Would you mind elaborating on this one as well? thanks again
(note, intersection of boundaries non-adjacent unless tile is 3x3 or smaller)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page