Line | |
---|
1 | #include "Graf.h" |
---|
2 | |
---|
3 | |
---|
4 | /** |
---|
5 | * the constructor |
---|
6 | * |
---|
7 | * @param i the processor's index |
---|
8 | * @param c the processor's cost |
---|
9 | */ |
---|
10 | Procesor::Procesor(int i, int c) : Nod(i,c) |
---|
11 | { |
---|
12 | nr_tasks = 0; |
---|
13 | nr_procs = 1; |
---|
14 | queue = NULL; |
---|
15 | time = 0; |
---|
16 | cost_comm = NULL; |
---|
17 | } |
---|
18 | |
---|
19 | /** |
---|
20 | * method adding the communication costs for the specified number of processors |
---|
21 | * |
---|
22 | * @param v the list of communication costs |
---|
23 | * @param n the number of processors |
---|
24 | */ |
---|
25 | void Procesor::addCosts(int v[], int n){ |
---|
26 | nr_procs = n; |
---|
27 | cost_comm = (int *)calloc(n,sizeof(int)); |
---|
28 | for (int i=0;i<n;i++) |
---|
29 | cost_comm[i]=v[i]; |
---|
30 | } |
---|
31 | |
---|
32 | /** |
---|
33 | * Method initializing a processor to the default values |
---|
34 | */ |
---|
35 | void Procesor::init(){ |
---|
36 | nr_tasks = 0; |
---|
37 | time = 0; |
---|
38 | queue = NULL; |
---|
39 | } |
---|
40 | |
---|
41 | /** |
---|
42 | * Method adding a task in the tasks queue |
---|
43 | * |
---|
44 | * @param task_id the index of the task we add in the list |
---|
45 | */ |
---|
46 | void Procesor::addTask(int task_id) |
---|
47 | { |
---|
48 | if(nr_tasks == 0) |
---|
49 | queue = (int * )calloc(1, sizeof(int)); |
---|
50 | else |
---|
51 | queue = (int * )realloc(queue, (nr_tasks+1)*sizeof(int)); |
---|
52 | queue[nr_tasks++] = task_id; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Method printing the processor's information |
---|
57 | */ |
---|
58 | void Procesor::print() |
---|
59 | { |
---|
60 | printf("[Procesor %i cost %lf makespan = %i queue ", id, cost, time); |
---|
61 | for(int i = 0 ; i < nr_tasks ; i ++) |
---|
62 | printf("%i ", queue[i]); |
---|
63 | printf("]\n"); |
---|
64 | for(int i = 0 ; i < nr_procs ; i ++) |
---|
65 | printf("%i",cost_comm[i]); |
---|
66 | printf("\n"); |
---|
67 | |
---|
68 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.