my_rtrm.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. #include "my_rtrm.h"
  2. #include "idag_defs.h"
  3. #include "libfunctions.h"
  4. #include "noc_functions.h"
  5. #include "sig_aux.h"
  6. #include "controller_core.h"
  7. #include "common_core.h"
  8. #include "signal_handlers.h"
  9. #include "scc_signals.h"
  10. #include "idag_defs.h"
  11. #include "paxos_signal_handlers.h"
  12. #include "apps.h"
  13. #ifdef PLAT_SCC
  14. int idag_mask[X_max*Y_max];
  15. int low_voltage_core[X_max*Y_max];
  16. int timer_schedule[X_max*Y_max];
  17. volatile int *manager_result_out;
  18. volatile int *index_bottom;
  19. RCCE_FLAG flag_data_written;
  20. RCCE_FLAG proposal_number_lock;
  21. int num_idags_x = 1; //FIXME
  22. #else
  23. int X_max, Y_max;
  24. int *pid_num = NULL;
  25. int *idag_mask = NULL;
  26. int *low_voltage_core = NULL;
  27. int *timer_schedule = NULL;
  28. int *manager_result_out = NULL;
  29. int *index_bottom = NULL;
  30. int num_idags_x;
  31. sem_t *flag_data_written;
  32. sem_t *scc_lock;
  33. sem_t *proposal_number_lock;
  34. #endif
  35. int node_id = -1;
  36. int my_idag = -1;
  37. int num_idags = 0;
  38. int DDS_count = 0;
  39. int my_cores_count = 0;
  40. int nodes_ended_cnt = 0;
  41. int nodes_initialised = 0;
  42. int stats_replied = 0;
  43. int paxos_stats_replied = 0;
  44. int num_apps_terminated = 0;
  45. int num_apps = 0;
  46. int idags_replied = 0;
  47. int index_top = 0;
  48. int last_index_bottom = 0;
  49. int NUES;
  50. int manager_to_fail = -1;
  51. int *sig_array = NULL;
  52. int *data_array = NULL;
  53. int *idag_id_arr = NULL;
  54. int *proposal_number_global;
  55. char paxos_scen[MAX_STR_NAME_SIZE];
  56. char app_input_file[MAX_STR_NAME_SIZE];
  57. FILE *log_file = NULL;
  58. FILE *init_ack_file = NULL;
  59. core_states state;
  60. inter_list **core_inter_head;
  61. inter_list **core_inter_tail;
  62. inter_list *init_pending_head;
  63. inter_list *init_pending_tail;
  64. app my_app;
  65. metrics my_stats = {0,0,0,0,0,0,0,0};
  66. metrics total_stats = {0,0,0,0,0,0,0,0};
  67. metrics paxos_node_stats = {0,0,0,0,0,0,0,0};
  68. metrics paxos_total_stats = {0,0,0,0,0,0,0,0};
  69. DDS_list *DDS = NULL;
  70. DDS_list *DDS_tail = NULL;
  71. core_list *my_cores = NULL;
  72. core_list *my_cores_tail = NULL;
  73. time_t cur_time;
  74. timer_t timerid;
  75. timer_t inter_timer;
  76. timer_t controller_timer;
  77. timer_t epfd_timer;
  78. timer_t pfd_timer;
  79. struct tm *cur_t;
  80. struct sigevent sev;
  81. struct itimerspec its;
  82. struct itimerspec chk_timer;
  83. struct timeval time_val;
  84. /* Dimos variables */
  85. int PREPARE_ACCEPT_SENT = 0;
  86. int controllers_replied = 0;
  87. int delay = 500;
  88. char *tabs;
  89. #ifdef PLAT_SCC
  90. int RCCE_APP(int argc, char *argv[]) {
  91. char error_str[64];
  92. int error, str_len, sig_array_local[LINE_SIZE];
  93. RCCE_init(&argc, &argv);
  94. node_id = RCCE_ue();
  95. #else
  96. int main(int argc, char *argv[]) {
  97. int segment_id;
  98. #endif
  99. int num_of_bytes;
  100. int i;
  101. int j;
  102. int k;
  103. int c;
  104. int one_idag;
  105. int one_core;
  106. int app_cnt = 0;
  107. int time_passed = -1;
  108. int time_next;
  109. int init_core;
  110. int timer_init_null = 0;
  111. int executed_app_type_number = 0; /* Used for the initialization of init_app type */
  112. int executed_app_array_size = 0; /* Used for the initialization of init_app type */
  113. int Selfopt_Radius,Selfopt_Rounds,Max_SelfOpt_Interval_MS;
  114. float avg_cluster_util;
  115. char scen_directory[MAX_STR_NAME_SIZE];
  116. char scen_num[MAX_STR_NAME_SIZE];
  117. char idag_defs_file_name[MAX_STR_NAME_SIZE];
  118. char app_input_file_name[MAX_STR_NAME_SIZE];
  119. char time_log_file_name[MAX_STR_NAME_SIZE];
  120. char init_ack_file_name[MAX_STR_NAME_SIZE];
  121. inter_list *tmp_inter_list;
  122. inter_list *tmp_inter_prev;
  123. inter_list *tmp_pending_head;
  124. FILE *app_input;
  125. FILE *time_log;
  126. struct tm start_time_of_day, *end_time_of_day;
  127. pid_t p;
  128. DDS_list *tmp_DDS;
  129. core_list *tmp_cores_list;
  130. struct timeval time_val;
  131. setvbuf(stdout, NULL, _IONBF, 0);
  132. if (argc < 21) {
  133. printf("USAGE: ./my_rtrm <options>\n\n");
  134. printf("options:\n");
  135. printf("\t-d <scen_dir> : <scen_dir> = Directory of all scenarios.\n");
  136. printf("\t-n <scen_num> : <scen_num> = Scenario number to be executed.\n");
  137. printf("\t-i <idag_defs> : <idag_defs> = File with the definitions of grid and idags.\n");
  138. printf("\t-a <app_input> : <app_input> = File with application characteristics.\n");
  139. printf("\t-p <paxos_scen> : <paxos_scen> = File with failure characteristics.\n");
  140. printf("\t-x X : X = X * 6 will be the horizontal dimension of the grid.\n");
  141. printf("\t-y Y : Y = Y * 8 will be the vertical dimension of the grid.\n");
  142. printf("\t-t <app_type> : <app_type> M for MATRIX_MUL, S for SVM, F for FFT, A for Artificial \n");
  143. printf("\t-r <region_r> : Selfopt radius \n");
  144. printf("\t-u <rounds> : Selfopt rounds \n");
  145. exit(0);
  146. }
  147. /* Put h last in getopt in order to work correctly */
  148. while ((c = getopt(argc, argv, "d:n:i:x:y:a:p:t:r:u:h")) != -1){
  149. switch(c){
  150. case 'd':
  151. strcpy(scen_directory, optarg);
  152. if (node_id == 0)
  153. printf("Scenario directory : %s...\n",scen_directory);
  154. break;
  155. case 'n':
  156. strcpy(scen_num, optarg);
  157. if (node_id == 0)
  158. printf("Scenario number : %s...\n",scen_num);
  159. break;
  160. case 'i':
  161. strcpy(idag_defs_file_name,optarg);
  162. if (node_id == 0)
  163. printf("Idag definitions file name : %s...\n",idag_defs_file_name);
  164. break;
  165. case 'x':
  166. #ifdef PLAT_LINUX
  167. X_max = atoi(optarg) * 6;
  168. #endif
  169. if (node_id == 0)
  170. printf("X = %d...\n",X_max);
  171. break;
  172. case 'y':
  173. #ifdef PLAT_LINUX
  174. Y_max = atoi(optarg) * 8;
  175. #endif
  176. if (node_id == 0)
  177. printf("Y = %d...\n",Y_max);
  178. break;
  179. case 'r':
  180. Selfopt_Radius = atoi(optarg);
  181. if (node_id == 0)
  182. printf("Selfopt_Radius = %d...\n",Selfopt_Radius);
  183. break;
  184. case 'u':
  185. Selfopt_Rounds = atoi(optarg);
  186. if (node_id == 0)
  187. printf("Selfopt_Rounds = %d...\n",Selfopt_Rounds);
  188. Max_SelfOpt_Interval_MS = LEAST_SELF_OPT_INTERVAL_MS;
  189. for (i=1; i<Selfopt_Rounds; i++) {
  190. Max_SelfOpt_Interval_MS = 2 * Max_SelfOpt_Interval_MS;
  191. }
  192. break;
  193. case 'a':
  194. strcpy(app_input_file, optarg);
  195. if (node_id == 0)
  196. printf("Application input file %s...\n",app_input_file);
  197. break;
  198. case 'p':
  199. strcpy(paxos_scen, optarg);
  200. if (node_id == 0)
  201. printf("Paxos scenario file name %s...\n", paxos_scen);
  202. break;
  203. case 't':
  204. if (!strcmp(optarg,"M")) { /* FIXME merge 10.7.2017 executed_app and executed_app_type_number */
  205. executed_app = MATRIX_MUL;
  206. executed_app_type_number = 0;
  207. executed_app_array_size = MATRIX_ARRAY_SIZE;
  208. //printf("Input application type is Matrix mul\n");
  209. } else if (!strcmp(optarg,"S")) {
  210. executed_app = SVM;
  211. executed_app_type_number = 1;
  212. executed_app_array_size = SVM_ARRAY_SIZE;
  213. //printf("Input application type is SVM\n");
  214. } else if (!strcmp(optarg,"F")) {
  215. executed_app = FFT;
  216. executed_app_type_number = 2;
  217. executed_app_array_size = FFT_ARRAY_SIZE;
  218. //printf("Input application type is FFT\n");
  219. } else if (!strcmp(optarg,"A")) {
  220. executed_app = ARTIFICIAL;
  221. executed_app_type_number = 3;
  222. //printf("Input application type is FFT\n");
  223. } else {
  224. printf("Input application type is wrong. Options are M,S,F\n");
  225. }
  226. break;
  227. /*
  228. if (cur_agent.app_type == 0)
  229. executed_app = MATRIX_MUL;
  230. else if (cur_agent.app_type == 1)
  231. executed_app = SVM;
  232. else if (cur_agent.app_type == 2)
  233. executed_app = FFT;
  234. */
  235. case 'h':
  236. printf("USAGE: ./my_rtrm <options>\n\n");
  237. printf("options:\n");
  238. printf("\t-d <scen_dir> : <scen_dir> = Directory of all scenarios.\n");
  239. printf("\t-n <scen_num> : <scen_num> = Scenario number to be executed.\n");
  240. printf("\t-i <idag_defs> : <idag_defs> = File with the definitions of grid and idags.\n");
  241. printf("\t-a <app_input> : <app_input> = File with application characteristics.\n");
  242. printf("\t-p <paxos_scen> : <paxos_scen> = File with failure characteristics.\n");
  243. printf("\t-x X : X = X * 6 will be the horizontal dimension of the grid.\n");
  244. printf("\t-y Y : Y = Y * 8 will be the vertical dimension of the grid.\n");
  245. printf("\t-t <app_type> : <app_type> M for MATRIX_MUL, S for SVM, F for FFT \n");
  246. printf("\t-r <region_r> : Selfopt radius \n");
  247. printf("\t-u <rounds> : Selfopt rounds \n");
  248. exit(0);
  249. break;
  250. }
  251. }
  252. #ifdef PLAT_SCC
  253. NUES = RCCE_num_ues();
  254. RCCE_flag_alloc(&flag_data_written);
  255. RCCE_flag_write(&flag_data_written, RCCE_FLAG_UNSET, node_id);
  256. RCCE_flag_alloc(&proposal_number_lock);
  257. RCCE_flag_write(&proposal_number_lock, RCCE_FLAG_UNSET, node_id);
  258. sig_array = (int *) RCCE_malloc(MAX_SIGNAL_LIST_LEN * LINE_SIZE * sizeof(int));//NUES * NUES
  259. data_array = (int *) RCCE_malloc(MAX_DATA_LIST_LEN * LINE_SIZE * sizeof(int));
  260. #ifndef ARTIFICIAL_APPS_SIM
  261. if (executed_app == MATRIX_MUL) {
  262. num_of_bytes = NUES * MAX_ARRAY_SIZE * sizeof(int);
  263. } else if (executed_app == SVM) {
  264. num_of_bytes = NUES * SVM_ARRAY_SIZE * sizeof(float);
  265. } else if (executed_app == FFT) {
  266. num_of_bytes = NUES * FFT_ARRAY_SIZE * sizeof(float);
  267. }
  268. manager_result_out = (volatile int*) RCCE_shmalloc(num_of_bytes);
  269. #endif
  270. num_of_bytes = NUES * sizeof(int);
  271. index_bottom = (volatile int*) RCCE_shmalloc(num_of_bytes);
  272. proposal_number_global = (int *)RCCE_shmalloc(sizeof(int *));
  273. *proposal_number_global = 0;
  274. for (i=0; i<LINE_SIZE; i++)
  275. sig_array_local[i] = NO_SIG;
  276. for (i=0; i<MAX_SIGNAL_LIST_LEN; i++) {
  277. error = RCCE_put((t_vcharp)(&sig_array[i*LINE_SIZE]), (t_vcharp)(&sig_array_local[0]), LINE_SIZE * sizeof(int), node_id);
  278. if (error != RCCE_SUCCESS) {
  279. RCCE_error_string(error, error_str, &str_len);
  280. fprintf(log_file,"I got an error in put 2 with descr %s\n",error_str);
  281. fflush(log_file);
  282. }
  283. }
  284. #else
  285. idag_mask = (int *) malloc(X_max*Y_max*sizeof(int));
  286. low_voltage_core = (int *) malloc(X_max*Y_max*sizeof(int));
  287. timer_schedule = (int *) malloc(X_max*Y_max*sizeof(int));
  288. NUES = X_max * Y_max;
  289. node_id = 0;
  290. num_of_bytes = NUES * sizeof(pid_t);
  291. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  292. pid_num = (int *) shmat (segment_id, NULL, 0);
  293. num_of_bytes = NUES * MAX_SIGNAL_LIST_LEN * LINE_SIZE * sizeof(int);
  294. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  295. sig_array = (int *) shmat (segment_id, NULL, 0); //(int *) RCCE_malloc(MAX_SIGNAL_LIST_LEN * LINE_SIZE * sizeof(int));//NUES * NUES
  296. for (i = 0; i < MAX_SIGNAL_LIST_LEN*LINE_SIZE; i++) {
  297. sig_array[i] = NO_SIG;
  298. }
  299. num_of_bytes = NUES * MAX_DATA_LIST_LEN * LINE_SIZE * sizeof(int);
  300. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  301. data_array = (int *) shmat (segment_id, NULL, 0); //(int *) RCCE_malloc(3 * LINE_SIZE * sizeof(int));
  302. if (executed_app == MATRIX_MUL) {
  303. num_of_bytes = NUES * MAX_ARRAY_SIZE * sizeof(int);
  304. } else if (executed_app == SVM) {
  305. num_of_bytes = NUES * SVM_ARRAY_SIZE * sizeof(int);
  306. } else if (executed_app == FFT) {
  307. num_of_bytes = NUES * FFT_ARRAY_SIZE * sizeof(float);
  308. }
  309. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  310. manager_result_out = (int *) shmat (segment_id, NULL, 0); //(volatile int*) RCCE_shmalloc(num_of_bytes);
  311. num_of_bytes = NUES * sizeof(int);
  312. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  313. index_bottom = (int *) shmat (segment_id, NULL, 0); //(volatile int*) RCCE_shmalloc(num_of_bytes);
  314. //for (i=0; i<LINE_SIZE; i++)
  315. // sig_array_local[i] = NO_SIG;
  316. //#if defined(BASIC_PAXOS)
  317. num_of_bytes = sizeof(sem_t *);
  318. if ((segment_id = shmget(IPC_PRIVATE, num_of_bytes, IPC_CREAT | S_IRUSR | S_IWUSR)) < 0){
  319. printf("Unable to allocate shared memory!\n");
  320. exit(1);
  321. }
  322. proposal_number_lock = (sem_t *) shmat (segment_id, NULL, 0);
  323. if (sem_init(proposal_number_lock, 1, 1) == -1){
  324. printf("I am %d error\n",node_id);
  325. perror("sem_init");
  326. }
  327. num_of_bytes = sizeof(sem_t *);
  328. if ((segment_id = shmget(IPC_PRIVATE, num_of_bytes, IPC_CREAT | S_IRUSR | S_IWUSR)) < 0){
  329. printf("Unable to allocate shared memory!\n");
  330. exit(1);
  331. }
  332. num_of_bytes = sizeof(int *);
  333. if ((segment_id = shmget(IPC_PRIVATE, num_of_bytes, IPC_CREAT | S_IRUSR | S_IWUSR)) < 0){
  334. printf("Unable to allocate shared memory!\n");
  335. exit(1);
  336. }
  337. proposal_number_global = (int *) shmat (segment_id, NULL, 0);
  338. *proposal_number_global = 0;
  339. //#endif
  340. num_of_bytes = NUES * sizeof(sem_t);
  341. segment_id = shmget (IPC_PRIVATE, num_of_bytes, IPC_CREAT | S_IRUSR | S_IWUSR);
  342. scc_lock = (sem_t *) shmat (segment_id, NULL, 0);
  343. if (sem_init(&scc_lock[node_id], 1, 1) == -1){
  344. printf("I am %d error\n",node_id);
  345. perror("sem_init");
  346. }
  347. segment_id = shmget (IPC_PRIVATE, num_of_bytes,
  348. IPC_CREAT | S_IRUSR | S_IWUSR);
  349. flag_data_written = (sem_t *) shmat (segment_id, NULL, 0);
  350. if (sem_init(&flag_data_written[node_id], 1, 0) == -1){
  351. printf("I am %d error\n",node_id);
  352. perror("sem_init");
  353. }
  354. #endif
  355. init_speedup_structs();
  356. core_inter_head = (inter_list **) malloc(X_max*Y_max*sizeof(inter_list *));
  357. core_inter_tail = (inter_list **) malloc(X_max*Y_max*sizeof(inter_list *));
  358. for (i=0; i<X_max*Y_max; i++){
  359. core_inter_head[i] = NULL;
  360. core_inter_tail[i] = NULL;
  361. timer_schedule[i] = 0;
  362. }
  363. read_idag_defs(scen_directory, scen_num, idag_defs_file_name, paxos_scen);
  364. global_idag_defs();
  365. /* Initialise structs for mapping of scc coordinates to normal ones*/
  366. create_scc2grid_mapping(scen_directory, scen_num);
  367. create_grid2scc_mapping(scen_directory, scen_num);
  368. initialize_PAXOS_data(scen_directory,scen_num);
  369. #ifdef MANAGER
  370. if (manager_to_fail == -1){
  371. time_t t;
  372. srand((unsigned) time(&t));
  373. manager_to_fail = rand() % 8;
  374. //printf("MANAGER TO FAIL IS OF APP %d\n",manager_to_fail);
  375. }
  376. #endif
  377. /* Create rest of idags and assign only their node id */
  378. #ifdef PLAT_LINUX
  379. printf("I an idag with node_id = %d, pid = %d\n",0,getpid());
  380. for (i=1; i < num_idags; i++) {
  381. p = fork();
  382. if (p == 0) {
  383. node_id = idag_id_arr[i];
  384. idle_agent_actions(scen_directory,scen_num);
  385. printf("I am newly created idag with i = %d and node_id = %d\n",i,node_id);
  386. fflush(stdout);
  387. break;
  388. }
  389. }
  390. #endif
  391. if ((node_id != idag_id_arr[0]) && (is_core_idag(node_id) == 1)) {
  392. idle_agent_actions(scen_directory,scen_num); //dimos comment out
  393. } else if (node_id != idag_id_arr[0]) {
  394. common_node_actions(scen_directory,scen_num,Selfopt_Radius,Max_SelfOpt_Interval_MS);
  395. } else {
  396. index_bottom[node_id] = 0;
  397. install_signal_handlers();
  398. #ifdef PLAT_LINUX
  399. sig_SEGV_enable();
  400. #endif
  401. sev.sigev_notify = SIGEV_SIGNAL;
  402. sev.sigev_signo = SIG_TIMER;
  403. sev.sigev_value.sival_ptr = &timerid;
  404. if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) printf("timer_create error\n");
  405. if (my_cores == NULL) {
  406. my_cores = (core_list *) malloc(sizeof(core_list));
  407. my_cores_tail = my_cores;
  408. }
  409. my_cores_count++;
  410. my_cores_tail->core_id = node_id;
  411. my_cores_tail->offered_to = -1;
  412. my_cores_tail->next = NULL;
  413. DDS = (DDS_list *) malloc(sizeof(DDS_list));
  414. DDS->agent_id = node_id;
  415. DDS->next = NULL;
  416. DDS_tail = DDS;
  417. DDS_count++;
  418. for (i = 0; i < NUES; i++)
  419. if (node_id != i && idag_mask[i] == node_id){
  420. if (my_cores == NULL) {
  421. my_cores = (core_list *) malloc(sizeof(core_list));
  422. my_cores_tail = my_cores;
  423. } else {
  424. my_cores_tail->next = (core_list *) malloc(sizeof(core_list));
  425. my_cores_tail = my_cores_tail->next;
  426. }
  427. my_cores_count++;
  428. my_cores_tail->core_id = i;
  429. my_cores_tail->offered_to = -1;
  430. my_cores_tail->next = NULL;
  431. #ifdef PLAT_LINUX
  432. p = fork();
  433. if (p==0){
  434. node_id = i;
  435. common_node_actions(scen_directory, scen_num);
  436. }
  437. #endif
  438. }
  439. DDS->num_of_cores = my_cores_count;
  440. log_file = create_log_file(node_id, 0, scen_directory, scen_num);
  441. setbuf(log_file, NULL);
  442. fprintf(log_file,"Selfopt_Radius = %d Selfopt_Rounds = %d Max_SelfOpt_Interval_MS = %d\n",Selfopt_Radius,Selfopt_Rounds,Max_SelfOpt_Interval_MS);
  443. if (node_id == 0) {
  444. #ifdef RESOURCE_ALGO_ORIG
  445. printf("Resource algo is original\n");
  446. fprintf(log_file,"Resource algo is original\n");
  447. #elif RESOURCE_ALGO_UPDATED
  448. printf("Resource algo is updated\n");
  449. fprintf(log_file,"Resource algo is updated\n");
  450. #else
  451. printf("Resource algo not chosen. Fallback to original\n");
  452. fprintf(log_file,"Resource algo not chosen. Fallback to original\n");
  453. #endif
  454. }
  455. alive = (int *)malloc(X_max*Y_max*sizeof(int));
  456. suspected = (int *)malloc(X_max*Y_max*sizeof(int));
  457. for (i = 0; i < X_max*Y_max; i++){
  458. alive[i] = 0;
  459. suspected[i] = 0;
  460. }
  461. printf("DELAY = %d\n",delay);
  462. #if defined(EPFD) || defined(tEPFD)
  463. sev.sigev_notify = SIGEV_SIGNAL;
  464. sev.sigev_signo = SIG_EPFD_TIMER;
  465. sev.sigev_value.sival_ptr = &epfd_timer;
  466. if (timer_create(CLOCK_REALTIME, &sev, &epfd_timer) == -1)
  467. printf("timer_create error\n");
  468. else
  469. fprintf(log_file,"I succesfully created epfd_timer\n");
  470. #endif
  471. #if defined(PFD) || defined(tPFD)
  472. sev.sigev_notify = SIGEV_SIGNAL;
  473. sev.sigev_signo = SIG_PFD_TIMER;
  474. sev.sigev_value.sival_ptr = &pfd_timer;
  475. if (timer_create(CLOCK_REALTIME, &sev, &pfd_timer) == -1)
  476. printf("timer_create error\n");
  477. else
  478. fprintf(log_file,"I succesfully created pfd_timer\n");
  479. #endif
  480. cur_time = time(NULL);
  481. cur_t = localtime(&cur_time);
  482. fprintf(log_file, "[%d:%d:%d]: Initialized node_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,node_id);
  483. #ifdef PLAT_SCC
  484. RCCE_barrier(&RCCE_COMM_WORLD);
  485. #else
  486. sleep(1);
  487. #endif
  488. for (tmp_cores_list = my_cores->next; tmp_cores_list != NULL; tmp_cores_list = tmp_cores_list->next) {
  489. one_core = tmp_cores_list->core_id;
  490. if (core_inter_head[one_core] == NULL){
  491. core_inter_head[one_core] = (inter_list *) malloc(sizeof(inter_list));
  492. core_inter_tail[one_core] = core_inter_head[one_core];
  493. } else {
  494. core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
  495. core_inter_tail[one_core] = core_inter_tail[one_core]->next;
  496. }
  497. core_inter_tail[one_core]->type = INIT_CORE;
  498. core_inter_tail[one_core]->next = NULL;
  499. scc_kill(one_core, SIG_INIT, core_inter_head[one_core]);
  500. }
  501. while (nodes_initialised != my_cores_count-1) {
  502. scc_pause();
  503. scc_signals_check();
  504. }
  505. #ifdef PLAT_SCC
  506. RCCE_barrier(&RCCE_COMM_WORLD);
  507. #else
  508. sleep(1);
  509. #endif
  510. printf("End of initialisation\n");
  511. //print_grid();
  512. /* Open the Time Log File*/
  513. #ifdef PLAT_SCC
  514. strcpy(time_log_file_name, "/shared/herc/");
  515. #else
  516. strcpy(time_log_file_name, "../");
  517. #endif
  518. strcat(time_log_file_name,scen_directory);
  519. strcat(time_log_file_name ,"/");
  520. strcat(time_log_file_name ,scen_num);
  521. strcat(time_log_file_name, "/times_log.txt");
  522. printf("Time Log File Path = %s ... ",time_log_file_name);
  523. fflush(stdout);
  524. fprintf(log_file,"time log file path = %s\n",time_log_file_name);
  525. fflush(log_file);
  526. if ((time_log = fopen(time_log_file_name, "w")) == NULL){
  527. printf("Error!\n");
  528. fflush(stdout);
  529. perror("open time_log");
  530. }else{
  531. printf("Success!\n");
  532. fflush(stdout);
  533. }
  534. /* done */
  535. /* Init app file is kept in linux for compatibility of result gathering scripts */
  536. #ifdef PLAT_SCC
  537. strcpy(init_ack_file_name, "/shared/herc/");
  538. #else
  539. strcpy(init_ack_file_name, "../");
  540. #endif
  541. strcat(init_ack_file_name, scen_directory);
  542. strcat(init_ack_file_name, "/");
  543. strcat(init_ack_file_name, scen_num);
  544. strcat(init_ack_file_name, "/init_ack.txt");
  545. //printf("file path = %s\n",app_input_file_name);
  546. if ((init_ack_file = fopen(init_ack_file_name, "w")) == NULL){
  547. printf("Cannot open input file with file path = %s ",init_ack_file_name);
  548. perror("open app_input");
  549. }
  550. /* Open the Application Input File*/
  551. #ifdef PLAT_SCC
  552. strcpy(app_input_file_name, "/shared/herc/");
  553. #else
  554. strcpy(app_input_file_name, "../");
  555. #endif
  556. strcat(app_input_file_name, scen_directory);
  557. strcat(app_input_file_name, "/");
  558. strcat(app_input_file_name, scen_num);
  559. strcat(app_input_file_name, "/inputs/");
  560. strcat(app_input_file_name, app_input_file);
  561. printf("App Input File Path = %s ...",app_input_file_name);
  562. fprintf(log_file,"file path = %s\n",app_input_file_name);
  563. if ((app_input = fopen(app_input_file_name, "r")) == NULL){
  564. printf("Error!\n");
  565. perror("open app_input");
  566. }else{
  567. printf("Success!\n");
  568. fflush(stdout);
  569. }
  570. /* done */
  571. fscanf(app_input,"%d",&time_next);
  572. state = IDLE_CHK_APP_FILE;
  573. its.it_interval.tv_sec = 0;
  574. its.it_interval.tv_nsec = 0;
  575. its.it_value.tv_sec = 0;
  576. its.it_value.tv_nsec = 10 * MS;
  577. if (timer_settime(timerid, 0, &its, NULL) == -1) perror("timer_settime error9");
  578. gettimeofday(&time_val, NULL);
  579. cur_t = localtime(&time_val.tv_sec);
  580. start_time_of_day = *cur_t;
  581. while (state != IDAG_ENDING)
  582. if (state == IDLE_IDAG) {
  583. scc_pause();
  584. scc_signals_check();
  585. if (num_apps_terminated == num_apps)
  586. state = USER_INPUT;
  587. else if (!timer_init_null && init_pending_head != NULL) {
  588. its.it_value.tv_sec = 10;
  589. its.it_value.tv_nsec = 0;
  590. if (timer_settime(timerid, 0, &its, NULL) == -1) perror("timer_settime error9");
  591. timer_init_null = 1;
  592. }
  593. } else if (state == IDLE_IDAG_INIT_SEND) {
  594. signals_enable();
  595. tmp_inter_prev = NULL;
  596. tmp_pending_head = init_pending_head;
  597. while (tmp_pending_head != NULL) {
  598. init_core = tmp_pending_head->data.new_app.num_of_cores;
  599. for (tmp_inter_list = core_inter_head[init_core]; tmp_inter_list != NULL; tmp_inter_list = tmp_inter_list->next)
  600. if (tmp_inter_list->type == INIT_APP) break;
  601. if (tmp_inter_list == NULL) {
  602. 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);
  603. fflush(log_file);
  604. if (core_inter_head[init_core] == NULL){
  605. core_inter_head[init_core] = (inter_list *) malloc(sizeof(inter_list));
  606. core_inter_tail[init_core] = core_inter_head[init_core];
  607. } else {
  608. core_inter_tail[init_core]->next = (inter_list *) malloc(sizeof(inter_list));
  609. core_inter_tail[init_core] = core_inter_tail[init_core]->next;
  610. }
  611. core_inter_tail[init_core]->type = INIT_APP;
  612. core_inter_tail[init_core]->data.new_app = tmp_pending_head->data.new_app;
  613. core_inter_tail[init_core]->data.new_app.num_of_cores = 0;
  614. core_inter_tail[init_core]->next = NULL;
  615. if (core_inter_head[init_core]->next == NULL) {
  616. //kill(pid_num[sender_id],SIG_INIT_APP);
  617. scc_kill(init_core, SIG_INIT_APP, core_inter_head[init_core]);
  618. my_stats.msg_count++;
  619. my_stats.distance += distance(node_id,init_core);
  620. }
  621. if (tmp_inter_prev == NULL) {
  622. tmp_inter_list = init_pending_head;
  623. init_pending_head = init_pending_head->next;
  624. tmp_pending_head = init_pending_head;
  625. //free(tmp_inter_list);
  626. } else {
  627. tmp_inter_list = tmp_inter_prev->next;
  628. tmp_inter_prev->next = tmp_inter_list->next;
  629. tmp_pending_head = tmp_inter_prev->next;
  630. if (tmp_inter_prev->next == NULL) init_pending_tail = tmp_inter_prev;
  631. }
  632. free(tmp_inter_list);
  633. } else {
  634. tmp_inter_prev = tmp_pending_head;
  635. tmp_pending_head = tmp_pending_head->next;
  636. }
  637. }
  638. timer_init_null = 0;
  639. state = IDLE_IDAG;
  640. fprintf(log_file,"I exit this fuck\n");
  641. fflush(log_file);
  642. } else if (state == IDLE_CHK_APP_FILE) {
  643. scc_pause();
  644. scc_signals_check();
  645. } else if (state == CHK_APP_FILE) {
  646. signals_disable();
  647. time_passed++;
  648. //if (time_for_farman > 0) time_for_farman -= 10;a
  649. //printf("time passed=%d | time next=%d\n",time_passed,time_next);
  650. if (time_next == time_passed) {
  651. fscanf(app_input,"%d",&init_core);
  652. num_apps++;
  653. fprintf(log_file,"idag_mask[%d] = %d\n",init_core,idag_mask[init_core]);
  654. if (idag_mask[init_core] == init_core){
  655. fprintf(log_file,"init_core %d is a controller. New init_core = %d\n",init_core,init_core+1);
  656. printf("init_core %d is a controller. New init_core = %d\n",init_core,init_core+1);
  657. init_core++;
  658. }
  659. printf("time = %d, id = %d\n",time_passed,app_cnt);
  660. gettimeofday(&time_val, NULL);
  661. cur_t = localtime(&time_val.tv_sec);
  662. 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);
  663. fflush(log_file);
  664. 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);
  665. fflush(time_log);
  666. for (tmp_inter_list = core_inter_head[init_core]; tmp_inter_list != NULL; tmp_inter_list = tmp_inter_list->next)
  667. if (tmp_inter_list->type == INIT_APP) break;
  668. signals_enable();
  669. if (tmp_inter_list == NULL) {
  670. if (core_inter_head[init_core] == NULL){
  671. core_inter_head[init_core] = (inter_list *) malloc(sizeof(inter_list));
  672. core_inter_tail[init_core] = core_inter_head[init_core];
  673. } else {
  674. core_inter_tail[init_core]->next = (inter_list *) malloc(sizeof(inter_list));
  675. core_inter_tail[init_core] = core_inter_tail[init_core]->next;
  676. }
  677. core_inter_tail[init_core]->type = INIT_APP;
  678. #ifndef ARTIFICIAL_APPS_SIM
  679. /* FIXME scanned for old app inputs compatibility reasons but it is discarded */
  680. fscanf(app_input,"%d",&core_inter_tail[init_core]->data.new_app.array_size);
  681. core_inter_tail[init_core]->data.new_app.array_size = executed_app_array_size;
  682. #else
  683. fscanf(app_input,"%f",&core_inter_tail[init_core]->data.new_app.var);
  684. fscanf(app_input,"%f",&core_inter_tail[init_core]->data.new_app.A);
  685. #endif
  686. fscanf(app_input,"%d",&core_inter_tail[init_core]->data.new_app.workld);
  687. core_inter_tail[init_core]->data.new_app.app_type = executed_app_type_number;
  688. /* FIXME for the time being, do not scan for app type. All apps are of the same type, read from argv */
  689. core_inter_tail[init_core]->data.new_app.id = app_cnt++;
  690. core_inter_tail[init_core]->data.new_app.num_of_cores = 0;
  691. core_inter_tail[init_core]->next = NULL;
  692. /*printf("time = %d, id = %d, workld = %d\n",time_passed,core_inter_tail[init_core]->data.new_app.id,core_inter_tail[init_core]->data.new_app.workld);
  693. gettimeofday(&time_val, NULL);
  694. cur_t = localtime(&time_val.tv_sec);
  695. fprintf(log_file, "[%d:%d:%d]: Initialising app_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,core_inter_tail[init_core]->data.new_app.id);
  696. fflush(log_file);
  697. 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,core_inter_tail[init_core]->data.new_app.id);
  698. fflush(time_log);*/
  699. if (core_inter_head[init_core]->next == NULL) {
  700. //kill(pid_num[init_core],SIG_INIT_APP);
  701. scc_kill(init_core, SIG_INIT_APP, core_inter_head[init_core]);
  702. my_stats.msg_count++;
  703. my_stats.distance += distance(node_id,init_core);
  704. }
  705. } else {
  706. if (init_pending_head == NULL){
  707. init_pending_head = (inter_list *) malloc(sizeof(inter_list));
  708. init_pending_tail = init_pending_head;
  709. } else {
  710. init_pending_tail->next = (inter_list *) malloc(sizeof(inter_list));
  711. init_pending_tail = init_pending_tail->next;
  712. }
  713. init_pending_tail->type = INIT_APP;
  714. /* FIXME scanned for old app inputs compatibility reasons but it is discarded */
  715. #ifndef ARTIFICIAL_APPS_SIM
  716. fscanf(app_input,"%d",&init_pending_tail->data.new_app.array_size);
  717. init_pending_tail->data.new_app.array_size = executed_app_array_size;
  718. #else
  719. fscanf(app_input,"%f",&init_pending_tail->data.new_app.var);
  720. fscanf(app_input,"%f",&init_pending_tail->data.new_app.A);
  721. #endif
  722. fscanf(app_input,"%d",&init_pending_tail->data.new_app.workld);
  723. core_inter_tail[init_core]->data.new_app.app_type = executed_app_type_number;
  724. /* FIXME for the time being, do not scan for app type. All apps are of the same type, read from argv */
  725. init_pending_tail->data.new_app.id = app_cnt++;
  726. init_pending_tail->data.new_app.num_of_cores = init_core;
  727. init_pending_tail->next = NULL;
  728. }
  729. if (fscanf(app_input,"%d",&time_next) == EOF) {
  730. //state = USER_INPUT;
  731. state = IDLE_IDAG;
  732. time_passed = -1;
  733. } else {
  734. its.it_value.tv_sec = 0;
  735. its.it_value.tv_nsec = 10 * MS;
  736. if (timer_settime(timerid, 0, &its, NULL) == -1) printf("timer_settime error11\n");
  737. state = IDLE_CHK_APP_FILE;
  738. }
  739. } else {
  740. state = IDLE_CHK_APP_FILE;
  741. its.it_value.tv_sec = 0;
  742. its.it_value.tv_nsec = 10 * MS;
  743. if (timer_settime(timerid, 0, &its, NULL) == -1) printf("timer_settime error92\n");
  744. }
  745. signals_enable();
  746. } else if (state == USER_INPUT) {
  747. //while (num_apps_terminated != num_apps) {//pause(); my_cores_count
  748. // scc_pause();
  749. // scc_signals_check();
  750. //}
  751. for (k=0; k<15000; k++) {//pause(); my_cores_count
  752. scc_pause();
  753. scc_signals_check();
  754. }
  755. for (j=0; j<num_idags; j++) {
  756. one_idag = idag_id_arr[j];
  757. fprintf(log_file, "Sending to controller core %d\n",one_idag);
  758. if (one_idag != idag_id_arr[0]) {
  759. if (core_inter_head[one_idag] == NULL){
  760. core_inter_head[one_idag] = (inter_list *) malloc(sizeof(inter_list));
  761. core_inter_tail[one_idag] = core_inter_head[one_idag];
  762. } else {
  763. core_inter_tail[one_idag]->next = (inter_list *) malloc(sizeof(inter_list));
  764. core_inter_tail[one_idag] = core_inter_tail[one_idag]->next;
  765. }
  766. core_inter_tail[one_idag]->type = DEBUG_IDAG_REQ_DDS;
  767. core_inter_tail[one_idag]->data.reg.C = -1;
  768. core_inter_tail[one_idag]->data.reg.r = 0;
  769. core_inter_tail[one_idag]->next = NULL;
  770. if (core_inter_head[one_idag]->next == NULL)
  771. scc_kill(one_idag, SIG_REQ_DDS, core_inter_head[one_idag]);
  772. else {
  773. fprintf(log_file,"interaction in debug req dds is %d\n",core_inter_head[one_idag]->type);
  774. fflush(log_file);
  775. }
  776. } else {
  777. printf("Number of agents in region = %d\n",DDS_count);
  778. tmp_DDS = DDS;
  779. i=0;
  780. while (tmp_DDS != NULL) {
  781. printf("Agent no %d is %d with %d cores\n",i,tmp_DDS->agent_id,tmp_DDS->num_of_cores);
  782. tmp_DDS = tmp_DDS->next;
  783. i++;
  784. }
  785. }
  786. }
  787. while (idags_replied < num_idags - 1) {
  788. scc_pause();
  789. scc_signals_check();
  790. }
  791. fprintf(log_file,"killing\n");
  792. fflush(log_file);
  793. for (i=1; i<num_idags; i++){
  794. printf("i am killing %d\n",idag_id_arr[i]);
  795. one_core = idag_id_arr[i];
  796. if (core_inter_head[one_core] == NULL){
  797. core_inter_head[one_core] = (inter_list *) malloc(sizeof(inter_list));
  798. core_inter_tail[one_core] = core_inter_head[one_core];
  799. } else {
  800. core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
  801. core_inter_tail[one_core] = core_inter_tail[one_core]->next;
  802. fprintf(log_file,"I am still doing smth with idag %d interaction = %d\n",one_core,core_inter_head[one_core]->type);
  803. fflush(log_file);
  804. }
  805. core_inter_tail[one_core]->type = TERMINATION_STATS;
  806. core_inter_tail[one_core]->next = NULL;
  807. signals_disable();
  808. scc_kill(one_core, SIG_TERMINATE, core_inter_head[one_core]);
  809. signals_enable();
  810. }
  811. tmp_cores_list = my_cores;
  812. my_cores = my_cores->next;
  813. free(tmp_cores_list);
  814. inter_list tmp_inter_list;
  815. for (; my_cores != NULL; my_cores = my_cores->next) {
  816. tmp_cores_list = my_cores;
  817. one_core = my_cores->core_id;
  818. if (core_inter_head[one_core] == NULL){
  819. core_inter_head[one_core] = (inter_list *) malloc(sizeof(inter_list));
  820. core_inter_tail[one_core] = core_inter_head[one_core];
  821. } else {
  822. core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
  823. core_inter_tail[one_core] = core_inter_tail[one_core]->next;
  824. fprintf(log_file,"I am still doing smth with my node %d interaction = %d\n",one_core,core_inter_head[one_core]->type);
  825. fflush(log_file);
  826. }
  827. core_inter_tail[one_core]->type = TERMINATION_STATS;
  828. core_inter_tail[one_core]->next = NULL;
  829. //kill(pid_num[one_core], SIG_TERMINATE);
  830. signals_disable();
  831. scc_kill(one_core, SIG_TERMINATE, core_inter_head[one_core]);
  832. signals_enable();
  833. /* 8.7.2016 Paxos Stats */
  834. tmp_inter_list.next = NULL;
  835. tmp_inter_list.type = PAXOS_STATS_REQ;
  836. scc_kill(one_core, SIG_PAXOS_STATS_REQ, &tmp_inter_list);
  837. paxos_node_stats.msg_count++;
  838. paxos_node_stats.distance += distance(node_id,one_core);
  839. my_stats.msg_count++;
  840. my_stats.distance += distance(node_id,one_core);
  841. free(tmp_cores_list);
  842. }
  843. state = IDAG_ENDING;
  844. } else {
  845. printf("my_rtrm.c : Unknown state node_id = %d state = %d\n",node_id,state);
  846. state = IDLE_IDAG;
  847. }
  848. while (state == IDAG_ENDING) {
  849. scc_pause();
  850. scc_signals_check();
  851. if (stats_replied == my_cores_count+num_idags-2 && paxos_stats_replied == my_cores_count+num_idags-2) state = TERMINATED;
  852. }
  853. #ifdef PLAT_LINUX
  854. for (i=0; i<my_cores_count-1; i++)
  855. wait(NULL); //wait for children
  856. for (i=0; i<num_idags-1; i++)
  857. wait(NULL);//wait for the other idags
  858. #endif
  859. total_stats.msg_count += my_stats.msg_count;
  860. total_stats.message_size += my_stats.message_size;
  861. total_stats.distance += my_stats.distance;
  862. total_stats.app_turnaround += my_stats.app_turnaround;
  863. total_stats.comp_effort += my_stats.comp_effort;
  864. total_stats.cores_utilized += my_stats.cores_utilized;
  865. total_stats.times_accessed += my_stats.times_accessed;
  866. paxos_total_stats.msg_count += paxos_node_stats.msg_count;
  867. paxos_total_stats.fd_msg_count += paxos_node_stats.fd_msg_count;
  868. avg_cluster_util = (float) my_stats.cores_utilized / (my_stats.times_accessed * (my_cores_count-1));
  869. printf("I am %d with cores_utilized = %d times_accessed = %d my_cores_count = %d and avg_cluster_util = %0.2f\n",
  870. node_id,my_stats.cores_utilized,my_stats.times_accessed,my_cores_count,avg_cluster_util);
  871. fprintf(log_file,"cores_utilized = %d times_accessed = %d my_cores_count = %d and avg_cluster_util = %0.2f\n",
  872. my_stats.cores_utilized,my_stats.times_accessed,my_cores_count,avg_cluster_util);
  873. gettimeofday(&time_val, NULL);
  874. end_time_of_day = localtime(&time_val.tv_sec);
  875. fprintf(log_file,"================= DRTRM STATS ==================\n");
  876. fprintf(log_file,"Total message count = %lld\n",total_stats.msg_count);
  877. fprintf(log_file,"Total message size = %d\n",total_stats.message_size);
  878. fprintf(log_file,"Total distance = %d\n",total_stats.distance);
  879. fprintf(log_file,"Total app turnaround time = %d\n",total_stats.app_turnaround);
  880. fprintf(log_file,"Total computational effort = %d\n",total_stats.comp_effort);
  881. fprintf(log_file,"Total cores_utilized = %d\n",total_stats.cores_utilized);
  882. fprintf(log_file,"Total times_accessed = %d\n",total_stats.times_accessed);
  883. fprintf(log_file,"================= PAXOS STATS ==================\n");
  884. fprintf(log_file,"Total message count = %lld\n",paxos_total_stats.msg_count);
  885. printf("================= DRTRM STATS ==================\n");
  886. printf("Total message count = %lld\n",total_stats.msg_count);
  887. printf("Total message size = %d\n",total_stats.message_size);
  888. printf("Total distance = %d\n",total_stats.distance);
  889. printf("Total app turnaround time = %d\n",total_stats.app_turnaround);
  890. printf("Total computational effort = %d\n",total_stats.comp_effort);
  891. printf("Total cores_utilized = %d\n",total_stats.cores_utilized);
  892. printf("Total times_accessed = %d\n",total_stats.times_accessed);
  893. printf("================= PAXOS STATS ==================\n");
  894. printf("Start Time: [%d:%d:%d]\n",start_time_of_day.tm_hour,start_time_of_day.tm_min,start_time_of_day.tm_sec);
  895. printf("End Time: [%d:%d:%d]\n",end_time_of_day->tm_hour,end_time_of_day->tm_min,end_time_of_day->tm_sec);
  896. #ifdef PFD
  897. printf("Perfect Failure Detector\n");
  898. #elif tPFD
  899. printf("tweaked Perfect Failure Detector\n");
  900. #endif
  901. printf("PAXOS Total message count = %lld\n",paxos_total_stats.msg_count);\
  902. printf("Failure Detection Total message count = %d\n",paxos_total_stats.fd_msg_count);
  903. for (i=0; i<NUES; i++){
  904. free(core_inter_head[i]);
  905. free(core_inter_tail[i]);
  906. }
  907. free(core_inter_head);
  908. free(core_inter_tail);
  909. #ifdef PLAT_SCC
  910. RCCE_flag_free(&flag_data_written);
  911. RCCE_free((t_vcharp) sig_array);
  912. RCCE_free((t_vcharp) data_array);
  913. RCCE_free((t_vcharp) proposal_number_global);
  914. fclose(init_ack_file);
  915. #else
  916. shmdt(pid_num);
  917. for (i=0; i<NUES; i++) {
  918. sem_destroy(&flag_data_written[i]);
  919. sem_destroy(&scc_lock[i]);
  920. }
  921. shmdt(flag_data_written);
  922. shmdt(scc_lock);
  923. shmdt(manager_result_out);
  924. shmdt(index_bottom);
  925. #endif
  926. cur_time = time(NULL);
  927. cur_t = localtime(&cur_time);
  928. fprintf(log_file, "[%d:%d:%d]: I ended well\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec);
  929. fclose(log_file);
  930. printf("[%d:%d:%d]: I ended well\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec);
  931. //}
  932. }
  933. return 0;
  934. }