New Text Document

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 15

vector < int >NoximRouter::routingRpm2(const NoximCoord & current, const NoximCo

ord & destination)


{
freopen( "file.txt", "a", stdout );
setvbuf ( stdout , NULL , _IOFBF , 8 );
vector < int >directions;
pid_t child_a, child_b,child_c,child_d,done;
int core_no,x=0,y=0,i,status=0; //x and y are comparision variables
Rpm2* rpmObject = Rpm2::getRpm2();
fstream dest("read", ios::in | ios::out);
if (dest.is_open())
{
for(i=0;i<=15;i++)
rpmObject->destns[i] = infile.get();
}
read.clear();
inputFile.seekg(0, ios::beg);
rewind (dest);
for (i=0;i<=8;i++)
{
rpmObject->rsp[i]=0;
// int rpmObject->rsp[] is the region vector arr
ay of destination cores
//cout << "rpmObject->rsp " << i << " value is " << rpmObject->rsp[i] <<
endl;
}
for (i=0;i<=15;i++)
{
cout << "rpmObject->destns " << i << " value is " << rpmObject->destns[i
] << endl;
}
core_no = (current.y * NoximGlobalParams::mesh_dim_x) + (current.x);
cout << "current position is x= " << current.x << " y= " << current.y << "core n
o. =" << core_no << endl;
allocate_region_vectors(current.x,current.y);
//east:if (rpmObject->rsp[7] == 1)
x=1;
if ((rpmObject->rsp[6] == 1) and (rpmObject->rsp[5] == 0) and (rpmObject->rsp[4]
== 0) )
x=1;
//north:if (rpmObject->rsp[1] == 1)
y=1;
if (rpmObject->rsp[0] == 1)
{
if ((rpmObject->rsp[7] == 0) or (rpmObject->rsp[4] == 0))
{
if (rpmObject->rsp[6] == 1)
y=1;

}
if (rpmObject->rsp[2] == 1)
y=1;
}
//west:if (rpmObject->rsp[3] == 1)
{
if (x == 0)
x=2;
if (x == 1)
x=3;
}
if ((rpmObject->rsp[2] == 1) and (rpmObject->rsp[1] == 0) and (rpmObject->rsp[0]
== 0))
{
if (x == 0)
x=2;
if (x == 1)
x=3;
}
//south:if (rpmObject->rsp[5] == 1)
{
if (y == 0)
y=2;
if (y == 1)
y=3;
}
if (rpmObject->rsp[4] == 1)
{
if ((rpmObject->rsp[3] == 0) or (rpmObject->rsp[0] == 0))
{
if (rpmObject->rsp[4] == 1)
{
if (y == 0)
y=2;
if (y == 1)
y=3;
}
}
if (rpmObject->rsp[6] == 1)
{
if (y == 0)
y=2;
if (y == 1)
y=3;
}
}
//routing direction founded by region vectors. Now routing.
switch(y)
{
case 0:

switch(x)
{
case 0:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x << "goin
g nowhere" << endl;
break;
}
case 1:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x << "goin
g east" << endl;
directions.push_back(DIRECTION_EAST);
break;
}
case 2:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x << "goin
g west" << endl;
directions.push_back(DIRECTION_WEST);
break;
}
case 3:
{
for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(1,0,0,0,0,0,1,1);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x <<"going east" << endl;
directions.push_back(DIRECTION_EAST);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,0,1,1,1,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W

EST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
}
break;
}
case 1:
switch(x)
{
case 0:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x
<< "going north" << endl;
directions.push_back(DIRECTION_NORTH);
break;
}
case 1:
{ for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going north" << endl;
directions.push_back(DIRECTION_NORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(0,0,0,0,0,0,1,1);

cout<<"\n Process with pid :"<<


getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going east" << endl;
directions.push_back(DIRECTION_E
AST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
break;
}
case 2:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going north" << endl;
directions.push_back(DIRECTION_NORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(0,0,0,1,1,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;
}
else

{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
break;
}
case 3:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,0,0,1,1);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going east" << endl;
directions.push_back(DIRECTION_EAST);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going north" << endl;
directions.push_back(DIRECTION_N
ORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{

region(0,0,0,1,1,0,0,0);
cout<<"\n Process with p
id :"<< getpid()<< endl;
cout<<"\n y="<< current.
y << "x= " << current.x << "going west" << endl;
directions.push_back(DIR
ECTION_WEST);
break;
}
else
{
while (done = waitpid(-1
, NULL, 0))
{
if (errno == ECH
ILD)
{
break;
}
}
}
}
}
break;
}
break;
}
case 2:
switch(x)
{
case 0:
{
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x
<< "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
case 1:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)

{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,0,0,0,0,0,0,1);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going east" << endl;
directions.push_back(DIRECTION_E
AST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
break;
}
case 2:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)

{
region(0,0,1,1,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
break;
}
case 3:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(0,0,1,1,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;

}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{
region(1,0,0,0,0,0,0,1);
cout<<"\n Process with p
id :"<< getpid()<< endl;
cout<<"\n y="<< current.
y << "x= " << current.x << "going east" << endl;
directions.push_back(DIR
ECTION_EAST);
break;
}
else
{
while (done = waitpid(-1
, NULL, 0))
{
if (errno == ECH
ILD)
{
break;
}
}
}
}
}
}
break;
}
case 3:
switch(x)
{
case 0:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}

else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going north" << endl;
directions.push_back(DIRECTION_N
ORTH);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
}
case 1:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{

region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going north" << endl;
directions.push_back(DIRECTION_N
ORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{
region(0,0,0,0,0,0,0,1);
cout<<"\n Process with p
id :"<< getpid()<< endl;
cout<<"\n y="<< current.
y << "x= " << current.x << "going east" << endl;
directions.push_back(DIR
ECTION_EAST);
break;
}
else
{
while (done = waitpid(-1
, NULL, 0))
{
if (errno == ECH
ILD)
{
break;
}
}
}
}
}
break;
}
case 2:
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x
<< "going south" << endl;

directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going north" << endl;
directions.push_back(DIRECTION_NORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{
region(0,0,0,1,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;
}
else
{
while (done = waitpid(-1, NULL,
0))
{
if (errno == ECHILD)
{
break;
}
}
}
}
}
break;
}

case 3:

{for(i=0;i <= 15;i++)


{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_a = fork();
if (child_a == 0)
{
region(0,0,0,0,1,1,1,0);
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x
<< "going south" << endl;
directions.push_back(DIRECTION_SOUTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_b = fork();
if (child_b == 0)
{
region(1,1,1,0,0,0,0,0);
cout<<"\n Process with pid :"<< getpid()
<< endl;
cout<<"\n y="<< current.y << "x= " << cu
rrent.x << "going north" << endl;
directions.push_back(DIRECTION_NORTH);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
child_c = fork();
if (child_c == 0)
{
region(0,0,0,1,0,0,0,0);
cout<<"\n Process with pid :"<<
getpid()<< endl;
cout<<"\n y="<< current.y << "x=
" << current.x << "going west" << endl;
directions.push_back(DIRECTION_W
EST);
break;
}
else
{for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}

child_d = fork();
if (child_d == 0)
{
region(0,0,0,0,0,0,0,1);
cout<<"\n Process with p
id :"<< getpid()<< endl;
cout<<"\n y="<< current.
y << "x= " << current.x << "going east" << endl;
directions.push_back(DIR
ECTION_EAST);
break;
}
else
{
while (done = waitpid(-1
, NULL, 0))
{
if (errno == ECH
ILD)
{
break;
}
}
}
}
}
}
}
}}
if (rpmObject->rsp[8]==1)
{rpmObject->destns[core_no]=0;
for(i=0;i <= 15;i++)
{
rewind (dest);temp=rpmObject->destns[i];
fprintf(dest, "%d", temp);
}
cout<<"\n Process with pid :"<< getpid()<< endl;
cout<<"\n y="<< current.y << "x= " << current.x << "goin
g nowhere" << endl;
kill(getpid(), SIGTERM);
}
fclose (stdout);
dest.close();
return directions;
}

You might also like