Bladeren bron

DRTRM v1.0

Your Name 6 jaren geleden
bovenliggende
commit
982d56d5f8
9 gewijzigde bestanden met toevoegingen van 82 en 445 verwijderingen
  1. 2 0
      Makefile
  2. 0 0
      README.md
  3. 22 13
      apps.c
  4. 0 1
      common_core.c
  5. 0 1
      controller_core.c
  6. 3 9
      my_rtrm.c
  7. 31 230
      resource_negotiation.c
  8. 1 33
      scc_signals.c
  9. 23 158
      signal_handlers.c

+ 2 - 0
Makefile

@@ -64,6 +64,8 @@ ifeq ($(RESOURCE_ALGO), ORIGINAL)
 	MY_FLAGS += -DRESOURCE_ALGO_ORIG
 else ifeq ($(RESOURCE_ALGO), UPDATED)
 	MY_FLAGS += -DRESOURCE_ALGO_UPDATED
+else ifeq ($(RESOURCE_ALGO), UPDATED_GENEROUS)
+        MY_FLAGS += -DRESOURCE_ALGO_UPDATED_GENEROUS
 else
 	MY_FLAGS += -DRESOURCE_ALGO_ORIG
 endif

+ 0 - 0
README.md


+ 22 - 13
apps.c

@@ -3,12 +3,13 @@
 #include "libfunctions.h"
 #include "my_rtrm.h"
 #include <time.h>
+#include <math.h>
 
 #define SWAP(a,b) {float tmp; tmp=a; a=b; b=tmp;}
 #define FFT_MAX 136192
 #define PAGE_SIZE 4096
-#define ARTIFICIAL_ROUND_DURATION_SEC 1
-#define ARTIFICIAL_ROUND_DURATION_NSEC 500000000 /* 1 ms */
+#define ARTIFICIAL_ROUND_DURATION_SEC 0.5
+#define ARTIFICIAL_ROUND_DURATION_NSEC 500000000 /* 500 ms */
  
 static float **svm_vectors, *svm_coef;
 static int *vector, **matrix;
