forked from happyer/distributed-computing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.go
44 lines (37 loc) · 1016 Bytes
/
schedule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package mapreduce
import "fmt"
// schedule starts and waits for all tasks in the given phase (Map or Reduce).
func (mr *Master) schedule(phase jobPhase) {
var ntasks int
var nios int // number of inputs (for reduce) or outputs (for map)
switch phase {
case mapPhase:
ntasks = len(mr.files)
nios = mr.nReduce
case reducePhase:
ntasks = mr.nReduce
nios = len(mr.files)
}
fmt.Printf("Schedule: %v %v tasks (%d I/Os)\n", ntasks, phase, nios)
//use go routing,worker rpc executor task,
done := make(chan bool)
for i := 0; i < ntasks; i++ {
go func(number int) {
args := DoTaskArgs{mr.jobName, mr.files[number], phase, number, nios}
var worker string
reply := new(struct{})
ok := false
for ok != true {
worker = <- mr.registerChannel
ok = call(worker, "Worker.DoTask", args, reply)
}
done <- true
mr.registerChannel <- worker
}(i)
}
//wait for all task is complate
for i := 0; i< ntasks; i++ {
<- done
}
fmt.Printf("Schedule: %v phase done\n", phase)
}