j-o-caml (6) [email protected] pauillac.inria.fr/~levy/qinghua/j-o-caml qinghua, december 4
TRANSCRIPT
![Page 2: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/2.jpg)
Plan of this class
• concurrency
• threads, locks, conditions, shared memory
• communication channels, CML
• distributed setting
• principles of Jocaml
• a concurrent labeling program ?!!!
![Page 3: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/3.jpg)
Exercices
• ???
![Page 4: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/4.jpg)
Threads
• light weight processes are implemented in Thread module
• both VM threads (byte code) and Linux threads (binary if available)
produces
![Page 5: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/5.jpg)
Concurrency - Shared memory
• critical sections -- locks
![Page 6: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/6.jpg)
Concurrency - Shared memory
concurrent FIFO with locks + condition variables
![Page 7: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/7.jpg)
Concurrency - Shared memory
• locks and condition variables are light implementations of old Hoare/Hansen/Dijkstra monitors
• implemented in many languages with shared memory [Modula3, C#]
• curiously missing in Java [locks but no conditions !]
• impossible to write correct version of readers/writers without them
![Page 8: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/8.jpg)
Communication channels• John Reppy’s Event module for CML (SML/NJ) in Ocaml
![Page 9: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/9.jpg)
Distributed environments
• asynchronous communications
• rendez-vous on unlocalized channels are impossible
because of distributed consensus
• need for join patterns
![Page 10: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/10.jpg)
Join-Patterns
• asynchronous channels
![Page 11: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/11.jpg)
Join-Patterns
• synchronous channels
• join patterns [waiting for presence of several messages]
![Page 12: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/12.jpg)
Join-Patterns
• actors without memory state !
half of J.-P. Banatre multi-functions paradigm
• hiding internal channels
![Page 13: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/13.jpg)
Join-Patterns
• collectors are frequent programming scheme
• example of a compute server
![Page 14: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/14.jpg)
Distribution
• server side (with help of nameserver) on here.inria.fr
• client side (with help of nameserver)
![Page 15: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/15.jpg)
Real examples
• ray tracers (given in standard jocaml release)
• one of which won the ICFP programming contest
• slight modifications to get the concurrent or distributed version
• join patterns are polyphonic C# (Benton), VB 9.0 (Russo)
• Jocaml [without mobility] now follows Ocaml releases
• and mobility ?
General philosophy• concurrent programming is very hard
• distribution is impossible to debug
• local and remote behaviors should be identical
![Page 16: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/16.jpg)
Combien d’objetsdans une image?
Jean-Jacques LévyINRIA
![Page 17: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/17.jpg)
Labeling
16 objects in this picture
1
1
2 3
4 5 6
78 9
10
11 12
13 14
![Page 18: J-O-Caml (6) jean-jacques.levy@inria.fr pauillac.inria.fr/~levy/qinghua/j-o-caml Qinghua, December 4](https://reader036.vdocument.in/reader036/viewer/2022070400/56649f125503460f94c25c5b/html5/thumbnails/18.jpg)
Concurrent algorithm
1) first pass
2) scan pixels left-to-right, top-to-bottom giving a new object id each time a new object is met, can be done on dual-core with half image per core.
3) second pass
4) generate equivalences between ids due to new adjacent relations met during scan of pixels, taking care of border (generating new equivalences)
5) third pass
6) compute the number of equivalence classes and give result in parallel
7) think of the distributed setting with several machines on the net