-
Notifications
You must be signed in to change notification settings - Fork 2
Erlang Parallel Building Blocks
License
baryluk/epbb
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Erlang parallel building blocks Copyright (c) 2011, Witold Baryluk All rights reserved. Licensed under BSD license, see LICENSE for details. Somtimes we need to start multiple parallal tasks and then wait until all of them completes. This is acomplished using epbb module, with new_group/0, spawn/2, spawn_list/2, go/1, async_go/1, barrier/0,1 and sync/1 functions: Example: P = self(), Group = epbb2:new_group(), Group1 = epbb2:spawn_list([ fun(U) -> io:format("A~n"), epbb2:barrier(U), io:format("K~n") end, fun(U) -> io:format("B~n"), epbb2:barrier(U), io:format("L~n") end, fun(U) -> io:format("C~n"), epbb2:barrier(U), io:format("M~n") end ], Group), Group2 = epbb2:spawn(fun(U) -> io:format("D~n"), epbb2:barrier(U), io:format("N~n") end, Group1), {Group3, goed} = epbb2:go(Group2), {_, synced} = epbb2:sync(Group3), io:format("Z~n"). It will display A, B, C, D before K, L, M, N which will be before Z. Actuall A, B, C, D can be permuted. Similary K, L, M, N. But ordering beetween groups will be conserved. For example on my machine it output gives: C B A D N K L M Z ok There are two identical APIs which can be used. epbb and epbb2, they just differ in implementation. epbb is based on direct handling of processes in sync function in calling processes. epbb2 starts new controling processes in new_group, and all other calls are actually just sending messages to this controling process. It is more flexible, more robust and should be faster, if you have multiple groups, or want to perform something in the calling processes without worring about usage of barriers in spawned processes. Instead of fun/1, one can pass fun/0 to spawn/spawn_list functions, but then using of epbb2:barrier/1 is impossible (or rather not recommended, because it is possible to use epbb2:barrier/0, for same functionality, Pid/Ref of parent/controlling process, will be just implicitly stored in process' dictionary under key '$epbb2_parent'). Spawned tasks, can perform currently actions: - epbb2:barrier() - must be called by all spawned processes to make progress through it - epbb2:iamdone() - called automatically when processes ends TODO: - reduce - broadcast_to_other - send_to_parent - receive_from_parent Two last functions involves parent to communicate with all processes, this means that all spawned processes should follow same code path.
About
Erlang Parallel Building Blocks
Resources
License
Stars
Watchers
Forks
Releases
No releases published