idag_defs.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. #include "idag_defs.h"
  2. #include "variables.h"
  3. void global_idag_defs(void) {
  4. #ifdef NO_ISLANDS
  5. return;
  6. #endif
  7. #ifdef LOW_VOLTAGE_0
  8. low_voltage_core[0] = 1;
  9. low_voltage_core[1] = 1;
  10. low_voltage_core[2] = 1;
  11. low_voltage_core[3] = 1;
  12. low_voltage_core[12] = 1;
  13. low_voltage_core[13] = 1;
  14. low_voltage_core[14] = 1;
  15. low_voltage_core[15] = 1;
  16. #endif
  17. #ifdef LOW_VOLTAGE_1
  18. low_voltage_core[4] = 1;
  19. low_voltage_core[5] = 1;
  20. low_voltage_core[6] = 1;
  21. low_voltage_core[7] = 1;
  22. low_voltage_core[16] = 1;
  23. low_voltage_core[17] = 1;
  24. low_voltage_core[18] = 1;
  25. low_voltage_core[19] = 1;
  26. #endif
  27. #ifdef LOW_VOLTAGE_2
  28. low_voltage_core[8] = 1;
  29. low_voltage_core[9] = 1;
  30. low_voltage_core[10] = 1;
  31. low_voltage_core[11] = 1;
  32. low_voltage_core[20] = 1;
  33. low_voltage_core[21] = 1;
  34. low_voltage_core[22] = 1;
  35. low_voltage_core[23] = 1;
  36. #endif
  37. #ifdef LOW_VOLTAGE_3
  38. low_voltage_core[24] = 1;
  39. low_voltage_core[25] = 1;
  40. low_voltage_core[26] = 1;
  41. low_voltage_core[27] = 1;
  42. low_voltage_core[36] = 1;
  43. low_voltage_core[37] = 1;
  44. low_voltage_core[38] = 1;
  45. low_voltage_core[39] = 1;
  46. #endif
  47. #ifdef LOW_VOLTAGE_4
  48. low_voltage_core[28] = 1;
  49. low_voltage_core[29] = 1;
  50. low_voltage_core[30] = 1;
  51. low_voltage_core[31] = 1;
  52. low_voltage_core[40] = 1;
  53. low_voltage_core[41] = 1;
  54. low_voltage_core[42] = 1;
  55. low_voltage_core[43] = 1;
  56. #endif
  57. #ifdef LOW_VOLTAGE_5
  58. low_voltage_core[32] = 1;
  59. low_voltage_core[33] = 1;
  60. low_voltage_core[34] = 1;
  61. low_voltage_core[35] = 1;
  62. low_voltage_core[44] = 1;
  63. low_voltage_core[45] = 1;
  64. low_voltage_core[46] = 1;
  65. low_voltage_core[47] = 1;
  66. #endif
  67. }
  68. void read_idag_defs(char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE], char idag_defs_file_name[SCEN_NUM_SIZE], char paxos_scen[PAXOS_SCEN_SIZE]) {
  69. int i, j, cnt, core_index, time;
  70. char paxos_path[MAX_STR_NAME_SIZE];
  71. FILE *paxos_conf_file;
  72. /* Simulating centralized approach. Controller core is 0 */
  73. #ifdef SINGLE_IDAG
  74. num_idags = 1;
  75. idag_id_arr = (int *) malloc(num_idags * sizeof(int));
  76. idag_id_arr[0] = 0;
  77. for (i=0; i<X_max*Y_max; i++)
  78. idag_mask[i] = 0;
  79. num_idags_x = 1;
  80. #else
  81. char idag_defs_path[MAX_STR_NAME_SIZE];
  82. FILE *idag_defs_file;
  83. #ifdef PLAT_SCC
  84. strcpy(idag_defs_path, "/shared/herc/");
  85. #else
  86. strcpy(idag_defs_path, "../");
  87. #endif
  88. strcat(idag_defs_path, scen_directory);
  89. strcat(idag_defs_path, "/");
  90. strcat(idag_defs_path, scen_num);
  91. strcat(idag_defs_path, "/idag_defs/");
  92. strcat(idag_defs_path, idag_defs_file_name);
  93. if (node_id == 0){
  94. printf("Idag_defs_path = %s\n",idag_defs_path);
  95. fflush(stdout);
  96. }
  97. if ((idag_defs_file = fopen(idag_defs_path, "r")) == NULL){
  98. printf("Cannot open input file with file path = %s ",idag_defs_path);
  99. perror("open idag_defs_path");
  100. }
  101. fscanf(idag_defs_file, "%d", &num_idags);
  102. idag_id_arr = (int *) malloc(num_idags * sizeof(int));
  103. for (i=0; i<num_idags; i++)
  104. fscanf(idag_defs_file, "%d", &idag_id_arr[i]);
  105. for (i = X_max*Y_max - 2*X_max; i >= 0; i -= 2*X_max) {
  106. for (j = i; j < i+2*X_max-1; j+=2){
  107. //printf("%d | ",j+1);
  108. fscanf(idag_defs_file, "%d", &idag_mask[j+1]);
  109. }
  110. //printf("\n");
  111. for (j = i; j < i+2*X_max-1; j+=2){
  112. //printf("%d | ",j);
  113. fscanf(idag_defs_file, "%d", &idag_mask[j]);
  114. }
  115. //printf("\n");
  116. }
  117. for (i=0;i <X_max*Y_max; i++){
  118. idag_mask[i] = idag_id_arr[idag_mask[i]];
  119. }
  120. num_idags_x = num_idags / 2; /* FIXME deprecated, keeping for time being only for compatibility */
  121. #endif
  122. /*dimos*/
  123. //fclose(idag_defs_file);
  124. #ifdef PLAT_SCC
  125. strcpy(paxos_path, "/shared/herc/");
  126. #else
  127. strcpy(paxos_path, "../");
  128. #endif
  129. strcat(paxos_path, scen_directory);
  130. strcat(paxos_path, "/paxos/");
  131. strcat(paxos_path, paxos_scen);
  132. if ((paxos_conf_file = fopen(paxos_path, "r")) == NULL){
  133. printf("Cannot open input file with file path = %s\n ",paxos_path);
  134. perror("open paxos_path");
  135. }
  136. fscanf(paxos_conf_file,"%d", &cnt);
  137. for (i = 0; i < cnt; i++){
  138. fscanf(paxos_conf_file,"%d", &core_index);
  139. fscanf(paxos_conf_file,"%d", &time);
  140. timer_schedule[idag_id_arr[core_index]] = time;
  141. }
  142. fclose(paxos_conf_file);
  143. }
  144. void print_grid(){
  145. int k,i,j;
  146. for (i = 0; i < 4*X_max; i++) printf("%s=",KMAG);
  147. printf("%s GRID ",KMAG);
  148. for (i = 0; i < 4*X_max; i++) printf("%s=",KMAG);
  149. printf("\n");
  150. for (i = X_max*Y_max - 2*X_max; i >= 0; i -= 2*X_max){
  151. for (j = i; j < i+2*X_max-1; j+=2){
  152. for (k = 0; k < num_idags; k++){
  153. if (idag_mask[j+1] == idag_id_arr[k]){
  154. if (k == 0){
  155. printf("%s%d\t",KRED,j+1);
  156. fflush(stdout);
  157. }
  158. else if (k == 1){
  159. printf("%s%d\t",KGRN,j+1);
  160. fflush(stdout);
  161. }
  162. else if (k == 2){
  163. printf("%s%d\t",KBLU,j+1);
  164. fflush(stdout);
  165. }
  166. else if (k == 3){
  167. printf("%s%d\t",KYEL,j+1);
  168. fflush(stdout);
  169. }
  170. else if (k == 4){
  171. printf("%s%d\t",KMAG,j+1);
  172. fflush(stdout);
  173. }
  174. else if (k == 5){
  175. printf("%s%d\t",KCYN,j+1);
  176. fflush(stdout);
  177. }
  178. else if (k == 6){
  179. printf("%s%d\t",KWHT,j+1);
  180. fflush(stdout);
  181. }
  182. else if (k == 7){
  183. printf("%s%d\t",KBLK,j+1);
  184. fflush(stdout);
  185. }
  186. }
  187. }
  188. }
  189. printf("\n");
  190. for (j = i; j < i+2*X_max-1; j+=2){
  191. for (k = 0; k < num_idags; k++){
  192. if (idag_mask[j] == idag_id_arr[k]){
  193. if (k == 0){
  194. printf("%s%d\t",KRED,j);
  195. fflush(stdout);
  196. }
  197. else if (k == 1){
  198. printf("%s%d\t",KGRN,j);
  199. fflush(stdout);
  200. }
  201. else if (k == 2){
  202. printf("%s%d\t",KBLU,j);
  203. fflush(stdout);
  204. }
  205. else if (k == 3){
  206. printf("%s%d\t",KYEL,j);
  207. fflush(stdout);
  208. }
  209. else if (k == 4){
  210. printf("%s%d\t",KMAG,j+1);
  211. fflush(stdout);
  212. }
  213. else if (k == 5){
  214. printf("%s%d\t",KCYN,j+1);
  215. fflush(stdout);
  216. }
  217. else if (k == 6){
  218. printf("%s%d\t",KWHT,j+1);
  219. fflush(stdout);
  220. }
  221. else if (k == 7){
  222. printf("%s%d\t",KBLK,j+1);
  223. fflush(stdout);
  224. }
  225. }
  226. }
  227. }
  228. printf("%s\n",KNRM);
  229. }
  230. for (i = 0; i < 4*X_max; i++) printf("%s=",KMAG);
  231. printf("%s GRID ",KMAG);
  232. for (i = 0; i < 4*X_max; i++) printf("%s=",KMAG);
  233. printf("%s\n",KNRM);
  234. }
  235. int is_core_idag (int core_id) {
  236. int i, is_idag = 0;
  237. for (i=0; i<num_idags; i++)
  238. if (idag_id_arr[i] == core_id) {
  239. is_idag = 1;
  240. break;
  241. }
  242. return is_idag;
  243. }
  244. int im_manager(){
  245. if (state == IDLE_AGENT ||
  246. state == IDLE_AGENT_WAITING_OFF ||
  247. state == AGENT_INIT_STATE ||
  248. state == AGENT_ENDING ||
  249. state == AGENT_INIT_APP_INIT ||
  250. state == AGENT_INIT_CHK_OFFERS ||
  251. state == AGENT_SELF_OPT ||
  252. state == AGENT_SELF_CHK_OFFERS ||
  253. state == AGENT_ZOMBIE ||
  254. state == AGENT_INIT_APP_INIT ||
  255. state == AGENT_INIT_IDLE_INIT ||
  256. state == AGENT_ZOMBIE ||
  257. pending_state == IDLE_AGENT ||
  258. pending_state == IDLE_AGENT_WAITING_OFF ||
  259. pending_state == AGENT_INIT_STATE ||
  260. pending_state == AGENT_ENDING ||
  261. pending_state == AGENT_INIT_APP_INIT ||
  262. pending_state == AGENT_INIT_CHK_OFFERS ||
  263. pending_state == AGENT_SELF_OPT ||
  264. pending_state == AGENT_SELF_CHK_OFFERS ||
  265. pending_state == AGENT_ZOMBIE ||
  266. pending_state == AGENT_INIT_APP_INIT ||
  267. pending_state == AGENT_INIT_IDLE_INIT)
  268. {
  269. return 1;
  270. }else{
  271. return 0;
  272. }
  273. }
  274. int im_worker(){
  275. if (cur_agent.my_agent == -1)
  276. return 0;
  277. else
  278. return 1;
  279. }
  280. int im_controller(){
  281. if (my_idag == -1)
  282. return 1;
  283. else
  284. return 0;
  285. }