Mercurial > hg > y16 > e165725 > os > ex4.1
changeset 1:3dd454fa1460
multi cpu try
author | kono |
---|---|
date | Tue, 06 Dec 2011 14:05:02 +0900 |
parents | f4e31a8b6386 |
children | 535f2d4fba6b |
files | src/schedularSimulator/Run.java src/schedularSimulator/Task.java |
diffstat | 2 files changed, 34 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/schedularSimulator/Run.java Tue Dec 14 14:07:42 2010 +0900 +++ b/src/schedularSimulator/Run.java Tue Dec 06 14:05:02 2011 +0900 @@ -7,6 +7,17 @@ public class Run { static int quantum = 0; static final int BUFSIZ = 4096; + + int num_cpu = 4; + Task [] cpu; + + public Run(int j) { + num_cpu = j; + cpu = new Task[j]; + for(int i =0; i<num_cpu;i++) { + cpu[i] = new Task(i); + } + } /* 標準入力から与えられたタスクのデータを読み込み、 @@ -21,14 +32,13 @@ public static void main(String args[]) throws FileNotFoundException { - Run self = new Run(); + Run self = new Run(4); self.task_init(args); } public void task_init(String args[]) throws FileNotFoundException { String name; - int time; int length; int priority; LinkedList<Task> task_list = new LinkedList<Task>() ; @@ -48,7 +58,7 @@ } type = 'n'; // scanner.next().charAt(0); System.out.println("type= "+type); - time = scanner.nextInt(); // System.out.println("time= "+time); + scanner.nextInt(); // System.out.println("time= "+time); name = scanner.next(); // System.out.println("name= "+name); length = scanner.nextInt(); // System.out.println("length= "+length); priority = scanner.nextInt(); // System.out.println("priority= "+priority); @@ -106,13 +116,22 @@ sjf(LinkedList<Task> task_list) { Comparator<Task> comp = new by_length(); - PriorityQueue<Task> list = new PriorityQueue<Task>(1024,comp); - for (Task q: task_list) { - list.add(q); + PriorityQueue<Task> [] list = new PriorityQueue[num_cpu] ; + for(int i = 0;i<num_cpu;i++) { + list[i] = new PriorityQueue<Task>(1024,comp); } - while (!list.isEmpty()) { - Task q = list.poll(); - q.exec_task(quantum,list); + { + int i = 0; + for (Task q: task_list) { + list[i++].add(q); + if (i>=num_cpu) i = 0; + } + } + for(int i = 0; i < num_cpu ; i++) { + while (!list[i].isEmpty()) { + Task q = list[i].poll(); + cpu[i].exec_task(q,quantum); + } } }
--- a/src/schedularSimulator/Task.java Tue Dec 14 14:07:42 2010 +0900 +++ b/src/schedularSimulator/Task.java Tue Dec 06 14:05:02 2011 +0900 @@ -7,6 +7,7 @@ static int task_clock = 0; static int total_wait = 0; static int total_turn_around = 0; + int cpu; int priority; @@ -45,7 +46,11 @@ task_count ++; } - int exec_task(int quantum,Collection<Task>list) + public Task(int i) { + cpu = i; + } + + int exec_task(Task t,int quantum) { int exec_time; if (quantum!=0 && quantum < length) {