@@ -560,14 +561,23 @@ void app_init (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE])
 }
 
 int get_max_cores_count(app cur_app){
-	
-	/*if (cur_app.var < 1.0)
-		return (int) ceilf(2.0*cur_app.A - 1);
-	else
-		return (int) ceilf(cur_app.A + cur_app.A*cur_app.var - cur_app.var);*/
 #ifdef SINGLE_WORKER
 	return 2;
-#else	
+#elif ARTIFICIAL_APPS_SIM
+	int tmp_max_cores=MAX_WORKERS_COUNT; /* FIXME 31.10.2017 unable to send more than 8 workers via MPB */
+	
+	if (cur_app.var < 1.0) {
+                tmp_max_cores = (int) ceilf(2.0*cur_app.A - 1);
+        } else {
+                tmp_max_cores = (int) ceilf(cur_app.A + (cur_app.A*cur_app.var) - cur_app.var);
+	}
+
+	if (tmp_max_cores < MAX_WORKERS_COUNT) {
+		return tmp_max_cores;
+	} else {
+		return MAX_WORKERS_COUNT;
+	}
+#else
 	if (executed_app == FFT) {
 		return 3;
 	}	else {
@@ -591,7 +601,7 @@ float Speedup_Artificial_App(app cur_app, int num_of_cores) {
 			} else {
 				res = cur_app.A;
 			}
-		} else {
+		} else { /* For n=1, result is 1*/
 			if ((num_of_cores >= 1) && (num_of_cores <= (cur_app.A + cur_app.A*cur_app.var - cur_app.var))) {
 				res = (num_of_cores*cur_app.A*(cur_app.var + 1)) / (cur_app.A + cur_app.var*(num_of_cores-1 + cur_app.A));
 			} else {
@@ -606,8 +616,8 @@ float Speedup_Artificial_App(app cur_app, int num_of_cores) {
 
 float Speedup(app cur_app, int num_of_cores) {
 	if ((num_of_cores < 2) || (num_of_cores > get_max_cores_count(cur_app))) {
-                return 0;
-        } else {
+		return 0;
+	} else {
 #ifndef ARTIFICIAL_APPS_SIM
 		return Exec_Speedup[num_of_cores-2];
 #else
@@ -620,7 +630,7 @@ int get_times(app cur_app, int num_of_cores) {
 #ifndef ARTIFICIAL_APPS_SIM
 	return (cur_app.workld * Exec_Latencies[num_of_cores-2]);
 #else
-	return cur_app.workld * (ARTIFICIAL_ROUND_DURATION_NSEC / ((int) Speedup_Artificial_App(cur_app, num_of_cores+1))); /* FIXME cutting off floating points -- +1 is because in Speedup calc it is -1*/
+	return cur_app.workld * (ARTIFICIAL_ROUND_DURATION_SEC / ((int) Speedup_Artificial_App(cur_app, num_of_cores+1))); /* FIXME cutting off floating points -- +1 is because in Speedup calc it is -1*/
 #endif
 }
 
@@ -665,7 +675,6 @@ void matrix_transpose(int n1, float *src, float *dest, int node_id, int myFirst,
 						//fprintf(log_file,"src + 1 = %f\n",src[2*(v*n1p+h)+1]);
 						//fprintf(log_file,"dest = %f\n",dest[2*(h*n1p+v)]);
 						//fprintf(log_file,"dest + 1 = %f\n",dest[2*(h*n1p+v)+1]);
-						//fflush(log_file);
 						dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
 						dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
 						//fprintf(log_file,"yolo\n");

+ 0 - 1
common_core.c

@@ -256,7 +256,6 @@ void common_node_actions(char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_
 				//den stamataw edw thn diadikasia tou selfopt gia na mhn meinoun oi mexri twra prosfores kai oxi mono anapanthtes
 				if (selfopt_time_rem == 0) {//state = AGENT_SELF_CHK_OFFERS;
 					fprintf(log_file,"Timer is zero\n");
-					fflush(log_file);
 					if (selfopt_man_offers == NULL)
 						state = AGENT_ENDING;
 					else state = AGENT_SELF_CHK_OFFERS;

+ 0 - 1
controller_core.c

@@ -252,7 +252,6 @@ void idle_agent_actions(char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_N
 			scc_pause();
 			if (paxos_state == NEW_IDAG){
 				fprintf(log_file, "I will check for signals now!\n");
-				fflush(log_file);
 			}
 			scc_signals_check();
 		} else {

+ 3 - 9
my_rtrm.c

@@ -529,6 +529,9 @@ int main(int argc, char *argv[]) {
 #elif RESOURCE_ALGO_UPDATED
 		printf("Resource algo is updated\n");
 		fprintf(log_file,"Resource algo is updated\n");
+#elif RESOURCE_ALGO_UPDATED_GENEROUS
+		printf("Resource algo is updated generous\n");
+                fprintf(log_file,"Resource algo is updated generous\n");
 #else
 		printf("Resource algo not chosen. Fallback to original\n");
 		fprintf(log_file,"Resource algo not chosen. Fallback to original\n");
@@ -611,7 +614,6 @@ int main(int argc, char *argv[]) {
 	 printf("Time Log File Path = %s ... ",time_log_file_name);
 	 fflush(stdout);
 	 fprintf(log_file,"time log file path = %s\n",time_log_file_name);
-	 fflush(log_file);  
 
 	 if ((time_log = fopen(time_log_file_name, "w")) == NULL){
 		  printf("Error!\n");
@@ -684,7 +686,6 @@ int main(int argc, char *argv[]) {
 			if (num_apps_terminated == num_apps) {
 				state = USER_INPUT;
 				fprintf(log_file,"All apps terminated. Switching to USER_INPUT\n");
-				fflush(log_file);
 			} else if (!timer_init_null && init_pending_head != NULL) {
 				its.it_value.tv_sec = 10;
 				its.it_value.tv_nsec = 0;
@@ -702,7 +703,6 @@ int main(int argc, char *argv[]) {
 
 				if (tmp_inter_list == NULL) {
 					fprintf(log_file,"I am sending an aborted init_app to %d with id %d\n",init_core,tmp_pending_head->data.new_app.id);
-					fflush(log_file);
 
 					if (core_inter_head[init_core] == NULL){
 						core_inter_head[init_core] = (inter_list *) malloc(sizeof(inter_list));
@@ -744,7 +744,6 @@ int main(int argc, char *argv[]) {
 			timer_init_null = 0;
 			state = IDLE_IDAG;
 			fprintf(log_file,"I exit this fuck\n");
-			fflush(log_file);
 		} else if (state == IDLE_CHK_APP_FILE) {
 			scc_pause();
 			scc_signals_check();
@@ -769,7 +768,6 @@ int main(int argc, char *argv[]) {
 				cur_t = localtime(&time_val.tv_sec);
 					
 				fprintf(log_file, "[%d:%d:%d]: Initialising app_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,app_cnt);
-				fflush(log_file);
 				fprintf(time_log, "[%d:%d:%d:%ld] app_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,time_val.tv_usec,app_cnt);
 				fflush(time_log);
 
@@ -900,7 +898,6 @@ int main(int argc, char *argv[]) {
 						scc_kill(one_idag, SIG_REQ_DDS, core_inter_head[one_idag]);
 					else {
 						fprintf(log_file,"interaction in debug req dds is %d\n",core_inter_head[one_idag]->type);
-						fflush(log_file);
 					}
 				} else {
 					printf("Number of agents in region = %d\n",DDS_count);
@@ -920,7 +917,6 @@ int main(int argc, char *argv[]) {
 			}		
 
 			fprintf(log_file,"killing\n");
-			fflush(log_file);
 			for (i=1; i<num_idags; i++){
 				printf("i am killing %d\n",idag_id_arr[i]);
 				one_core = idag_id_arr[i];
@@ -932,7 +928,6 @@ int main(int argc, char *argv[]) {
 					core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
 					core_inter_tail[one_core] = core_inter_tail[one_core]->next;
 					fprintf(log_file,"I am still doing smth with idag %d interaction = %d\n",one_core,core_inter_head[one_core]->type);
-					fflush(log_file);
 				}
 
 				core_inter_tail[one_core]->type = TERMINATION_STATS;
@@ -957,7 +952,6 @@ int main(int argc, char *argv[]) {
 					core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
 					core_inter_tail[one_core] = core_inter_tail[one_core]->next;
 					fprintf(log_file,"I am still doing smth with my node %d interaction = %d\n",one_core,core_inter_head[one_core]->type);
-					fflush(log_file);
 				}
 
 				core_inter_tail[one_core]->type = TERMINATION_STATS;

+ 31 - 230
resource_negotiation.c

@@ -17,6 +17,8 @@ int offer_cores(core_list *cores, app req_app, region req_reg, int *Offered_core
 	}
 #elif RESOURCE_ALGO_UPDATED
 	return offer_cores_updated(cores, req_app, req_reg, Offered_cores, req_id);
+#elif RESOURCE_ALGO_UPDATED_GENEROUS
+	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
@@ -36,12 +38,9 @@ int offer_cores_original(core_list *cores, app req_app, region req_reg, int *Off
                 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;
         }
 
@@ -136,7 +135,6 @@ int offer_cores_original(core_list *cores, app req_app, region req_reg, int *Off
                                 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);
@@ -177,8 +175,8 @@ int offer_cores_original(core_list *cores, app req_app, region req_reg, int *Off
         }
         #endif
         fprintf(log_file,"I will offer %d cores\n",Of_cores_num);
-        fflush(log_file);
-        return Of_cores_num;
+        
+	return Of_cores_num;
 }
        
 
@@ -198,7 +196,6 @@ int offer_cores_updated(core_list *cores, app req_app, region req_reg, int *Offe
 
 		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;
 		}
 	}
@@ -277,7 +274,6 @@ int offer_cores_updated(core_list *cores, app req_app, region req_reg, int *Offe
 				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);
@@ -309,232 +305,44 @@ int offer_cores_updated(core_list *cores, app req_app, region req_reg, int *Offe
 			}
 
 			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);
+				#ifdef RESOURCE_ALGO_UPDATED_GENEROUS
+				if ((Cores_receiver + Of_cores_num) > 1) {
+					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, Cores_giver %d, Cores_receiver %d, Of_cores_num %d\n",
+							get_times(my_app, Cores_giver - (Of_cores_num + 1)), get_times(req_app, Cores_receiver + Of_cores_num + 1), Cores_giver, Cores_receiver, Of_cores_num);
+					} else {
+						gain_total = 0.0;
+						fprintf(log_file,"Refused bargain with giver_times %d receiver_times %d, Cores_giver %d, Cores_receiver %d, Of_cores_num %d\n",
+                                                	get_times(my_app, Cores_giver - (Of_cores_num + 1)), get_times(req_app, Cores_receiver + Of_cores_num + 1), Cores_giver, Cores_receiver, Of_cores_num);
+					}
 				} else {
-					gain_total = 0.0;
-					fprintf(log_file,"Abandoning because I will finish earlier!\n");
-					fflush(log_file);
+					Offered_cores[Of_cores_num++] = GreedyChoice->core_id;
+                                        GreedyChoice->offered_to = req_id;
 				}
+				#else
+					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, Cores_giver %d, Cores_receiver %d, Of_cores_num %d\n",
+                                                        get_times(my_app, Cores_giver - (Of_cores_num + 1)), get_times(req_app, Cores_receiver + Of_cores_num + 1), Cores_giver, Cores_receiver, Of_cores_num);
+                                        } else {
+                                                gain_total = 0.0;
+                                                fprintf(log_file,"Refused bargain with giver_times %d receiver_times %d, Cores_giver %d, Cores_receiver %d, Of_cores_num %d\n",
+                                                        get_times(my_app, Cores_giver - (Of_cores_num + 1)), get_times(req_app, Cores_receiver + Of_cores_num + 1), Cores_giver, Cores_receiver, Of_cores_num);
+                                        }
+				#endif
 			}
 		}
 	}
 	#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;
@@ -548,17 +356,14 @@ int offer_cores_fft_original(core_list *cores, app req_app, region req_reg, int
 		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;
 	}
 
@@ -674,7 +479,6 @@ int offer_cores_fft_original(core_list *cores, app req_app, region req_reg, int
 					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);
@@ -763,11 +567,9 @@ int offer_cores_fft_updated(core_list *cores, app req_app, region req_reg, int *
 		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);
@@ -882,7 +684,6 @@ int offer_cores_fft_updated(core_list *cores, app req_app, region req_reg, int *
 					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);

+ 1 - 33
scc_signals.c

@@ -83,7 +83,6 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 			sig_array_local[3] = ref_inter_list->data.reg.r;
 			
 			fprintf(log_file, "a C=%d r=%d\n",ref_inter_list->data.reg.C,ref_inter_list->data.reg.r);
-			fflush(log_file);
 			//if (ref_inter_list->type == IDAG_FIND_IDAGS_PENDING) ref_inter_list->type = IDAG_FIND_IDAGS;
 			//else if (ref_inter_list->type == SELFOPT_IDAG_FIND_IDAGS_PENDING) ref_inter_list->type = SELFOPT_IDAG_FIND_IDAGS;
 
@@ -95,7 +94,6 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 			sig_array_local[3] = ref_inter_list->data.reg.r;
 			
 			fprintf(log_file, "a C=%d r=%d\n",ref_inter_list->data.reg.C,ref_inter_list->data.reg.r);
-			fflush(log_file);
 			//my_stats.message_size += sizeof(region);
 
 			//if (ref_inter_list->type == IDAG_REQ_DDS_PENDING) ref_inter_list->type = IDAG_REQ_DDS;
@@ -136,7 +134,6 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 			increase_cnt = 2;
 			*/
 			//fprintf(log_file, "Cores=%d r=%d\n",sig_array_local[5],ref_inter_list->data.reg_arr.region_arr[0].r);
-                        //fflush(log_file);
 			//free(ref_inter_list->data.reg_arr.region_arr);
 		} else if (ref_inter_list->type == SELFOPT_REQ_CORES_PENDING) {
 			sig_array_local[2] = my_app.id;
@@ -155,30 +152,25 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 			increase_cnt = 2;
 			*/
 			//fprintf(log_file, "Cores=%d r=%d\n",sig_array_local[5],ref_inter_list->data.reg_arr.region_arr[0].r);
-			//fflush(log_file);
 			//free(ref_inter_list->data.reg_arr.region_arr);
 		} else if (ref_inter_list->type == REP_AGENT_REQ_CORES) {//I am the agent
 			/* pre write these info and keep data_array only for cores. Besides, a great amount of offers will be zero */
 			sig_array_local[2] = ref_inter_list->data.off_arr.num_of_offers;
 			fprintf(log_file, "num_of_offers=%d\n",ref_inter_list->data.off_arr.num_of_offers);
-			fflush(log_file);	
 			
 			if (ref_inter_list->data.off_arr.num_of_offers > 0) {		
 				sig_array_local[3] = ref_inter_list->data.off_arr.offer_arr[0].num_of_cores;
 				fprintf(log_file, "num_of_cores=%d\n",ref_inter_list->data.off_arr.offer_arr[0].num_of_cores);
-				fflush(log_file);
 				
 				memcpy(&sig_array_local[4],&ref_inter_list->data.off_arr.offer_arr[0].spd_loss,sizeof(int));
 				fprintf(log_file, "spd_loss=%0.2f\n",ref_inter_list->data.off_arr.offer_arr[0].spd_loss);
-				fflush(log_file);
 			}	
 		} else if (ref_inter_list->type == INIT_WORK_NODE) {
 			if (ref_inter_list->data.work_bounds[0] != -1) {
 				gettimeofday(&time_val, NULL);
 				cur_t = localtime(&time_val.tv_sec);
 				//fprintf(app_log_file,"[%d:%d:%d:%ld] I init work to %d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,time_val.tv_usec,target_ID);
-				//fflush(app_log_file);
-				
+			
 				/* 2.7.2016 - Changed by dimos - Instead of valid i send the app_id */
 				sig_array_local[2] = my_app.id;
 				sig_array_local[3] = node_id;
@@ -190,12 +182,10 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 #endif
 				/********/
 				fprintf(log_file, "work_time1=%d work_time2=%d\n",ref_inter_list->data.work_bounds[0],ref_inter_list->data.work_bounds[1]);
-				fflush(log_file);
 				//my_stats.message_size += 5 * sizeof(int);
 			} else {
 				sig_array_local[2] = -1;
 				fprintf(log_file, "i=%d\n",sig_array_local[0]);
-				fflush(log_file);
 				//my_stats.message_size += sizeof(int);
 			}
 			//clear = 1;
@@ -204,7 +194,6 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 				gettimeofday(&time_val, NULL);
 				cur_t = localtime(&time_val.tv_sec);
 				//fprintf(app_log_file,"[%d:%d:%d:%ld] I appoint work to %d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,time_val.tv_usec,target_ID);
-				//fflush(app_log_file);
 				
 				/* 2.7.2016 - Changed by dimos - Instead of valid i send the app_id */
 				sig_array_local[2] = my_app.id;
@@ -222,17 +211,14 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 			//clear = 1;
 		} else if (ref_inter_list->type == REP_AGENT_OFFER_SENT) {
 			fprintf(log_file, "I have to reply %d for %d offers\n",target_ID,ref_inter_list->data.offer_acc_array[0]);
-			fflush(log_file);
 						
 			sig_array_local[2] = ref_inter_list->data.offer_acc_array[1];
 			fprintf(log_file, "offer_ans=%d\n",ref_inter_list->data.offer_acc_array[1]);
-			fflush(log_file);
 			//free(ref_inter_list->data.offer_acc_array);
 			//clear = 1;
 		} else if (ref_inter_list->type == IDAG_ADD_CORES_DDS) {
 			sig_array_local[2] = ref_inter_list->data.app_cores[0];
 			fprintf(log_file, "app_cores=%d\n",ref_inter_list->data.app_cores[0]);
-			fflush(log_file);
 			
 			/* FIXME change position of orig_sender and new_owner in the creation of the list */
 			//8 elements available,  3 allready in use
@@ -244,13 +230,11 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 				for (i=1; i<=ref_inter_list->data.app_cores[0]; i++){
 					sig_array_local[i+2] = ref_inter_list->data.app_cores[i];
 					fprintf(log_file, "core=%d\n",ref_inter_list->data.app_cores[i]);
-					fflush(log_file);
 				}
 			} else {
 				//I am an idag and i have to send to other idags my original sender		
 				sig_array_local[3] = ref_inter_list->data.app_cores[ref_inter_list->data.app_cores[0]+1];
 				fprintf(log_file, "orig_sender=%d\n",ref_inter_list->data.app_cores[ref_inter_list->data.app_cores[0]+1]);
-				fflush(log_file);
 				
 				if (ref_inter_list->data.app_cores[0] > 4)
 					increase_cnt++;
@@ -258,22 +242,18 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 				for (i=1; i<=ref_inter_list->data.app_cores[0]; i++){
 					sig_array_local[i+3] = ref_inter_list->data.app_cores[i];//LINE_SIZE+i-1
 					fprintf(log_file, "core=%d\n",ref_inter_list->data.app_cores[i]);
-					fflush(log_file);
 				}
 			}
 		} else if (ref_inter_list->type == IDAG_REM_CORES_DDS) {
 			//fprintf(log_file, "I am in add/remove/remove_app to %d with %d cores\n",sender_id,tmp_inter_list->data.app_cores[0]);			
-			//fflush(log_file);
 			sig_array_local[2] = ref_inter_list->data.app_cores[0];
 			fprintf(log_file, "app_cores=%d\n",ref_inter_list->data.app_cores[0]);
-			fflush(log_file);
 			
 			/* FIXME change position of orig_sender and new_owner in the creation of the list */ 
 			//8 elements available,  3 allready in use
 			if (my_idag != -1) {
 				sig_array_local[3] = ref_inter_list->data.app_cores[ref_inter_list->data.app_cores[0]+1];
 				fprintf(log_file, "new_owner=%d\n",ref_inter_list->data.app_cores[ref_inter_list->data.app_cores[0]+1]);
-				fflush(log_file);
 			  
 				if (ref_inter_list->data.app_cores[0] > 4)
 					increase_cnt++;
@@ -281,7 +261,6 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 				for (i=1; i<=ref_inter_list->data.app_cores[0]; i++) {			
 					sig_array_local[i+3] = ref_inter_list->data.app_cores[i];//LINE_SIZE+i-1
 					fprintf(log_file, "core=%d\n",ref_inter_list->data.app_cores[i]);
-					fflush(log_file);
 				}	
 			} else {
 				//I am an idag and i have to send to other idags my original sender
@@ -289,7 +268,6 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 				fprintf(log_file, "orig_sender=%d\n",ref_inter_list->data.app_cores[ref_inter_list->data.app_cores[0]+1]);
 				sig_array_local[4] = ref_inter_list->data.app_cores[ref_inter_list->data.app_cores[0]+2];
 				fprintf(log_file, "new_owner=%d\n",ref_inter_list->data.app_cores[ref_inter_list->data.app_cores[0]+2]);
-				fflush(log_file);
 			  
 				if (ref_inter_list->data.app_cores[0] > 3)
 					increase_cnt++;
@@ -297,15 +275,12 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 				for (i=1; i<=ref_inter_list->data.app_cores[0]; i++) {			
 					sig_array_local[i+4] = ref_inter_list->data.app_cores[i];//LINE_SIZE+i-1
 					fprintf(log_file, "core=%d\n",ref_inter_list->data.app_cores[i]);
-					fflush(log_file);
 				}
 			}
 		} else if (ref_inter_list->type == REMOVE_APP) {
 			//fprintf(log_file, "I am in add/remove/remove_app to %d with %d cores\n",sender_id,tmp_inter_list->data.app_cores[0]);			
-			//fflush(log_file);
 			sig_array_local[2] = ref_inter_list->data.app_cores[0];
 			fprintf(log_file, "app_cores=%d\n",ref_inter_list->data.app_cores[0]);
-			fflush(log_file);
 			
 			//8 elements available,  3 already in use
 			if (my_idag != -1) {
@@ -315,13 +290,11 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 				for (i=1; i<=ref_inter_list->data.app_cores[0]; i++){			
 					sig_array_local[i+2] = ref_inter_list->data.app_cores[i];//LINE_SIZE+i-1
 					fprintf(log_file, "core=%d\n",ref_inter_list->data.app_cores[i]);
-					fflush(log_file);
 				}
 			} else {
 				//I am an idag and i have to send to other idags my original sender
 				sig_array_local[3] = ref_inter_list->data.app_cores[1];
 				fprintf(log_file, "or_sender=%d\n",ref_inter_list->data.app_cores[0]);
-				fflush(log_file);
 				
 				if (ref_inter_list->data.app_cores[0] > 4)
 					increase_cnt++;
@@ -329,7 +302,6 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 				for (i=2; i<=(ref_inter_list->data.app_cores[0]+1); i++){			
 					sig_array_local[i+2] = ref_inter_list->data.app_cores[i];//LINE_SIZE+i-1
 					fprintf(log_file, "core=%d\n",ref_inter_list->data.app_cores[i]);
-					fflush(log_file);
 				}
 			}
 		/* PAXOS INTERACTIONS */
@@ -414,16 +386,13 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 	#ifdef PLAT_SCC
 	if (strcmp(sig2string(sig),"SIG_HEARTBEAT_REQ") != 0 && strcmp(sig2string(sig), "SIG_HEARTBEAT_REP") != 0){
 		fprintf(log_file,"Trying to acquire lock %d\n",target_ID);
-		fflush(log_file);
 	}
 	RCCE_acquire_lock(target_ID);
 	//fprintf(log_file,"I successfully acquired lock %d\n",target_ID);
-	//fflush(log_file);
 	RCCE_shflush();
 	old_value = index_bottom[target_ID];
 	if (strcmp(sig2string(sig),"SIG_HEARTBEAT_REQ") != 0 && strcmp(sig2string(sig), "SIG_HEARTBEAT_REP") != 0){
 		fprintf(log_file,"I read bottom index %d increase_cnt=%d and target_ID %d\n",old_value,increase_cnt,target_ID);
-		fflush(log_file);
 	}
 
 	error = RCCE_put((t_vcharp)(&sig_array[old_value*LINE_SIZE]), (t_vcharp)(&sig_array_local[0]), increase_cnt * LINE_SIZE * sizeof(int), target_ID);
@@ -440,7 +409,6 @@ int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
 
 	if (strcmp(sig2string(sig),"SIG_HEARTBEAT_REQ") != 0 && strcmp(sig2string(sig), "SIG_HEARTBEAT_REP") != 0){
 		fprintf(log_file,"I leave\n");
-		fflush(log_file);
 	}
 	#else
 	

File diff suppressed because it is too large
+ 23 - 158
signal_handlers.c