Upload
canh
View
1
Download
0
Embed Size (px)
DESCRIPTION
aa
Citation preview
TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT TP.HCM
KHOA CÔNG NGHỆ THÔNG TIN
--- ---
BÁO CÁO MÔN HỌC:
ĐIỆN TOÁN ĐÁM MÂY
ĐỀ TÀI:
SORT SỐ ÂM, DƯƠNG, NGUYÊN, KHÔNG NGUYÊN
Giáo viên hướng dẫn : TS. Đặng Thanh Dũng
Sinh viên thực hiện :
Bùi Thị Lan Anh 12110003
Nguyễn Phong Cảnh 12110013
Nguyễn Ngân Giang 12110038
TP.HCM , tháng 4 năm 2015
1. Tổng quan đề tài:
ĐỀ TÀI: Sort (số âm, dương, nguyên, không nguyên)
+ Input: Text files chứa các số (âm, dương, nguyên, không nguyên)
+ Data: 1Mb
+ CM CT chạy đúng
+ Chạy trên cloud với data 20 Mb
2. Phân tích đề tài:
a. Cấu trúc file Input- File txt chứa nhiều dòng, mỗi dòng chứa nhiều số bao gồm: số âm,
dương, nguyên, không nguyênb. Cấu trúc file output
- File txt chứa nhiều dòng, mỗi dòng 1 số đã được sắp xếp theo thứ tự tăng dần
c. Cấu trúc dữ liệu MapperInput- Là danh sách các cặp (k,v), trong đó:
k là: documentID
v là: nội dung documentID
d. Cấu trúc dữ liệu MapperOutput- Là danh sách các cặp (k,v), trong đó:
k là : số lấy ra từ file
v là : số lấy ra từ file
e. Cấu trúc dữ liệu ReducerInput- Là danh sách các cặp (k,v), trong đó:
k là : số lấy ra từ filev là : số lấy ra từ file
f. Cấu trúc dữ liệu Reducer Output- Là giá trị của v trong cặp (k,v)
g. Sơ đồ
Input1
1 7 8 9 -9999 -2.3 -6.33 -9 55
Mapper
Input2
0.6 2.2 1000000000 7 8 9 8 9 0
Input3
555 15000 -9.99 -9.4 0 4 1.4 4.1 56.56
Mapper Mapper
Shuffle and Sort
Reducer
k v0.6 0.62.2 2.21000000000 10000000007 78 89 98 89 90 0
k v555 55515000 15000-9.99 -9.999.4 9.40 04 41.4 1.44.1 4.156.56 56.56
k v1 17 78 89 9-9999 -9999-2.3 -2.3-6.33 -6.33-9 -955 55
-9999-9.99-9-6.33-2.3011.4…….56.56555150001000000000
h. Thuật toán của Mapper
Value: nội dung document idline = convert(Value) to stringString itr[] = line.split();While(itr.next!=null){
t=itr.next;k=t;v=t;output(k,v)
}
SortMapper.java :
public class SortMapper extends MapReduceBase implementsMapper<LongWritable, Text, FloatWritable, Text> {
private Text text = new Text();private FloatWritable fW = new FloatWritable();
public void map(LongWritable key, Text value,OutputCollector<FloatWritable, Text> output, Reporter reporter)
throws IOException {String line = value.toString();//Dua value ve thanh kieu StringStringTokenizer itr = new StringTokenizer(line);/*Tach line thanh cac chuoi
nho*//*StringTokenizer giup tach mot String thanh nhung tokens*/
while(itr.hasMoreTokens()) {String t=itr.nextToken();/*Lay phan tu tiep theo*/fW.set(Float.parseFloat(t));//ep t ve kieu thuc va dat cho fWtext.set(t);//dat text cung la toutput.collect(fW, text );//key,value
}}
}
Thuật toán Reducer
foreach( (k,v) : (key, value))Print value
SortReducer.java:
public class SortReducer extends MapReduceBaseimplements Reducer<FloatWritable, Text, FloatWritable, Text> {
public void reduce(FloatWritable key, Iterator<Text> values,OutputCollector<FloatWritable, Text> output,
Reporter reporter)throws IOException {
// TODO Auto-generated method stub
/*Goi hasNext() cua Iterator voi vai tro bieu thuc logicchay vong lap xem con phan tu nao de xu ly nua ko*/
while (values.hasNext()) {output.collect(key, values.next());/*Goi next() cua
Iterator de lay phan tu tiep theo moi lan di qua vong lap*/
}}
}
Sort.java:
public class Sort {
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(Sort.class);conf.setOutputKeyClass(FloatWritable.class);conf.setOutputValueClass(Text.class);
conf.setMapperClass(SortMapper.class);conf.setReducerClass(SortReducer.class);
conf.setInputFormat(TextInputFormat.class);conf.setOutputFormat(FileOutPutFormat.class);
FileInputFormat.setInputPaths(conf,new Path("SortInput"));FileOutputFormat.setOutputPath(conf, new Path("SortOutput"));JobClient.runJob(conf);}
}