Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
2421 Discussions

Help with concurrent_hash_map / parallel_for

scasey67
Beginner
124 Views
I am a noobie concerning threading, so I thought that I would start with Threading Building Blocks for my application. I 'think' I am creating things appropriately, but I am getting compilier errors (on VS 2005 - Error C2784). I am able to create the map and populate it, but I don't think I am doing the parallel iteration correctly. For instance, I 'think' I am setting the blocked_range correctly, but I am probably wrong. I have the O'Reilly book, but there isn't a concise example of what I am attempting to do, which is to basically iterate the hash map and call a method on the type T.

typedef concurrent_hash_map CollectionOfFoos;
typedef concurrent_hash_map::const_iterator FoosIterator;

struct UpdateFoos
{
float DeltaT;

UpdateFoos(float elapsed_time) : DeltaT(elapsed_time) {};

void operator()(blocked_range& range) const
{
for (FoosIterator iter = range.begin(); iter != range.end(); ++iter)
{
iter->second->update(DeltaT);
}
}
};

CollectionOfFoos Foos;
...
// populate foos - not having problem with this.
...

void updateElapsedTime(float delta_t)
{
parallel_for(blocked_range(Foos.begin(), Foos.end(), 10000), UpdateFoos(delta_t));
}

Again, I 'think' I am doing this correctly, but considering the compiler error I am obviously not. I left out StringHashCompare, but it is basically the same as the examples except for the usemy data type.

I appreciate any help, thanks!
0 Kudos
1 Reply
scasey67
Beginner
124 Views
Quoting - scasey67
I am a noobie concerning threading, so I thought that I would start with Threading Building Blocks for my application. I 'think' I am creating things appropriately, but I am getting compilier errors (on VS 2005 - Error C2784). I am able to create the map and populate it, but I don't think I am doing the parallel iteration correctly. For instance, I 'think' I am setting the blocked_range correctly, but I am probably wrong. I have the O'Reilly book, but there isn't a concise example of what I am attempting to do, which is to basically iterate the hash map and call a method on the type T.

typedef concurrent_hash_map CollectionOfFoos;
typedef concurrent_hash_map::const_iterator FoosIterator;

struct UpdateFoos
{
float DeltaT;

UpdateFoos(float elapsed_time) : DeltaT(elapsed_time) {};

void operator()(blocked_range& range) const
{
for (FoosIterator iter = range.begin(); iter != range.end(); ++iter)
{
iter->second->update(DeltaT);
}
}
};

CollectionOfFoos Foos;
...
// populate foos - not having problem with this.
...

void updateElapsedTime(float delta_t)
{
parallel_for(blocked_range(Foos.begin(), Foos.end(), 10000), UpdateFoos(delta_t));
}

Again, I 'think' I am doing this correctly, but considering the compiler error I am obviously not. I left out StringHashCompare, but it is basically the same as the examples except for the usemy data type.

I appreciate any help, thanks!

After reading through a bunch of posts I had come across this:
http://software.intel.com/en-us/forums/showpost.php?p=51548

I had used the search function, but the thread abovedidn't come up for me.

Question answered.
Reply