• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can i process iterator in parallel?

 
rudra tripathy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have one iterator of size, say 100. I want to divide it 10 batch of 10 and process it. Is it possible?
 
Henry Wong
author
Marshal
Pie
Posts: 21493
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rudra tripathy wrote:
I have one iterator of size, say 100. I want to divide it 10 batch of 10 and process it. Is it possible?


If you are asking if iterators are thread safe, that would depend on where you got the iterator from.... In most cases, however, iterators are not thread safe, so you will need to wrap it with a lock.

If you are asking if iterators are thread safe, and can distribute (divide up) the element into specific batches. The only way to do that is to have a thread specifically for dispatch -- it is not possible (read very difficult) to dispatch evenly if the workers threads are responsible for fetching the elements. Have a thread do it, and move it to the individual data structures for the threads.

So, the answer is yes... but not without some help from you.
Henry
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rudra tripathy wrote:Hi All,

I have one iterator of size, say 100. I want to divide it 10 batch of 10 and process it. Is it possible?


The Iterator doesn't have a size. The thing it's iterating over does. You can certainly divide the processing up, yes. I probably wouldn't do it with multiple threads accessing the iterator though, or, if I did, I'd be careful about synchronization.
 
rudra tripathy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry/Jeff,

Thanks for the clarification.

Thanks and Regards,
Rudra
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic