• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
GPars in Saga Groovy Study
 

GPars in Saga Groovy Study

on

  • 1,198 views

佐賀Groovy勉強会のGParsの資料です。

佐賀Groovy勉強会のGParsの資料です。

Statistics

Views

Total Views
1,198
Views on SlideShare
936
Embed Views
262

Actions

Likes
0
Downloads
11
Comments
0

3 Embeds 262

http://d.hatena.ne.jp 251
http://naokirin.hatenablog.com 9
http://webcache.googleusercontent.com 2

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    GPars in Saga Groovy Study GPars in Saga Groovy Study Presentation Transcript

    • Groovy with GPars @Naoki RinGParsGParsGPars 6 GroovyMap/ReduceFork/Join withAgentDataflowVariableDataflowsDataflowQueue @Naoki Rin
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 Twitter @Naoki RinMap/ReduceFork/Join Hatena id:naokirin Groovy 1 JavaAgent Groovy GroovyDataflowVariableDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 . .1 GPars 2Map/ReduceFork/Join . .3 4Agent . .5DataflowVariableDataflows 6DataflowQueue ..
    • GParsGroovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • GParsGroovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/Join Groovy DSL Groovy1.8AgentDataflowVariableDataflowsDataflowQueue
    • GParsGroovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/Join Groovy DSL Groovy1.8Agent GroovyDataflowVariableDataflowsDataflowQueue
    • GParsGroovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/Join Groovy DSL Groovy1.8Agent GroovyDataflowVariableDataflowsDataflowQueue
    • GParsGroovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/Join Groovy DSL Groovy1.8Agent GroovyDataflowVariableDataflowsDataflowQueue
    • GParsGroovy with GPars @Naoki RinGPars Groovy 1.8 GPars 0.11GParsGPars 6 GroovyMap/ReduceFork/Join Groovy 1.8.2 GPars 0.12 GPars 0.12 Groovy gpars-0.11.jarAgent gpars-0.12.jar OK Groovy 1.8 @Grab OKDataflowVariableDataflowsDataflowQueue GPars 0.12
    • GPars 6Groovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • GPars 6Groovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/Join StmAgent Groovy CSPDataflowVariableDataflowsDataflowQueue
    • GPars 6Groovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/Join StmAgent Groovy CSPDataflowVariableDataflowsDataflowQueue
    • GPars 6Groovy with GPars @Naoki RinGParsGParsGPars 6 GParsMap/ReduceFork/Join StmAgent Groovy CSPDataflowVariableDataflows 4DataflowQueue
    • Groovy with GPars @Naoki RinGPars (Data Parallelism)GParsGPars 6Map/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGPars (Data Parallelism)GParsGPars 6 Go!Map/ReduceFork/Join ( ) Go! Map/Reduce Go!Agent Map/Reduce Fork/Join Go!DataflowVariableDataflows Fork/JoinDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 GroovyMap/ReduceFork/Join GParsPool - JSR-166y(ParallelArray) DSLAgent GParsExecutorsPool -DataflowVariable Java ExecutorDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 import groovyx.gpars.GParsPoolMap/ReduceFork/Join . GParsPool.withPool { assert ([2, 3, 4, 5]== [1, 2, 3, 4].collectParallel {it + 1}) } .Agent withPool collectParallel() collectDataflowVariableDataflowsDataflowQueue .. .
    • xxxParallelGroovy with GPars @Naoki RinGPars withPool xxxParallel()GParsGPars 6Map/ReduceFork/Join withPool xxx findAll() findAllParallel() import groovyx.gpars.GParsPoolAgent GParsPool.withPool { assert ([1, 2, 3, 4 ].findAll{it % 2 == 0}DataflowVariableDataflows == [1, 2, 3, 4 ].findAllParallel{it % 2 == 0})DataflowQueue } .
    • xxxParallelGroovy with GPars @Naoki RinGParsGPars GParsPool.withPoolGPars 6Map/ReduceFork/Join anyParallel() findParallel() collectParallel() foldParallel() countParallel() grepParallel() eachParallel() groupByParallel() eachWithIndexParallel() maxParallel()Agent everyParallel() minParallel() findAllParallel() splitParallel()DataflowVariableDataflowsDataflowQueue findAnyParallel() sumParallel()
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 withPoolMap/ReduceFork/Join import groovyx.gpars.GParsPool . GParsPool.withPool(10) { // }Agent withPool . +1DataflowVariableDataflowsDataflowQueue .. .
    • Groovy with GPars @Naoki RinGParsGPars withPoolGPars 6 . import groovyx.gpars.ParallelEnhancerMap/Reduce def list = [4, 1, 5, 3, 2 ]Fork/Join ParallelEnhancer.enhanceInstance(list) assert (list.findParallel {it == 3} == 3) . Parallel import groovyx.gpars.GParsPoolAgent .GParsPool.withPool{ . . def data = (1..3).makeConcurrent()DataflowVariableDataflows assert( data.collect {it ** 2} == [1, 4, 9] )DataflowQueue } .
    • ( )Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/Join GParsPool.withPool() { Future result = {it * 2}.callAsync(3) assert 6 == result.get() .}Agent withPool callAsync() . Future get()DataflowVariableDataflowsDataflowQueue .. .
    • Map/ReduceGroovy with GPars @Naoki RinGParsGParsGPars 6 Map/ReduceMap/ReduceFork/Join GPars map /Agent reduce map (DataflowVariableDataflows )DataflowQueue
    • GPars Map/ReduceGroovy with GPars @Naoki RinGParsGPars GPars Map/Reduce Parallel ArrayGPars 6Map/Reduce Parallel ArrayFork/Join parallel Parallel Array getParallel() ParallelAgent ArrayDataflowVariable Parallel Array MapDataflowsDataflowQueue collection
    • Map/ReduceGroovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/Join map() Parallel Array(AbstractPAWrapper) reduce() T filter() Parallel Array(AbstractPAWrapper) size() int sum() TAgent min() T max() TDataflowVariable sort() Parallel Array(AbstractPAWrapper)DataflowsDataflowQueue groupBy() Map combine() Map
    • Map/ReduceGroovy with GPars @Naoki RinGParsGParsGPars 6 Map . GParsPool.withPool {Map/Reduce println (”Hello World”.parallelFork/Join .map{[it, 1]} .combine(0) { sum, value -> sum + value} .getParallel() .sort{-it.value} .collection) }Agent .DataflowVariableDataflows [l=3, o=2, H=1, e=1, W=1, =1, d=1, r=1]DataflowQueue
    • Fork/JoinGroovy with GPars @Naoki RinGPars forkGParsGPars 6Map/ReduceFork/Join join forkAgentDataflowVariableDataflowsDataflowQueue
    • Fork/JoinGroovy with GPars @Naoki RinGParsGParsGPars 6 forkOffChild() -Map/ReduceFork/Join runChildDirectly() - GPars 0.12Agent getChildrenResults() - forkDataflowVariable runForkJoin() -DataflowsDataflowQueue withPool Fork/Join
    • Fork/JoinGroovy with GPars @Naoki RinGParsGPars fibonacciGPars 6 . import groovyx.gpars.GParsPoolMap/Reduce Closure fib = {number -> if (number <= 2) {Fork/Join return 1 } forkOffChild(number - 1) final def result = runChildDirectly(number - 2) return (Integer) getChildrenResults().sum() + result }Agent GParsPool.withPool {DataflowVariable assert 55 == GParsPool.runForkJoin(10, fib)DataflowsDataflowQueue } .
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • GParsGroovy with GPars @Naoki RinGParsGPars .GPars 6 import static groovyx.gpars.actor.Actors.* def console = actor { //Map/ReduceFork/Join loop { react {msg -> println msg } } }Agent . console.send ’Hello World!’ //DataflowVariableDataflowsDataflowQueue Hello World
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 1 import static groovyx.gpars.actor.Actors.*Map/ReduceFork/Join . def console = actor { react {msg -> println msg } }Agent react . reactDataflowVariableDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/Join console.send ’Hello World!’ // console ’Hello World!’ // . console << ’Hello World!’ // console.call ’Hello World!’ //Agent .DataflowVariableDataflowsDataflowQueue .. .
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 . import static groovyx.gpars.actor.Actors.*Map/ReduceFork/Join def console = actor { loop{ react {msg -> println msg } }Agent } . loop reactDataflowVariableDataflowsDataflowQueue
    • reactorGroovy with GPars @Naoki RinGParsGParsGPars 6Map/Reduce reactorFork/Join import static groovyx.gpars.actor.Actors.* def console = reactor { // } . actor{loop{react{ }}} reactor{}Agent .DataflowVariableDataflowsDataflowQueue .. .
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/Join console.send ’Hello!’ console.send ’Hello!!’ . console.stop() console.join() join() .AgentDataflowVariableDataflowsDataflowQueue .. .
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/Reduce def console = reactor {reply it.reverse()}Fork/Join assert ’Hello!’ == console.sendAndWait(’ !olleH’) . reply sendAndWait() .Agent .. .DataflowVariableDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 def parrot = reactor { .Map/Reduce println ’Parrot: ’ + itFork/Join sender.send it } def mary = actor { println ’Mary: Hello!’ parrot.send ’Hello!’Agent react{println ’Mary: Good!’} } .DataflowVariableDataflows senderDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 ( )Map/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • GParsGroovy with GPars @Naoki RinGParsGParsGPars 6 . import groovyx.gpars.GParsPool import groovyx.gpars.agent.AgentMap/ReduceFork/Join def agent = new Agent(1) GParsPool.withPool { (1..10).eachParallel {value -> agent {updateValue(it * value)} } }Agent println agent.val .DataflowVariableDataflowsDataflowQueue 3628800
    • AgentGroovy with GPars @Naoki RinGParsGParsGPars 6 Agent import groovyx.gpars.agent.AgentMap/Reduce .Fork/Join def intAgent = new Agent(0) def stringAgent = new Agent<String>() assert 0 == intAgent.val . AgentAgent GroovyDataflowVariableDataflows .valDataflowQueue .. .
    • Groovy with GPars @Naoki RinGParsGPars .GPars 6 import groovyx.gpars.agent.Agent def jvmLangList = new Agent<List<String>>()Map/ReduceFork/Join jvmLangList {updateValue([’Java’])} jvmLangList.send {it << ’Scala’} jvmLangList.call {it.add ’Clojure’} jvmLangList jvmLangList.val + ’Groovy’ assert [’Java’, ’Scala’, ’Clojure’, ’Groovy’] . == jvmLangList.valAgent updateValue()DataflowVariableDataflowsDataflowQueue
    • Groovy with GPars @Naoki Rin .GParsGPars def members = new Agent([’Jones’])GPars 6 final Thread t1 = Thread.start { members {it.add ’Bob’}Map/Reduce members {it.add ’Davis’}Fork/Join } final Thread t2 = Thread.start { members {it.add ’Alice’} members {it.remove(0)} }Agent // [Jones, Bob, Davis, Alice] . members.valAsync {println it}DataflowVariable .valDataflowsDataflowQueue valAsync() valAsync()
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • ( )Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue
    • GPars DataflowGroovy with GPars @Naoki RinGPars .GParsGPars 6 import groovyx.gpars.dataflow.Dataflow import groovyx.gpars.dataflow.DataflowVariableMap/Reduce final def x = new DataflowVariable()Fork/Join final def y = new DataflowVariable() final def z = new DataflowVariable() Dataflow.task { z << x.val + y.val } Dataflow.task { x << 5 } Dataflow.task { y << 10 }Agent . println z.valDataflowVariableDataflowsDataflowQueue 15
    • DataflowVariableGroovy with GPars @Naoki RinGParsGPars . DataflowVariableGPars 6 import static groovyx.gpars.dataflow.Dataflow.task import groovyx.gpars.dataflow.DataflowVariableMap/ReduceFork/Join final def x = new DataflowVariable() final def y = new DataflowVariable() task{y << x.val + 1} task{x << 1} .Agent assert 2 == y.val DataflowVariableDataflowVariableDataflowsDataflowQueue Dataflow.task task
    • Groovy with GPars @Naoki RinGParsGParsGPars 6 . import static groovyx.gpars.dataflow.Dataflow.task import groovyx.gpars.dataflow.DataflowVariableMap/ReduceFork/Join def x = new DataflowVariable() def y = new DataflowVariable() task {x << y.val} task {y << x.val}Agent println x.val // ! .DataflowVariableDataflowsDataflowQueue
    • DataflowsGroovy with GPars @Naoki RinGParsGPars DataflowsGPars 6 . import static groovyx.gpars.dataflow.Dataflow.task import groovyx.gpars.dataflow.DataflowsMap/ReduceFork/Join final def dfs = new Dataflows() task {dfs[0] = dfs.x + ” ” + dfs.y} task {dfs.y = ”Groovy!”} task {dfs.x = ”Hello”} assert ”Hello Groovy!” == dfs[0] .Agent Dataflows DataflowVariableDataflowVariableDataflowsDataflowQueue
    • DataflowQueueGroovy with GPars @Naoki RinGParsGParsGPars 6 DatafowQueue . import groovyx.gpars.dataflow.DataflowQueueMap/ReduceFork/Join final def queue = new DataflowQueue() queue << ’a’ queue << ’b’ queue << ’c’ assert ’a’ == queue.valAgent assert ’b’ == queue.val assert ’c’ == queue.val .DataflowVariable DataflowQueueDataflowsDataflowQueue .val
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/Join GPars GroovyAgentDataflowVariableDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/Join Groovy http://gihyo.jp/book/2011/978-4-7741-4727-7 GPars Users Guide http://gpars.org/0.12/guide/index.htmlAgent GPars JavadocDataflowVariable http://gpars.org/0.12/javadocDataflowsDataflowQueue
    • Groovy with GPars @Naoki RinGParsGParsGPars 6Map/ReduceFork/JoinAgentDataflowVariableDataflowsDataflowQueue