/* Skeleton's heuristics for double objective functions */ /*-------------------------------------------------------- Created by Veronika Rehn - Veronika.Rehn@ens-lyon.fr Using Skeleton's heuristics created by Anne Benoit - Anne.Benoit@ens-lyon.fr Created: March 2007 ---------------------------------------------------------- This is a template for skeleton mapping. The application and platform parameters must be directly coded in this file. -----------------------------------------------------------*/ #include #include #define DEBUG 1 #define MEGADEBUG 0 #define MAXINT 1000000 #define STARTDIC 10 #define PREC 0.0001 #define MAXDOUBLE 1.7976931348623158e+308 #define INCREASE 20.0 int getBestPos(double pp[], int bestCut, double globalBest) { double best=MAXDOUBLE; int i; int bestPos=-1; for (i=bestCut*4;imax) max=p1; if (p2>max) max=p2; if (p3>max) max=p3; //printf("max out of (%f, %f, %f) = %f\n",p1,p2,p3,max); return max; } int main(int argc, char *argv[]) { int i,ii,j,jj,k,kk; char fname[40]; char per_fname[40]; char lat_fname[40]; int nbheur=6; //----- For the result plots ------// // FILE *plot[nbheur]; //----- Generating the platforms and the applications -------// int nbapp=4; //50; stages int nbtree=50;//50; // double fixp=3.80; //fixed period int tr=10; //testrange double fixedperiod[tr][nbapp]; double fixedlatency[tr][nbapp]; //------- 5 stages ------------- fixedperiod[0][0]=9.0; fixedperiod[1][0]=9.3; fixedperiod[2][0]=9.7; fixedperiod[3][0]=10.0; fixedperiod[4][0]=10.3; fixedperiod[5][0]=10.7; fixedperiod[6][0]=11.0; fixedperiod[7][0]=11.3; fixedperiod[8][0]=11.7; fixedperiod[9][0]=12.0; fixedlatency[0][0]=9.0; fixedlatency[1][0]=9.7; fixedlatency[2][0]=10.3; fixedlatency[3][0]=11.0; fixedlatency[4][0]=11.7; fixedlatency[5][0]=12.3; fixedlatency[6][0]=13.0; fixedlatency[7][0]=13.7; fixedlatency[8][0]=14.3; fixedlatency[9][0]=20.0; //------- 10 stages --------------- fixedperiod[0][1]=10; fixedperiod[1][1]=11; fixedperiod[2][1]=12; fixedperiod[3][1]=13; fixedperiod[4][1]=14; fixedperiod[5][1]=15; fixedperiod[6][1]=16; fixedperiod[7][1]=17; fixedperiod[8][1]=18; fixedperiod[9][1]=29; fixedlatency[0][1]=13.0; fixedlatency[1][1]=15.0; fixedlatency[2][1]=17.0; fixedlatency[3][1]=19.0; fixedlatency[4][1]=21.0; fixedlatency[5][1]=23.0; fixedlatency[6][1]=25.0; fixedlatency[7][1]=27.0; fixedlatency[8][1]=29.0; fixedlatency[9][1]=31.0; //------- 20 stages --------------- fixedperiod[0][2]=10.0; fixedperiod[1][2]=11.0; fixedperiod[2][2]=12.0; fixedperiod[3][2]=13.0; fixedperiod[4][2]=14.0; fixedperiod[5][2]=15.0; fixedperiod[6][2]=16.0; fixedperiod[7][2]=17.0; fixedperiod[8][2]=18.0; fixedperiod[9][2]=19.0; fixedlatency[0][2]=20.0; fixedlatency[1][2]=21.0; fixedlatency[2][2]=22.0; fixedlatency[3][2]=23.0; fixedlatency[4][2]=24.0; fixedlatency[5][2]=25.0; fixedlatency[6][2]=27.0; fixedlatency[7][2]=29.0; fixedlatency[8][2]=32.0; fixedlatency[9][2]=35.0; //------- 40 stages --------------- fixedperiod[0][3]=15.0; fixedperiod[1][3]=16.0; fixedperiod[2][3]=17.0; fixedperiod[3][3]=18.0; fixedperiod[4][3]=19.0; fixedperiod[5][3]=20.0; fixedperiod[6][3]=21.0; fixedperiod[7][3]=22.0; fixedperiod[8][3]=23.0; fixedperiod[9][3]=24.0; fixedlatency[0][3]=32.0; fixedlatency[1][3]=34.0; fixedlatency[2][3]=36.0; fixedlatency[3][3]=38.0; fixedlatency[4][3]=40.0; fixedlatency[5][3]=42.0; fixedlatency[6][3]=44.0; fixedlatency[7][3]=46.0; fixedlatency[8][3]=48.0; fixedlatency[9][3]=50.0; double fixp,fixl; int nbproc[nbapp], nbstage[nbapp], maxproc=0, maxstage=0; FILE *idf[nbapp]; int tree; double totperiod[tr][nbheur][nbapp]; double totlatency[tr][nbheur][nbapp]; double latency[tr][nbheur][nbapp]; int n,p,l,ll,nbint; int maxproc2; double maxperiod, maxp, max1, max2, maxs; double ss; int maxsta; double kkk, kkmax, kkmin; int heuristic; int z; //fprintf(stderr,"permier boucle; totperiod, totlatency etc initialized;\n"); for (i=0; imaxproc) maxproc=nbproc[k]; } double B[nbapp], s[nbapp][maxproc]; for (k=0; kmaxstage) maxstage=nbstage[k]; */ /* } */ // appli k /* nbstage[0]=10; */ /* maxstage=nbstage[0]; */ nbstage[0]=5; nbstage[1]=10; nbstage[2]=20; nbstage[3]=40; maxstage=nbstage[3]; /* // appli k */ /* for (k=0; kmaxstage) maxstage=nbstage[k]; */ /* } */ double w[nbapp][maxstage], d[nbapp][maxstage+1]; for (k=0; kp (nbstage>nbproc) l = n/p; if (n%p !=0) l++; nbint = n/l; if (n%l !=0) nbint++; if (DEBUG) fprintf(idf[k],"l=%d, nbint=%d\n", l, nbint); int usedproc[p]; printf("hello appli=%d platform=%d\n",k,tree); //************ part I: min latence with fixed period ************************* // *********** Heuristic 1: Splitting bicritaire to diminuate ************ // *********** period until period is reached ************ // *********** uses Splitting heuristic by Anne Benoit ************ heuristic=0; int start[p], end[p]; double per[p], pp[24]; for(j=0; jmaxs)&&(usedproc[j]==0)) { maxproc=j; maxs=s[k][j]; } if (DEBUG) printf("fastest proc: %d, speed %f\n", maxproc, maxs); if (maxperiod==-1) { // First time in the loop: start[p]=0 and end[p]=n-1; start[maxproc]=0; end[maxproc]=n-1; usedproc[maxproc]=1; // compute the corresponding period per[maxproc] = (d[k][0]+d[k][n])/B[k]; for (i=0; imaxp) && (end[j]-start[j]!=0) && (per[j]>fixp)){ maxp=per[j]; maxproc2=j; } if (maxproc2!=-1) { //printf("Spliting maxproc2=%d\n", maxproc2); // Find l where to cut the interval to min the max of the 2 resultant periods ll=-1; for (l=start[maxproc2]; lpp[1]) pp[0]=pp[2]; else pp[0]=pp[1]; // Case 2: start..l on maxproc and l..end on maxproc2 pp[4]=(d[k][start[maxproc2]]+d[k][l+1])/B[k]; for(j=start[maxproc2]; j<=l; j++) pp[4]+=w[k][j]/s[k][maxproc]; pp[5]=(d[k][l+1]+d[k][end[maxproc2]+1])/B[k]; for(j=l+1; j<=end[maxproc2]; j++) pp[5]+=w[k][j]/s[k][maxproc2]; if (pp[4]>pp[5]) pp[3]=pp[4]; else pp[3]=pp[5]; //if (k==3) //printf("l=%d -- pp: 0=%f, 1=%f, 2=%f, 3=%f, 4=%f, 5=%f, maxp=%f\n",l,pp[0],pp[1],pp[2],pp[3],pp[4],pp[5],maxp); // Find out if this l is better, and for which configuration if ((pp[0] < maxp)&&(pp[0] maxperiod) maxperiod=per[j]; } if (DEBUG) fprintf(idf[k],"H1: maxperiod=%f\n\n", maxperiod); if (DEBUG) fprintf(idf[k],"H1: latence=%f\n\n", latency[z][heuristic][k]); if (DEBUG) if (maxperiod>fixp) fprintf(idf[k],"H1: FIXED PERIOD NOT REACHED!!\n\n"); //fprintf(plot[heuristic], "%d %f\n", n, maxperiod); totperiod[z][heuristic][k]+=maxperiod; totlatency[z][heuristic][k]+=latency[z][heuristic][k]; printf("\nheuristic 2a starts, fixedp=%f\n",fixp); // *********** Heuristic 2a: 3-Exploration mono-criterion: ************ // *********** searching for pair c1, c2 ************ // *********** that increases the less L ************ heuristic=1; double newlatency; //global temporary latency double llat[6]; //temporary latency in 3explo-step // double ratio[6]; //ratio int maxproc1; double maxs1,minlat,mind,max3; double llat1,llat2; int bestcut=-1;; int c1,c2,loop; for(j=0; jmaxs)&&(usedproc[j]==0)) { maxproc=j; maxs=s[k][j]; } //if(maxproc==-1)kk=0; //find second fastest proc (maxproc1) for (j=0; jmaxs1)&&(usedproc[j]==0)&& (maxproc!=j)) { //printf("found one: %d\n",j); maxproc1=j; maxs1=s[k][j]; } } if (MEGADEBUG) printf("maxproc %d\n",maxproc); if(maxperiod==-1) { // First time in the loop: start[p]=0 and end[p]=n-1; start[maxproc]=0; end[maxproc]=n-1; usedproc[maxproc]=1; // compute the corresponding period per[maxproc] = (d[k][0]+d[k][n])/B[k]; for (i=0; imaxp) && (end[j]-start[j]!=0) && (per[j]>fixp)){ maxp=per[j]; maxproc2=j; } if (MEGADEBUG) printf("maxproc=%d, maxproc1=%d, macproc2=%d to split\n",maxproc,maxproc1,maxproc2); if (maxp > fixp) { minlat=MAXDOUBLE; // c1=-1; c2=-1; ll=-1; if((maxproc1!=-1) && ((end[maxproc2]-start[maxproc2])>1)) { // 2 procs are free, and interval can be cut in 3 parts for (ii=start[maxproc2];ii=maxp) { kk=0; printf("period not diminuated even with cuts"); } } } } if (MEGADEBUG) printf("\nperform the best cut avec cut1=%d, cut2=%d, p1=%f, p2=%f, p3=%f, lat=%f\n",c1+1,c2+1,max1,max2,max3,newlatency); if (DEBUG) fprintf(idf[k],"H2b: interval1 %d-%d, interval2 %d-%d, interval3 %d-%d\n",start[maxproc2],c1,c1+1,c2,c2+1,end[maxproc2]); if(c1>c2)printf("\n!!!!!!!!!!!!!!!!!!!!!ATTENTION!!!!!!!!!!!!!!!!\nc1 > c2"); if(ll!=-1) { usedproc[maxproc]=1; usedproc[maxproc1]=1; //Perform the best cut switch(ll) { case 0: latency[z][heuristic][k]=newlatency; end[maxproc]=end[maxproc2]; end[maxproc2]=c1; end[maxproc1]=c2; start[maxproc1]=c1+1; start[maxproc]=c2+1; per[maxproc2]=max1; per[maxproc1]=max2; per[maxproc]=max3; break; case 1: latency[z][heuristic][k]=newlatency; end[maxproc1]=end[maxproc2]; end[maxproc2]=c1; end[maxproc]=c2; start[maxproc]=c1+1; start[maxproc1]=c2+1; per[maxproc2]=max1; per[maxproc]=max2; per[maxproc1]=max3; break; case 2: latency[z][heuristic][k]=newlatency; end[maxproc1]=c1; end[maxproc]=c2; start[maxproc]=c1+1; start[maxproc1]=start[maxproc2]; start[maxproc2]=c2+1; per[maxproc1]=max1; per[maxproc]=max2; per[maxproc2]=max3; break; case 3: latency[z][heuristic][k]=newlatency; end[maxproc1]=c1; end[maxproc]=end[maxproc2]; end[maxproc2]=c2; start[maxproc1]=start[maxproc2]; start[maxproc2]=c1+1; start[maxproc]=c2+1; per[maxproc1]=max1; per[maxproc2]=max2; per[maxproc]=max3; break; case 4:latency[z][heuristic][k]=newlatency; end[maxproc]=c1; end[maxproc1]=c2; start[maxproc]=start[maxproc2]; start[maxproc1]=c1+1; start[maxproc2]=c2+1; per[maxproc]=max1; per[maxproc1]=max2; per[maxproc2]=max3; break; case 5:latency[z][heuristic][k]=newlatency; end[maxproc1]=end[maxproc2]; end[maxproc]=c1; end[maxproc2]=c2; start[maxproc]=start[maxproc2]; start[maxproc2]=c1+1; start[maxproc1]=c2+1; per[maxproc]=max1; per[maxproc2]=max2; per[maxproc1]=max3; break; //default: //continue; } } // no possible pair c1,c2 was found else { kk=0; printf("attention! no possible cut was found!\n"); } } else { //only 1 proc is free, or interval < 3, so we do only 1 cut //search for fastest comm printf("only 1 proc is free, or interval < 3, so we do only 1 cut\n"); // Find the proc with the biggest period that we can split (to put on maxproc) maxproc2=-1; maxp=0; for (j=0; jmaxp) && (end[j]-start[j]!=0) && (per[j]>fixp)){ maxp=per[j]; maxproc2=j; } if (MEGADEBUG) printf("maxproc2 to split: %d to put on maxproc %d\n",maxproc2,maxproc); if ((maxproc!=-1)) { bestcut=-1; mind=MAXDOUBLE; printf("start[maxproc2]=%d,end[maxproc2]=%d\n",start[maxproc2],end[maxproc2]); for (j=start[maxproc2]+1;j<=end[maxproc2];j++){ printf("j=%d\n",j); if (d[k][j]pp[1]) pp[0]=pp[2]; else pp[0]=pp[1]; llat1=latency[z][heuristic][k]-per[maxproc2]+pp[1]+pp[2]-(d[k][bestcut]/B[k]); // Case 2: start..bestcut on maxproc and bestcut..end on maxproc2 pp[4]=(d[k][start[maxproc2]]+d[k][bestcut])/B[k]; for(j=start[maxproc2]; jpp[5]) pp[3]=pp[4]; else pp[3]=pp[5]; llat2=latency[z][heuristic][k]-per[maxproc2]+pp[4]+pp[5]-(d[k][bestcut]/B[k]); // if (k==3) // printf("l=%d -- pp: 0=%f, 1=%f, 2=%f, 3=%f, 4=%f, 5=%f\n",l,pp[0],pp[1],pp[2],pp[3],pp[4],pp[5]); // Find out if this cut increases p max, and for which configuration latency is the best if (llat1 maxperiod) maxperiod=per[j]; } if (DEBUG) fprintf(idf[k],"H2a: maxperiod=%f\n\n", maxperiod); if (DEBUG) fprintf(idf[k],"H2a: latence=%f\n\n", latency[z][heuristic][k]); if (DEBUG) if (maxperiod>fixp) fprintf(idf[k],"H2a: FIXED PERIOD NOT REACHED!!\n\n"); //fprintf(plot[heuristic], "%d %f\n", n, maxperiod); totperiod[z][heuristic][k]+=maxperiod; totlatency[z][heuristic][k]+=latency[z][heuristic][k]; // *********** Heuristic 2b: 3-Exploration bi-criterion: ************ // *********** searching for pair c1, c2 ************ // *********** that has best ratio on profit l/p ************ heuristic=2; double gain[6]; double maxgain,globalgain; // double llat1,llat2; for(j=0; jmaxs)&&(usedproc[j]==0)) { maxproc=j; maxs=s[k][j]; } //if(maxproc==-1)kk=0; //find second fastest proc (maxproc1) for (j=0; jmaxs1)&&(usedproc[j]==0)&& (maxproc!=j)) { //printf("found one: %d\n",j); maxproc1=j; maxs1=s[k][j]; } } if (MEGADEBUG) printf("maxproc %d\n",maxproc); if(maxperiod==-1) { // First time in the loop: start[p]=0 and end[p]=n-1; start[maxproc]=0; end[maxproc]=n-1; usedproc[maxproc]=1; // compute the corresponding period per[maxproc] = (d[k][0]+d[k][n])/B[k]; for (i=0; imaxp) && (end[j]-start[j]!=0) && (per[j]>fixp)){ maxp=per[j]; maxproc2=j; } if (MEGADEBUG) printf("maxproc=%d, maxproc1=%d, macproc2=%d to split\n",maxproc,maxproc1,maxproc2); if (maxp > fixp) { globalgain=MAXDOUBLE; // c1=-1; c2=-1; ll=-1; if((maxproc1!=-1) && ((end[maxproc2]-start[maxproc2])>1)) { // 2 procs are free, and interval can be cut in 3 parts for (ii=start[maxproc2];ii0) && (gain[j]=maxp) { kk=0; printf("period not diminuated even with cuts"); } } } } if (MEGADEBUG) printf("\nperform the best cut avec c1=%d, c2=%d, p1=%f, p2=%f, p3=%f, lat=%f\n",c1,c2,max1,max2,max3,newlatency); if (DEBUG) fprintf(idf[k],"H2b: interval1 %d-%d, interval2 %d-%d, interval3 %d-%d\n",start[maxproc2],c1,c1+1,c2,c2+1,end[maxproc2]); if(c1>c2)printf("\n!!!!!!!!!!!!!!!!!!!!!ATTENTION!!!!!!!!!!!!!!!!\nc1 > c2"); if(ll!=-1) { usedproc[maxproc]=1; usedproc[maxproc1]=1; //Perform the best cut switch(ll) { case 0: latency[z][heuristic][k]=newlatency; end[maxproc]=end[maxproc2]; end[maxproc2]=c1; end[maxproc1]=c2; start[maxproc1]=c1+1; start[maxproc]=c2+1; per[maxproc2]=max1; per[maxproc1]=max2; per[maxproc]=max3; break; case 1: latency[z][heuristic][k]=newlatency; end[maxproc1]=end[maxproc2]; end[maxproc2]=c1; end[maxproc]=c2; start[maxproc]=c1+1; start[maxproc1]=c2+1; per[maxproc2]=max1; per[maxproc]=max2; per[maxproc1]=max3; break; case 2: latency[z][heuristic][k]=newlatency; end[maxproc1]=c1; end[maxproc]=c2; start[maxproc]=c1+1; start[maxproc1]=start[maxproc2]; start[maxproc2]=c2+1; per[maxproc1]=max1; per[maxproc]=max2; per[maxproc2]=max3; break; case 3: latency[z][heuristic][k]=newlatency; end[maxproc1]=c1; end[maxproc]=end[maxproc2]; end[maxproc2]=c2; start[maxproc1]=start[maxproc2]; start[maxproc2]=c1+1; start[maxproc]=c2+1; per[maxproc1]=max1; per[maxproc2]=max2; per[maxproc]=max3; break; case 4:latency[z][heuristic][k]=newlatency; end[maxproc]=c1; end[maxproc1]=c2; start[maxproc]=start[maxproc2]; start[maxproc1]=c1+1; start[maxproc2]=c2+1; per[maxproc]=max1; per[maxproc1]=max2; per[maxproc2]=max3; break; case 5:latency[z][heuristic][k]=newlatency; end[maxproc1]=end[maxproc2]; end[maxproc]=c1; end[maxproc2]=c2; start[maxproc]=start[maxproc2]; start[maxproc2]=c1+1; start[maxproc1]=c2+1; per[maxproc]=max1; per[maxproc2]=max2; per[maxproc1]=max3; break; //default: //continue; } } // no possible pair c1,c2 was found else { kk=0; printf("attention! no possible cut was found!\n"); } } else { //only 1 proc is free, or interval < 3, so we do only 1 cut //search for fastest comm printf("\nonly 1 proc is free, or interval < 3, so we do only 1 cut\n"); // Find the proc with the biggest period that we can split (to put on maxproc) maxproc2=-1; maxp=0; for (j=0; jmaxp) && (end[j]-start[j]!=0) && (per[j]>fixp)){ maxp=per[j]; maxproc2=j; } if (MEGADEBUG) printf("maxproc2 to split: %d to put on maxproc %d\n",maxproc2,maxproc); if ((maxproc!=-1)) { bestcut=-1; mind=MAXDOUBLE; for (j=start[maxproc2]+1;j<=end[maxproc2];j++) if (d[k][j]pp[1]) pp[0]=pp[2]; else pp[0]=pp[1]; llat1=latency[z][heuristic][k]-per[maxproc2]+pp[1]+pp[2]-(d[k][bestcut]/B[k]); // Case 2: start..bestcut on maxproc and bestcut..end on maxproc2 pp[4]=(d[k][start[maxproc2]]+d[k][bestcut])/B[k]; for(j=start[maxproc2]; jpp[5]) pp[3]=pp[4]; else pp[3]=pp[5]; llat2=latency[z][heuristic][k]-per[maxproc2]+pp[4]+pp[5]-(d[k][bestcut]/B[k]); // if (k==3) // printf("l=%d -- pp: 0=%f, 1=%f, 2=%f, 3=%f, 4=%f, 5=%f\n",l,pp[0],pp[1],pp[2],pp[3],pp[4],pp[5]); // Find out if this cut increases p max, and for which configuration latency is the best if (llat1maxp) maxp=pp[0]; } else { ll=bestcut; jj=2; max1=pp[4]; max2=pp[5]; if(pp[3]>maxp) maxp=pp[3]; } if (DEBUG) printf("bestcut=%d, max1=%f, max2=%f\n",bestcut,max1,max2); //perform cut usedproc[maxproc]=1; if (jj==1) { latency[z][heuristic][k]=llat1; end[maxproc]=end[maxproc2]; end[maxproc2]=bestcut-1; start[maxproc]=bestcut; per[maxproc2]=max1; per[maxproc]=max2; } else { latency[z][heuristic][k]=llat2; end[maxproc2]=bestcut-1; start[maxproc]=start[maxproc2]; start[maxproc2]=bestcut; per[maxproc]=max1; per[maxproc2]=max2; } } else { // no possible cut was found kk=0; } } else { //no more proc free kk=0; } } } else { //maxp <= fixp, we do not need to split anymore kk=0; } } else { //no more proc free kk=0; printf("no more proc free\n"); } } for (j=0; j maxperiod) maxperiod=per[j]; } if (DEBUG) fprintf(idf[k],"H2b: maxperiod=%f\n\n", maxperiod); if (DEBUG) fprintf(idf[k],"H2b: latence=%f\n\n", latency[z][heuristic][k]); if (DEBUG) if (maxperiod>fixp) fprintf(idf[k],"H2b: FIXED PERIOD NOT REACHED!!\n\n"); //fprintf(plot[heuristic], "%d %f\n", n, maxperiod); totperiod[z][heuristic][k]+=maxperiod; totlatency[z][heuristic][k]+=latency[z][heuristic][k]; /************* Heuristic 3: Splitting bicritaire ************/ /************* Binary search over latency ************/ /************* increase (fraction Lopt/L) ************/ heuristic=3; printf("\n\n-----------------------------------------------------------------\n"); printf("heuristic 3\n"); printf("-----------------------------------------------------------------\n"); kkmax=STARTDIC; int cutcomm[n+1], actend,actproc,nextproc,lll,jjj,proc; double lopt; double kkremain; double nexts,tmplatency,latence,globalmaxp; double ratio1,ratio2,minratio; int oldStart[p], oldEnd[p],oldUsedproc[p]; //storing old values double oldMaxp, oldLatency, oldPer[p]; if (MEGADEBUG) { printf("\nPLATFORM:\n"); printf("nb stages: %d,n=%d, nb procs: %d, p=%d\n",nbstage[k],n,nbproc[k],p); printf("links:"); for(j=0;jmaxs)&&(usedproc[j]==0)) { maxproc=j; maxs=s[k][j]; } // all stages on fastest proc start[maxproc]=0; end[maxproc]=n-1; usedproc[maxproc]=1; per[maxproc]=(d[k][0]+d[k][n])/B[k]; for (i=0; i PREC) { //kkk=(kkmax-kkmin)/2; kkk=kkmin+(kkmax-kkmin)/2; kkremain=kkk; if (MEGADEBUG) printf("-------------------------------\ndichotomy with kkk=%f, kkmax=%f; kkmin=%f\n", kkk, kkmax, kkmin); ll=1; // currently there is a solution lll=-1; // Initialising maxsta=0; // starting stage for(j=0; j0) { loop++; nexts=-1; nextproc=-1; minratio=MAXDOUBLE; for (j=0; jnexts)&&(usedproc[j]==0)) { nextproc=j; nexts=s[k][j]; } if (MEGADEBUG) printf("\nLOOP %d:\n-------\n",loop); if (MEGADEBUG) printf("nextproc=%d\n",nextproc); if (MEGADEBUG) printf("kkremain when entering the loop: %f, tmplatency %f, maxp %f\n",kkremain,tmplatency,maxp); //bestratio=-1; bestcut=-1; // config=-1; //looking for link to cut where d[link] <= remaining latency increase and which max gain=delatL/deltaP for (ii=1;ii=ii) && (start[jj]<=ii)) { actend=end[jj]; actproc=jj; } } if (MEGADEBUG) printf("link ii=%d, actproc=%d, start=%d, end=%d\n", ii,actproc,start[actproc],end[actproc]); //splitting interval on actproc? // Case 1: start..ii-1 on actproc and ii..end on nextproc pp[1]=(d[k][start[actproc]]+d[k][nextproc])/B[k]; for(j=start[actproc]; jpp[1]) pp[0]=pp[2]; else pp[0]=pp[1]; llat1=tmplatency-per[actproc]+pp[1]+pp[2]-(d[k][ii]/B[k]); ratio1=(llat1-tmplatency)/(per[actproc]-pp[0]); // Case 2: start..ii-1 on nextproc and ii..end on actproc pp[4]=(d[k][start[actproc]]+d[k][ii])/B[k]; for(j=start[actproc]; jpp[5]) pp[3]=pp[4]; else pp[3]=pp[5]; llat2=tmplatency-per[actproc]+pp[4]+pp[5]-(d[k][ii]/B[k]); ratio2=(llat2-tmplatency)/(per[actproc]-pp[3]); if (((ratio10)) { lll=ii; proc=actproc, jjj=1; minratio=ratio1; latence=llat1; max1=pp[1]; max2=pp[2]; maxp=pp[0]; } else if ((ratio20)) { lll=ii; proc=actproc, jjj=2; minratio=ratio2; latence=llat2; max1=pp[4]; max2=pp[5]; maxp=pp[3]; } if (MEGADEBUG) printf("act: link=%d with ratio1=%f, llat1=%f and pp1=%f, ratio2=%f, llat2=%f and pp2=%f\n", ii,ratio1,llat1,pp[0],ratio2,llat2,pp[3]); if (MEGADEBUG) printf("act best: link=%d with ratio=%f, l=%f and maxp=%f, tmplatency=%f\n",lll,minratio,latence,maxp,tmplatency); } } if (lll!=-1) { if (MEGADEBUG) printf("latence %f, tmplatency %f, resulting kkremain %f\n",latence,tmplatency,kkremain); kkremain=kkremain-(latence-tmplatency); if (MEGADEBUG) printf("possible increase after split: %f, %d\nactproc %d, nextproc %d, cutcomm %d\n",kkremain,kkremain>0,proc,nextproc,lll); if (MEGADEBUG) printf("start actproc=%d, end=%d\n",start[proc],end[proc]); // Perform the best cut //printf("k=%d: cut with ll=%d\n",k,ll); usedproc[nextproc]=1; usedproc[actproc]=1; cutcomm[lll]=1; if (maxp>globalmaxp) globalmaxp=maxp; if (jjj==1) { tmplatency-=per[proc]; end[nextproc]=end[proc]; end[proc]=lll-1; start[nextproc]=lll; per[proc]=max1; per[nextproc]=max2; //tmplatency=per[nextproc]+per[proc]-(d[k][lll]/B[k]); tmplatency=latence; } else { tmplatency-=per[proc]; start[nextproc]=start[proc]; end[nextproc]=lll-1; start[proc]=lll; per[nextproc]=max1; per[proc]=max2; // tmplatency=per[nextproc]+per[proc]-(d[k][lll]/B[k]); tmplatency=latence; } if (DEBUG) printf("splitting interval: actproc: %d, p=%f, next proc: %d, p=%f, l=%f\n", proc,per[proc], nextproc,per[nextproc], tmplatency); for (j=0;j maxperiod) maxperiod=per[j]; } if (maxperiod>fixp) { ll=0; printf("this was not a valid solution, globalmaxp %f, fixp %f\n",maxperiod,fixp); } else {latency[z][heuristic][k]=tmplatency; maxp=maxperiod;} // Loop on the dichotomy if (ll){ solfound=1; printf("sol found, kkmax=kkk, maxp=%f\n",maxp); kkmax=kkk; printf("\n***************************\nsol found=1; old sol = sol;\n**********************************\n"); for (j=0; j=STARTDIC) { printf("INCREASE DIC START\n"); } if (DEBUG) fprintf(idf[k],"H3: maxincrease=%f\n\n", kkmax); //fprintf(plot[heuristic], "%d %f\n", n, maxperiod); //totperiod[heuristic][k]+=kkmax; for (j=0; j maxperiod) maxperiod=per[j]; } if (DEBUG) fprintf(idf[k],"H3: maxperiod=%f\n", maxperiod); if (DEBUG) fprintf(idf[k],"H3: latence=%f\n\n", latency[z][heuristic][k]); if (DEBUG) if (maxperiod>fixp) fprintf(idf[k],"H3: FIXED PERIOD NOT REACHED!!\n\n"); if (DEBUG) if (solfound!=1) fprintf(idf[k],"H3: NO SOL FOUND!! maxperiod=%f, lat=%f\n\n",maxperiod,latency[z][heuristic][k]); //fprintf(plot[heuristic], "%d %f\n", n, maxperiod); totperiod[z][heuristic][k]+=maxperiod; totlatency[z][heuristic][k]+=latency[z][heuristic][k]; /************************* part II: min period with fixed latency *******************************/ /* Heuristic 4: Splitting to diminuate period */ /* while latency is not exceeded */ /* uses Splitting heuristic by Anne Benoit */ heuristic=4; // int start[p], end[p]; // double per[p], pp[6]; // double tmplatency; printf("\nheuristic 4 starts\n\n"); for(j=0; jmaxs)&&(usedproc[j]==0)) { maxproc=j; maxs=s[k][j]; } //printf("fastest proc: %d, speed %f\n", maxproc, maxs); if (maxperiod==-1) { // First time in the loop: start[p]=0 and end[p]=n-1; start[maxproc]=0; end[maxproc]=n-1; usedproc[maxproc]=1; // compute the corresponding period per[maxproc] = (d[k][0]+d[k][n])/B[k]; for (i=0; imaxp) && (end[j]-start[j]!=0)){ maxp=per[j]; maxproc2=j; } if (maxproc2!=-1) { //printf("Spliting maxproc2=%d\n", maxproc2); // Find l where to cut the interval to min the max of the 2 resultant periods ll=-1; for (l=start[maxproc2]; lpp[1]) pp[0]=pp[2]; else pp[0]=pp[1]; // Case 2: start..l on maxproc and l..end on maxproc2 pp[4]=(d[k][start[maxproc2]]+d[k][l+1])/B[k]; for(j=start[maxproc2]; j<=l; j++) pp[4]+=w[k][j]/s[k][maxproc]; pp[5]=(d[k][l+1]+d[k][end[maxproc2]+1])/B[k]; for(j=l+1; j<=end[maxproc2]; j++) pp[5]+=w[k][j]/s[k][maxproc2]; if (pp[4]>pp[5]) pp[3]=pp[4]; else pp[3]=pp[5]; // if (k==3) // printf("l=%d -- pp: 0=%f, 1=%f, 2=%f, 3=%f, 4=%f, 5=%f\n",l,pp[0],pp[1],pp[2],pp[3],pp[4],pp[5]); // Find out if this l is better, and for which configuration if ((pp[0] < maxp)&&(pp[0] maxperiod) maxperiod=per[j]; } if (DEBUG) fprintf(idf[k],"H4: maxperiod=%f\n\n", maxperiod); if (DEBUG) fprintf(idf[k],"H4: latence=%f\n\n", latency[z][heuristic][k]); if (DEBUG) if (maxperiod>fixp) fprintf(idf[k],"H4: FIXED PERIOD NOT REACHED!!\n\n"); //fprintf(plot[heuristic], "%d %f\n", n, maxperiod); totperiod[z][heuristic][k]+=maxperiod; totlatency[z][heuristic][k]+=latency[z][heuristic][k]; /************* Heuristic 5: Splitting bicritaire ************/ /************* min period with fixed latency. ************/ /************* Permitted latency increase is knwon ************/ /************* increase = L - Lopt ************/ heuristic=5; //heuristic=1; printf("\n\n-----------------------------------------------------------------\n"); printf("heuristic 5\n"); printf("-----------------------------------------------------------------\n"); // kkmax=STARTDIC; if (MEGADEBUG) { printf("\nPLATFORM:\n"); printf("nb stages: %d,n=%d, nb procs: %d, p=%d\n",nbstage[k],n,nbproc[k],p); printf("links:"); for(j=0;jmaxs)&&(usedproc[j]==0)) { maxproc=j; maxs=s[k][j]; } // all stages on fastest proc start[maxproc]=0; end[maxproc]=n-1; usedproc[maxproc]=1; per[maxproc]=(d[k][0]+d[k][n])/B[k]; for (i=0; i0) { loop++; nexts=-1; nextproc=-1; minratio=MAXDOUBLE; for (j=0; jnexts)&&(usedproc[j]==0)) { nextproc=j; nexts=s[k][j]; } if (MEGADEBUG) printf("\nLOOP %d:\n-------\n",loop); if (MEGADEBUG) printf("nextproc=%d\n",nextproc); if (MEGADEBUG) printf("kkremain when entering the loop: %f, tmplatency %f, maxp %f\n",kkremain,tmplatency,maxp); //bestratio=-1; bestcut=-1; // config=-1; for (ii=1;ii=ii) && (start[jj]<=ii)) { actend=end[jj]; actproc=jj; } } if (MEGADEBUG) printf("link ii=%d, actproc=%d, start=%d, end=%d\n", ii,actproc,start[actproc],end[actproc]); //splitting interval on actproc? // Case 1: start..ii-1 on actproc and ii..end on nextproc pp[1]=(d[k][start[actproc]]+d[k][nextproc])/B[k]; for(j=start[actproc]; jpp[1]) pp[0]=pp[2]; else pp[0]=pp[1]; llat1=tmplatency-per[actproc]+pp[1]+pp[2]-(d[k][ii]/B[k]); ratio1=(llat1-tmplatency)/(per[actproc]-pp[0]); // Case 2: start..ii-1 on nextproc and ii..end on actproc pp[4]=(d[k][start[actproc]]+d[k][ii])/B[k]; for(j=start[actproc]; jpp[5]) pp[3]=pp[4]; else pp[3]=pp[5]; llat2=tmplatency-per[actproc]+pp[4]+pp[5]-(d[k][ii]/B[k]); ratio2=(llat2-tmplatency)/(per[actproc]-pp[3]); if (((ratio10)) { lll=ii; proc=actproc, jjj=1; minratio=ratio1; latence=llat1; max1=pp[1]; max2=pp[2]; maxp=pp[0]; } else if ((ratio20)) { lll=ii; proc=actproc, jjj=2; minratio=ratio2; latence=llat2; max1=pp[4]; max2=pp[5]; maxp=pp[3]; } if (MEGADEBUG) printf("act: link=%d with ratio1=%f, llat1=%f and pp1=%f, ratio2=%f, llat2=%f and pp2=%f\n", ii,ratio1,llat1,pp[0],ratio2,llat2,pp[3]); if (MEGADEBUG) printf("act best: link=%d with ratio=%f, l=%f and maxp=%f, tmplatency=%f\n",lll,minratio,latence,maxp,tmplatency); } } if (lll!=-1) { if (MEGADEBUG) printf("latence %f, tmplatency %f, resulting kkremain %f\n",latence,tmplatency,kkremain); kkremain=kkremain-(latence-tmplatency); if (MEGADEBUG) printf("possible increase after split: %f, %d\nactproc %d, nextproc %d, cutcomm %d\n",kkremain,kkremain>0,proc,nextproc,lll); if (MEGADEBUG) printf("start actproc=%d, end=%d\n",start[proc],end[proc]); // Perform the best cut //printf("k=%d: cut with ll=%d\n",k,ll); usedproc[nextproc]=1; usedproc[actproc]=1; cutcomm[lll]=1; if (maxp>globalmaxp) globalmaxp=maxp; if (jjj==1) { tmplatency-=per[proc]; end[nextproc]=end[proc]; end[proc]=lll-1; start[nextproc]=lll; per[proc]=max1; per[nextproc]=max2; //tmplatency=per[nextproc]+per[proc]-(d[k][lll]/B[k]); tmplatency=latence; } else { tmplatency-=per[proc]; start[nextproc]=start[proc]; end[nextproc]=lll-1; start[proc]=lll; per[nextproc]=max1; per[proc]=max2; // tmplatency=per[nextproc]+per[proc]-(d[k][lll]/B[k]); tmplatency=latence; } if (MEGADEBUG) printf("splitting interval: actproc: %d, p=%f, next proc: %d, p=%f, l=%f\n", proc,per[proc], nextproc,per[nextproc], tmplatency); for (j=0;j maxperiod) maxperiod=per[j]; } if (tmplatency>fixl) { ll=0; printf("this was not a valid solution, tmplatency %f, fixl %f\n",tmplatency,fixl); /* no solution found, when splitting, hence all stages stay on fastest proc */ // latency[z][heuristic][k]=lopt; maxp=p_lopt; for(j=0; jmaxs)&&(usedproc[j]==0)) { maxproc=j; maxs=s[k][j]; } // all stages on fastest proc start[maxproc]=0; end[maxproc]=n-1; usedproc[maxproc]=1; per[maxproc]=(d[k][0]+d[k][n])/B[k]; for (i=0; i maxperiod) maxperiod=per[j]; } if (DEBUG) fprintf(idf[k],"H5: maxperiod=%f\n", maxperiod); if (DEBUG) fprintf(idf[k],"H5: latence=%f\n\n", latency[z][heuristic][k]); if (DEBUG) if (maxperiod>fixp) fprintf(idf[k],"H5: FIXED PERIOD NOT REACHED!!\n\n"); //fprintf(plot[heuristic], "%d %f\n", n, maxperiod); totperiod[z][heuristic][k]+=maxperiod; totlatency[z][heuristic][k]+=latency[z][heuristic][k]; fprintf(stderr,"\nbefore close\n\n"); if (DEBUG) fclose(idf[k]); } } //printf("nach for uber k=nbapp, tree=%d\n\n",tree); } //printf("nach for uber tree=nbtree\n\n"); // Printing the plots for (i=0; i(totperiod[kk][i][k]/nbtree)) minp=totperiod[kk][i][k]/nbtree; if(minl>(totlatency[kk][i][k]/nbtree)) minl=totlatency[kk][i][k]/nbtree; } lowerboundl=0; lowerboundl=0; if (i<4) { printf("H%d:\n",i); printf("minp=%f, lbp=%f\n",minp,lowerboundp ); for(kk=0;kk(fixedperiod[kk][k])) lowerboundp=fixedperiod[kk][k]; } if (i>3) { for(kk=0;kk(fixedlatency[kk][k])) lowerboundl=fixedlatency[kk][k]; } //printf("totperiod[%d][%d]=%lf, nbtree=%d\n",i,k,totperiod[i][k],nbtree); sprintf(fname,"plots/Heuristic-%.2d_%.2d",i+1,nbstage[k]); doubleObjFile=fopen(fname,"a"); //fprintf(plot[i], "%d %f\n", k+1, totperiod[i][k]/nbtree); for (z=0;z3) fprintf(latencyFile,"%d %f\n",0,lowerboundl); fclose(doubleObjFile); } fprintf(stderr,"all is printed\n"); fclose(periodFile); fclose(latencyFile); fprintf(stderr,"and closed again\n"); //fclose(plot[i]); } /* for(i=0;i