Mercurial > hg > Database > Alice
changeset 157:12c8be670e0f working
add statement class
author | sugi |
---|---|
date | Tue, 11 Dec 2012 19:58:47 +0900 |
parents | e0f077820d59 |
children | 3151fd83d3e4 |
files | src/alice/test/codesegment/local/bitonicsort/DataList.java src/alice/test/codesegment/local/bitonicsort/EvenPhase.java src/alice/test/codesegment/local/bitonicsort/OddPhase.java src/alice/test/codesegment/local/bitonicsort/RangeInfo.java src/alice/test/codesegment/local/bitonicsort/SetTask.java |
diffstat | 5 files changed, 108 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/codesegment/local/bitonicsort/DataList.java Tue Dec 11 15:50:17 2012 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/DataList.java Tue Dec 11 19:58:47 2012 +0900 @@ -11,40 +11,20 @@ public class DataList { public List<Integer> table = new LinkedList<Integer>(); - public int num; - public String position; public DataList(){}; public DataList(List<Integer> numbers){ table = numbers; } - public DataList(List<Integer> numbers,int arrayNum){ - table = numbers; - num = arrayNum; - } - public DataList(List<Integer> numbers ,int arrayNum ,String p){ - table = numbers; - num = arrayNum; - position = p; - } - public DataList getSubList(int start, int size, int arrayNum){ + public DataList createDataList(int start, int size){ List<Integer> table2 = new LinkedList<Integer>(); ListIterator<Integer> iter = table.listIterator(start); for (int i=start;i<(start+size);i++){ table2.add(iter.next()); } - //System.out.println(table2); - return new DataList(table2,arrayNum); + return new DataList(table2); } - public DataList createDataList(int start, int size, int arrayNum, String p){ - List<Integer> table2 = new LinkedList<Integer>(); - ListIterator<Integer> iter = table.listIterator(start); - for (int i=start;i<(start+size);i++){ - table2.add(iter.next()); - } - //System.out.println(table2); - return new DataList(table2,arrayNum,p); - } + }
--- a/src/alice/test/codesegment/local/bitonicsort/EvenPhase.java Tue Dec 11 15:50:17 2012 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/EvenPhase.java Tue Dec 11 19:58:47 2012 +0900 @@ -8,19 +8,24 @@ import alice.datasegment.Receiver; public class EvenPhase extends CodeSegment{ - private Receiver info1; - private Receiver info2; - private Receiver info3 = ids.create(CommandType.PEEK); - private Receiver info4 = ids.create(CommandType.PEEK); + private Receiver info0 = ids.create(CommandType.PEEK); // range + private Receiver info1; // Array1 + private Receiver info2; // Array2 + private Receiver info3 = ids.create(CommandType.PEEK); // block_num + private Receiver info4 = ids.create(CommandType.PEEK); // last_block_num + //private Receiver info5 = ids.create(CommandType.PEEK); // sort_count + //private Receiver info6 = ids.create(CommandType.PEEK); // count - public EvenPhase(String key1){ + public EvenPhase(String key0 ,String key1){ + info0.setKey(key0); info1 = ids.create(CommandType.TAKE); info1.setKey("local",key1); info3.setKey("block_num"); info4.setKey("last_block_num"); } - public EvenPhase(String key1,String key2){ + public EvenPhase(String key0,String key1,String key2){ + info0.setKey(key0); info1 = ids.create(CommandType.TAKE); info1.setKey("local",key1); info2 = ids.create(CommandType.TAKE); @@ -31,29 +36,36 @@ @Override public void run() { - - DataList list1 = info1.asClass(DataList.class); - DataList list2 = info2.asClass(DataList.class); - int block_num = info3.asInteger(); + RangeInfo info = info0.asClass(RangeInfo.class); + if (info2==null){ + DataList list = info1.asClass(DataList.class); + ods.update("local", info.range+"b", list); + System.out.println("next Odd "+info.range+" "+info.range+"b"+" "+(info.range+1)+"f"); + new OddPhase(info0.key,info.range+"b",(info.range+1)+"f"); + } else { + DataList list1 = info1.asClass(DataList.class); + DataList list2 = info2.asClass(DataList.class); + int block_num = info3.asInteger(); + list2.table = quickSort(list1.table,list2.table); - list2.table = quickSort(list1.table,list2.table); - System.out.println(list2.num+""+list2.table); - if (!list2.position.equals("last")){ - ods.update("local", list2.num+"f", - list2.createDataList(0, block_num/2, list2.num, "f")); - ods.update("local", list2.num+"b", - list2.createDataList(block_num/2, block_num/2, list2.num, "b")); - new OddPhase(list2.num+"b",(list2.num+1)+"f"); - } else { - int last_block_num = info4.asInteger(); - ods.update("local", list2.num+"f", - list2.createDataList(0, block_num/2, list2.num, "f")); - ods.update("local", list2.num+"b", - list2.createDataList(block_num/2, last_block_num, list2.num, "last")); - new OddPhase(list2.num+"b"); + if (!info.lastFlag){ + ods.update("local", info.range+"f", + list2.createDataList(0, block_num/2)); + ods.update("local", info.range+"b", + list2.createDataList(block_num/2, block_num/2)); + System.out.println("next Odd "+info.range+" "+ info.range+"b"+" "+(info.range+1)+"f"); + new OddPhase(info0.key,info.range+"b",(info.range+1)+"f"); + } else { + int last_block_num = info4.asInteger(); + ods.update("local", info.range+"f", + list2.createDataList(0, block_num/2)); + ods.update("local", info.range+"b", + list2.createDataList(block_num/2, last_block_num)); + System.out.println("next Odd "+info.range+" "+ info.range+"b"); + new OddPhase(info0.key ,info.range+"b"); + } + } - - }
--- a/src/alice/test/codesegment/local/bitonicsort/OddPhase.java Tue Dec 11 15:50:17 2012 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/OddPhase.java Tue Dec 11 19:58:47 2012 +0900 @@ -8,52 +8,80 @@ import alice.datasegment.Receiver; public class OddPhase extends CodeSegment{ - private Receiver info1; - private Receiver info2; - private Receiver info3 = ids.create(CommandType.PEEK); + private Receiver info0 = ids.create(CommandType.PEEK); // range + private Receiver info1; // Array1 + private Receiver info2; // Array2 + private Receiver info3 = ids.create(CommandType.PEEK); // block_num + private Receiver info4 = ids.create(CommandType.PEEK); // last_block_num + //private Receiver info5 = ids.create(CommandType.PEEK); // sort_count + //private Receiver info6 = ids.create(CommandType.PEEK); // count - public OddPhase(String key1){ + public OddPhase(String key0,String key1){ + info0.setKey(key0); info1 = ids.create(CommandType.TAKE); info1.setKey("local",key1); info3.setKey("block_num"); + info4.setKey("last_block_num"); } - public OddPhase(String key1,String key2){ + public OddPhase(String key0,String key1,String key2){ + info0.setKey(key0); info1 = ids.create(CommandType.TAKE); info1.setKey("local",key1); info2 = ids.create(CommandType.TAKE); info2.setKey("local",key2); info3.setKey("block_num"); + info4.setKey("last_block_num"); } @Override public void run() { + RangeInfo info = info0.asClass(RangeInfo.class); int block_num = info3.asInteger(); if (info2==null){ DataList list = info1.asClass(DataList.class); list.table = quickSort(list.table); - if (!list.position.equals("last")){ //(-1b,0f)のタスクが存在する + if (!info.lastFlag){ /* * ソートされたlistから指定した部分をコピーしている * ソートしている最中にlistを2つ作った方がいいかも。 */ - ods.update("local", list.num+"f", - list.createDataList(0, block_num/2, list.num, "f")); - ods.update("local", list.num+"b", - list.createDataList(block_num/2, block_num/2, list.num, "b")); - new EvenPhase((list.num-1)+"b",list.num+"f"); + + ods.update("local", info.range+"f", + list.createDataList(0, block_num/2)); + ods.update("local", info.range+"b", + list.createDataList(block_num/2, block_num/2)); + + if (info.range==0){ + //System.out.println("next Even "+info.range+" "+info.range+"f"); + new EvenPhase(info0.key,info.range+"f"); + } else { + //System.out.println("next Even "+info.range+" "+ (info.range-1)+"b"+" "+(info.range)+"f"); + new EvenPhase(info0.key,(info.range-1)+"b",info.range+"f"); + } } else { - System.out.println("list.num "+list.num); - ods.update("local", list.num+"f",list); + ods.update("local", info.range+"f",list); + System.out.println("next Even "+info.range+" "+ (info.range-1)+"b"+" "+(info.range)+"f"); + new EvenPhase(info0.key,(info.range-1)+"b",info.range+"f"); } } else { DataList list1 = info1.asClass(DataList.class); DataList list2 = info2.asClass(DataList.class); list2.table = quickSort(list1.table,list2.table); - - - System.out.println("end"); + + ods.update("local", info.range+"f", + list2.createDataList(0, block_num/2)); + ods.update("local", info.range+"b", + list2.createDataList(block_num/2, block_num/2)); + + if (info.range==0){ + System.out.println("next Even2b "+info.range+" "+ info.range+"f"); + new EvenPhase(info0.key,info.range+"f"); + } else { + System.out.println("next Even2b "+info.range+" "+ (info.range-1)+"b"+" "+info.range+"f"); + new EvenPhase(info0.key,(info.range-1)+"b",info.range+"f"); + } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/codesegment/local/bitonicsort/RangeInfo.java Tue Dec 11 19:58:47 2012 +0900 @@ -0,0 +1,16 @@ +package alice.test.codesegment.local.bitonicsort; + +import org.msgpack.annotation.Message; + +@Message +public class RangeInfo { + public int range; + public boolean lastFlag; + + public RangeInfo(){} + public RangeInfo(int i,boolean flag){ + range = i; + lastFlag = flag; + } + +}
--- a/src/alice/test/codesegment/local/bitonicsort/SetTask.java Tue Dec 11 15:50:17 2012 +0900 +++ b/src/alice/test/codesegment/local/bitonicsort/SetTask.java Tue Dec 11 19:58:47 2012 +0900 @@ -32,13 +32,15 @@ String key = "array"; int i = 0; for (i = 0;i< conf.getSplitNum()-1; i++){ - ods.update("local", key+i, list.createDataList(i*block_num, block_num,i,"nolast")); - new OddPhase(key+i); + ods.put("local", "range"+i, new RangeInfo(i,false)); + ods.update("local", key+i, list.createDataList(i*block_num, block_num)); + new OddPhase("range"+i,key+i); } // 最後のblockは端数 - ods.update("local", key+i, list.createDataList(i*block_num, last_block_num,i,"last")); - new OddPhase(key+i); + ods.put("local", "range"+i, new RangeInfo(i,true)); + ods.update("local", key+i, list.createDataList(i*block_num, last_block_num)); + new OddPhase("range"+i,key+i); } ods.update("local", "count", sort_count-1);