# HG changeset patch # User sugi # Date 1369121389 -32400 # Node ID 6f82362088750940247fd14260a7432352bf16b1 # Parent e5d0bd8200c607c795bd8557f09c5e0ceeffe12e not use MappedByteBuffer diff -r e5d0bd8200c6 -r 6f8236208875 .settings/org.eclipse.core.resources.prefs --- a/.settings/org.eclipse.core.resources.prefs Wed May 08 18:34:40 2013 +0900 +++ b/.settings/org.eclipse.core.resources.prefs Tue May 21 16:29:49 2013 +0900 @@ -1,4 +1,5 @@ eclipse.preferences.version=1 encoding//src/alice/test/codesegment/local/bitonicsort/SortTest.java=UTF-8 +encoding//src/alice/test/codesegment/local/wordcount/SeparateArray.java=UTF-8 encoding//src/alice/test/codesegment/local/wordcount/SetTask.java=UTF-8 encoding//src/alice/test/codesegment/local/wordcount/WordCount.java=UTF-8 diff -r e5d0bd8200c6 -r 6f8236208875 src/alice/test/codesegment/local/wordcount/Range.java --- a/src/alice/test/codesegment/local/wordcount/Range.java Wed May 08 18:34:40 2013 +0900 +++ b/src/alice/test/codesegment/local/wordcount/Range.java Tue May 21 16:29:49 2013 +0900 @@ -1,17 +1,16 @@ package alice.test.codesegment.local.wordcount; -import org.msgpack.annotation.Message; - -@Message public class Range { - public int start; - public int end; - public boolean flag; - public Range(int _start, int _end, boolean _flag) { - start = _start; - end = _end; - flag = _flag; + public char[] array; + public char nextchar; + + public Range(int size){ + this.array = new char[size]; + } + + public Range(char[] _array) { + this.array = _array; } } diff -r e5d0bd8200c6 -r 6f8236208875 src/alice/test/codesegment/local/wordcount/ReadFileTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/codesegment/local/wordcount/ReadFileTest.java Tue May 21 16:29:49 2013 +0900 @@ -0,0 +1,46 @@ +package alice.test.codesegment.local.wordcount; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; + +public class ReadFileTest { + + public static void main(String[] args){ + WordConfig conf = new WordConfig(args); + BufferedReader br = null; + int i = 0; + try { + br= new BufferedReader( + new InputStreamReader( + new FileInputStream( + new File(conf.filename) + ))); + int size = 4; // Kbyte + + Range range = new Range(size); + int check = br.read(range.array); + for (;check!=-1;i++){ + + char[] array; + array = new char[size]; + check = br.read(array); + range.nextchar = array[0]; + System.out.print(range.array); // ods + System.out.println(range.nextchar); + range = new Range(array); + } + System.out.println(i); + } catch (FileNotFoundException e) { + System.out.println("file was not found"); + System.exit(1); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +} diff -r e5d0bd8200c6 -r 6f8236208875 src/alice/test/codesegment/local/wordcount/SeparateArray.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/codesegment/local/wordcount/SeparateArray.java Tue May 21 16:29:49 2013 +0900 @@ -0,0 +1,57 @@ +package alice.test.codesegment.local.wordcount; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import alice.codesegment.CodeSegment; + +public class SeparateArray extends CodeSegment{ + + private WordConfig conf; + + SeparateArray(WordConfig conf){ + this.conf = conf; + } + + @Override + public void run() { + + // cpu分だけTaskをあらかじめ作成 + int cpu_num = Runtime.getRuntime().availableProcessors(); + for (int cnt =0;cnt < cpu_num;cnt++){ + new WordCount(); + } + + BufferedReader br = null; + int i = 0; + try { + br= new BufferedReader( + new InputStreamReader( + new FileInputStream( + new File(conf.filename) + ))); + int size = conf.division * 1024; // Kbyte + Range range = new Range(size); + int check = br.read(range.array); + for (;check!=-1;i++){ + + char[] array; + array = new char[size]; + check = br.read(array); + range.nextchar = array[0]; + ods.put("array", range); + range = new Range(array); + } + new CorrectResult(i); + } catch (FileNotFoundException e) { + System.exit(1); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff -r e5d0bd8200c6 -r 6f8236208875 src/alice/test/codesegment/local/wordcount/SetTask.java --- a/src/alice/test/codesegment/local/wordcount/SetTask.java Wed May 08 18:34:40 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -package alice.test.codesegment.local.wordcount; - -import alice.codesegment.CodeSegment; -import java.io.*; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; - -public class SetTask extends CodeSegment { - - private WordConfig conf; - - public SetTask(WordConfig conf) { - this.conf = conf; - } - - @Override - public void run() { - FileInputStream input; - try { - input = new FileInputStream(new File(conf.filename)); - FileChannel channel = input.getChannel(); - int length = (int)channel.size(); - MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, length); - ods.put("array", buffer); - int start=0,end=0,i=0; - int size = conf.division * 1024; - - System.out.println(length); - for (;start+size