Skip to content

Commit 1b220e8

Browse files
authored
Add files via upload
1 parent be7e75f commit 1b220e8

File tree

7 files changed

+446
-0
lines changed

7 files changed

+446
-0
lines changed

Extended_PEFT_2016.pdf

976 KB
Binary file not shown.

IPEFT.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "core.cpp"
2+
#include "debug.cpp"
3+
#include <fstream>
4+
/* Author: Sahil Malik 14/2/2018 */
5+
int main(int argc,char* argv[])
6+
{
7+
//system("cls");
8+
if(argv[1]==NULL){
9+
cout<<"\n\tError! No Input File Supplied.\n\n";
10+
cout<<"\tProgram Will Now Exit\n\n";
11+
getchar();
12+
exit(0);
13+
}
14+
15+
read(argv[1]);
16+
//display();
17+
for(int i=nodes-1;i>=0;i--) pct(i);
18+
//show_PCT();
19+
//show_RANK_PCT();
20+
for(int i=nodes-1;i>=0;i--) cnct(i);
21+
// CNCT[0][0]=67;
22+
//show_CNCT();
23+
for(int i=0;i<nodes;i++)
24+
aest(i);
25+
for(int i=nodes-1;i>=0;i--)
26+
{ alst(i);
27+
cnp(i);
28+
}
29+
ipeft_algorithm();
30+
//show_AEST();
31+
//show_ALST();
32+
//show_CNP();
33+
//show_EFT();
34+
//show_EFT_CNCT();
35+
ofstream ofs;
36+
ofs.open("IPEFT.txt",ios_base::app);
37+
ofs<<AFT[nodes-1]<<"\n";
38+
return 0;
39+
}

IPEFT.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
116
2+
116
3+
116
4+
116
5+
116
6+
140
7+
27

