I want to compute an easy parallelizable calculation (e.g. Mandelbrot) with Orleans on different grains parallel and merge the result back together once the grains are done. However, I am not sure how to do this or if Orleans is even the right framework for this kind of problem. Also let me mention that this won't be any project which will go in production, I am just playing around with Orleans.
Here is my idea so far: I have one graintype (let's call it "maingrain") which is an entry point for the client (might also be a grain). This grain then estimates the amount of needed processing power and divides the task into smaller parts which are distributed to other grains from another graintype (I will call these "subgrains"). It's no big deal to let these subgrains do the work and wait for a result which can be returned to the client, however I am not sure how to handle the subgrains.
Lets say, there is a call where I want to use 10 subgrains. I get each by a new GUID and let them work. They are done and the client gets the result. Now there is a call where I want to use X subgrains:
How would you do it? Thank you.
You can mark the subgrain as "StatelessWorker" using the Orleans.Concurrency.StatelessWorkerAttribute. This will then automatically scale out the grain (create multiple instances of the same grain) when there's a backlog of messages in it's queue, allowing for these sub tasks to be processed in parallel.
Found this quite interesting regarding stateless workers: http://encloudify.blogspot.co.uk/2014/05/grains-grains-and-more-grains.html