On Saturday, March 19, 2016 at 11:56:37 AM UTC-4, Brian Adkins wrote:
> On Saturday, March 19, 2016 at 11:45:46 AM UTC-4, Brian Adkins wrote:
> > I've put together a very simple (31 lines) example of parallel task 
> > execution here:
> > 
> > https://gist.github.com/lojic/6cee4fcd4220e2788ece
> > 
> > The example contains a lot of boilerplate (only a few lines are specific to 
> > the problem), so before I go about eliminating the boilerplate myself, I 
> > thought I'd ask if this has already been done in a general and reusable way 
> > - has it?
> > 
> > I'm fairly new to parallel programming in Racket, but thus far I seem to 
> > encounter the same pattern repeatedly:
> > 
> > 1) Create a pair of place channels to allow sending units of work to 
> > parallel workers and retrieving results
> > 
> > 2) Create one place per core which repeatedly grabs a unit of work from the 
> > queue, calls a function with the unit of work, and places the result on the 
> > queue
> > 
> > 3) Write all the units of work to the queue
> > 
> > 4) Retrieve all the results from the queue
> > 
> > It think this can all be boiled down to specifying:
> > 1) The name of the function to do the work (line 4)
> > 2) The list of units of work (line 23)
> > 
> > The rest of the example is generic.
> > 
> > Thanks,
> > Brian
> 
> This example is probably clearer:
> 
> https://gist.github.com/lojic/d92bd1f537410f6dc4e9
> 
> It's shorter, and by using place/context, I eliminated a lot of cruft. All of 
> main is now generic.

Well, this isn't exactly what I had in mind, but I did create a simple function 
to create the work queue, start the places and send the queue to each place:

https://github.com/lojic/LearningRacket/blob/master/exercism.io/async-task.rkt

and used it in this simple exercise to compute letter frequency for strings in 
parallel:

https://github.com/lojic/LearningRacket/blob/master/exercism.io/parallel-letter-frequency/parallel-letter-frequency.rkt

I originally had these two lines in async-task.rkt:

https://github.com/lojic/LearningRacket/blob/master/exercism.io/parallel-letter-frequency/parallel-letter-frequency.rkt#L8-L9

but it didn't seem write to give up control of populating the queue since 
passing a list won't always make sense i.e. in the case of the input being a 
stream of events.

I'm probably prematurely optimizing the aesthetics - once I've used places 
enough, I expect some better, common patterns will emerge.

Brian

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to