core.cpp

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
/*-----------------------------------------------------------------------------------------------------*/
2+
#include <iostream>
3+
#include <vector>
4+
#include <fstream>
5+
#include <climits>
6+
#include <set>
7+
#include <algorithm>
8+
#define MAX 700
9+
using namespace std;
10+
int nodes,n_proc,weight[MAX][MAX],identity[MAX][MAX],adj[MAX][MAX],PCT[MAX][MAX],RANK_PCT[MAX],CNCT[MAX][MAX],EST[MAX][MAX]={0},EFT[MAX][MAX]={0};
11+
int AFT[MAX],tp[MAX],processor_assigned[MAX],EFT_CNCT[MAX][MAX]={0};
12+
float AEST[MAX],ALST[MAX];
13+
bool CNP[MAX];
14+
set<int> arr;
15+
void init()
16+
{
17+
for(int i=0;i<nodes;i++)
18+
for(int j=0;j<nodes;j++)
19+
cout<<EFT[i][j];
20+
}
21+
/*-----------------------------------------------------------------------------------------------------*/
22+
int round(float var)
23+
{
24+
int value = (int)(var * 100 + .5);
25+
return value / 100;
26+
}
27+
/*-----------------------------------------------------------------------------------------------------*/
28+
void read(char* file_name)
29+
{
30+
fstream ifs;
31+
ifs.open(file_name);
32+
ifs>>nodes;
33+
ifs>>n_proc;
34+
for(int i=0;i<nodes;i++)
35+
for(int j=0;j<n_proc;j++)
36+
ifs>>weight[i][j];
37+
for (int i = 0; i <n_proc; i++)
38+
for(int j=0;j<n_proc;j++)
39+
ifs>>identity[i][j];
40+
for(int i=0;i<nodes;i++)
41+
for(int j=0;j<nodes;j++)
42+
ifs>>adj[i][j];
43+
cout<<"\n\tFile Name Supplied: "<<file_name<<endl;
44+
cout<<"\n\tGraph Supplied Nodes: "<<nodes<<"\n\n\tWith Discrete Processors: "<<n_proc<<endl<<endl;
45+
}
46+
/*-----------------------------------------------------------------------------------------------------*/
47+
inline bool check_exit_node(int p)
48+
{
49+
bool flag=true;
50+
for(int i=0;i<nodes;i++)
51+
if(adj[p][i]!=-1) return false;
52+
return flag;
53+
}
54+
/*-----------------------------------------------------------------------------------------------------*/
55+
void pct(int p)
56+
{
57+
if(check_exit_node(p)==true){ /* Handling PCT of Exit Nodes*/
58+
for(int i=0;i<n_proc;i++)
59+
PCT[p][i]=0;
60+
int temp=0;
61+
for(int i=0;i<n_proc;i++)
62+
temp+=weight[p][i];
63+
temp/=n_proc;
64+
RANK_PCT[p]=temp;
65+
return;
66+
}
67+
for(int i=0;i<nodes;i++)
68+
{
69+
70+
if(adj[p][i]!=-1) /*If a successor of current node*/
71+
{
72+
int max=0;
73+
for(int j=0;j<n_proc;j++){
74+
for(int k=0;k<n_proc;k++){
75+
max=PCT[i][j]+weight[i][j]+adj[p][i]*identity[j][k];
76+
if(PCT[p][k]<max) PCT[p][k]=max;
77+
}
78+
}
79+
}
80+
81+
}
82+
float temp=0;
83+
for(int i=0;i<n_proc;i++) temp=temp+PCT[p][i]+weight[p][i];
84+
temp/=n_proc;
85+
RANK_PCT[p]=round(temp);
86+
}
87+
/*-----------------------------------------------------------------------------------------------------*/
88+
inline bool check_entry_node(int p)
89+
{
90+
for(int i=0;i<nodes;i++)
91+
if(adj[i][p]!=-1) return false;
92+
return true;
93+
}
94+
/*-----------------------------------------------------------------------------------------------------*/
95+
void aest(int p)
96+
{
97+
AEST[p]=0.0;
98+
if(check_entry_node(p)) return;
99+
for(int i=0;i<nodes;i++)
100+
{
101+
float max=0;
102+
float temp=0;
103+
if(adj[i][p]!=-1){
104+
for(int j=0;j<n_proc;j++)
105+
temp+=float(weight[i][j]);
106+
temp=temp/n_proc;
107+
temp=round(temp);
108+
max=round(AEST[i]+adj[i][p]+temp);
109+
if(max>AEST[p]) AEST[p]=round(max);
110+
}
111+
}
112+
}
113+
/*-----------------------------------------------------------------------------------------------------*/
114+
void alst(int p)
115+
{
116+
CNP[p]=true;
117+
if(check_exit_node(p)){
118+
ALST[p]=round(AEST[p]);
119+
return;
120+
}
121+
ALST[p]=INT_MAX;
122+
float min=INT_MAX;
123+
for(int i=0;i<nodes;i++){
124+
if(adj[p][i]!=-1){
125+
min=round(ALST[i]-adj[p][i]);
126+
if(min<ALST[p]) ALST[p]=round(min);
127+
}
128+
}
129+
float temp=0;
130+
for(int j=0;j<n_proc;j++) temp+=float(weight[p][j]);
131+
temp/=n_proc;
132+
temp=round(temp);
133+
ALST[p]-=temp;
134+
ALST[p]=round(ALST[p]);
135+
}
136+
/*-----------------------------------------------------------------------------------------------------*/
137+
void cnct(int p)
138+
{
139+
if(check_exit_node(p)==true){ /* Handling PCT of Exit Nodes*/
140+
for(int i=0;i<n_proc;i++)
141+
CNCT[p][i]=0;
142+
return;
143+
}
144+
int temp_arr[MAX][MAX],nos=0;
145+
for(int i=0;i<nodes;i++)
146+
for(int j=0;j<n_proc;j++)
147+
temp_arr[i][j]=INT_MAX;
148+
149+
for(int i=0;i<nodes;i++){
150+
if(adj[p][i]!=-1) /*if a successor of CN*/
151+
{
152+
nos++;
153+
for(int j=0;j<n_proc;j++)
154+
for(int k=0;k<n_proc;k++)
155+
temp_arr[j][k]=CNCT[i][j]+weight[i][j]+adj[p][i]*identity[j][k];
156+
for(int j=0;j<n_proc;j++)
157+
{
158+
int min=INT_MAX;
159+
for(int k=0;k<n_proc;k++)
160+
if(temp_arr[k][j]<min) min=temp_arr[k][j];
161+
if(CNCT[p][j]<min) CNCT[p][j]=min;
162+
}
163+
}
164+
}
165+
}
166+
/*-----------------------------------------------------------------------------------------------------*/
167+
void cnp(int p){
168+
if(abs(ALST[p]-AEST[p])==0){
169+
CNP[p]=false;
170+
arr.insert(p);
171+
return;
172+
}
173+
for(int i=0;i<nodes;i++)
174+
if(adj[p][i]!=-1 ){
175+
if(CNP[i]==true && arr.find(i)!=arr.end()){
176+
CNP[p]=true;
177+
return ;
178+
}
179+
else if(arr.find(i)!=arr.end()) CNP[p]=true;
180+
else CNP[p] =false;
181+
}
182+
}
183+
/*-----------------------------------------------------------------------------------------------------*/
184+
inline int eft(int ni,int pj){
185+
return (EST[ni][pj]+weight[ni][pj]);
186+
}
187+
/*-----------------------------------------------------------------------------------------------------*/
188+
void est(int ni)
189+
{
190+
int temp[MAX]={0};
191+
for(int i=0;i<n_proc;i++) temp[i]=0;
192+
register int mt=0;
193+
for(int i=0;i<nodes;i++)
194+
{
195+
if(adj[i][ni]!=-1){
196+
for(int j=0;j<n_proc;j++){
197+
mt=AFT[i]+identity[processor_assigned[i]][j]*adj[i][ni];
198+
if(temp[j]<=mt) temp[j]=mt;
199+
}
200+
}
201+
}
202+
for(int i=0;i<n_proc;i++){
203+
if(tp[i]>temp[i]) EST[ni][i]=tp[i];
204+
else EST[ni][i]=temp[i];
205+
}
206+
}
207+
/*-----------------------------------------------------------------------------------------------------*/
208+
bool f(int i,int j){return RANK_PCT[i]<RANK_PCT[j];}
209+
void ipeft_algorithm()
210+
{
211+
//CNCT[0][0]=67;
212+
vector<int> ready_list;
213+
for(int i=0;i<nodes;i++) ready_list.push_back(i);
214+
sort(ready_list.begin(),ready_list.end(),f);
215+
while(ready_list.size()){
216+
int curr=ready_list.back();
217+
est(curr);
218+
for(int i=0;i<n_proc;i++)
219+
EFT[curr][i]=eft(curr,i);
220+
//cout<<EFT[curr][0]<<" "<<EFT[curr][1]<<" "<<EFT[curr][2]<<" "<<endl;
221+
if(CNP[curr]==true)
222+
for(int i=0;i<n_proc;i++)
223+
EFT_CNCT[curr][i]=EFT[curr][i];
224+
else
225+
for(int i=0;i<n_proc;i++)
226+
EFT_CNCT[curr][i]=EFT[curr][i]+CNCT[curr][i];
227+
int min=INT_MAX;
228+
int pro=0;
229+
for(int i=0;i<n_proc;i++)
230+
if(min>EFT_CNCT[curr][i])
231+
{
232+
pro=i;
233+
min=EFT_CNCT[curr][i];
234+
}
235+
processor_assigned[curr]=pro;
236+
AFT[curr]=EFT[curr][pro];
237+
tp[pro]=EFT[curr][pro];
238+
cout<<"\tProcess:"<<curr+1<<" Processor: "<<pro<<" AFT: "<<AFT[curr]<<endl;
239+
ready_list.pop_back();
240+
}
241+
}
242+
/*-----------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)