Mercurial > hg > Members > tatsuki > Alice
changeset 225:bc061ee5f31f
bitonic sort work but data is not sorted
author | sugi |
---|---|
date | Thu, 28 Mar 2013 18:10:24 +0900 |
parents | 409d7679cf7b |
children | 6d546924eea0 |
files | src/alice/datasegment/DataSegmentKey.java src/alice/datasegment/LocalDataSegmentManager.java src/alice/datasegment/Receiver.java src/alice/test/codesegment/local/bitonicsort/DataList.java src/alice/test/codesegment/local/bitonicsort/OddPhase.java src/alice/test/codesegment/local/bitonicsort/SetTask.java src/alice/test/codesegment/local/bitonicsort/ShowData.java |
diffstat | 7 files changed, 49 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/datasegment/DataSegmentKey.java Thu Mar 28 00:21:38 2013 +0900 +++ b/src/alice/datasegment/DataSegmentKey.java Thu Mar 28 18:10:24 2013 +0900 @@ -23,7 +23,8 @@ dataList.remove(0); } case PUT: - int index = tailIndex.getAndIncrement(); + int index = tailIndex; + tailIndex++; DataSegmentValue dsv = new DataSegmentValue(index, cmd.val, cmd.obj,cmd.reverseKey); dataList.add(dsv); // Process waiting peek and take commands
--- a/src/alice/datasegment/LocalDataSegmentManager.java Thu Mar 28 00:21:38 2013 +0900 +++ b/src/alice/datasegment/LocalDataSegmentManager.java Thu Mar 28 18:10:24 2013 +0900 @@ -65,7 +65,7 @@ public void put(String key, Value val) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, reverseKey); - addCommand(dataSegmentKey, cmd); + submitCommand(dataSegmentKey, cmd); if (logger.isDebugEnabled()) logger.debug(cmd.getCommandString()); } @@ -73,7 +73,7 @@ public void putObject(String key, Object obj) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); Command cmd = new Command(CommandType.PUT, null, key, obj, 0, 0, null, null, reverseKey); - addCommand(dataSegmentKey, cmd); + submitCommand(dataSegmentKey, cmd); if (logger.isDebugEnabled()) logger.debug(cmd.getCommandString()); } @@ -85,7 +85,7 @@ public void update(String key, Value val) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, reverseKey); - addCommand(dataSegmentKey, cmd); + submitCommand(dataSegmentKey, cmd); if (logger.isDebugEnabled()) logger.debug(cmd.getCommandString()); } @@ -93,7 +93,7 @@ public void updateObject(String key, Object val) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, reverseKey); - addCommand(dataSegmentKey, cmd); + submitCommand(dataSegmentKey, cmd); if (logger.isDebugEnabled()) logger.debug(cmd.getCommandString()); }
--- a/src/alice/datasegment/Receiver.java Thu Mar 28 00:21:38 2013 +0900 +++ b/src/alice/datasegment/Receiver.java Thu Mar 28 18:10:24 2013 +0900 @@ -9,7 +9,7 @@ * */ public class Receiver { - public ReceiverData data = new ReceiveRemoteData(); + private ReceiverData data = new ReceiveRemoteData(); public InputDataSegment ids; public int index; public String from;
--- a/src/alice/test/codesegment/local/bitonicsort/DataList.java Thu Mar 28 00:21:38 2013 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/DataList.java Thu Mar 28 18:10:24 2013 +0900 @@ -17,7 +17,9 @@ public DataList createDataList(int start, int size){ int[] table2 = new int[size]; - for (int i=start,j=0;i<(start+size);i++,j++){ + int end = start+size-1; + //System.out.println(start+" "+end); + for (int i=start,j=0;i<end;i++,j++){ table2[j] = table[i]; } return new DataList(table2);
--- a/src/alice/test/codesegment/local/bitonicsort/OddPhase.java Thu Mar 28 00:21:38 2013 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/OddPhase.java Thu Mar 28 18:10:24 2013 +0900 @@ -28,34 +28,40 @@ @Override public void run() { RangeInfo info = info0.asClass(RangeInfo.class); + DataList list1 = info1.asClass(DataList.class); + DataList list2 = info2.asClass(DataList.class); int sort_count = info5.asInteger(); int count = info6.asInteger(); - //System.out.println("count is " +count); int i = info.range; - if (count<sort_count){ - DataList list1 = info1.asClass(DataList.class); - DataList list2 = info2.asClass(DataList.class); - - Sort.quickSort(list1,0,list1.table.length-1); - Sort.quickSort(list2,0,list2.table.length-1); - DataList.merge(list1,list2); - + + Sort.quickSort(list1,0,list1.table.length-1); + Sort.quickSort(list2,0,list2.table.length-1); + DataList.merge(list1,list2); + + if (count%2==0&&i==0){ ods.flip(info1); + } else if (count%2==0&&info.lastFlag){ ods.flip(info2); - - - - if (i+2 < SetInfo.array.length){ - String f = (count%2==1) ? SetInfo.array[i] : SetInfo.array[i+1]; - String b = (count%2==1) ? SetInfo.array[i+1] : SetInfo.array[i+2]; - new OddPhase(info0.key, f, b,count,info6.key); - } + } + ods.flip(info1); + ods.flip(info2); + + if (count>sort_count){ + System.out.println(SetInfo.result[i*2]+" "+SetInfo.result[i*2+1]); + ods.put(SetInfo.result[i*2], list1); + ods.put(SetInfo.result[i*2+1], list2); + } else if (count%2==0&&info.lastFlag){ + //System.out.println(info0.key+" "+info1.key+" "+info2.key+" "+(count+2)+" "+info6.key); + new OddPhase(info0.key, info1.key, info2.key,count+2,info6.key); + ods.update(info6.key, count+2); } else { - ods.put(SetInfo.result[i*2], info1); - ods.put(SetInfo.result[i*2+1], info2); + String f = (count%2==1) ? SetInfo.array[2*i] : SetInfo.array[2*i+1]; + String b = (count%2==1) ? SetInfo.array[2*i+1] : SetInfo.array[2*i+2]; + //System.out.println(info0.key+" "+f+" "+b+" "+(count+1)+" "+info6.key); + new OddPhase(info0.key, f, b,count,info6.key); + ods.update(info6.key, count+1); } - ods.update(info6.key, count+1); }
--- a/src/alice/test/codesegment/local/bitonicsort/SetTask.java Thu Mar 28 00:21:38 2013 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/SetTask.java Thu Mar 28 18:10:24 2013 +0900 @@ -29,20 +29,24 @@ System.out.println("sort start"); t = System.currentTimeMillis(); - { int i = 0; for (i = 0;i< sort_count/2; i++){ // anonymas datasegmaents should be used. - ods.put(SetInfo.range[i], new RangeInfo(i,i==sort_count-1)); + //System.out.print(SetInfo.range[i]); + ods.put(SetInfo.range[i], new RangeInfo(i,i==(sort_count/2)-1)); + //System.out.print(SetInfo.array[i*2]+" "); ods.update(SetInfo.array[i*2], list.createDataList(i*2*block_num, block_num)); + //System.out.print(SetInfo.array[i*2+1]+" "); ods.update(SetInfo.array[i*2+1], list.createDataList((i*2+1)*block_num, block_num)); ods.update(SetInfo.count[i], 0); + System.out.println(SetInfo.range[i]+" "+SetInfo.array[i*2]+" "+SetInfo.array[i*2+1]+" "+0+" "+SetInfo.count[i]); new OddPhase(SetInfo.range[i],SetInfo.array[i*2],SetInfo.array[i*2+1],0,SetInfo.count[i]); + } - - ods.put("arraynum",i); - new ShowData(i+1); + + ods.put("arraynum",i*2+1); + new ShowData(i*2); }
--- a/src/alice/test/codesegment/local/bitonicsort/ShowData.java Thu Mar 28 00:21:38 2013 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/ShowData.java Thu Mar 28 18:10:24 2013 +0900 @@ -7,25 +7,20 @@ public class ShowData extends CodeSegment{ private Receiver[] info; - private Receiver info0 = ids.create(CommandType.PEEK); public ShowData(int cnt) { info = new Receiver[cnt]; for (int i= 0;i < cnt; i++) info[i] = ids.create(CommandType.PEEK); for (int i= 0;i < cnt; i++) - info[i].setKey("array"+i,1); - - info0.setKey("arraynum"); + info[i].setKey(SetInfo.result[i]); } @Override public void run() { System.out.println(System.currentTimeMillis() -SetTask.t +" ms"); - int cnt = info0.asInteger(); int size = 0; - - for (int i= 0;i < cnt; i++){ + for (int i= 0;i < info.length; i++){ DataList dlist = info[i].asClass(DataList.class); size += dlist.table.length; } @@ -33,12 +28,12 @@ DataList list = new DataList(size); int start = 0; - for (int i= 0;i < cnt; i++){ + for (int i= 0;i < info.length; i++){ DataList dlist = info[i].asClass(DataList.class); System.arraycopy(dlist.table, 0, list.table, start, dlist.table.length); start += dlist.table.length; } - + list.showData(); System.out.println("size check :"+ list.table.length); Sort.check(list); System.exit(0);