123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960 |
- #include "resource_negotiation.h"
- #include "noc_functions.h"
- #include "apps.h"
- extern app my_app;
- int offer_cores_original(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id);
- int offer_cores_updated(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id);
- int offer_cores_fft_original(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id);
- int offer_cores(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id) {
- #ifdef RESOURCE_ALGO_ORIG
- if (executed_app != FFT) {
- return offer_cores_original(cores, req_app, req_reg, Offered_cores, req_id);
- } else {
- return offer_cores_fft_original(cores, req_app, req_reg, Offered_cores, req_id);
- }
- #elif RESOURCE_ALGO_UPDATED
- return offer_cores_updated(cores, req_app, req_reg, Offered_cores, req_id);
- #else
- return offer_cores_original(cores, req_app, req_reg, Offered_cores, req_id);
- #endif
- }
- /* Speedup is calculated correclty inside Speedup function */
- int offer_cores_original(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id) {
- int Of_cores_num=0, min_dist=0, cur_dist=0;
- float gain_total=0.1, base_receiver=0.0, base_giver=0.0, gain_receiver=0.0, loss_giver=0.0, share_giver=0.0, new_gain=0.0;
- int Cores_receiver = req_app.num_of_cores, Cores_giver = my_app.num_of_cores;
- core_list *tmp, *GreedyChoice;
- int offered_cnt=0, counted_cores=0;
- for (tmp=cores; tmp!=NULL; tmp=tmp->next) {
- if (distance(req_reg.C, tmp->core_id) <= req_reg.r) share_giver++;
- counted_cores++;
- if (tmp->offered_to != -1) offered_cnt++;
- fprintf(log_file,"Core %d is offered to %d\n",tmp->core_id,tmp->offered_to);
- }
- fprintf(log_file,"Proceeding\n");
- fflush(log_file);
- if (offered_cnt == (counted_cores-2) && my_idag != -1) {
- fprintf(log_file,"I did not give up my only not offered core\n");
- fflush(log_file);
- return 0;
- }
- share_giver = share_giver / (float) region_count(req_reg);
- if (my_idag == -1) {
- while (gain_total > 0.0) {
- gain_total = 0.0;
- GreedyChoice = NULL;//-1;
- min_dist = -1;
- base_giver = 0;
- tmp = cores->next;//very important!!! that way i avoid giving up my agent core
- while (tmp != NULL) {
- cur_dist = distance(req_reg.C, tmp->core_id);
- if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- //Of_cores_num == 0 to be the first offered core
- //Cores_receiver == 0 to avoid providing the core to an non-initial core search
- if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 0) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- //gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- }
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- gain_total = new_gain;
- GreedyChoice = tmp;//->core_id;
- break;
- #ifdef LOW_VOLTAGE_ISLANDS_4
- } else if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 1) {
- if (Cores_receiver == 0 && Of_cores_num == 0) gain_receiver = 1000; //0 sto init_app
- else gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- gain_total = new_gain;
- GreedyChoice = tmp;//->core_id;
- break;
- #endif
- } else if (low_voltage_core[tmp->core_id] == 0) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- }
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- if (new_gain > gain_total){
- gain_total = new_gain;
- min_dist = cur_dist;
- GreedyChoice = tmp;//->core_id;
- } else if (new_gain == gain_total && cur_dist < min_dist) {
- //printf("I am %d and i change offer to %d with cores %d->%d with distances %d->%d\n",
- // node_id,req_id,GreedyChoice->core_id,tmp->core_id,min_dist,cur_dist);
- min_dist = cur_dist;
- GreedyChoice = tmp;
- }
- }
- }
- tmp = tmp->next;
- }
- if (gain_total > 0.0) {
- Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- GreedyChoice->offered_to = req_id;
- }
- }
- }
- #ifndef GREEDY_MANAGER
- else {
- while (gain_total > 0.0) {
- gain_total = 0.0;
- GreedyChoice = NULL;//-1;
- min_dist = -1;
- base_giver = Speedup(my_app, Cores_giver - Of_cores_num);
- tmp = cores->next->next;//very important!!! that way i avoid giving up my only working core
- while (tmp != NULL) {
- if (core_inter_head[tmp->core_id] != NULL &&
- (core_inter_head[tmp->core_id]->type == INIT_WORK_NODE_PENDING || core_inter_head[tmp->core_id]->type == INIT_WORK_NODE)) {
- fprintf(log_file,"Core %d is about to start work type = %d\n",tmp->core_id,core_inter_head[tmp->core_id]->type);
- fflush(log_file);
- tmp = tmp->next;
- } else {
- cur_dist = distance(req_reg.C, tmp->core_id);
- if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver); /* + 1 is ommited due to workload convention */
- }
- loss_giver = base_giver - Speedup(my_app, Cores_giver - (Of_cores_num + 1));
- new_gain = gain_receiver - loss_giver;
- if (new_gain > gain_total){
- gain_total = new_gain;
- min_dist = cur_dist;
- GreedyChoice = tmp;//->core_id;
- } else if (new_gain == gain_total && cur_dist < min_dist) {
- //printf("I am %d and i change offer to %d with cores %d->%d with distances %d->%d\n",
- // node_id,req_id,GreedyChoice->core_id,tmp->core_id,min_dist,cur_dist);
- min_dist = cur_dist;
- GreedyChoice = tmp;
- }
- }
- tmp = tmp->next;
- }
- }
- if (gain_total > 0.0) {
- Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- GreedyChoice->offered_to = req_id;
- }
- }
- }
- #endif
- fprintf(log_file,"I will offer %d cores\n",Of_cores_num);
- fflush(log_file);
- return Of_cores_num;
- }
-
- /* Speedup is calculated correclty inside Speedup function */
- int offer_cores_updated(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id) {
- int Of_cores_num=0, min_dist=0, cur_dist=0, offered_cnt=0, counted_cores=0;
- float gain_total=0.1, base_receiver=0.0, base_giver=0.0, gain_receiver=0.0, loss_giver=0.0, new_gain=0.0;
- int Cores_receiver = req_app.num_of_cores, Cores_giver = my_app.num_of_cores;
- core_list *tmp, *GreedyChoice;
- if (my_idag != -1) {
- for (tmp=cores; tmp!=NULL; tmp=tmp->next) {
- counted_cores++;
- if (tmp->offered_to != -1) offered_cnt++;
- fprintf(log_file,"Core %d is offered to %d\n",tmp->core_id,tmp->offered_to);
- }
- if (offered_cnt == (counted_cores-2)) {
- fprintf(log_file,"I did not give up my only not offered core\n");
- fflush(log_file);
- return 0;
- }
- }
- if (my_idag == -1) {
- while (gain_total > 0.0) {
- gain_total = 0.0;
- GreedyChoice = NULL;//-1;
- min_dist = -1;
- base_giver = 0;
- tmp = cores->next;//very important!!! that way i avoid giving up my agent core
-
- while (tmp != NULL) {
- cur_dist = distance(req_reg.C, tmp->core_id);
- if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- //Of_cores_num == 0 to be the first offered core
- //Cores_receiver == 0 to avoid providing the core to an non-initial core search
- if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 0) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver;
- }
-
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- gain_total = new_gain;
- GreedyChoice = tmp;//->core_id;
- break;
- } else if (low_voltage_core[tmp->core_id] == 0) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver;
- }
-
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- if (new_gain > gain_total){
- gain_total = new_gain;
- min_dist = cur_dist;
- GreedyChoice = tmp;
- } else if (new_gain == gain_total && cur_dist < min_dist) {
- min_dist = cur_dist;
- GreedyChoice = tmp;
- }
- }
- }
- tmp = tmp->next;
- }
- if (gain_total > 0.0) {
- Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- GreedyChoice->offered_to = req_id;
- }
- }
- }
- #ifndef GREEDY_MANAGER
- else {
- while (gain_total > 0.0) {
- gain_total = 0.0;
- GreedyChoice = NULL;//-1;
- min_dist = -1;
- base_giver = Speedup(my_app, Cores_giver - Of_cores_num);
-
- tmp = cores->next->next;//very important!!! that way i avoid giving up my only working core
-
- while (tmp != NULL) {
- if (core_inter_head[tmp->core_id] != NULL &&
- (core_inter_head[tmp->core_id]->type == INIT_WORK_NODE_PENDING || core_inter_head[tmp->core_id]->type == INIT_WORK_NODE)) {
- fprintf(log_file,"Core %d is about to start work type = %d\n",tmp->core_id,core_inter_head[tmp->core_id]->type);
- fflush(log_file);
- tmp = tmp->next;
- } else {
- cur_dist = distance(req_reg.C, tmp->core_id);
- if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver; /* + 1 is ommited due to workload convention */
- }
-
- loss_giver = base_giver - Speedup(my_app, Cores_giver - (Of_cores_num + 1));
-
- new_gain = gain_receiver - loss_giver;
- if (new_gain > gain_total){
- gain_total = new_gain;
- min_dist = cur_dist;
- GreedyChoice = tmp;
- } else if (new_gain == gain_total && cur_dist < min_dist) {
- min_dist = cur_dist;
- GreedyChoice = tmp;
- }
- }
- tmp = tmp->next;
- }
- }
- if (gain_total > 0.0) {
- if (get_times(my_app, Cores_giver - (Of_cores_num + 1)) > get_times(req_app, Cores_receiver + Of_cores_num + 1)) {
- Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- GreedyChoice->offered_to = req_id;
- fprintf(log_file,"Accepted bargain with giver_times %d receiver_times %d\n",get_times(my_app, Cores_giver - (Of_cores_num + 1)),get_times(req_app, Cores_receiver + Of_cores_num + 1));
- fflush(log_file);
- } else {
- gain_total = 0.0;
- fprintf(log_file,"Abandoning because I will finish earlier!\n");
- fflush(log_file);
- }
- }
- }
- }
- #endif
- fprintf(log_file,"I will offer %d cores\n",Of_cores_num);
- fflush(log_file);
- return Of_cores_num;
- }
- // int offer_cores_fft(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id) {
- // int Of_cores_num=0, min_dist=0, cur_dist=0;
- // float gain_total=0.1,base_receiver=0.0,base_giver=0.0,gain_receiver=0.0,loss_giver=0.0,share_giver=0.0,new_gain=0.0;
- // int Cores_receiver = req_app.num_of_cores, Workers_giver = my_app.num_of_cores-1;
- // core_list *tmp, *GreedyChoice;
- // int offered_cnt=0, counted_cores=0;
- //
- // for (tmp=cores; tmp!=NULL; tmp=tmp->next) {
- // if (distance(req_reg.C, tmp->core_id) <= req_reg.r) share_giver++;
- // counted_cores++;
- // if (tmp->offered_to != -1) offered_cnt++;
- // fprintf(log_file,"Core %d is offered to %d\n",tmp->core_id,tmp->offered_to);
- // }
- // fflush(log_file);
- //
- // if (offered_cnt == (counted_cores-2) && my_idag != -1) {
- // fprintf(log_file,"I did not give up my only not offered core\n");
- // fflush(log_file);
- // return 0;
- // }
- // share_giver = share_giver / (float) region_count(req_reg);
- //
- // if (my_idag == -1) {
- // while (gain_total > 0.0) {
- // gain_total = 0.0;
- // GreedyChoice = NULL;//-1;
- // min_dist = -1;
- // base_giver = 0;
- // tmp = cores->next;//very important!!! that way i avoid giving up my agent core
- //
- // while (tmp != NULL) {
- // cur_dist = distance(req_reg.C, tmp->core_id);
- // if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- // //Of_cores_num == 0 to be the first offered core
- // //Cores_receiver == 0 to avoid providing the core to an non-initial core search
- // if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 0) {
- // if ((Cores_receiver + Of_cores_num) == 0) {
- // gain_receiver = 1000; //0 sto init_app
- // } else if ((Cores_receiver + Of_cores_num) == 1) {
- // gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- // } else { /* (Cores_receiver + Of_cores_num) > 1 */
- // base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num - 1);
- // gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num) - base_receiver); /* + 1 is ommited due to workload convention */
- // }
- //
- // loss_giver = 0;
- // new_gain = gain_receiver - loss_giver;
- // gain_total = new_gain;
- // GreedyChoice = tmp;//->core_id;
- // break;
- // #ifdef LOW_VOLTAGE_ISLANDS_4
- // } else if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 1) {
- // if (Cores_receiver == 0 && Of_cores_num == 0) gain_receiver = 1000; //0 sto init_app
- // else gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver); /* +1 stands for the possibly offered core */
- //
- // loss_giver = 0;
- // new_gain = gain_receiver - loss_giver;
- // gain_total = new_gain;
- // GreedyChoice = tmp;//->core_id;
- // break;
- // #endif
- // } else if (low_voltage_core[tmp->core_id] == 0) {
- // if ((Cores_receiver + Of_cores_num) == 0) {
- // gain_receiver = 1000; //0 sto init_app
- // } else if ((Cores_receiver + Of_cores_num) == 1) {
- // gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- // } else { /* (Cores_receiver + Of_cores_num) > 1 */
- // base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num - 1);
- // gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num) - base_receiver); /* + 1 is ommited due to workload convention */
- // }
- //
- // loss_giver = 0;
- // new_gain = gain_receiver - loss_giver;
- // if (new_gain > gain_total){
- // gain_total = new_gain;
- // min_dist = cur_dist;
- // GreedyChoice = tmp;//->core_id;
- // } else if (new_gain == gain_total && cur_dist < min_dist) {
- // //printf("I am %d and i change offer to %d with cores %d->%d with distances %d->%d\n",
- // // node_id,req_id,GreedyChoice->core_id,tmp->core_id,min_dist,cur_dist);
- // min_dist = cur_dist;
- // GreedyChoice = tmp;
- // }
- // }
- // }
- //
- // tmp = tmp->next;
- // }
- //
- // if (gain_total > 0.0) {
- // Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- // GreedyChoice->offered_to = req_id;
- // }
- // }
- //
- // /* FFT app requires only power of 2 exec cores plus its manager
- // * I do not include higher than 5 because it will create no speedup
- // */
- // if ((Cores_receiver + Of_cores_num) == 4) {
- // for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- // if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- // fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- // tmp->offered_to = -1;
- // Of_cores_num--;
- // break;
- // }
- // }
- // }
- // /*
- // else if (Of_cores_num > 4) {
- //
- // }
- // */
- // }
- // #ifndef GREEDY_MANAGER
- // else {
- //
- // if (((Workers_giver == 4) && (Cores_receiver < 3)) || ((Workers_giver == 2) && (Cores_receiver < 2))) {
- //
- // while (gain_total > 0.0) {
- // gain_total = 0.0;
- // GreedyChoice = NULL;//-1;
- // min_dist = -1;
- // base_giver = Speedup(my_app, Workers_giver - Of_cores_num);
- //
- // tmp = cores->next->next;//very important!!! that way i avoid giving up my only working core
- //
- // while (tmp != NULL) {
- // if (core_inter_head[tmp->core_id] != NULL &&
- // (core_inter_head[tmp->core_id]->type == INIT_WORK_NODE_PENDING || core_inter_head[tmp->core_id]->type == INIT_WORK_NODE)) {
- // fprintf(log_file,"Core %d is about to start work type = %d\n",tmp->core_id,core_inter_head[tmp->core_id]->type);
- // fflush(log_file);
- // tmp = tmp->next;
- // } else {
- // cur_dist = distance(req_reg.C, tmp->core_id);
- // if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- // if ((Cores_receiver + Of_cores_num) == 0) {
- // gain_receiver = 1000; //0 sto init_app
- // } else if ((Cores_receiver + Of_cores_num) == 1) {
- // gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- // } else { /* (Cores_receiver + Of_cores_num) > 1 */
- // base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num - 1);
- // gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num) - base_receiver); /* + 1 is ommited due to workload convention */
- // }
- //
- // loss_giver = base_giver - Speedup(my_app, Workers_giver - Of_cores_num - 1);
- //
- // new_gain = gain_receiver - loss_giver;
- // if (new_gain > gain_total){
- // gain_total = new_gain;
- // min_dist = cur_dist;
- // GreedyChoice = tmp;//->core_id;
- // } else if (new_gain == gain_total && cur_dist < min_dist) {
- // //printf("I am %d and i change offer to %d with cores %d->%d with distances %d->%d\n",
- // // node_id,req_id,GreedyChoice->core_id,tmp->core_id,min_dist,cur_dist);
- // min_dist = cur_dist;
- // GreedyChoice = tmp;
- // }
- // }
- //
- // tmp = tmp->next;
- // }
- // }
- //
- // if (gain_total > 0.0) {
- // Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- // GreedyChoice->offered_to = req_id;
- // }
- // }
- //
- // if ((Cores_receiver + Of_cores_num) == 4) {
- // for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- // if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- // fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- // tmp->offered_to = -1;
- // Of_cores_num--;
- // break;
- // }
- // }
- // }
- //
- // }
- // }
- // #endif
- //
- // /* FFT app requires only power of 2 exec cores plus its manager */
- // /*
- // if (my_idag == -1) {
- //
- // if (executed_app == FFT) {
- // if (Of_cores_num == 3) {
- // for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- // if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- // fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- // tmp->offered_to = -1;
- // Of_cores_num--;
- // break;
- // }
- // }
- // } else if (Of_cores_num > 4) {
- //
- // }
- // }
- // */
- // return Of_cores_num;
- // }
- int offer_cores_fft_original(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id) {
- int Of_cores_num=0, min_dist=0, cur_dist=0;
- float gain_total=0.1,base_receiver=0.0,base_giver=0.0,gain_receiver=0.0,loss_giver=0.0,share_giver=0.0,new_gain=0.0;
- int Cores_receiver = req_app.num_of_cores, Workers_giver = my_app.num_of_cores-1;
- core_list *tmp, *GreedyChoice;
- int offered_cnt=0, counted_cores=0;
- for (tmp=cores; tmp!=NULL; tmp=tmp->next) {
- if (distance(req_reg.C, tmp->core_id) <= req_reg.r) share_giver++;
- counted_cores++;
- if (tmp->offered_to != -1) offered_cnt++;
- fprintf(log_file,"Core %d is offered to %d\n",tmp->core_id,tmp->offered_to);
- }
- fflush(log_file);
- if (offered_cnt == (counted_cores-2) && my_idag != -1) {
- fprintf(log_file,"I did not give up my only not offered core\n");
- fflush(log_file);
- return 0;
- }
- if (Cores_receiver == 2) {
- fprintf(log_file,"Receiver already has two cores\n");
- fflush(log_file);
- return 0;
- }
- share_giver = share_giver / (float) region_count(req_reg);
- if (my_idag == -1) {
- while ((gain_total > 0.0) && ((Cores_receiver + Of_cores_num) <= 1)) {
- gain_total = 0.0;
- GreedyChoice = NULL;//-1;
- min_dist = -1;
- base_giver = 0;
- tmp = cores->next;//very important!!! that way i avoid giving up my agent core
-
- while (tmp != NULL) {
- cur_dist = distance(req_reg.C, tmp->core_id);
- if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- //Of_cores_num == 0 to be the first offered core
- //Cores_receiver == 0 to avoid providing the core to an non-initial core search
- if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 0) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- //gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- }
-
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- gain_total = new_gain;
- GreedyChoice = tmp;//->core_id;
- break;
- #ifdef LOW_VOLTAGE_ISLANDS_4
- } else if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 1) {
- if (Cores_receiver == 0 && Of_cores_num == 0) gain_receiver = 1000; //0 sto init_app
- else gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver); /* +1 stands for the possibly offered core */
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- gain_total = new_gain;
- GreedyChoice = tmp;//->core_id;
- break;
- #endif
- } else if (low_voltage_core[tmp->core_id] == 0) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- }
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- if (new_gain > gain_total){
- gain_total = new_gain;
- min_dist = cur_dist;
- GreedyChoice = tmp;//->core_id;
- } else if (new_gain == gain_total && cur_dist < min_dist) {
- //printf("I am %d and i change offer to %d with cores %d->%d with distances %d->%d\n",
- // node_id,req_id,GreedyChoice->core_id,tmp->core_id,min_dist,cur_dist);
- min_dist = cur_dist;
- GreedyChoice = tmp;
- }
- }
- }
- tmp = tmp->next;
- }
- if (gain_total > 0.0) {
- Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- GreedyChoice->offered_to = req_id;
- }
- }
-
- /* FFT app requires only power of 2 exec cores plus its manager
- * I do not include higher than 5 because it will create no speedup
- */
- if ((Cores_receiver + Of_cores_num) == 4) {
- for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- tmp->offered_to = -1;
- Of_cores_num--;
- break;
- }
- }
- }
- /*
- else if (Of_cores_num > 4) {
-
- }
- */
- }
- #ifndef GREEDY_MANAGER
- else {
-
- if (((Workers_giver == 4) && (Cores_receiver < 3)) || ((Workers_giver == 2) && (Cores_receiver < 2))) {
-
- while (gain_total > 0.0) {
- gain_total = 0.0;
- GreedyChoice = NULL;//-1;
- min_dist = -1;
- base_giver = Speedup(my_app, Workers_giver - Of_cores_num);
-
- tmp = cores->next->next;//very important!!! that way i avoid giving up my only working core
-
- while (tmp != NULL) {
- if (core_inter_head[tmp->core_id] != NULL &&
- (core_inter_head[tmp->core_id]->type == INIT_WORK_NODE_PENDING || core_inter_head[tmp->core_id]->type == INIT_WORK_NODE)) {
- fprintf(log_file,"Core %d is about to start work type = %d\n",tmp->core_id,core_inter_head[tmp->core_id]->type);
- fflush(log_file);
- tmp = tmp->next;
- } else {
- cur_dist = distance(req_reg.C, tmp->core_id);
- if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver); /* + 1 is ommited due to workload convention */
- }
-
- loss_giver = base_giver - Speedup(my_app, Workers_giver - (Of_cores_num + 1));
-
- new_gain = gain_receiver - loss_giver;
- if (new_gain > gain_total){
- gain_total = new_gain;
- min_dist = cur_dist;
- GreedyChoice = tmp;//->core_id;
- } else if (new_gain == gain_total && cur_dist < min_dist) {
- //printf("I am %d and i change offer to %d with cores %d->%d with distances %d->%d\n",
- // node_id,req_id,GreedyChoice->core_id,tmp->core_id,min_dist,cur_dist);
- min_dist = cur_dist;
- GreedyChoice = tmp;
- }
- }
- tmp = tmp->next;
- }
- }
- if (gain_total > 0.0) {
- Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- GreedyChoice->offered_to = req_id;
- }
- }
-
- if ((Cores_receiver + Of_cores_num) == 4) {
- for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- tmp->offered_to = -1;
- Of_cores_num--;
- break;
- }
- }
- }
-
- }
- }
- #endif
- /* FFT app requires only power of 2 exec cores plus its manager */
- /*
- if (my_idag == -1) {
-
- if (executed_app == FFT) {
- if (Of_cores_num == 3) {
- for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- tmp->offered_to = -1;
- Of_cores_num--;
- break;
- }
- }
- } else if (Of_cores_num > 4) {
-
- }
- }
- */
- return Of_cores_num;
- }
- int offer_cores_fft_updated(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id) { /* 26.5.2017 - I am not sure if it is correct. Has not been used to measure F_min_max0 */
- int Of_cores_num=0, min_dist=0, cur_dist=0;
- float gain_total=0.1,base_receiver=0.0,base_giver=0.0,gain_receiver=0.0,loss_giver=0.0,share_giver=0.0,new_gain=0.0;
- int Cores_receiver = req_app.num_of_cores, Workers_giver = my_app.num_of_cores-1;
- core_list *tmp, *GreedyChoice;
- int offered_cnt=0, counted_cores=0;
- for (tmp=cores; tmp!=NULL; tmp=tmp->next) {
- if (distance(req_reg.C, tmp->core_id) <= req_reg.r) share_giver++;
- counted_cores++;
- if (tmp->offered_to != -1) offered_cnt++;
- fprintf(log_file,"Core %d is offered to %d\n",tmp->core_id,tmp->offered_to);
- }
- fflush(log_file);
- if (offered_cnt == (counted_cores-2) && my_idag != -1) {
- fprintf(log_file,"I did not give up my only not offered core\n");
- fflush(log_file);
- return 0;
- }
- share_giver = share_giver / (float) region_count(req_reg);
- if (my_idag == -1) {
- while ((gain_total > 0.0) && ((Cores_receiver + Of_cores_num) <= 2)) {
- gain_total = 0.0;
- GreedyChoice = NULL;//-1;
- min_dist = -1;
- base_giver = 0;
- tmp = cores->next;//very important!!! that way i avoid giving up my agent core
-
- while (tmp != NULL) {
- cur_dist = distance(req_reg.C, tmp->core_id);
- if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- //Of_cores_num == 0 to be the first offered core
- //Cores_receiver == 0 to avoid providing the core to an non-initial core search
- if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 0) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- //gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- }
-
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- gain_total = new_gain;
- GreedyChoice = tmp;//->core_id;
- break;
- #ifdef LOW_VOLTAGE_ISLANDS_4
- } else if (low_voltage_core[tmp->core_id] && Of_cores_num == 0 && Cores_receiver == 1) {
- if (Cores_receiver == 0 && Of_cores_num == 0) gain_receiver = 1000; //0 sto init_app
- else gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver); /* +1 stands for the possibly offered core */
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- gain_total = new_gain;
- GreedyChoice = tmp;//->core_id;
- break;
- #endif
- } else if (low_voltage_core[tmp->core_id] == 0) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver);
- }
- loss_giver = 0;
- new_gain = gain_receiver - loss_giver;
- if (new_gain > gain_total){
- gain_total = new_gain;
- min_dist = cur_dist;
- GreedyChoice = tmp;//->core_id;
- } else if (new_gain == gain_total && cur_dist < min_dist) {
- //printf("I am %d and i change offer to %d with cores %d->%d with distances %d->%d\n",
- // node_id,req_id,GreedyChoice->core_id,tmp->core_id,min_dist,cur_dist);
- min_dist = cur_dist;
- GreedyChoice = tmp;
- }
- }
- }
- tmp = tmp->next;
- }
- if (gain_total > 0.0) {
- Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- GreedyChoice->offered_to = req_id;
- }
- }
-
- /* FFT app requires only power of 2 exec cores plus its manager
- * I do not include higher than 5 because it will create no speedup
- */
- if ((Cores_receiver + Of_cores_num) == 4) {
- for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- tmp->offered_to = -1;
- Of_cores_num--;
- break;
- }
- }
- }
- /*
- else if (Of_cores_num > 4) {
-
- }
- */
- }
- #ifndef GREEDY_MANAGER
- else {
-
- if (((Workers_giver == 4) && (Cores_receiver < 3)) || ((Workers_giver == 2) && (Cores_receiver < 2))) {
-
- while (gain_total > 0.0) {
- gain_total = 0.0;
- GreedyChoice = NULL;//-1;
- min_dist = -1;
- base_giver = Speedup(my_app, Workers_giver - Of_cores_num);
-
- tmp = cores->next->next;//very important!!! that way i avoid giving up my only working core
-
- while (tmp != NULL) {
- if (core_inter_head[tmp->core_id] != NULL &&
- (core_inter_head[tmp->core_id]->type == INIT_WORK_NODE_PENDING || core_inter_head[tmp->core_id]->type == INIT_WORK_NODE)) {
- fprintf(log_file,"Core %d is about to start work type = %d\n",tmp->core_id,core_inter_head[tmp->core_id]->type);
- fflush(log_file);
- tmp = tmp->next;
- } else {
- cur_dist = distance(req_reg.C, tmp->core_id);
- if (tmp->offered_to == -1 && cur_dist <= req_reg.r) {
- if ((Cores_receiver + Of_cores_num) == 0) {
- gain_receiver = 1000; //0 sto init_app
- } else if ((Cores_receiver + Of_cores_num) == 1) {
- gain_receiver = 100; //no worker cores -- in case I have only one worker core then I should not be here
- } else { /* (Cores_receiver + Of_cores_num) > 1 */
- base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
- gain_receiver = share_giver * (Speedup(req_app, Cores_receiver + Of_cores_num + 1) - base_receiver); /* + 1 is ommited due to workload convention */
- }
-
- loss_giver = base_giver - Speedup(my_app, Workers_giver - (Of_cores_num + 1));
-
- new_gain = gain_receiver - loss_giver;
- if (new_gain > gain_total){
- gain_total = new_gain;
- min_dist = cur_dist;
- GreedyChoice = tmp;//->core_id;
- } else if (new_gain == gain_total && cur_dist < min_dist) {
- //printf("I am %d and i change offer to %d with cores %d->%d with distances %d->%d\n",
- // node_id,req_id,GreedyChoice->core_id,tmp->core_id,min_dist,cur_dist);
- min_dist = cur_dist;
- GreedyChoice = tmp;
- }
- }
- tmp = tmp->next;
- }
- }
- if (gain_total > 0.0) {
- Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
- GreedyChoice->offered_to = req_id;
- }
- }
-
- if ((Cores_receiver + Of_cores_num) == 4) {
- for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- tmp->offered_to = -1;
- Of_cores_num--;
- break;
- }
- }
- }
-
- }
- }
- #endif
- /* FFT app requires only power of 2 exec cores plus its manager */
- /*
- if (my_idag == -1) {
-
- if (executed_app == FFT) {
- if (Of_cores_num == 3) {
- for (tmp = my_cores->next; tmp!=NULL; tmp=tmp->next) {
- if (tmp->core_id == Offered_cores[Of_cores_num-1]) {
- fprintf(log_file,"Abandoning offered core %d because FFT needs 2 cores\n",tmp->core_id);
- tmp->offered_to = -1;
- Of_cores_num--;
- break;
- }
- }
- } else if (Of_cores_num > 4) {
-
- }
- }
- */
- return Of_cores_num;
- }
|