-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (39 loc) · 1.07 KB
/
main.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
45
46
package main
import (
"fmt"
"os"
"math"
)
const numWorkers = 8
//number of bytes in each inputFile-chunk
const chunkSize = 64000
//number of reduce tasks
const R = 8
func checkArgs(argc int, argv []string) (string, string) {
if argc != 3 {
fmt.Fprintf(os.Stderr, "Usage: ./main <input_file.txt> <*.so>\n")
os.Exit(1)
}
if _, err := os.Stat(argv[1]); os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "'%s' not in current directory\n",argv[1])
os.Exit(1)
}
return argv[1], argv[2]
}
func getNumMapTasks(filePath string) int {
file := safeOpen(filePath, "r")
fileInfo, fileStatErr := file.Stat()
if fileStatErr != nil {
fmt.Fprintf(os.Stderr, "error stat on file '%s'\n",filePath);
os.Exit(1);
}
fileSize := fileInfo.Size()
numMapTasks := float64(fileSize) / float64(chunkSize)
return int(math.Ceil(numMapTasks))
}
func main() {
inputFilePath, soFilepath := checkArgs(len(os.Args), os.Args)
numMapTasks := getNumMapTasks(inputFilePath)
createOutputDirs([]string {"./intermediate_files","./output_files"})
launchWorkers(inputFilePath, soFilepath, numMapTasks)
}