Parcourir la source

Initial commit

Bill Tsou il y a 8 ans
commit
83afc742f3
28 fichiers modifiés avec 14422 ajouts et 0 suppressions
  1. 147 0
      Makefile
  2. 939 0
      apps.backup.c
  3. 1178 0
      apps.c
  4. 20 0
      apps.h
  5. 1439 0
      common_core.c
  6. 8 0
      common_core.h
  7. 360 0
      controller_core.c
  8. 9 0
      controller_core.h
  9. 318 0
      idag_defs.c
  10. 16 0
      idag_defs.h
  11. 363 0
      libfunctions.c
  12. 21 0
      libfunctions.h
  13. 9 0
      macros.h
  14. 1502 0
      my_rtrm.c
  15. 33 0
      my_rtrm.h
  16. 267 0
      noc_functions.c
  17. 11 0
      noc_functions.h
  18. 314 0
      offer_cores_backup.c
  19. 2107 0
      paxos_signal_handlers.c
  20. 41 0
      paxos_signal_handlers.h
  21. 672 0
      scc_signals.c
  22. 11 0
      scc_signals.h
  23. 105 0
      sig_aux.c
  24. 13 0
      sig_aux.h
  25. 3933 0
      signal_handlers.c
  26. 31 0
      signal_handlers.h
  27. 312 0
      structs.h
  28. 243 0
      variables.h

+ 147 - 0
Makefile

@@ -0,0 +1,147 @@
+#
+# Makefile
+#
+# my_rtrm
+#
+
+ifeq ($(PLATFORM),SCC)
+	CFLAGS = -Wall -g
+	SHELL=sh
+	RCCEROOT=../../bRCCE_V2.0
+	include $(RCCEROOT)/common/symbols
+	PLATFORM_INCLUDES = $(RCCEINCLUDE)/RCCE.h variables.h structs.h macros.h
+	MY_FLAGS += -DPLAT_SCC
+else
+	CCOMPILE = gcc
+	CFLAGS = -O0 -Wall -g #-O0 -Wextra
+	MY_FLAGS += -DPLAT_LINUX
+	PLATFORM_INCLUDES = variables.h structs.h macros.h
+endif
+
+OBJS=my_rtrm.o libfun.o nocfun.o sigaux.o controller.o common_node.o signal_handlers.o scc_signals.o idag_defs.o paxos_signal_handlers.o apps.o $(ARCHIVE)
+
+#
+#PAXOS OBJECTS
+#
+ifeq ($(SCEN),BASIC_PAXOS)
+	MY_FLAGS += -DBASIC_PAXOS
+else
+	MY_FLAGS += -DPLAIN
+endif
+
+ifeq ($(FAILURE),CONTROLLER)
+	MY_FLAGS += -DCONTROLLER
+else ifeq ($(FAILURE),MANAGER)
+	MY_FLAGS += -DMANAGER
+else ifeq ($(FAILURE),WORKER)
+	MY_FLAGS += -DWORKER
+endif
+
+ifeq ($(DETECTOR), PFD)
+	MY_FLAGS += -DPFD
+else ifeq ($(DETECTOR), EPFD)
+	MY_FLAGS += -DEPFD
+else ifeq ($(DETECTOR), tPFD)
+	MY_FLAGS += -DtPFD
+else ifeq ($(DETECTOR), tEPFD)
+	MY_FLAGS += -DtEPFD
+endif
+
+#
+#
+#
+
+#
+#PAXOS SCENARIA
+#
+ifeq ($(IDAG_CONF),PAXOS_1)
+  MY_FLAGS += -DPAXOS_CONF_1 -DIDAGS_4
+endif
+#
+#
+#
+ifeq ($(SINGLE_WORKER),1)
+  MY_FLAGS += -DSINGLE_WORKER
+endif
+
+ifeq ($(SINGLE_IDAG),1)
+  MY_FLAGS += -DSINGLE_IDAG
+endif
+
+ifeq ($(VERBOSE_WORKER),1)
+  MY_FLAGS += -DVERBOSE_WORKER
+endif
+
+ifeq ($(EXTRA_DELAY),1)
+  MY_FLAGS += -DEXTRA_DELAY
+endif
+
+ifeq ($(NO_ISLANDS),1)
+  MY_FLAGS += -DNO_ISLANDS
+endif
+
+ifeq ($(LOW_VOLTAGE),0)
+  MY_FLAGS += -DLOW_VOLTAGE_0
+endif
+
+ifeq ($(LOW_VOLTAGE),1)
+  MY_FLAGS += -DLOW_VOLTAGE_1
+endif
+
+ifeq ($(LOW_VOLTAGE),2)
+  MY_FLAGS += -DLOW_VOLTAGE_2
+endif
+
+ifeq ($(LOW_VOLTAGE),3)
+  MY_FLAGS += -DLOW_VOLTAGE_3
+endif
+
+ifeq ($(LOW_VOLTAGE),4)
+  MY_FLAGS += -DLOW_VOLTAGE_4
+endif
+
+ifeq ($(LOW_VOLTAGE),5)
+  MY_FLAGS += -DLOW_VOLTAGE_5
+endif
+
+my_rtrm:$(OBJS) 
+	cd ./../bin && $(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o my_rtrm $(OBJS) -pthread -lrt -lm
+
+nocfun.o: noc_functions.c noc_functions.h my_rtrm.h idag_defs.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/nocfun.o -c noc_functions.c
+
+libfun.o: libfunctions.c libfunctions.h my_rtrm.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/libfun.o -c libfunctions.c
+
+sigaux.o: sig_aux.c sig_aux.h my_rtrm.h signal_handlers.h paxos_signal_handlers.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/sigaux.o -c sig_aux.c
+
+scc_signals.o: scc_signals.c scc_signals.h my_rtrm.h signal_handlers.h paxos_signal_handlers.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/scc_signals.o -c scc_signals.c
+
+controller.o: controller_core.c controller_core.h libfunctions.h my_rtrm.h noc_functions.h sig_aux.h signal_handlers.h paxos_signal_handlers.h scc_signals.h idag_defs.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/controller.o -c controller_core.c
+
+common_node.o: common_core.c common_core.h libfunctions.h my_rtrm.h noc_functions.h sig_aux.h signal_handlers.h paxos_signal_handlers.h apps.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/common_node.o -c common_core.c
+
+my_rtrm.o: my_rtrm.c libfunctions.h my_rtrm.h noc_functions.h sig_aux.h controller_core.h common_core.h signal_handlers.h paxos_signal_handlers.h scc_signals.h idag_defs.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/my_rtrm.o -c my_rtrm.c
+
+signal_handlers.o: signal_handlers.c libfunctions.h my_rtrm.h noc_functions.h sig_aux.h scc_signals.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/signal_handlers.o -c signal_handlers.c
+
+paxos_signal_handlers.o: paxos_signal_handlers.c libfunctions.h my_rtrm.h noc_functions.h sig_aux.h scc_signals.h signal_handlers.h sig_aux.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/paxos_signal_handlers.o -c paxos_signal_handlers.c
+	
+idag_defs.o: idag_defs.c idag_defs.h my_rtrm.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/idag_defs.o -c idag_defs.c
+	
+apps.o: apps.c apps.h scc_signals.h libfunctions.h $(PLATFORM_INCLUDES)
+	$(CCOMPILE) $(CFLAGS) $(MY_FLAGS) -o ./../bin/apps.o -c apps.c	
+
+clean:
+	rm -f ./../bin/my_rtrm ./../bin/my_rtrm.o ./../bin/libfun.o ./../bin/nocfun.o ./../bin/sigaux.o ./../bin/common_node.o ./../bin/controller.o ./../bin/signal_handlers.o ./../bin/paxos_signal_handlers.o ./../bin/scc_signals.o ./../bin/idag_defs.o ./../bin/apps.o
+	rm -rf ./../scenaria/6x6/paxos_log_files/*
+	rm -rf ./../scenaria/6x6/log_files/*
+	rm -rf ./../scenaria/6x6/app_logs/*

+ 939 - 0
apps.backup.c

@@ -0,0 +1,939 @@
+#include "apps.h"
+#include "scc_signals.h"
+#include "libfunctions.h"
+#include "my_rtrm.h"
+
+#define SWAP(a,b) {float tmp; tmp=a; a=b; b=tmp;}
+#define FFT_MAX 136192
+#define PAGE_SIZE 4096
+
+/*
+static float input_vector[25][10] = {
+  {-0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119},
+  {-0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467},
+  {-0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565},
+  {-0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533},
+  {-0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941},
+  {-1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784},
+  {0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575},
+  {0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371},
+  {1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241},
+  {1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752},
+  {-0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115},
+  {-0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876},
+  {-0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559},
+  {-0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523},
+  {1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364},
+  {-0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320},
+  {3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579},
+  {-0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210},
+  {1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734},
+  {-0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990},
+  {-0.632187, -0.629597, -0.560808, -0.439143, -0.550906, -3.344673, -1.389866, 0.268649, 0.664319, 1.150327},
+  {-0.205756, -0.210472, -0.151426, -0.121347, 0.196067, -3.136218, -2.621049, -0.026517, 0.358534, 0.714117},
+  {-0.418011, -0.424854, -0.461205, -0.428858, -0.801747, 1.933860, -0.129047, -0.674498, -0.880092, -0.752953},
+  {-0.625461, -0.633598, -0.651167, -0.621632, -0.312866, -3.908468, -2.380095, -0.118114, 0.233478, 0.722539},
+  {-0.525633, -0.521436, -0.552314, -0.527505, -0.233392, -3.763046, -2.487090, -0.133160, 0.156544, 0.642195},
+};
+*/
+/*
+static float input_vector[2][D_sv] = {
+  {-0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
+   -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
+   -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
+   -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
+   -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
+   -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
+   0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
+   0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
+   1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
+   1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752},
+  {-0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
+   -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
+   -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
+   -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
+   1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
+   -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
+   3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
+   -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
+   1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
+   -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990},
+};
+*/
+static float input_vector[1][D_sv] = {
+  {-0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
+   -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
+   -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
+   -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
+   -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
+   -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
+   0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
+   0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
+   1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
+   1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
+  -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
+   -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
+   -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
+   -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
+   1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
+   -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
+   3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
+   -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
+   1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
+   -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990,
+   -0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
+   -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
+   -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
+   -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
+   -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
+   -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
+   0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
+   0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
+   1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
+   1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
+  -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
+   -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
+   -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
+   -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
+   1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
+   -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
+   3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
+   -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
+   1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
+   -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990,
+   -0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
+   -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
+   -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
+   -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
+   -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
+   -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
+   0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
+   0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
+   1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
+   1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
+  -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
+   -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
+   -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
+   -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
+   1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
+   -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
+   3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
+   -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
+   1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
+   -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990,
+   -0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
+   -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
+   -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
+   -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
+   -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
+   -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
+   0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
+   0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
+   1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
+   1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
+  -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
+   -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
+   -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
+   -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
+   1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
+   -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
+   3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
+   -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
+   1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
+   -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990,
+   -0.390695, -0.381094, -0.341754, -0.272043, -0.588159, 2.297114, -0.116822, -0.507031, -0.563574, -0.534119,
+   -0.250457, -0.240673, -0.210423, -0.217804, -0.453731, 1.784484, -0.142005, -0.230148, -0.339593, -0.298467,
+   -0.177671, -0.183887, -0.191644, -0.205313, -0.441613, 1.599526, 0.023297, -0.322458, -0.539978, -0.457565,
+   -0.149024, -0.140364, -0.142723, -0.066651, -0.344126, 1.830863, 0.154307, -0.171898, -0.343950, -0.379533,
+   -0.155498, -0.154145, -0.181875, -0.189322, -0.122244, -3.037579, -1.476675, -0.089878, 0.004249, 0.169941,
+   -1.786535, -1.809749, -1.445913, -1.050310, -0.095173, 2.964720, 4.706277, -0.649227, -1.362017, -1.447784,
+   0.034026, 0.038159, -0.018497, -0.067303, 0.059710, -2.908602, -1.484229, 0.108804, 0.292757, 0.566575,
+   0.527511, 0.518252, 0.762342, 1.148066, 0.772846, -2.113671, -2.704303, -0.664257, 0.460104, 1.295371,
+   1.370790, 1.383803, 1.340450, 0.634441, -0.596868, -2.427651, -2.352223, 0.454767, 1.405430, 1.838241,
+   1.455314, 1.464866, 2.487861, 2.464788, 1.963237, 0.324097, -1.869693, -2.554004, -2.022594, 1.114752,
+  -0.664593, -0.687087, -0.075215, 0.583554, 0.927597, 3.671647, 3.835722, 0.694133, -2.007198, -2.345115,
+   -0.343777, -0.344074, -0.221304, -0.153775, -0.494637, 1.743759, -0.590775, -0.413656, -0.389204, -0.221876,
+   -0.159571, -0.163080, -0.513428, -0.775665, -0.891170, -3.118664, -1.247074, 0.913688, 1.009656, 1.170559,
+   -0.761538, -0.755972, -0.773967, -0.674253, -0.978258, 1.514730, -0.145977, -0.620700, -0.857082, -0.765523,
+   1.344641, 1.329151, 1.633256, 2.020196, 1.777348, -1.744907, -5.928727, -4.032057, -0.585966, 1.072364,
+   -0.468882, -0.486856, 0.935241, 2.032263, 2.219547, -0.225632, -3.438104, -4.412505, -0.550391, 2.234320,
+   3.177341, 3.204259, 2.749250, 1.741244, 1.197538, -2.985864, -6.084715, -1.447878, 0.904210, 1.495579,
+   -0.998953, -1.005918, -0.988911, -0.863153, -1.003750, 1.256336, -0.471785, -0.860056, -0.872804, -0.629210,
+   1.957319, 1.966453, 1.840960, 1.405216, 1.313205, -0.956540, -3.535391, -2.280320, -1.179478, -0.458734,
+   -0.326054, -0.331524, -0.134208, -0.218622, -0.158037, 3.128528, 4.020623, -1.129257, -1.524952, -1.377990	
+  },
+};
+
+
+static float **svm_vectors, *svm_coef;
+static int *vector, **matrix;
+//static float matr_speedup[NUM_OF_MATRICES][MAX_WORKERS_COUNT];
+//static int matr_times[NUM_OF_MATRICES][MAX_WORKERS_COUNT];
+
+static float Exec_Speedup[MAX_WORKERS_COUNT];
+static int Exec_Latencies[MAX_WORKERS_COUNT];
+//static float **vectors, *coef;
+
+//2*(N+rootN*pad_length)*sizeof(float)+PAGE_SIZE);
+static int P = 1;						/* DEFAULT_P = 1			 */
+static int M = 16;					/* DEFAULT_M = 10			 */
+static int N = 65536; 			/* N = 2^M 				 */
+static int rootN = 256;			/* rootN = sqrt(N)			 */
+static int num_cache_lines = 65536;
+#define PADLENGTH 2
+
+
+static float *x_local;	/* x is the original time-domain data	 */
+static float *trans;          /* trans is used as scratch space        */
+static float *umain;          /* umain is roots of unity for 1D FFTs   */
+static float *umain2;         /* umain2 is entire roots of unity matrix*/
+static float *upriv;
+
+void execute_workload_svm (int lower_bound, int upper_bound);
+void execute_workload_matrix (int lower_bound, int upper_bound);
+
+void matrix_transpose(int n1, float *src, float *dest, int node_id, int myFirst, int myLast, int pad_length);
+void FFT1D(int direction, int M, int N, float *x, float *scratch, float *upriv, float *umain2, int node_id, int myFirst, int myLast, int pad_length, int P);
+void copyColumn(int n1, float *src, float *dest);
+void single_FFT1D(int direction, int M, int N, float *u, float *x);
+void twiddle_Col(int direction, int n1, int N, int j, float *u, float *x, int pad_length);
+void reverse(int N, int M, float *x);
+int reverse_bit(int M, int k);
+
+void execute_workload_svm (int lower_bound, int upper_bound) {
+	int i = 0, j = 0;
+	float diff = 0, norma = 0, local_sum[N_sv];
+	int vector_id = 0;
+
+	if (base_offset == -1) {
+		base_offset = cur_agent.my_agent * N_sv;
+		//fprintf(log_file, "My agent is %d. Calculated base_offset is %d\n",cur_agent.my_agent,base_offset);
+	}
+	
+	for (i = lower_bound; i <= upper_bound; i++) {
+		local_sum[i] = 0;
+		scc_signals_check();
+		
+		for (j = 0; j < D_sv; j++){
+			diff = input_vector[vector_id][j] - svm_vectors[j][i];
+			norma += diff*diff;
+		}
+		local_sum[i] += (float) (exp((double) (-gamma*norma))*svm_coef[i]);
+		norma = 0;
+	}
+	/*	
+	for (i=lower_bound; i<=upper_bound; i++) 
+		manager_result_out[base_offset+i] = (int) local_sum[i];
+	*/	
+}
+
+void execute_workload_matrix (int lower_bound, int upper_bound) {
+	int i, j, local_sum[MAX_ARRAY_SIZE];
+	
+	if (base_offset == -1) {
+		//matrix_out = (int*) shmat (cur_agent.segment_id, NULL, 0);
+		base_offset = cur_agent.my_agent * MAX_ARRAY_SIZE;
+	}
+	
+	for (i=lower_bound; i<=upper_bound; i++) {
+		local_sum[i] = 0;
+		scc_signals_check();
+		//signals_enable();
+		for (j=0; j<cur_agent.array_size; j++)
+			local_sum[i] += matrix[i][j] * vector[j];
+		//signals_disable();
+	}
+
+	for (i=lower_bound; i<=upper_bound; i++) 
+		manager_result_out[base_offset+i] = local_sum[i];
+}	
+
+void execute_workload_fft (int lower_bound, int upper_bound) {
+	int work_id = 0, pad_length = PADLENGTH;
+	
+	if ((lower_bound == 0) && (upper_bound == FFT_MAX)) {
+		P = 1;
+	}	else {
+		P = 2;
+	}	
+	
+	/* FIXME works only because fft is restricted to two workers */
+	if (lower_bound > 0) {
+		work_id = 1;
+	}	
+	
+	FFT1D(1, M, N, x_local, trans, upriv, umain2, work_id, lower_bound, upper_bound, pad_length, P); //HACK node_id - 1 important!!
+}
+
+void execute_workload (int lower_bound, int upper_bound) {
+	
+	if (executed_app == MATRIX_MUL) {
+		execute_workload_matrix (lower_bound, upper_bound);
+	} else if (executed_app == SVM) {
+		execute_workload_svm (lower_bound, upper_bound);			
+	}	else if (executed_app == FFT) {
+		execute_workload_fft (lower_bound, upper_bound);
+	}
+
+}
+
+void init_speedup_structs (void) {
+	
+	if (executed_app == MATRIX_MUL) {
+		if (MATRIX_ARRAY_SIZE == 1024) {
+#ifdef PLAT_SCC	
+			Exec_Speedup[0] = 1.0;
+			Exec_Speedup[1] = 1.188;
+			Exec_Speedup[2] = 2.264;
+			Exec_Speedup[3] = 3.0;
+			Exec_Speedup[4] = 3.429;
+			Exec_Speedup[5] = 4.0;
+			Exec_Speedup[6] = 8.0;
+			Exec_Speedup[7] = 0.0;
+			
+			Exec_Latencies[0] = 120;//29352;
+			Exec_Latencies[1] = 101;//15112;
+			Exec_Latencies[2] = 53;//11194;
+			Exec_Latencies[3] = 40;//10313;
+			Exec_Latencies[4] = 35;//8645;
+			Exec_Latencies[5] = 30;//7871;
+			Exec_Latencies[6] = 15;//6715;
+#else
+			Exec_Speedup[0] = 1.0;
+			Exec_Speedup[1] = 1.065;
+			Exec_Speedup[2] = 1.270;
+			Exec_Speedup[3] = 0.0;
+			Exec_Speedup[4] = 0.0;
+			Exec_Speedup[5] = 0.0;
+			Exec_Speedup[6] = 0.0;
+			Exec_Speedup[7] = 0.0;
+			
+			Exec_Latencies[0] = 100000000;//29352;
+			Exec_Latencies[1] = 31;//15112;
+			Exec_Latencies[2] = 29;//11194;
+			Exec_Latencies[3] = 24;//10313;
+			Exec_Latencies[4] = 0;//8645;
+			Exec_Latencies[5] = 0;//7871;
+			Exec_Latencies[6] = 0;//6715;
+			Exec_Latencies[7] = 0;//7014;
+#endif
+		} else if (MATRIX_ARRAY_SIZE == 2048) {
+#ifdef PLAT_SCC				
+			Exec_Speedup[0] = 1.0;
+			Exec_Speedup[1] = 1.091;
+			Exec_Speedup[2] = 1.2;
+			Exec_Speedup[3] = 1.491;
+			Exec_Speedup[4] = 1.791;
+			Exec_Speedup[5] = 2.824;
+			Exec_Speedup[6] = 3.0;
+
+			Exec_Latencies[0] = 240;//112276;
+			Exec_Latencies[1] = 220;//58880;
+			Exec_Latencies[2] = 200;//40305;
+			Exec_Latencies[3] = 161;//31705;
+			Exec_Latencies[4] = 134;//28309;
+			Exec_Latencies[5] = 85;//24512;
+			Exec_Latencies[6] = 80;//22239;
+			//matr_times[1][7] = 23;//20332;
+
+#else
+			Exec_Speedup[0] = 1.0;
+			Exec_Speedup[1] = 1.331;
+			Exec_Speedup[2] = 2.009;
+			Exec_Speedup[3] = 2.315;
+			Exec_Speedup[4] = 2.572;
+			Exec_Speedup[5] = 0.0;
+			Exec_Speedup[6] = 0.0;
+			Exec_Speedup[7] = 0.0;//5.522;
+
+			Exec_Latencies[0] = 100000000;//112276;
+			Exec_Latencies[1] = 116;//58880;
+			Exec_Latencies[2] = 87;//40305;
+			Exec_Latencies[3] = 58;//31705;
+			Exec_Latencies[4] = 50;//28309;
+			Exec_Latencies[5] = 45;//24512;
+			Exec_Latencies[6] = 0;//22239;
+			Exec_Latencies[7] = 0;//20332;
+#endif
+		} else if (MATRIX_ARRAY_SIZE == 4096) {
+#ifdef PLAT_SCC		
+			Exec_Speedup[0] = 1.0;
+			Exec_Speedup[1] = 2.001;
+			Exec_Speedup[2] = 2.976;
+			Exec_Speedup[3] = 4.032;
+			Exec_Speedup[4] = 5.034;
+			Exec_Speedup[5] = 6.25;
+			Exec_Speedup[6] = 6.678;
+			Exec_Speedup[7] = 6.819;
+
+			Exec_Latencies[0] = 750;//384005;
+			Exec_Latencies[1] = 374;//231583;
+			Exec_Latencies[2] = 252;//157966;
+			Exec_Latencies[3] = 186;//121222;
+			Exec_Latencies[4] = 149;//101208;
+			Exec_Latencies[5] = 120;//87852;
+			Exec_Latencies[6] = 110;//78093;
+#else 
+			Exec_Speedup[0] = 1.0;
+			Exec_Speedup[1] = 1.517;
+			Exec_Speedup[2] = 1.958;
+			Exec_Speedup[3] = 2.112;
+			Exec_Speedup[4] = 2.878;
+			Exec_Speedup[5] = 3.338;
+			Exec_Speedup[6] = 4.241;
+			Exec_Speedup[7] = 0.0;//5.073;
+						
+			Exec_Latencies[0] = 100000000;//384005;
+			Exec_Latencies[1] = 431;//231583;
+			Exec_Latencies[2] = 284;//157966;
+			Exec_Latencies[3] = 220;//121222;
+			Exec_Latencies[4] = 204;//101208;
+			Exec_Latencies[5] = 150;//87852;
+			Exec_Latencies[6] = 129;//78093;
+			Exec_Latencies[7] = 102;//75690;
+#endif
+		} else {
+			printf("Unknown array size\n");
+			exit(0);	
+		}
+	} else if (executed_app == SVM) {
+		Exec_Speedup[0] = 1.0; /* 1 worker */
+		Exec_Speedup[1] = 2.006;
+		Exec_Speedup[2] = 2.814;
+		Exec_Speedup[3] = 3.469;
+		Exec_Speedup[4] = 4.029;
+		Exec_Speedup[5] = 4.285;
+		Exec_Speedup[6] = 4.646;
+		Exec_Speedup[7] = 0.0;
+		
+		Exec_Latencies[0] = 28;
+		Exec_Latencies[1] = 14;
+		Exec_Latencies[2] = 10;
+		Exec_Latencies[3] = 8;
+		Exec_Latencies[4] = 7;
+		Exec_Latencies[5] = 7;
+		Exec_Latencies[6] = 6;
+		Exec_Latencies[7] = 6;
+	} else if (executed_app == FFT) {
+		Exec_Speedup[0] = 1.0; /* 1 worker */
+		Exec_Speedup[1] = 1.55;
+		Exec_Speedup[2] = 0;
+		Exec_Speedup[3] = 0;
+		Exec_Speedup[4] = 0;
+		Exec_Speedup[5] = 0;
+		Exec_Speedup[6] = 0;
+		Exec_Speedup[7] = 0;
+		
+		Exec_Latencies[0] = 772;
+		Exec_Latencies[1] = 498;
+		Exec_Latencies[2] = 0;
+		Exec_Latencies[3] = 0;
+		Exec_Latencies[4] = 0;
+		Exec_Latencies[5] = 0;
+		Exec_Latencies[6] = 0;
+		Exec_Latencies[7] = 0;
+	}	
+}
+
+void app_init (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]) {
+	int i, j, pad_length = PADLENGTH;
+	char buf[MAX_STR_NAME_SIZE], *buffer;
+	FILE *matrix_input, *support_vectors_file, *coef_file, *umain_file, *umain2_file, *x_local_file;
+	size_t bufsize = 32;
+	
+	if (executed_app == MATRIX_MUL) {
+		cur_agent.array_size = MATRIX_ARRAY_SIZE;
+		matrix = (int **) malloc(cur_agent.array_size * sizeof(int *));
+		#ifdef PLAT_SCC
+		strcpy(buf, "/shared/herc/");
+		#else
+		strcpy(buf, "../");
+		#endif
+		strcat(buf, scen_directory);
+		strcat(buf, "/MATRIX-inputs/");
+		strcat(buf, itoa(cur_agent.array_size));
+		fprintf(log_file,"matrix file path = %s\n",buf);
+
+		if ((matrix_input = fopen(buf, "r")) == NULL){
+					printf("Cannot open input file with file path = %s ",buf);
+					perror("open matrix_input");
+		}
+
+		for (i=0; i<cur_agent.array_size; i++) {
+			matrix[i] = (int *) malloc(cur_agent.array_size * sizeof(int));
+			for (j=0; j<cur_agent.array_size; j++) 
+				fscanf(matrix_input,"%d",&matrix[i][j]);
+		}
+
+		vector = (int *) malloc(cur_agent.array_size * sizeof(int));
+		for (j=0; j<cur_agent.array_size; j++) 
+			fscanf(matrix_input,"%d",&vector[j]);
+		
+		fclose(matrix_input);
+	} else if (executed_app == SVM) {
+		#ifdef PLAT_SCC
+		strcpy(buf, "/shared/herc/");
+		#else
+		strcpy(buf, "../");
+		#endif
+		strcat(buf,scen_directory);
+		//strcat(buf,"/");
+		//strcat(buf,scen_num);
+		strcat(buf,"/SVM-inputs/support_vectors_N_sv_");
+		strcat(buf,itoa(N_sv));
+		strcat(buf,"_D_sv_");
+		strcat(buf,itoa(D_sv));
+		strcat(buf,".dat");
+		fprintf(log_file,"svm file path = %s\n",buf);
+		
+		if ((support_vectors_file = fopen(buf,"r")) == NULL){
+			printf("Cannot open input file with file path = %s ",buf);
+			perror("open svm_input");
+		}
+		
+		#ifdef PLAT_SCC
+		strcpy(buf, "/shared/herc/");
+		#else
+		strcpy(buf, "../");
+		#endif
+		strcat(buf,scen_directory);
+		//strcat(buf,"/");
+		//strcat(buf,scen_num);
+		strcat(buf,"/SVM-inputs/sv_coef_N_sv_");
+		strcat(buf,itoa(N_sv));
+                strcat(buf,"_D_sv_");
+                strcat(buf,itoa(D_sv));
+                strcat(buf,".dat");
+		fprintf(log_file,"svm_coef file path = %s\n",buf);
+		
+		if ((coef_file = fopen(buf,"r")) == NULL){
+			printf("Cannot open input file with file path = %s ",buf);
+			perror("open svm_input");
+		}
+		
+		cur_agent.array_size = N_sv;
+		svm_vectors = (float **)malloc((D_sv)*sizeof(float *));
+		if (svm_vectors == NULL){
+			printf("--%d-- svm_vectors malloc fail!!\n", node_id);
+			perror("malloc error");
+		}
+		svm_coef = (float *)malloc((cur_agent.array_size)*sizeof(float));
+		if (svm_coef == NULL){
+			printf("--%d-- svm_coef malloc fail!!\n", node_id);
+			perror("malloc error");
+		}
+		
+		buffer = (char *)malloc(bufsize * sizeof(char));
+		for (i = 0; i < D_sv; i++) {
+			svm_vectors[i] = (float *)malloc((cur_agent.array_size)*sizeof(float));
+			if (svm_vectors[i] == NULL) {
+				printf("--%d-- svm_vectors[%d] malloc fail!!\n", node_id, i);
+				perror("malloc error");
+			} else {
+				for (j = 0; j < N_sv; j++) {
+					/* Read support svm_vectors */
+					if (j < cur_agent.array_size){
+						fscanf(support_vectors_file,"%f",&svm_vectors[i][j]);
+						fgetc(support_vectors_file);
+					}else{
+						getline(&buffer,&bufsize,support_vectors_file);
+					}
+				}
+			}
+		}
+
+		for (j = 0; j < N_sv; j++) {
+                	/* Read coefficients */
+                        fscanf(coef_file,"%f",&svm_coef[j]);
+                        fgetc(coef_file);
+                }
+
+		cur_agent.array_size = -1;
+		fclose(support_vectors_file);
+		fclose(coef_file);
+		free(buffer);
+	}	else if (executed_app == FFT) {
+		fprintf(log_file,"Initializing FFT application\n");
+		
+		x_local = (float *)malloc(2*(N+rootN*pad_length)*sizeof(float)+PAGE_SIZE);
+		if (x_local == NULL){
+			printf("Malloc error for x_local\n");
+			perror("malloc error");
+			exit(-1);
+		}
+		
+		trans = (float *)malloc(2*(N+rootN*pad_length)*sizeof(float)+PAGE_SIZE);
+		if (trans == NULL){
+			printf("Malloc error for trans\n");
+			perror("malloc error");
+			exit(-1);
+		}
+		
+		umain = (float *)malloc(2*rootN*sizeof(float));  
+		if (umain == NULL){
+			printf("Malloc error for umain\n");
+			perror("malloc error");
+			exit(-1);
+		}
+		
+		umain2 = (float *)malloc(2*(N+rootN*pad_length)*sizeof(float)+PAGE_SIZE);
+		if (umain2 == NULL){
+			printf("Malloc error for umain2\n");
+			perror("malloc error");
+			exit(-1);
+		}
+		
+		upriv = (float *)malloc(2*(rootN-1)*sizeof(float));
+		if (upriv == NULL){
+			printf("--%d-- Malloc error for upriv\n", node_id);
+			perror("malloc error");
+			exit(-1); 
+		}
+				
+		#ifdef PLAT_SCC
+		strcpy(buf, "/shared/herc/");
+		#else
+		strcpy(buf, "../");
+		#endif
+		strcat(buf,scen_directory);
+		//strcat(buf,"/");
+		//strcat(buf,scen_num);
+		strcat(buf,"/FFT-inputs/umain_file");
+		fprintf(log_file,"umain_file file path = %s\n",buf);
+		
+		if ((umain_file = fopen(buf,"r")) == NULL){
+					printf("Cannot open input file with file path = %s ",buf);
+					perror("open fft_input");
+		}
+		
+		for (i=0; i<2*rootN; i++) {
+			fscanf(umain_file,"%f",&umain[i]);
+		}
+		fclose(umain_file);
+		
+		#ifdef PLAT_SCC
+		strcpy(buf, "/shared/herc/");
+		#else
+		strcpy(buf, "../");
+		#endif
+		strcat(buf,scen_directory);
+		//strcat(buf,"/");
+		//strcat(buf,scen_num);
+		strcat(buf,"/FFT-inputs/umain2_file");
+		fprintf(log_file,"umain2_file file path = %s\n",buf);
+		
+		if ((umain2_file = fopen(buf,"r")) == NULL){
+					printf("Cannot open input file with file path = %s ",buf);
+					perror("open umain_file");
+		}
+		
+		//for (i=0; i<2*(N+rootN*pad_length)+PAGE_SIZE; i++) {
+		for (i=0; i<2*(N+rootN*pad_length); i++) {
+			fscanf(umain2_file,"%f",&umain2[i]);
+		}
+		fclose(umain2_file);
+		
+		#ifdef PLAT_SCC
+		strcpy(buf, "/shared/herc/");
+		#else
+		strcpy(buf, "../");
+		#endif
+		strcat(buf,scen_directory);
+		//strcat(buf,"/");
+		//strcat(buf,scen_num);
+		strcat(buf,"/FFT-inputs/x_local_file");
+		fprintf(log_file,"x_local_file file path = %s\n",buf);
+		
+		if ((x_local_file = fopen(buf,"r")) == NULL){
+					printf("Cannot open input file with file path = %s ",buf);
+					perror("open x_local_file");
+		}
+		
+		//for (i=0;i<2*(N+rootN*pad_length)+PAGE_SIZE;i++) {
+		for (i=0; i<2*(N+rootN*pad_length); i++) {
+			fscanf(x_local_file,"%f",&x_local[i]);
+		}
+		fclose(x_local_file);
+		
+		for (i = 0; i < 2*(rootN-1); i++){
+			upriv[i] = umain[i];
+		}
+		
+	}	
+}
+
+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	
+	if (executed_app == FFT) {
+		return 3;
+	}	else {
+		return MAX_WORKERS_COUNT;
+	}
+#endif	
+}
+
+float Speedup(app cur_app, int num_of_cores) {
+	/*
+	int type;
+	
+	if (cur_app.array_size == 1024) type = 0;
+	else if (cur_app.array_size == 2048) type = 1;
+	else if (cur_app.array_size == 4096) type = 2;
+	else {
+		fprintf(log_file, "Unknown array size = %d\n",cur_app.array_size);
+		fflush(log_file);
+		return 0.0;
+	}
+
+	return matr_speedup[type][num_of_cores-1];
+	*/
+	if (num_of_cores > get_max_cores_count(cur_app)) {
+                return 0;
+        } else {
+		return Exec_Speedup[num_of_cores-2];
+	}
+}
+
+int get_times(app cur_app, int num_of_cores) {
+	/*
+	int type;
+
+	if (cur_app.array_size == 1024) type = 0;
+	else if (cur_app.array_size == 2048) type = 1;
+	else if (cur_app.array_size == 4096) type = 2;
+	else {
+		fprintf(log_file, "Unknown array size = %d\n",cur_app.array_size);
+		fflush(log_file);
+		return 0.0;
+	}
+	return (cur_app.workld * matr_times[type][num_of_cores-2]);
+	*/
+	return (cur_app.workld * Exec_Latencies[num_of_cores-2]);
+}
+
+void matrix_transpose(int n1, float *src, float *dest, int node_id, int myFirst, int myLast, int pad_length){
+	int i; 
+	int j; 
+	int k; 
+	int l; 
+	int m;
+	int blksize;
+	int numblks;
+	int firstfirst;
+	int h_off;
+	int v_off;
+	int v;
+	int h;
+	int n1p;
+	int row_count;
+
+	//fprintf(log_file,"I am inside matrix_transpose-0 node_id is %d n1 %d\n",node_id,n1);
+	blksize = myLast-myFirst;
+	numblks = (2*blksize)/num_cache_lines;
+	if (numblks * num_cache_lines != 2 * blksize) {
+		numblks ++;
+	}
+	blksize = blksize / numblks;
+	firstfirst = myFirst;
+	row_count = n1/P;
+	n1p = n1+pad_length;
+	for (l=node_id+1;l<P;l++) {
+		v_off = l*row_count;
+		for (k=0; k<numblks; k++) {
+			h_off = firstfirst;
+			for (m=0; m<numblks; m++) {
+				for (i=0; i<blksize; i++) {
+					v = v_off + i;
+					for (j=0; j<blksize; j++) {
+						h = h_off + j;
+						//fprintf(log_file,"Index dest is %d\n",2*(h*n1p+v));
+						//fprintf(log_file,"Index src is %d\n",2*(v*n1p+h));
+						//fprintf(log_file,"src = %f\n",src[2*(v*n1p+h)]);
+						//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");
+					}
+				}
+				h_off += blksize;
+			}
+			v_off+=blksize;
+		}
+	}
+	//fprintf(log_file,"I am inside matrix_transpose-A\n");
+	
+	for (l=0;l<node_id;l++) {
+		v_off = l*row_count;
+		for (k=0; k<numblks; k++) {
+			h_off = firstfirst;
+			for (m=0; m<numblks; m++) {
+				for (i=0; i<blksize; i++) {
+					v = v_off + i;
+					for (j=0; j<blksize; j++) {
+						h = h_off + j;
+						dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
+						dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
+					}
+				}
+				h_off += blksize;
+			}
+			v_off+=blksize;
+		}
+	}
+	//fprintf(log_file,"I am inside matrix_transpose-B\n");
+	
+	v_off = node_id*row_count;
+	for (k=0; k<numblks; k++) {
+		h_off = firstfirst;
+		for (m=0; m<numblks; m++) {
+			for (i=0; i<blksize; i++) {
+				v = v_off + i;
+				for (j=0; j<blksize; j++) {
+				  h = h_off + j;
+				  dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
+				  dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
+				}
+			}
+			h_off += blksize;
+		}
+		v_off+=blksize;
+	}
+	//fprintf(log_file,"I am inside matrix_transpose-C\n");
+}
+
+//FFT1D(1, M, N, x_local, trans, upriv, umain2, work_id, lower_bound, upper_bound, pad_length, P);
+void FFT1D(int direction, int M, int N, float *x, float *scratch, float *upriv, float *umain2, int node_id, int myFirst, int myLast, int pad_length, int P){
+	int j, m1, n1;
+	
+	printf("I am %d and I am inside FFT1D\n",node_id);
+	//fprintf(log_file,"I am inside FFT1D-A myFirst=%d myLast=%d\n",myFirst,myLast);
+	
+	m1 = M/2;
+	n1  = 1 << m1;
+	
+	matrix_transpose(n1, x, scratch, node_id, myFirst, myLast, pad_length);
+	//fprintf(log_file,"I am inside FFT1D-B\n");
+	
+	/* do n1 1D FFTs on columns */	
+	for (j = myFirst; j < myLast; j++){
+		single_FFT1D(direction, m1, n1, upriv, &scratch[2*j*(n1+pad_length)]);
+		twiddle_Col(direction, n1, N, j, umain2, &scratch[2*j*(n1+pad_length)],pad_length);
+	}
+	//fprintf(log_file,"I am inside FFT1D-C\n");
+	
+	matrix_transpose(n1, scratch, x, node_id, myFirst, myLast, pad_length);
+	//fprintf(log_file,"I am inside FFT1D-D\n");
+	
+	/* do n1 1D FFTs on columns again */
+	for (j = myFirst; j < myLast; j++) {
+		single_FFT1D(direction, m1, n1, upriv, &x[2*j*(n1+pad_length)]);
+	}
+	//fprintf(log_file,"I am inside FFT1D-E\n");
+	
+	matrix_transpose(n1, x, scratch, node_id, myFirst, myLast, pad_length);
+	//fprintf(log_file,"I am inside FFT1D-F\n");
+	/*for (j = myFirst; j < myLast; j++){
+		copyColumn(n1, &scratch[2*j*(n1+pad_length)], &x_shared[2*j*(n1+pad_length)]);
+	}*/
+	
+	return;
+
+}
+
+void copyColumn(int n1, float *src, float *dest){
+      
+	int i;
+
+	for (i = 0; i < n1; i++) {
+		dest[2*i] = src[2*i];
+		dest[2*i+1] = src[2*i+1];
+	}
+}
+
+void single_FFT1D(int direction, int M, int N, float *u, float *x){
+	
+	int j, k, q, L, r, Lstar;
+	float *u1, *x1, *x2;
+	float omega_r, omega_c, tau_r, tau_c, x_r, x_c;
+	
+	reverse(N, M, x);
+	
+	for (q=1; q<=M; q++) {
+		L = 1<<q; r = N/L; Lstar = L/2;
+		u1 = &u[2*(Lstar-1)];
+		for (k=0; k<r; k++) {
+			x1 = &x[2*(k*L)];
+			x2 = &x[2*(k*L+Lstar)];
+			for (j=0; j<Lstar; j++) {
+				omega_r = u1[2*j]; 
+				omega_c = direction*u1[2*j+1];
+				x_r = x2[2*j]; 
+				x_c = x2[2*j+1];
+				tau_r = omega_r*x_r - omega_c*x_c;
+				tau_c = omega_r*x_c + omega_c*x_r;
+				x_r = x1[2*j]; 
+				x_c = x1[2*j+1];
+				x2[2*j] = x_r - tau_r;
+				x2[2*j+1] = x_c - tau_c;
+				x1[2*j] = x_r + tau_r;
+				x1[2*j+1] = x_c + tau_c;
+			}
+		}
+	}
+	
+	return;
+}
+
+void twiddle_Col(int direction, int n1, int N, int j, float *u, float *x, int pad_length){
+ 
+	int i;
+	float omega_c, omega_r, x_r, x_c;
+	
+	for (i = 0; i < n1; i++) {
+		omega_r = u[2*(j*(n1+pad_length)+i)];
+		omega_c = direction*u[2*(j*(n1+pad_length)+i)+1];  
+		x_r = x[2*i]; 
+		x_c = x[2*i+1];
+		x[2*i] = omega_r*x_r - omega_c*x_c;
+		x[2*i+1] = omega_r*x_c + omega_c*x_r;
+	}
+	
+	return;
+}
+
+void reverse(int N, int M, float *x){
+  
+	int j, k;
+	
+	for (k = 0; k < N; k++){
+		j = reverse_bit(M, k);
+		if (j > k){
+		      SWAP(x[2*j], x[2*k]);
+		      SWAP(x[2*j+1], x[2*k+1]);  
+		}
+	}
+	
+	return;
+}
+
+int reverse_bit(int M, int k){
+	
+	int i, j = 0, tmp = k;
+	
+	for (i = 0; i < M; i++){
+		j = 2*j + (tmp&0x1);
+		tmp = tmp >> 1;
+	}
+	
+	return j;
+}

Fichier diff supprimé car celui-ci est trop grand
+ 1178 - 0
apps.c


+ 20 - 0
apps.h

@@ -0,0 +1,20 @@
+#ifndef __APPS_H__
+#define __APPS_H__
+
+#include "variables.h"
+
+#define MATRIX_ARRAY_SIZE 4096
+#define FFT_ARRAY_SIZE 256 
+#define N_sv 4096
+#define D_sv 4096
+#define gamma 0.12
+#define SVM_ARRAY_SIZE N_sv
+
+void init_speedup_structs (void);
+void app_init (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]);
+void execute_workload (int lower_bound, int upper_bound);
+int get_max_cores_count(app cur_app);
+int get_times(app cur_app, int num_of_cores);
+float Speedup(app cur_app, int num_of_cores);
+
+#endif

Fichier diff supprimé car celui-ci est trop grand
+ 1439 - 0
common_core.c


+ 8 - 0
common_core.h

@@ -0,0 +1,8 @@
+#ifndef __COMMON_NODE_H__
+#define __COMMON_NODE_H__
+
+#include "variables.h"
+void common_node_actions(char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]);
+void my_settimer(int msec);
+int my_gettimer(void);
+#endif

+ 360 - 0
controller_core.c

@@ -0,0 +1,360 @@
+#include <sys/wait.h>
+
+#include "controller_core.h"
+#include "my_rtrm.h"
+#include "libfunctions.h"
+#include "noc_functions.h"
+#include "sig_aux.h"
+#include "common_core.h"
+#include "signal_handlers.h"
+#include "scc_signals.h"
+#include "idag_defs.h"
+#include "structs.h"
+#include "variables.h"
+
+void idle_agent_actions(char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]){
+	int i, one_core; 
+	pid_t p;
+	core_list *tmp_cores_list;
+	inter_list tmp_inter_list;
+	float avg_cluster_util;
+	int init_delay_sec;
+	
+	
+	printf("I an idag with node_id = %d, pid = %d paxos_state = %s\n",node_id,getpid(),id2string(paxos_state));
+	if (paxos_state == NEW_IDAG){
+		fprintf(log_file,"I an idag with node_id = %d, pid = %d\n",node_id,getpid());
+	}
+	
+	if (paxos_state != NEW_IDAG)
+	{
+	  
+		its.it_value.tv_sec = 0;
+		its.it_interval.tv_sec = 0;//its.it_value.tv_sec;
+		its.it_interval.tv_nsec = 0;
+		nodes_initialised=0;
+		
+		index_bottom[node_id] = 0;
+
+		#ifdef PLAT_LINUX
+		for (i=(node_id * MAX_SIGNAL_LIST_LEN * LINE_SIZE); i<((node_id + 1) * MAX_SIGNAL_LIST_LEN * LINE_SIZE); i++) {
+				sig_array[i] = NO_SIG;
+		}
+
+		//semaphore inits
+		if (sem_init(&scc_lock[node_id], 1, 1) == -1){
+			printf("I am %d error\n",node_id);
+			perror("sem_init");
+		}
+
+		if (sem_init(&flag_data_written[node_id], 1, 0) == -1){
+			printf("I am %d error\n",node_id);
+			perror("sem_init");
+		}
+		#endif
+
+		install_signal_handlers();
+		#ifdef PLAT_LINUX
+		sig_SEGV_enable();
+		#endif
+
+		sev.sigev_notify = SIGEV_SIGNAL;
+		sev.sigev_signo = SIG_TIMER;
+		sev.sigev_value.sival_ptr = &timerid;
+		if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) printf("timer_create error\n");	  
+	  
+		DDS_count=0;
+		my_cores_count=0;
+		DDS=NULL;
+		my_cores=NULL;
+		
+		if (my_cores == NULL) {
+			my_cores = (core_list *) malloc(sizeof(core_list));
+			my_cores_tail = my_cores;
+		}
+		
+		my_cores_count++;
+		my_cores_tail->core_id = node_id;
+		my_cores_tail->offered_to = -1;
+		my_cores_tail->next = NULL;
+		
+		DDS = (DDS_list *) malloc(sizeof(DDS_list));
+		DDS->agent_id = node_id;
+		DDS->next = NULL;
+		DDS_tail = DDS;
+		DDS_count++;
+		for (i = 0; i < NUES; i++)
+			if (i != node_id && idag_mask[i] == node_id) {
+				if (my_cores == NULL) {
+					my_cores = (core_list *) malloc(sizeof(core_list));
+					my_cores_tail = my_cores;
+				} else {
+					my_cores_tail->next = (core_list *) malloc(sizeof(core_list));
+					my_cores_tail = my_cores_tail->next;
+				}
+
+				my_cores_count++;
+				my_cores_tail->core_id = i;
+				my_cores_tail->offered_to = -1;
+				my_cores_tail->next = NULL;
+				#ifdef PLAT_LINUX
+				/* 7.12.2015 I have to create new children only if i am initial IDAG */
+				p = fork();
+				if (p==0){
+					node_id = i;
+					common_node_actions(scen_directory, scen_num);
+				}
+					
+				#endif
+			}
+
+		DDS->num_of_cores = my_cores_count;
+		
+		if (log_file == NULL){
+			log_file = create_log_file(node_id, 0, scen_directory, scen_num);
+			setbuf(log_file, NULL);
+		}
+
+		fprintf(log_file,"my pid is %d\n",getpid());
+		cur_time = time(NULL);
+		cur_t = localtime(&cur_time);
+		fprintf(log_file, "[%d:%d:%d]: I initialized node_id=%d\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,node_id);
+
+		alive = (int *)malloc(X_max*Y_max*sizeof(int));
+		suspected = (int *)malloc(X_max*Y_max*sizeof(int));
+		
+		for (i = 0; i < X_max*Y_max; i++){
+			alive[i] = 1;
+			suspected[i] = 0;
+		}
+		
+		#ifdef PLAT_SCC
+		RCCE_barrier(&RCCE_COMM_WORLD);
+		#else
+		sleep(1);
+		#endif
+		
+		for (tmp_cores_list = my_cores->next; tmp_cores_list != NULL; tmp_cores_list = tmp_cores_list->next) {
+		  
+			one_core = tmp_cores_list->core_id;
+			if (core_inter_head[one_core] == NULL){
+				core_inter_head[one_core] = (inter_list *) malloc(sizeof(inter_list));
+				core_inter_tail[one_core] = core_inter_head[one_core];
+			} else {
+				core_inter_tail[one_core]->next = (inter_list *) malloc(sizeof(inter_list));
+				core_inter_tail[one_core] = core_inter_tail[one_core]->next;
+			}
+
+			core_inter_tail[one_core]->type = INIT_CORE;
+			core_inter_tail[one_core]->next = NULL;
+			
+			//if (paxos_state != NEW_IDAG)
+			signals_disable();
+			scc_kill(one_core, SIG_INIT, core_inter_head[one_core]);
+			signals_enable();
+		}
+		
+		state = IDLE_IDAG;
+
+		while (nodes_initialised != my_cores_count-1) {
+			scc_pause();
+			scc_signals_check();
+		}
+
+#ifdef PLAT_SCC
+		RCCE_barrier(&RCCE_COMM_WORLD);
+		#else
+		sleep(1);
+		#endif
+		#if defined(EPFD) || defined(tEPFD)
+		sev.sigev_notify = SIGEV_SIGNAL;
+		sev.sigev_signo = SIG_EPFD_TIMER;
+		sev.sigev_value.sival_ptr = &epfd_timer;
+		if (timer_create(CLOCK_REALTIME, &sev, &epfd_timer) == -1)
+			printf("timer_create error\n");
+		else
+			fprintf(log_file,"I succesfully created epfd_timer\n");
+		#endif
+			
+		#if defined(PFD) || defined(tPFD)
+		sev.sigev_notify = SIGEV_SIGNAL;
+		sev.sigev_signo = SIG_PFD_TIMER;
+		sev.sigev_value.sival_ptr = &pfd_timer;
+		if (timer_create(CLOCK_REALTIME, &sev, &pfd_timer) == -1)
+			printf("timer_create error\n");
+		else
+			fprintf(log_file,"I succesfully created pfd_timer\n");
+		#endif
+		if (node_id < 10){
+			init_delay_sec = node_id;
+		}else if (node_id < 100){
+			init_delay_sec = node_id%10;
+		}else{
+			init_delay_sec = node_id%100;
+		}
+		#if defined(EPFD) || defined(tEPFD)
+		its.it_interval.tv_sec = 0;
+		its.it_interval.tv_nsec = 0;
+		its.it_value.tv_sec = init_delay_sec;
+		its.it_value.tv_nsec = 0;
+		if (timer_settime(epfd_timer, 0, &its, NULL) == -1) perror("timer_settime error9");
+		#endif
+
+		#if defined (PFD) || defined (tPFD)
+		its.it_interval.tv_sec = 0;
+		its.it_interval.tv_nsec = 0;
+		its.it_value.tv_sec = init_delay_sec;
+		its.it_value.tv_nsec = 0;
+		if (timer_settime(pfd_timer, 0, &its, NULL) == -1) perror("timer_settime error9");
+		#endif
+	}
+	
+	if (paxos_state == NEW_IDAG){
+		tmp_inter_list.type = RECOVERED;
+		scc_kill(10,SIG_RECOVER,&tmp_inter_list);
+		state = IDLE_IDAG;
+		pending_state = NO_PENDING_STATE;
+		paxos_state = NO_PENDING_STATE;
+		fprintf(log_file,"state : %s\n",id2string(state));
+	}
+	time_t t;
+	srand((unsigned) time(&t));
+	
+	#ifdef CONTROLLER
+	/* Scenario pou peftei o controller */
+	 if (timer_schedule[node_id] != 0){
+		timer_schedule[node_id] = 8 + rand() % 10;
+	   	sev.sigev_notify = SIGEV_SIGNAL;
+		sev.sigev_signo = SIG_CTIMER;
+		sev.sigev_value.sival_ptr = &controller_timer;
+		if (timer_create(CLOCK_REALTIME, &sev, &controller_timer) == -1)
+			 printf("timer_create error\n");
+		else
+			 printf("Controller Timer created succesfully!\n");
+		its.it_interval.tv_sec = 0;
+		its.it_interval.tv_nsec = 0;
+		
+		its.it_value.tv_sec = timer_schedule[node_id];
+		its.it_value.tv_nsec = 0;
+		if (timer_settime(controller_timer, 0, &its, NULL) == -1)
+			 perror("controller_core.c : timer_settime error9");
+		else
+			 printf("%d : My timer will explode in %d seconds.\n", node_id, timer_schedule[node_id]);
+	 }
+	 #endif
+
+	while (state != IDAG_ENDING)
+		if (state == IDLE_IDAG) {
+			scc_pause();
+			if (paxos_state == NEW_IDAG){
+				fprintf(log_file, "I will check for signals now!\n");
+				fflush(log_file);
+			}
+			scc_signals_check();
+		} else {
+			printf("idle_agent.c : Uknown state node_id = %d state = %s\n",node_id,id2string(state));
+			state = IDLE_IDAG;
+	}
+	
+	//inter_list tmp_inter_list;
+	
+	tmp_cores_list = my_cores;
+	my_cores = my_cores->next;
+	free(tmp_cores_list);
+	for (; my_cores != NULL; my_cores = my_cores->next){
+		tmp_cores_list = my_cores;
+		one_core = my_cores->core_id;
+		if (core_inter_head[one_core] == NULL) {
+			core_inter_head[one_core] = (inter_list *) malloc(sizeof(inter_list));
+			core_inter_tail[one_core] = core_inter_head[one_core];
+		} else {
+			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);
+		}
+
+		core_inter_tail[one_core]->type = TERMINATION_STATS;
+		core_inter_tail[one_core]->next = NULL;
+		//kill(pid_num[one_core], SIG_TERMINATE);
+		//signals_disable();
+		scc_kill(one_core, SIG_TERMINATE, core_inter_head[one_core]);
+		
+		/* 8.7.2016 Paxos Stats */
+		tmp_inter_list.next = NULL;
+		tmp_inter_list.type = PAXOS_STATS_REQ;
+		scc_kill(one_core, SIG_PAXOS_STATS_REQ, &tmp_inter_list);
+		paxos_node_stats.msg_count++;
+		paxos_node_stats.distance += distance(node_id,one_core);
+		
+		//signals_enable();
+		my_stats.msg_count++;
+		my_stats.distance += distance(node_id,one_core);
+
+		free(tmp_cores_list);
+	}
+
+	while (state == IDAG_ENDING) {
+		scc_pause();
+		scc_signals_check();
+
+		/* 8.7.2016 Paxos stats */
+		if (paxos_stats_replied == my_cores_count -1) {
+			tmp_inter_list.next = NULL;
+			tmp_inter_list.type = PAXOS_STATS_REP;
+			
+			paxos_total_stats.msg_count += paxos_node_stats.msg_count;
+			paxos_total_stats.distance += paxos_node_stats.distance;
+			
+			tmp_inter_list.data.paxos_stats[0] = paxos_total_stats.msg_count;
+			tmp_inter_list.data.paxos_stats[1] = paxos_total_stats.fd_msg_count;
+			scc_kill(idag_id_arr[0], SIG_PAXOS_STATS_REP, &tmp_inter_list);
+			paxos_stats_replied++;
+		}
+		
+		if (stats_replied == my_cores_count-1 && paxos_stats_replied == my_cores_count) {
+			//printf("I am %d and all my cores replied their stats\n",node_id);
+			core_inter_head[0] = (inter_list *) malloc(sizeof(inter_list));
+			core_inter_tail[0] = core_inter_head[0];
+		
+			core_inter_tail[0]->type = REP_STATISTICS;
+			core_inter_tail[0]->next = NULL;
+
+			total_stats.msg_count += my_stats.msg_count;
+			total_stats.message_size += my_stats.message_size;
+			total_stats.distance += my_stats.distance; 
+			total_stats.app_turnaround += my_stats.app_turnaround;
+			total_stats.comp_effort += my_stats.comp_effort;
+			total_stats.cores_utilized += my_stats.cores_utilized;
+			total_stats.times_accessed += my_stats.times_accessed;
+
+			avg_cluster_util = (float) my_stats.cores_utilized / (my_stats.times_accessed * (my_cores_count-1));
+			printf("I am %d with cores_utilized = %d times_accessed = %d my_cores_count = %d and avg_cluster_util = %0.2f\n",
+				node_id,my_stats.cores_utilized,my_stats.times_accessed,my_cores_count,avg_cluster_util);
+ 			fprintf(log_file,"cores_utilized = %d times_accessed = %d my_cores_count = %d and avg_cluster_util = %0.2f\n",
+				my_stats.cores_utilized,my_stats.times_accessed,my_cores_count,avg_cluster_util);
+
+			core_inter_tail[0]->data.stats = total_stats;
+			//kill(pid_num[0], SIG_TERMINATE);
+			signals_disable();
+			scc_kill(idag_id_arr[0], SIG_TERMINATE, core_inter_head[0]);
+			signals_enable();
+			stats_replied++;
+			//my_cores_count = 0;
+		}
+	}
+	
+	#ifdef PLAT_SCC
+	RCCE_flag_free(&flag_data_written);
+	RCCE_free((t_vcharp) sig_array);
+	RCCE_free((t_vcharp) data_array);
+	#else
+	for (i=0; i<my_cores_count-1; i++) 
+		wait(NULL);  
+	#endif
+
+	cur_time = time(NULL);	
+	cur_t = localtime(&cur_time);
+	fprintf(log_file, "[%d:%d:%d]: I ended well\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec);	
+	fclose(log_file);
+	exit(0);
+}

+ 9 - 0
controller_core.h

@@ -0,0 +1,9 @@
+#ifndef __IDLE_AGENT_H__
+#define __IDLE_AGENT_H__
+
+#include "variables.h"
+
+void idle_agent_actions(char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]);
+
+
+#endif

+ 318 - 0
idag_defs.c

@@ -0,0 +1,318 @@
+#include "idag_defs.h"
+#include "variables.h"
+
+void global_idag_defs(void) {
+	#ifdef NO_ISLANDS
+	return;
+	#endif
+
+	#ifdef LOW_VOLTAGE_0
+	low_voltage_core[0] = 1;
+	low_voltage_core[1] = 1;
+	low_voltage_core[2] = 1;
+	low_voltage_core[3] = 1;
+	low_voltage_core[12] = 1;
+	low_voltage_core[13] = 1;
+	low_voltage_core[14] = 1;
+	low_voltage_core[15] = 1;
+	#endif
+	
+	#ifdef LOW_VOLTAGE_1
+	low_voltage_core[4] = 1;
+	low_voltage_core[5] = 1;
+	low_voltage_core[6] = 1;
+	low_voltage_core[7] = 1;
+	low_voltage_core[16] = 1;
+	low_voltage_core[17] = 1;
+	low_voltage_core[18] = 1;
+	low_voltage_core[19] = 1;
+	#endif
+
+	#ifdef LOW_VOLTAGE_2
+	low_voltage_core[8] = 1;
+	low_voltage_core[9] = 1;
+	low_voltage_core[10] = 1;
+	low_voltage_core[11] = 1;
+	low_voltage_core[20] = 1;
+	low_voltage_core[21] = 1;
+	low_voltage_core[22] = 1;
+	low_voltage_core[23] = 1;
+	#endif
+
+	#ifdef LOW_VOLTAGE_3
+	low_voltage_core[24] = 1;
+	low_voltage_core[25] = 1;
+	low_voltage_core[26] = 1;
+	low_voltage_core[27] = 1;
+	low_voltage_core[36] = 1;
+	low_voltage_core[37] = 1;
+	low_voltage_core[38] = 1;
+	low_voltage_core[39] = 1;
+	#endif
+
+	#ifdef LOW_VOLTAGE_4
+	low_voltage_core[28] = 1;
+	low_voltage_core[29] = 1;
+	low_voltage_core[30] = 1;
+	low_voltage_core[31] = 1;
+	low_voltage_core[40] = 1;
+	low_voltage_core[41] = 1;
+	low_voltage_core[42] = 1;
+	low_voltage_core[43] = 1;
+	#endif
+
+	#ifdef LOW_VOLTAGE_5
+	low_voltage_core[32] = 1;
+	low_voltage_core[33] = 1;
+	low_voltage_core[34] = 1;
+	low_voltage_core[35] = 1;
+	low_voltage_core[44] = 1;
+	low_voltage_core[45] = 1;
+	low_voltage_core[46] = 1;
+	low_voltage_core[47] = 1;
+	#endif
+}
+
+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]) {
+	 int i, j, cnt, core_index, time;
+	 char paxos_path[MAX_STR_NAME_SIZE];
+	 FILE *paxos_conf_file;
+	 
+/* Simulating centralized approach. Controller core is 0 */    
+#ifdef SINGLE_IDAG
+	num_idags = 1;
+	idag_id_arr = (int *) malloc(num_idags * sizeof(int));
+	idag_id_arr[0] = 0;
+
+	for (i=0; i<X_max*Y_max; i++)
+		idag_mask[i] = 0;
+
+	num_idags_x = 1;
+#else  
+	char idag_defs_path[MAX_STR_NAME_SIZE]; 
+	FILE *idag_defs_file;
+
+#ifdef PLAT_SCC
+	strcpy(idag_defs_path, "/shared/herc/");
+#else
+	strcpy(idag_defs_path, "../");
+#endif
+	strcat(idag_defs_path, scen_directory);
+	strcat(idag_defs_path, "/");
+	strcat(idag_defs_path, scen_num);
+	strcat(idag_defs_path, "/idag_defs/");
+	strcat(idag_defs_path, idag_defs_file_name);
+
+	if (node_id == 0){
+		printf("Idag_defs_path = %s\n",idag_defs_path);
+		fflush(stdout); 
+	}
+
+	if ((idag_defs_file = fopen(idag_defs_path, "r")) == NULL){
+		printf("Cannot open input file with file path = %s ",idag_defs_path);
+		perror("open idag_defs_path");
+	}
+
+	fscanf(idag_defs_file, "%d", &num_idags);
+
+	idag_id_arr = (int *) malloc(num_idags * sizeof(int));
+
+	for (i=0; i<num_idags; i++)
+		fscanf(idag_defs_file, "%d", &idag_id_arr[i]);
+
+	for (i = X_max*Y_max - 2*X_max; i >= 0; i -= 2*X_max) {
+		for (j = i; j < i+2*X_max-1; j+=2){
+			//printf("%d | ",j+1);
+			fscanf(idag_defs_file, "%d", &idag_mask[j+1]);
+		}
+		//printf("\n");
+		for (j = i; j < i+2*X_max-1; j+=2){
+			//printf("%d | ",j);
+			fscanf(idag_defs_file, "%d", &idag_mask[j]);
+		}
+		//printf("\n");
+	}
+	for (i=0;i <X_max*Y_max; i++){
+		idag_mask[i] = idag_id_arr[idag_mask[i]];
+	 }
+
+	num_idags_x = num_idags / 2; /* FIXME deprecated, keeping for time being only for compatibility */
+#endif  
+
+	 /*dimos*/
+	 //fclose(idag_defs_file);
+#ifdef PLAT_SCC
+	 strcpy(paxos_path, "/shared/herc/");
+#else 
+	 strcpy(paxos_path, "../");
+#endif
+	 strcat(paxos_path, scen_directory);
+	 strcat(paxos_path, "/paxos/");
+	 strcat(paxos_path, paxos_scen);
+	 
+	 if ((paxos_conf_file = fopen(paxos_path, "r")) == NULL){
+	   printf("Cannot open input file with file path = %s\n ",paxos_path);
+	   perror("open paxos_path");
+	 }
+	 
+	 fscanf(paxos_conf_file,"%d", &cnt);
+	 
+	 for (i = 0; i < cnt; i++){
+		fscanf(paxos_conf_file,"%d", &core_index);
+		fscanf(paxos_conf_file,"%d", &time);
+		timer_schedule[idag_id_arr[core_index]] = time;
+	 }
+	 
+	 fclose(paxos_conf_file);
+    
+}
+
+void print_grid(){
+	int k,i,j;
+	for (i = 0; i < 4*X_max; i++) printf("%s=",KMAG);
+	printf("%s GRID ",KMAG);
+	for (i = 0; i < 4*X_max; i++) printf("%s=",KMAG);
+	printf("\n");
+	for (i = X_max*Y_max - 2*X_max; i >= 0; i -= 2*X_max){
+	     for (j = i; j < i+2*X_max-1; j+=2){
+		      for (k = 0; k < num_idags; k++){
+			      if (idag_mask[j+1] == idag_id_arr[k]){
+				      if (k == 0){
+					      printf("%s%d\t",KRED,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 1){
+					      printf("%s%d\t",KGRN,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 2){
+					      printf("%s%d\t",KBLU,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 3){
+					      printf("%s%d\t",KYEL,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 4){
+					      printf("%s%d\t",KMAG,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 5){
+					      printf("%s%d\t",KCYN,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 6){
+					      printf("%s%d\t",KWHT,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 7){
+					      printf("%s%d\t",KBLK,j+1);
+					      fflush(stdout);
+				      }
+			      }
+		      }
+	      }
+	      printf("\n");
+	      for (j = i; j < i+2*X_max-1; j+=2){
+		      for (k = 0; k < num_idags; k++){
+			      if (idag_mask[j] == idag_id_arr[k]){
+				      if (k == 0){
+					      printf("%s%d\t",KRED,j);
+					      fflush(stdout);
+				      }
+				      else if (k == 1){
+					      printf("%s%d\t",KGRN,j);
+					      fflush(stdout);
+				      }
+				      else if (k == 2){
+					      printf("%s%d\t",KBLU,j);
+					      fflush(stdout);
+				      }
+				      else if (k == 3){
+					      printf("%s%d\t",KYEL,j);
+					      fflush(stdout);
+				      }
+				      else if (k == 4){
+					      printf("%s%d\t",KMAG,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 5){
+					      printf("%s%d\t",KCYN,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 6){
+					      printf("%s%d\t",KWHT,j+1);
+					      fflush(stdout);
+				      }
+				      else if (k == 7){
+					      printf("%s%d\t",KBLK,j+1);
+					      fflush(stdout);
+				      }				      
+			      }
+		      }
+	      }		
+	      printf("%s\n",KNRM);
+	}
+	for (i = 0; i < 4*X_max; i++) printf("%s=",KMAG);
+	printf("%s GRID ",KMAG);
+	for (i = 0; i < 4*X_max; i++) printf("%s=",KMAG);
+	printf("%s\n",KNRM);
+}
+
+
+int is_core_idag (int core_id) {
+    int i, is_idag = 0;
+    
+    for (i=0; i<num_idags; i++)
+      if (idag_id_arr[i] == core_id) {
+	      is_idag = 1;
+	      break;
+      }
+      
+    return is_idag;  
+}
+
+int im_manager(){
+	if (state == IDLE_AGENT ||
+	    state == IDLE_AGENT_WAITING_OFF ||
+	    state == AGENT_INIT_STATE ||
+	    state == AGENT_ENDING ||
+	    state == AGENT_INIT_APP_INIT ||
+	    state == AGENT_INIT_CHK_OFFERS || 
+	    state == AGENT_SELF_OPT ||
+	    state == AGENT_SELF_CHK_OFFERS ||
+	    state == AGENT_ZOMBIE ||
+	    state == AGENT_INIT_APP_INIT ||
+	    state == AGENT_INIT_IDLE_INIT ||
+	    state == AGENT_ZOMBIE ||
+	    pending_state == IDLE_AGENT || 
+	    pending_state == IDLE_AGENT_WAITING_OFF || 
+	    pending_state == AGENT_INIT_STATE || 
+	    pending_state == AGENT_ENDING || 
+	    pending_state == AGENT_INIT_APP_INIT || 
+	    pending_state == AGENT_INIT_CHK_OFFERS || 
+	    pending_state == AGENT_SELF_OPT || 
+	    pending_state == AGENT_SELF_CHK_OFFERS || 
+	    pending_state == AGENT_ZOMBIE || 
+	    pending_state == AGENT_INIT_APP_INIT || 
+	    pending_state == AGENT_INIT_IDLE_INIT)
+	{
+		return 1;
+	}else{
+		return 0;
+	}
+}
+
+int im_worker(){
+	if (cur_agent.my_agent == -1)
+		return 0;
+	else
+		return 1;
+}
+
+int im_controller(){
+	if (my_idag == -1)
+		return 1;
+	else
+		return 0;
+}

+ 16 - 0
idag_defs.h

@@ -0,0 +1,16 @@
+#ifndef __IDAG_DEFS_H__
+#define __IDAG_DEFS_H__
+
+#include "my_rtrm.h"
+#include "variables.h"
+
+void global_idag_defs(void);
+int is_core_idag (int core_id);
+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]);
+void print_grid();
+int im_manager();
+int im_worker();
+int im_controller();
+void my_settimer(int msec);
+int my_gettimer(void);
+#endif

+ 363 - 0
libfunctions.c

@@ -0,0 +1,363 @@
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <signal.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdarg.h>
+
+#include "libfunctions.h"
+#include "my_rtrm.h"
+
+void handler_Enter(int sender_id, char *handler){
+  
+	cur_time = time(NULL);
+	cur_t = localtime(&cur_time);
+	
+	if (sender_id == -1){
+		fprintf(log_file, "\n\n[%d:%d:%d]: I entered %s with state = %s\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,handler,id2string(state));
+	}else{
+		fprintf(log_file, "\n\n[%d:%d:%d]: I entered %s with sender = %d state = %s\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,handler,sender_id,id2string(state));
+	}
+	return;
+}
+
+void handler_Exit(int sender_id, char *handler){
+
+	cur_time = time(NULL);
+	cur_t = localtime(&cur_time);
+	
+	if (sender_id == -1){
+		fprintf(log_file, "\n\n[%d:%d:%d]: I leave %s with state = %s\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,handler,id2string(state));
+	}else{
+		fprintf(log_file, "\n\n[%d:%d:%d]: I leave %s with sender = %d state = %s\n",cur_t->tm_hour,cur_t->tm_min,cur_t->tm_sec,handler,sender_id,id2string(state));
+	}
+	return;
+}
+/* pl4tinum 11.10.2016 */
+char * app_state_2_string(application_states state_id){
+	if (state_id == 0)
+		return "NO_APP";
+	else if (state_id == 1)
+		return "APP_TERMINATED";
+	else if (state_id == 2)
+		return "RUNNING";
+	else
+		return "RESIZING";
+}
+
+/* pl4tinum 11.10.2016 */
+char * id2string(core_states state_id){
+	if (state_id == 0)
+		return "IDLE_CORE";
+	else if (state_id == 1)
+		return "WORKING_NODE";
+	else if (state_id == 2)
+		return "TERMINATED";
+	else if (state_id == 3)
+	/* Controller States */
+		return "IDLE_IDAG";
+	else if (state_id == 4)
+		return "IDLE_IDAG_INIT_SEND";
+	else if (state_id == 5)
+		return "IDLE_CHK_APP_FILE";
+	else if (state_id == 6)
+		return "CHK_APP_FILE";
+	else if (state_id == 7)
+		return "USER_INPUT";
+	/* Initial core States */
+	else if (state_id == 8)
+		return "INIT_MANAGER";
+	else if (state_id == 9)
+		return "INIT_MANAGER_SEND_OFFERS";
+	else if (state_id == 10)
+		return "IDLE_INIT_MAN";
+	else if (state_id == 11)
+		return "INIT_MAN_CHK_OFFERS";
+	/* Manager States */
+	else if (state_id == 12)
+		return "IDLE_AGENT";
+	else if (state_id == 13)
+		return "IDLE_AGENT_WAITING_OFF";
+	else if (state_id == 14)
+		return "AGENT_INIT_STATE";
+	else if (state_id == 15)
+		return "AGENT_SELF_OPT";
+	else if (state_id == 16)
+		return "AGENT_SELF_CHK_OFFERS";
+	else if (state_id == 17)
+		return "AGENT_ENDING";
+	else if (state_id == 18)
+		return "IDAG_ENDING";
+	else if (state_id == 19)
+		return "NO_PENDING_STATE";
+	else if (state_id == 20)
+		return "AGENT_ZOMBIE";
+	/* Multiple Pending States */
+	else if (state_id == 21)
+		return "AGENT_INIT_APP_INIT";
+	else if (state_id == 22)
+		return "AGENT_INIT_CHK_OFFERS";
+	else if (state_id == 23)
+		return "AGENT_INIT_IDLE_INIT";
+	else if (state_id == 24)
+		return "IDLE_INIT_IDLE_AGENT";
+	else if (state_id == 25)
+		return "IDLE_INIT_AGENT_SELFOPT";
+	else if (state_id == 26)
+		return "INIT_CHK_OFFERS_IDLE_AGENT";
+	else if (state_id == 27)
+		return "INIT_CHK_OFFERS_SELFOPT";
+	else if (state_id == 28)
+		return "PAXOS_ACTIVE";
+	else if (state_id == 29)
+		return "NEW_IDAG";
+	else if (state_id == 30)
+		return "NEW_AGENT";
+	else
+		return "error";
+}
+
+/* pl4tinum 11.10.2016 */
+char * inter2string(inter_types interaction){
+	if (interaction == 0)
+		return "INIT_CORE";
+	else if (interaction == 1)
+		return "REMOVE_APP";
+	else if (interaction == 2)
+		return "INIT_APP";
+	else if (interaction == 3)
+		return "DECLARE_INIT_AVAILABILITY";
+	else if (interaction == 4)
+		return "DEBUG_IDAG_REQ_DDS";
+	else if (interaction == 5)
+		return "IDAG_FIND_IDAGS_PENDING";
+	else if (interaction == 6)
+		return "IDAG_FIND_IDAGS";
+	else if (interaction == 7)
+		return "IDAG_REQ_DDS_PENDING";
+	else if (interaction == 8)
+		return "IDAG_REQ_DDS";
+	else if (interaction == 9)
+		return "REP_IDAG_FIND_IDAGS";
+	else if (interaction == 10)
+		return "REP_IDAG_REQ_DDS";
+	else if (interaction == 11)
+		return "AGENT_REQ_CORES";
+	else if (interaction == 12)
+		return "AGENT_REQ_CORES_PENDING";
+	else if (interaction == 13)
+		return "REP_AGENT_REQ_CORES";
+	else if (interaction == 14)
+		return "AGENT_OFFER_SENT";
+	else if (interaction == 15)
+		return "REP_AGENT_OFFER_SENT";
+	else if (interaction == 16)
+		return "REP_AGENT_OFFER_PENDING";
+	else if (interaction == 17)
+		return "SELFOPT_IDAG_FIND_IDAGS_PENDING";
+	else if (interaction == 18)
+		return "SELFOPT_IDAG_FIND_IDAGS";
+	else if (interaction == 19)
+		return "SELFOPT_IDAG_REQ_DDS_PENDING";
+	else if (interaction == 20)
+		return "SELFOPT_IDAG_REQ_DDS";
+	else if (interaction == 21)
+		return "SELFOPT_REQ_CORES_PENDING";
+	else if (interaction == 22)
+		return "SELFOPT_REQ_CORES";
+	else if (interaction == 23)
+		return "IDAG_ADD_CORES_DDS";
+	else if (interaction == 24)
+		return "IDAG_REM_CORES_DDS";
+	else if (interaction == 25)
+		return "INIT_AGENT";
+	else if (interaction == 26)
+		return "INIT_WORK_NODE_PENDING";
+	else if (interaction == 27)
+		return "APPOINT_WORK_NODE_PENDING";
+	else if (interaction == 28)
+		return "INIT_WORK_NODE";
+	else if (interaction == 29)
+		return "APPOINT_WORK_NODE";
+	else if (interaction == 30)
+		return "TERMINATION_STATS";
+	else if (interaction == 31)
+		return "REP_STATISTICS";
+	/* PAXOS Interactions */
+	else if (interaction == 32)
+		return "PAXOS_INIT";
+	else if (interaction == 33)
+		return "PREPARE_REQUEST";
+	else if (interaction == 34)
+		return "PREPARE_ACCEPT_NO_PREVIOUS";
+	else if (interaction == 35)
+		return "PREPARE_ACCEPT";
+	else if (interaction == 36)
+		return "ACCEPT_REQUEST";
+	else if (interaction == 37)
+		return "ACCEPTED";
+	else if (interaction == 38)
+		return "LEARN";
+	else if (interaction == 39)
+		return "LEARN_ACK";
+	else if (interaction == 40)
+		return "LEARN_ACK_CONTR";
+	else if (interaction == 41)
+		return "REINIT_APP";
+	else if (interaction == 42)
+		return "CONTR_TO";
+	else if (interaction == 43)
+		return "REMOVE_FROM_DDS";
+	else if (interaction == 44)
+		return "ADD_TO_DDS";
+	else if (interaction == 45)
+		return "HEARTBEAT_REQ";
+	else if (interaction == 46)
+		return "HEARTBEAT_REP";
+	else if (interaction == 47)
+		return "PAXOS_STATS_REQ";
+	else if (interaction == 48)
+		return "PAXOS_STATS_REP";
+		
+	return "error";
+}
+
+char * sig2string(int sig_id){
+	 if (sig_id == 0)
+		return "NO_SIG";
+	 else if (sig_id == SIG_BASE_NUM)
+		return "SIG_ACK";
+	 else if (sig_id == SIG_BASE_NUM + 1)
+		return "SIG_INIT";
+	 else if (sig_id == SIG_BASE_NUM + 2)
+		return "SIG_TERMINATE";
+	 else if (sig_id == SIG_BASE_NUM + 3)
+		return "SIG_INIT_APP";
+	 else if (sig_id == SIG_BASE_NUM + 4)
+		return "SIG_IDAG_FIND_IDAGS";
+	 else if (sig_id == SIG_BASE_NUM + 5)
+		return "SIG_REQ_DDS";
+	 else if (sig_id == SIG_BASE_NUM + 6)
+		return "SIG_REQ_CORES";
+	 else if (sig_id == SIG_BASE_NUM + 7)
+		return "SIG_REP_OFFERS";
+	 else if (sig_id == SIG_BASE_NUM + 8)
+		return "SIG_INIT_AGENT";
+	 else if (sig_id == SIG_BASE_NUM + 9)
+		return "SIG_ADD_CORES_DDS";
+	 else if (sig_id == SIG_BASE_NUM + 10)
+		return "SIG_REM_CORES_DDS";
+	 else if (sig_id == SIG_BASE_NUM + 11)
+		return "SIG_APPOINT_WORK";
+	 else if (sig_id == SIG_BASE_NUM + 12)
+		return "SIG_FINISH";
+	 else if (sig_id == SIG_BASE_NUM + 13)
+		return "SIG_REJECT";
+	 else if (sig_id == SIG_BASE_NUM + 14)
+		return "SIG_APP_TERMINATED";
+	 /* PAXOS SIGNALS */
+	 else if (sig_id == SIG_BASE_NUM + 15)
+		return "SIG_PREPARE_REQUEST";
+	 else if (sig_id == SIG_BASE_NUM + 16)
+		return "SIG_PREPARE_ACCEPT_NO_PREVIOUS";
+	 else if (sig_id == SIG_BASE_NUM + 17)
+		return "SIG_PREPARE_ACCEPT";
+	 else if (sig_id == SIG_BASE_NUM + 18)
+		return "SIG_ACCEPT_REQUEST";
+	 else if (sig_id == SIG_BASE_NUM + 19)
+		return "SIG_ACCEPTED";
+	 else if (sig_id == SIG_BASE_NUM + 20)
+		return "SIG_LEARN";
+	 else if (sig_id == SIG_BASE_NUM + 21)
+		return "SIG_LEARN_ACK";
+	 else if (sig_id == SIG_BASE_NUM + 22)
+		return "SIG_LEARN_ACK_CONTR";
+	 else if (sig_id == SIG_BASE_NUM + 23)
+		return "SIG_REINIT_APP";
+	 else if (sig_id == SIG_BASE_NUM + 24)
+		return  "SIG_CONTR_TO";
+	 else if (sig_id == SIG_BASE_NUM + 25)
+		return "SIG_REMOVE_FROM_DDS";
+	 else if (sig_id == SIG_BASE_NUM + 26)
+		return "SIG_ADD_TO_DDS";
+	 else if (sig_id == SIG_BASE_NUM + 27)
+		return "SIG_HEARTBEAT_REQ";
+	 else if (sig_id == SIG_BASE_NUM + 28)
+		return "SIG_HEARTBEAT_REP";
+	 else if (sig_id == SIG_BASE_NUM + 29)
+		return "SIG_FAIL";
+	 else if (sig_id == SIG_BASE_NUM + 30)
+		return "SIG_PAXOS_STATS_REQ";
+	 else if (sig_id == SIG_BASE_NUM + 31)
+		return "SIG_PAXOS_STATS_REP";
+	else
+		return "Unknown Sig";
+}
+
+char * itoa(int value){
+	char *tmp;
+	int size=1, i, threshold=10;
+
+	while (value >= threshold) {
+		size++;
+		threshold *= 10;
+	}
+	/*
+	if (value<10)
+		size = 1;
+	else if (value<100)
+		size = 2;
+	else if (value<1000)
+		size = 3;
+	else
+		size = 4;	
+	*/
+	tmp = (char *) malloc((size+1)*sizeof(char));
+	
+	for (i=size-1; i>=0; i--){
+		tmp[i] = (char) 48 + (value % 10);
+		value = value / 10;
+	}
+
+	tmp[size] = '\0';
+	return tmp;
+}
+
+FILE * create_log_file(int node_id, int log, char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]){
+	char log_file_name[MAX_STR_NAME_SIZE], *name;
+	FILE *log_file;
+
+#ifdef PLAT_SCC
+	strcpy(log_file_name, "/shared/herc/");
+#else 	
+	strcpy(log_file_name, "../");
+#endif
+	strcat(log_file_name, scen_directory);
+	strcat(log_file_name, "/");
+	strcat(log_file_name, scen_num);
+	if (log == 0)
+		strcat(log_file_name,"/log_files/log_file_");
+	else{
+		strcat(log_file_name,"/paxos_log_files/log_file_");
+	}
+	name = itoa(node_id);
+	strcat(log_file_name,name);
+	free(name);
+
+	//if ((fd = open(log_file_name, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) < 0) {
+	if ((log_file = fopen(log_file_name, "w")) == NULL){
+		printf("Open log error my id is %d path: %s \n ",node_id, log_file_name);
+		fflush(stdout);
+		perror("open log");
+	}
+	//free(log_file_name);
+	return log_file;
+}
+
+int majority(int cores){
+	return cores/2 + 1;
+}

+ 21 - 0
libfunctions.h

@@ -0,0 +1,21 @@
+#ifndef __LIBFUNCTIONS_H__
+#define __LIBFUNCTIONS_H__
+
+#include "variables.h"
+
+FILE * create_log_file(int node_id, int log, char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]);
+
+int majority(int cores);
+int get_id_from_pid(pid_t spid);
+
+char * itoa(int value);
+char * id2string(core_states state_id);
+char * sig2string(int sig_id);
+char * inter2string(inter_types interaction);
+char * app_state_2_string(application_states state_id);
+
+void handler_Enter(int sender_id, char *handler);
+void handler_Exit(int sender_id, char *handler);
+#endif
+
+

+ 9 - 0
macros.h

@@ -0,0 +1,9 @@
+#ifndef __MACROS_H__
+#define __MACROS_H__
+
+#define FOR_MY_CORES_LIST for(tmp_core_list=my_cores;tmp_core_list!=NULL;tmp_core_list=tmp_core_list->next)
+#define FOR_MY_DDS_LIST for(tmp_dds=DDS;tmp_dds!=NULL;tmp_dds=tmp_dds->next)
+#define FOR_MY_COWORKERS_LIST for(tmp_cowork_list=coworkers;tmp_cowork_list!=NULL;tmp_cowork_list=tmp_cowork_list->next)
+
+#define FOR_NUES for(k=0;k<X_max*Y_max;k++)
+#endif

Fichier diff supprimé car celui-ci est trop grand
+ 1502 - 0
my_rtrm.c


+ 33 - 0
my_rtrm.h

@@ -0,0 +1,33 @@
+#ifndef __MY_RTRM_H__
+#define __MY_RTRM_H__
+
+#include "variables.h"
+#define CLUSTER_SIZE 6
+//#define MAX_STR_NAME_SIZE 256
+
+#ifdef PLAT_SCC
+#include "RCCE.h"
+#else
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#define MAX_SIGNAL_LIST_LEN 256
+#endif
+
+int offer_cores(core_list *cores, app req_app, region req_reg, int *Offered_cores, int req_id);
+void send_next_signal(inter_list *head, int node_num);
+
+int PREPARE_ACCEPT_SENT;
+int CORE_HAS_ACCEPTED_VALUE;
+int SIG_LEARN_SENT;
+int proposal_number_personal;
+
+#ifdef PLAT_SCC
+  RCCE_FLAG proposal_number_lock;
+#else
+  sem_t *cores_detected;
+#endif
+int **core_detected;
+#endif

+ 267 - 0
noc_functions.c

@@ -0,0 +1,267 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "my_rtrm.h"
+#include "idag_defs.h"
+#include "libfunctions.h"
+#include "variables.h"
+
+/* FIXME num_idags_y to be removed from cluster info*/
+
+/*
+const int scc2grid_mapping[48] = {0, 6, 1, 7, 2, 8,
+				  3, 9, 4, 10, 5, 11,
+				  12, 18, 13, 19, 14, 20,
+				  15, 21, 16, 22, 17, 23,
+				  24, 30, 25, 31, 26, 32,
+				  27, 33, 28, 34, 29, 35,
+				  36, 42, 37, 43, 38, 44,
+				  39, 45, 40, 46, 41, 47};
+
+const int grid2scc_mapping[48] = {0, 2, 4, 6, 8, 10,
+				  1, 3, 5, 7, 9, 11,
+				  12, 14, 16, 18, 20, 22,
+				  13, 15, 17, 19, 21, 23,
+				  24, 26, 28, 30, 32, 34,
+				  25, 27, 19, 31, 33, 35,
+				  36, 38, 40, 42, 44, 46,
+				  37, 39, 41, 43, 45, 47};
+*/
+
+static int *scc2grid_mapping, *grid2scc_mapping;
+
+void create_scc2grid_mapping (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]) {
+    int i, j;
+    char scc2grid_path[MAX_STR_NAME_SIZE]; 
+    FILE *scc2grid_file;
+
+    scc2grid_mapping = (int *) malloc(X_max * Y_max * sizeof(int));
+#ifdef PLAT_SCC
+    strcpy(scc2grid_path, "/shared/herc/");
+#else
+    strcpy(scc2grid_path, "../");
+#endif
+    strcat(scc2grid_path, scen_directory);
+    strcat(scc2grid_path, "/");
+    strcat(scc2grid_path, scen_num);
+    strcat(scc2grid_path, "/grids/scc2grid_");
+    strcat(scc2grid_path, itoa(X_max));
+    strcat(scc2grid_path, "_");
+    strcat(scc2grid_path, itoa(Y_max));
+    
+    if (node_id == 0){
+	    printf("scc2grid_path = %s\n",scc2grid_path);
+	    fflush(stdout);
+    }
+  
+    if ((scc2grid_file = fopen(scc2grid_path, "r")) == NULL){
+      printf("Cannot open input file with file path = %s ",scc2grid_path);
+      perror("open scc2grid_path");
+    }
+    
+    for (i=0; i<Y_max; i++)
+      for (j=0; j<X_max; j++)
+	fscanf(scc2grid_file, "%d", &scc2grid_mapping[i*X_max + j]);  
+} 
+
+void create_grid2scc_mapping (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]) {
+    int i, j;
+    char grid2scc_path[MAX_STR_NAME_SIZE]; 
+    FILE *grid2scc_file;
+    
+    grid2scc_mapping = (int *) malloc(X_max * Y_max * sizeof(int));
+#ifdef PLAT_SCC
+    strcpy(grid2scc_path, "/shared/herc/");
+#else    
+    strcpy(grid2scc_path, "../");
+#endif
+    strcat(grid2scc_path, scen_directory);
+    strcat(grid2scc_path, "/");
+    strcat(grid2scc_path, scen_num);
+    strcat(grid2scc_path, "/grids/grid2scc_");
+    strcat(grid2scc_path, itoa(X_max));
+    strcat(grid2scc_path, "_");
+    strcat(grid2scc_path, itoa(Y_max));
+    
+    if (node_id == 0){
+	    printf("grid2scc_path = %s\n",grid2scc_path);
+	    fflush(stdout);
+    }
+  
+    if ((grid2scc_file = fopen(grid2scc_path, "r")) == NULL){
+      printf("Cannot open input file with file path = %s ",grid2scc_path);
+      perror("open grid2scc_path");
+    }
+    
+    for (i=0; i<Y_max; i++)
+      for (j=0; j<X_max; j++)
+	fscanf(grid2scc_file, "%d", &grid2scc_mapping[i*X_max + j]);  
+}
+
+int distance(int core_start, int core_fin) {
+	int x1,x2,y1,y2;
+
+	x1 = scc2grid_mapping[core_start] % X_max;
+	y1 = scc2grid_mapping[core_start] / X_max;
+
+	//printf("x1 = %d, y1 = %d\n",x1,y1);
+	x2 = scc2grid_mapping[core_fin] % X_max;
+	y2 = scc2grid_mapping[core_fin] / X_max;
+	//printf("x2 = %d, y2 = %d\n",x2,y2);
+
+	return abs(x1 - x2) + abs(y1 - y2);
+}
+extern FILE *log_file;
+void get_reg_idags(region cur_reg, int *region_idags){
+	int y,l,count=0,center_node,cur_line,i,j;
+
+	for (i=0; i<num_idags; i++) 
+	  region_idags[i]=0;
+	
+	region_idags[i] = -1; //the one reserved for count is set to -1 for safety
+	l = cur_reg.r;
+	//printf("x = %d, y = %d l=%d\n",x,y,l);
+
+	/* Lower half of area + center*/
+	/* Transpose to regural grid coordinates*/
+	center_node = scc2grid_mapping[cur_reg.C];
+	cur_line = center_node / X_max;
+	fprintf(log_file,"\t\tSearching for idags... num_idags = %d\n",num_idags);
+	while (cur_line >= 0 && l>=0){
+		cur_line = center_node / X_max;
+		for (i=0; i<=l; i++){
+			y = (center_node + i) / X_max;
+			if (y == cur_line){
+				for (j=0; j<num_idags; j++)
+					if (idag_id_arr[j] == idag_mask[grid2scc_mapping[center_node + i]]) break;
+			  
+				if (region_idags[j] == 0) {
+					region_idags[j] = 1;
+					count++;
+				}
+			}
+		
+			y = (center_node - i) / X_max;
+			if (y == cur_line && (center_node - i)>=0){
+				for (j=0; j<num_idags; j++)
+					if (idag_id_arr[j] == idag_mask[grid2scc_mapping[center_node - i]]) break;
+
+				if (region_idags[j] == 0) {
+					region_idags[j] = 1;
+					count++;
+				} 		
+			}
+		}
+
+		center_node -= X_max;
+		cur_line--;
+		l--;
+	}
+
+	/* Upper half of area */
+	if (cur_reg.C + X_max < X_max*Y_max) {
+		center_node = scc2grid_mapping[cur_reg.C + X_max];
+		l = cur_reg.r-1;	
+		cur_line = center_node / X_max;	
+		while (cur_line < Y_max && l>=0) {
+			cur_line = center_node / X_max;
+				for (i=0; i<=l; i++) {
+					y = (center_node + i) / X_max;
+				if (y == cur_line) {
+					for (j=0; j<num_idags; j++)
+						if (idag_id_arr[j] == idag_mask[grid2scc_mapping[center_node + i]]) break;
+
+					if (region_idags[j] == 0) {
+						region_idags[j] = 1;
+						count++;
+					}
+				}
+
+				y = (center_node - i) / X_max;
+				if (y == cur_line && (center_node - i)>=0) {
+					for (j=0; j<num_idags; j++)
+						if (idag_id_arr[j] == idag_mask[grid2scc_mapping[center_node - i]]) break;
+
+					if (region_idags[j] == 0) {
+						region_idags[j] = 1;
+						count++;
+					} 		
+				}
+			}
+
+			center_node += X_max;
+			cur_line++;
+			l--;	
+		}
+	}
+
+	region_idags[num_idags] = count;
+}
+
+int region_count(region cur_reg){
+	int x,y,l,count=0;
+
+	x = scc2grid_mapping[cur_reg.C] % X_max;
+	y = scc2grid_mapping[cur_reg.C] / X_max;
+	l = cur_reg.r;
+	//printf("x = %d, y = %d l=%d\n",x,y,l);
+	
+	while (y >= 0 && l>=0){
+		count++;////1 for center
+		if (x + l < X_max) count += l;
+		else count += X_max - x -1;
+
+		if (x - l >= 0) count += l;
+		else count += x;
+
+		y--;
+		l--;
+	}
+
+	y = (scc2grid_mapping[cur_reg.C] / X_max) + 1;
+	l = cur_reg.r - 1;
+
+	while (y < Y_max && l>=0){
+		count++;
+		if (x + l < X_max) count += l;
+		else count += X_max - x -1;
+
+		if (x - l >= 0) count += l;
+		else count += x;
+
+		y++;
+		l--;	
+	}
+
+	return count;
+}
+
+//returns on function name the idag_id and in call by name, cluster sizes
+int get_cluster_info(int idag_num, int *Cl_x_max, int *Cl_y_max){
+	int x_coord,y_coord, diff, tmp_cl_x, tmp_cl_y;
+	int num_idags_y = num_idags / num_idags_x;
+	
+	tmp_cl_x = X_max / num_idags_x;
+	tmp_cl_y = Y_max / num_idags_y;
+	x_coord = (idag_num % num_idags_x) * tmp_cl_x;
+	y_coord = (idag_num / num_idags_x) * tmp_cl_y;
+	
+	diff = X_max % num_idags_x;
+	if ((diff > 0) && (idag_num % num_idags_x < diff)){
+		x_coord += idag_num % num_idags_x;
+		tmp_cl_x++;
+	} else x_coord += diff;
+		
+	diff = Y_max % num_idags_y;
+	if ((diff > 0) && (idag_num / num_idags_x < diff)){
+		y_coord += idag_num / num_idags_x; //se poia grammh - ypsos tou y einai
+		tmp_cl_y++;	
+	} else y_coord += diff;
+
+	//printf("idag_id = %d, x_coord = %d, y_coord = %d\n",idag_num,x_coord,y_coord);
+	*Cl_x_max = tmp_cl_x;
+	*Cl_y_max = tmp_cl_y;
+	return (y_coord * X_max) + x_coord;
+}
+

+ 11 - 0
noc_functions.h

@@ -0,0 +1,11 @@
+#ifndef __NOC_FUNCTIONS_H__
+#define __NOC_FUNCTIONS_H__
+
+int distance(int core_start, int core_fin);
+void get_reg_idags(region cur_reg, int *region_idags);
+int region_count(region cur_reg);
+int get_cluster_info(int idag_num, int *Cl_x_max, int *Cl_y_max);
+void create_scc2grid_mapping (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]);
+void create_grid2scc_mapping (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]);
+
+#endif

+ 314 - 0
offer_cores_backup.c

@@ -0,0 +1,314 @@
+int offer_cores(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);	
+	}
+	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_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
+			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 == 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;
+					#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 == 0 && Of_cores_num == 1 && req_app.var < 1.0) gain_receiver = 1000000;
+						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;
+						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_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
+			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 == 0 && Of_cores_num == 1 && req_app.var < 1.0) gain_receiver = 1000000;
+						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 = 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
+
+	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, 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);	
+	}
+	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_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
+			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 == 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;
+					#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 == 0 && Of_cores_num == 1 && req_app.var < 1.0) gain_receiver = 1000000;
+						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;
+						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 {
+		while (gain_total > 0.0) {
+			gain_total = 0.0;
+			GreedyChoice = NULL;//-1;
+			min_dist = -1;
+			base_receiver = Speedup(req_app, Cores_receiver + Of_cores_num);
+			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 == 0 && Of_cores_num == 1 && req_app.var < 1.0) gain_receiver = 1000000;
+						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 = 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
+
+	if (my_idag == -1) {
+	/* FFT app requires only power of 2 exec cores plus its manager */
+	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;
+}

Fichier diff supprimé car celui-ci est trop grand
+ 2107 - 0
paxos_signal_handlers.c


+ 41 - 0
paxos_signal_handlers.h

@@ -0,0 +1,41 @@
+#ifndef __PAXOS_SIGNAL_HANDLERS_H__
+#define __PAXOS_SIGNAL_HANDLERS_H__
+
+#include "variables.h"
+
+#define PROP_NW 0
+#define PROP_NR 2
+#define PREV_CW 0
+#define PREV_CR 2
+#define VALUE_W 1
+#define VALUE_R 3
+
+/* PAXOS DECLARATIONS */
+int leader_preference();
+void initialize_PAXOS_data (char scen_directory[SCEN_DIR_SIZE], char scen_num[SCEN_NUM_SIZE]);
+void rollback();
+void find_app_info();
+void sig_CTIMER_handler(int signo, siginfo_t *info, void *context);
+void sig_NTIMER_handler(int signo, siginfo_t *info, void *context);
+void sig_ITIMER_handler(int signo, siginfo_t *info, void *context);
+void sig_PAXOS_INIT(int sender_id);
+void sig_PREPARE_REQUEST_handler(int sender_id);
+void sig_PREPARE_ACCEPT_NO_PREVIOUS_handler(int sender_id);
+void sig_PREPARE_ACCEPT_handler(int sender_id);
+void sig_ACCEPT_REQUEST_handler(int sender_id);
+void sig_ACCEPTED_handler(int sender_id);
+void sig_LEARN_handler(int sender_id);
+void sig_LEARN_ACK_handler(int sender_id);
+void sig_LEARN_ACK_CONTR_handler(int sender_id);
+void sig_REINIT_APP_handler(int sender_id);
+void sig_CONTR_TO_handler(int sender_id);
+void sig_REMOVE_FROM_DDS_handler(int sender_id);
+void sig_ADD_TO_DDS_handler(int sender_id, int *inc_cnt, int cur_index_top);
+void sig_HEARTBEAT_REQ_handler(int sender_id);
+void sig_HEARTBEAT_REP_handler(int sender_id);
+void sig_PFD_TIMER_handler(int signo, siginfo_t *info, void *context);
+void sig_EPFD_TIMER_handler(int signo, siginfo_t *info, void *context);
+void sig_FAIL_handler();
+void sig_PAXOS_STATS_REQ_handler(int sender_id);
+void sig_PAXOS_STATS_REP_handler(int sender_id);
+#endif

+ 672 - 0
scc_signals.c

@@ -0,0 +1,672 @@
+#include "scc_signals.h"
+
+#include "my_rtrm.h"
+#include "signal_handlers.h"
+#include "paxos_signal_handlers.h"
+#include "sig_aux.h"
+#include "libfunctions.h"
+#include "variables.h"
+#include "controller_core.h"
+
+int sig_read_ar[2 * LINE_SIZE];
+
+int R = 0;
+
+int find_sender_id(int SID){
+	
+	return SID % NUES;
+}
+
+int scc_kill(int target_ID, int sig, inter_list *ref_inter_list) {
+	int sig_array_local[2 * LINE_SIZE], old_value, new_value, i, increase_cnt=1;
+	int num_of_coworkers, counter;
+	core_list *tmp_core_list;
+	#ifdef PLAT_SCC
+	int str_len;
+	char error_str[64];
+	#endif
+	int error = 0;
+		
+	signals_disable();
+	
+	if (ref_inter_list == NULL)
+	  fprintf(log_file,"target_ID %d and sig %s ref_inter_list is NULL\n",target_ID,sig2string(sig));
+
+	//19.12.2015 Initial node sends SIG_INIT_APP when an app has terminated and receives no reply.
+	//Thus we dont initialize our counter. Same for SIG_ACK and SIG_FINISH
+
+	#if defined(tPFD) || defined(tEPFD)
+	if (
+	   (sig != SIG_INIT_APP) && (sig != SIG_ACK) && (sig != SIG_ADD_TO_DDS) && (sig != SIG_INIT)
+	   && (sig != SIG_PREPARE_REQUEST) && (sig != SIG_PREPARE_ACCEPT_NO_PREVIOUS) && (sig != SIG_PREPARE_ACCEPT)
+	   && (sig != SIG_ACCEPT_REQUEST) && (sig != SIG_ACCEPTED) && (sig != SIG_LEARN) && (sig != SIG_LEARN_ACK)
+	   && (sig != SIG_LEARN_ACK_CONTR) && (sig != SIG_REINIT_APP) && (sig != SIG_CONTR_TO) && (sig != SIG_REMOVE_FROM_DDS)
+	   && (sig != SIG_FAIL) && (sig != SIG_FINISH)
+	   ){
+		//suspected[target_ID]++;
+		//alive[target_ID] = 0;
+	}
+	#endif
+	
+	for (i=0; i<LINE_SIZE; i++) 
+		sig_array_local[i] = sig;
+	if (sig != SIG_HEARTBEAT_REP && sig != SIG_HEARTBEAT_REQ){
+		sig_array_local[1] = R++ * NUES + node_id;
+	}else{
+		sig_array_local[1] = node_id;
+	}
+
+	if (ref_inter_list != NULL) { //for a signal not associated with no inter_list interaction like SIG_FINISH
+		if (strcmp(sig2string(sig),"SIG_HEARTBEAT_REQ") != 0 && strcmp(sig2string(sig), "SIG_HEARTBEAT_REP") != 0)
+			fprintf(log_file,"\t\tI enter here with target_ID %d and sig %s {%d} type = %s\n",target_ID,sig2string(sig), sig_array_local[1], inter2string(ref_inter_list->type));
+		
+		if (ref_inter_list->type == INIT_APP) {
+			/*sig_array_local[2] = ref_inter_list->data.new_app.id;
+			sig_array_local[3] = ref_inter_list->data.new_app.array_size;
+			sig_array_local[4] = ref_inter_list->data.new_app.workld;
+			sig_array_local[5] = ref_inter_list->data.new_app.num_of_cores;
+			sig_array_local[6] = ref_inter_list->data.new_app.app_type;*/
+			
+			sig_array_local[2] = ref_inter_list->data.new_app.id;
+			sig_array_local[3] = ref_inter_list->data.new_app.array_size;
+			sig_array_local[4] = ref_inter_list->data.new_app.workld;
+			sig_array_local[5] = ref_inter_list->data.new_app.num_of_cores;
+			sig_array_local[6] = ref_inter_list->data.new_app.app_type;
+		
+			//my_stats.message_size += sizeof(app);
+			//clear = 1;
+		} else if (ref_inter_list->type == IDAG_FIND_IDAGS_PENDING || ref_inter_list->type == SELFOPT_IDAG_FIND_IDAGS_PENDING) {//I am the requesting common node
+			sig_array_local[2] = ref_inter_list->data.reg.C;
+			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;
+
+			//my_stats.message_size += sizeof(region);
+		} else if (ref_inter_list->type == IDAG_REQ_DDS_PENDING || ref_inter_list->type == SELFOPT_IDAG_REQ_DDS_PENDING 
+			|| ref_inter_list->type == DEBUG_IDAG_REQ_DDS) {
+		  
+			sig_array_local[2] = ref_inter_list->data.reg.C;
+			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;
+			//if (ref_inter_list->type == SELFOPT_IDAG_REQ_DDS_PENDING) ref_inter_list->type = SELFOPT_IDAG_REQ_DDS;
+		} else if (ref_inter_list->type == REP_IDAG_FIND_IDAGS) {//I am the idag
+			sig_array_local[2] = ref_inter_list->data.idags_in_reg[num_idags];
+			if (sig_array_local[2] > 5){
+				increase_cnt = 2;
+			}
+			counter=3;
+			for (i=0; i < num_idags; i++) {
+				if (ref_inter_list->data.idags_in_reg[i]) {
+					sig_array_local[counter++] = idag_id_arr[i];
+					fprintf(log_file, "\t\tidag=%d\n",idag_id_arr[i]);
+					my_stats.message_size += sizeof(int);
+				}
+			}
+
+		} else if (ref_inter_list->type == REP_IDAG_REQ_DDS) {
+			if (ref_inter_list->data.agents_in_reg == NULL)
+				sig_array_local[2] = DDS_count;
+			else	
+				sig_array_local[2] = ref_inter_list->data.agents_in_reg[0];
+		} else if (ref_inter_list->type == AGENT_REQ_CORES_PENDING) {
+			//my_stats.message_size += sizeof(app);
+			sig_array_local[2] = init_app.id;
+			sig_array_local[3] = init_app.array_size;
+			sig_array_local[4] = init_app.workld;
+			sig_array_local[5] = init_app.num_of_cores;
+			sig_array_local[6] = init_app.app_type;
+			
+			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); 
+			sig_array_local[6] = ref_inter_list->data.reg_arr.region_arr[0].C;
+			sig_array_local[7] = ref_inter_list->data.reg_arr.region_arr[0].r;
+			//my_stats.message_size += sizeof(region);
+			
+			//ref_inter_list->type = AGENT_REQ_CORES;
+			//free(ref_inter_list->data.reg_arr.region_arr);
+		} else if (ref_inter_list->type == SELFOPT_REQ_CORES_PENDING) {
+			//my_stats.message_size += sizeof(app);
+
+			sig_array_local[2] = my_app.id;
+			sig_array_local[3] = my_app.array_size;
+			sig_array_local[4] = my_app.workld;
+			sig_array_local[5] = my_app.num_of_cores;
+			
+			sig_array_local[6] = ref_inter_list->data.reg_arr.region_arr[0].C;
+			sig_array_local[7] = ref_inter_list->data.reg_arr.region_arr[0].r;
+			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);
+			//my_stats.message_size += sizeof(region);
+
+			//ref_inter_list->type = SELFOPT_REQ_CORES;
+			//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);
+				//i=1;
+				
+				/* 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;
+
+				sig_array_local[4] = my_app.array_size;
+				sig_array_local[5] = ref_inter_list->data.work_bounds[0];
+				sig_array_local[6] = ref_inter_list->data.work_bounds[1];
+				sig_array_local[7] = my_app.app_type;
+				/********/
+				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;
+		} else if (ref_inter_list->type == APPOINT_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 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;
+				
+				sig_array_local[3] = ref_inter_list->data.work_bounds[0];
+				sig_array_local[4] = ref_inter_list->data.work_bounds[1];
+				sig_array_local[7] = my_app.app_type;
+				fprintf(log_file, "work_time1=%d work_time2=%d\n",ref_inter_list->data.work_bounds[0],ref_inter_list->data.work_bounds[1]);
+				//my_stats.message_size += 3 * sizeof(int);
+			} else {
+				sig_array_local[2] = -1;
+				//my_stats.message_size += sizeof(int);
+			}
+			//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
+			if (my_idag != -1) {
+				if (ref_inter_list->data.app_cores[0] > 5){
+					increase_cnt=2;
+				}
+			  
+				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++;
+				
+				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++;
+			  
+				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
+				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]);
+				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++;
+			  
+				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) {
+				if (ref_inter_list->data.app_cores[0] > 5)
+					increase_cnt++;
+			  
+				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++;
+				
+				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 */
+		} else if (ref_inter_list->type == PREPARE_REQUEST){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.proposal_number; // proposal_number
+		} else if (ref_inter_list->type == PREPARE_ACCEPT){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.accepted_values[0]; // highest accepted proposal_number
+			sig_array_local[3] = ref_inter_list->data.accepted_values[1]; // highest accepted value
+			sig_array_local[4] = ref_inter_list->data.accepted_values[2]; // state
+		} else if (ref_inter_list->type == PREPARE_ACCEPT_NO_PREVIOUS){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.accepted_values[0]; // highest accepted proposal_number
+			sig_array_local[3] = ref_inter_list->data.accepted_values[1]; // highest accepted value
+			sig_array_local[4] = ref_inter_list->data.accepted_values[2]; // state
+		} else if (ref_inter_list->type == ACCEPT_REQUEST){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.accepted_values[0];
+			sig_array_local[3] = ref_inter_list->data.accepted_values[1];
+		} else if (ref_inter_list->type == ACCEPTED){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.accepted_values[0];
+			sig_array_local[3] = ref_inter_list->data.accepted_values[1];
+		} else if (ref_inter_list->type == LEARN){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.accepted_values[0];
+			sig_array_local[3] = ref_inter_list->data.accepted_values[1];
+		} else if (ref_inter_list->type == LEARN_ACK_CONTR){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.controller_index;
+		} else if (ref_inter_list-> type == REINIT_APP){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.reappointed_app.id;
+			sig_array_local[3] = ref_inter_list->data.reappointed_app.array_size;
+			sig_array_local[4] = ref_inter_list->data.reappointed_app.workld;
+			sig_array_local[5] = ref_inter_list->data.reappointed_app.num_of_cores;
+		} else if (ref_inter_list->type == ADD_TO_DDS){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.workers_info[0];
+			counter = ref_inter_list->data.workers_info[0];
+			if (counter > 5){
+				fprintf(log_file,"\t\tI am sending more than 5 workers. I have to use two lines!\n");
+				increase_cnt = 2;
+			}
+			while (counter > 0){
+				sig_array_local[2+counter] = ref_inter_list->data.workers_info[counter];
+				fprintf(log_file,"\t\tsig_array_local[%d] = %d\n",2+counter,sig_array_local[2+counter]);
+				counter--;
+			 }
+			 fprintf(log_file,"MY COUNTER = %d\n",sig_array_local[2]);
+		} else if (ref_inter_list->type == REMOVE_FROM_DDS){
+			paxos_node_stats.msg_count++;
+		} else if (ref_inter_list->type == PAXOS_STATS_REQ){
+			paxos_node_stats.msg_count++;
+		} else if (ref_inter_list->type == PAXOS_STATS_REP){
+			paxos_node_stats.msg_count++;
+			sig_array_local[2] = ref_inter_list->data.paxos_stats[0];
+			sig_array_local[3] = ref_inter_list->data.paxos_stats[1];
+		} else if (ref_inter_list->type == HEARTBEAT_REQ){
+			  paxos_node_stats.fd_msg_count++;
+		} else if (ref_inter_list->type == HEARTBEAT_REP){
+			  paxos_node_stats.fd_msg_count++;
+		} else if (ref_inter_list->type == INIT_AGENT){
+			sig_array_local[2] = ref_inter_list->data.one_app.new_app.id;
+			sig_array_local[3] = ref_inter_list->data.one_app.new_app.array_size;
+			sig_array_local[4] = ref_inter_list->data.one_app.new_app.workld;
+			sig_array_local[5] = ref_inter_list->data.one_app.new_app.num_of_cores;
+			sig_array_local[6] = ref_inter_list->data.one_app.new_app.app_type;
+		}
+		/* END*/
+		
+	}
+	
+	#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);
+	if (error != RCCE_SUCCESS) {
+		RCCE_error_string(error, error_str, &str_len);
+		fprintf(log_file,"I got an error in put with descr %s\n",error_str);
+		fflush(log_file);	
+	}
+	
+	new_value = (old_value + increase_cnt) % MAX_SIGNAL_LIST_LEN;
+	index_bottom[target_ID] = new_value;
+	//RCCE_shflush();	
+	RCCE_release_lock(target_ID);
+
+	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
+	
+	sem_wait(&scc_lock[target_ID]);
+	old_value = index_bottom[target_ID];
+	int mem_offset = target_ID * MAX_SIGNAL_LIST_LEN * LINE_SIZE;
+	mem_offset += old_value * LINE_SIZE;
+	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\n",old_value,increase_cnt);
+		/*if (old_value == 63 && increase_cnt == 2){
+			fprintf(log_file,"\t\tindex_bottom[%d]=%d.\n\t\tI wrote from position %d till %d and %d till %d\n",target_ID,index_bottom[target_ID],mem_offset,mem_offset+7,target_ID * MAX_SIGNAL_LIST_LEN * LINE_SIZE,target_ID * MAX_SIGNAL_LIST_LEN * LINE_SIZE + LINE_SIZE);
+		}else{
+			fprintf(log_file,"\t\tindex_bottom[%d]=%d.\n\t\tI wrote from position %d till %d\n",target_ID,index_bottom[target_ID],mem_offset,mem_offset+increase_cnt*LINE_SIZE);
+		}*/
+	}
+	for (i=0; i<increase_cnt * LINE_SIZE; i++){
+		if (old_value == MAX_SIGNAL_LIST_LEN-1 && increase_cnt == 2){
+			if (i <= 7){
+				sig_array[mem_offset + i] = sig_array_local[i];
+			}else{
+				sig_array[(target_ID * MAX_SIGNAL_LIST_LEN * LINE_SIZE) + i - LINE_SIZE] = sig_array_local[i];
+			}
+		}else{
+			sig_array[mem_offset + i] = sig_array_local[i];
+		}
+	}
+		
+	new_value = (old_value + increase_cnt) % MAX_SIGNAL_LIST_LEN;
+	index_bottom[target_ID] = new_value;
+	
+	sem_post(&scc_lock[target_ID]);
+	
+	#endif
+	
+	signals_enable();
+
+	return error;
+}
+
+void scc_signals_check(void) {
+	int sender_id, tmp_bottom, i, mem_offset, increase_cnt=1;
+	char *sig_buf, *st_buf;
+	//int sig_read_ar[LINE_SIZE]
+	#ifdef PLAT_SCC
+	int error, str_len; 
+	#endif
+	char error_str[64];
+	
+	signals_disable();
+	#ifdef PLAT_SCC
+	RCCE_acquire_lock(node_id);
+	#else
+	sem_wait(&scc_lock[node_id]);
+	#endif
+
+	/* Overflow check */
+	tmp_bottom = index_bottom[node_id];
+
+	//last_index_bottom = tmp_bottom;
+
+	while (index_top != tmp_bottom) {
+
+		#ifdef EXTRA_DELAY
+		scc_pause;
+		#endif
+	
+		#ifdef PLAT_SCC
+		error = RCCE_get((t_vcharp)(&sig_read_ar[0]), (t_vcharp)(&sig_array[index_top*LINE_SIZE]), LINE_SIZE * sizeof(int), node_id);
+		RCCE_release_lock(node_id);
+
+		if (error != RCCE_SUCCESS) {
+			RCCE_error_string(error, error_str, &str_len);
+			fprintf(log_file,"I got an error in get from %d with descr %s\n",sender_id,error_str);
+			fflush(log_file);
+		#else
+		mem_offset = (node_id * MAX_SIGNAL_LIST_LEN * LINE_SIZE) + (index_top * LINE_SIZE); //node offset
+		for (i = 0; i < LINE_SIZE; i++)
+			sig_read_ar[i] = sig_array[mem_offset + i];
+		
+		sem_post(&scc_lock[node_id]);
+		error_str[0] = '0';
+
+		if (error_str[0] == '1') {
+			printf("DAFUQ ?\n");
+		#endif
+		} else {
+			sender_id = find_sender_id(sig_read_ar[1]);
+		  	if (sig_read_ar[0] != NO_SIG){
+				st_buf = id2string(state);
+				sig_buf = sig2string(sig_read_ar[0]);
+				if (strcmp(sig2string(sig_read_ar[0]),"Unknown Sig") == 0){
+						fprintf(log_file,"I read Unknown sig and its number is %d\n",sig_read_ar[0]);
+				}else if (strcmp(sig2string(sig_read_ar[0]),"SIG_HEARTBEAT_REQ") != 0 && strcmp(sig2string(sig_read_ar[0]), "SIG_HEARTBEAT_REP") != 0){
+					fprintf(log_file,"\t\tmy index_top = %d and index_bottom = %d\n",index_top,tmp_bottom);
+					fprintf(log_file,"\t\tI read sig %s {%d} - %d from sender_id %d. Current state = %s\n",sig_buf, sig_read_ar[1], sig_read_ar[0], sender_id, st_buf);
+					//fprintf(log_file,"\t\tindex_top[%d]=%d.\n\t\tI read from position %d till %d\n",node_id,index_top,mem_offset,mem_offset+7);
+				}
+			}
+			
+			
+			/* Failure Detector */
+			#if defined(tPFD) || defined(tEPFD)
+			alive[sender_id] = 1;
+			suspected[sender_id] = 0;
+			#endif
+			/********************/
+			
+			if (paxos_state == FAILED_CORE && sig_read_ar[0] == SIG_RECOVER){
+				fail_flag = 1;
+			} else if (paxos_state != FAILED_CORE)
+			if (sig_read_ar[0] == SIG_INIT) {
+				sig_INIT_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_ACK) {
+				sig_ACK_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_TERMINATE) {
+				sig_TERMINATE_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_INIT_APP) {
+				sig_INIT_APP_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_IDAG_FIND_IDAGS) {
+				sig_IDAG_FIND_IDAGS_handler(sender_id, &increase_cnt, index_top);
+			} else if (sig_read_ar[0] == SIG_REQ_DDS) {
+				sig_REQ_DDS_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_REQ_CORES) {
+				sig_REQ_CORES_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_REP_OFFERS) {
+				sig_REP_OFFERS_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_INIT_AGENT) {
+				sig_INIT_AGENT_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_ADD_CORES_DDS) {
+				sig_ADD_CORES_DDS_handler(sender_id, &increase_cnt, index_top);
+			} else if (sig_read_ar[0] == SIG_REM_CORES_DDS) {
+				sig_REM_CORES_DDS_handler(sender_id, &increase_cnt, index_top);
+			} else if (sig_read_ar[0] == SIG_APPOINT_WORK) {
+				sig_APPOINT_WORK_handler(sender_id, &increase_cnt, index_top);
+				//sig_APPOINT_WORK_handler(sender_id);
+				//increase_cnt = 2;
+			} else if (sig_read_ar[0] == SIG_FINISH) {
+				sig_FINISH_handler(sender_id, &increase_cnt, index_top);
+			} else if (sig_read_ar[0] == SIG_REJECT) {
+				sig_REJECT_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_APP_TERMINATED) {
+				num_apps_terminated++;
+				fprintf(log_file,"app_terminated = %d sender_id = %d\n",num_apps_terminated,sender_id);
+				printf("app_terminated = %d sender_id = %d\n",num_apps_terminated,sender_id);
+			/* PAXOS SIGNALS HANDLING */
+			} else if (sig_read_ar[0] == SIG_PREPARE_REQUEST){
+				sig_PREPARE_REQUEST_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_PREPARE_ACCEPT_NO_PREVIOUS){
+				sig_PREPARE_ACCEPT_NO_PREVIOUS_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_PREPARE_ACCEPT){
+				sig_PREPARE_ACCEPT_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_ACCEPT_REQUEST){
+				sig_ACCEPT_REQUEST_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_ACCEPTED){
+				sig_ACCEPTED_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_LEARN){
+				sig_LEARN_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_REINIT_APP){
+				sig_REINIT_APP_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_CONTR_TO){
+				sig_CONTR_TO_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_REMOVE_FROM_DDS){
+				sig_REMOVE_FROM_DDS_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_ADD_TO_DDS){
+				sig_ADD_TO_DDS_handler(sender_id,&increase_cnt,index_top);
+			} else if (sig_read_ar[0] == SIG_HEARTBEAT_REQ){
+				sig_HEARTBEAT_REQ_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_HEARTBEAT_REP){
+				sig_HEARTBEAT_REP_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_FAIL){
+				sig_FAIL_handler();
+			} else if (sig_read_ar[0] == SIG_PAXOS_STATS_REQ){
+				sig_PAXOS_STATS_REQ_handler(sender_id);
+			} else if (sig_read_ar[0] == SIG_PAXOS_STATS_REP){
+				sig_PAXOS_STATS_REP_handler(sender_id);
+			/* END OF PAXOS SIGNAL HANDLING */
+			} else if (sig_read_ar[0] != NO_SIG) {
+				fprintf(log_file,"I read smth different than no_sig which is %d from %d\n",sig_read_ar[0],sender_id);
+				fflush(log_file);
+			}
+
+			if (sig_read_ar[0] != NO_SIG)
+				if (strcmp(sig2string(sig_read_ar[0]),"SIG_HEARTBEAT_REQ") != 0 && strcmp(sig2string(sig_read_ar[0]), "SIG_HEARTBEAT_REP") != 0)
+					fprintf(log_file,"I invalidated sender_ids %d signals increase_cnt=%d\n",sender_id,increase_cnt);
+
+			index_top = (index_top + increase_cnt) % MAX_SIGNAL_LIST_LEN;
+			increase_cnt = 1;
+
+			#ifdef PLAT_SCC
+			RCCE_acquire_lock(node_id);
+			#else
+			sem_wait(&scc_lock[node_id]);
+			#endif
+
+			tmp_bottom = index_bottom[node_id];
+			
+			if (paxos_state ==  NEW_IDAG){
+				fprintf(log_file,"\t\tmy index_top = %d and index_bottom = %d\n",index_top,tmp_bottom);
+				break;
+			}
+			
+
+		}
+	}
+
+	#ifdef PLAT_SCC
+	RCCE_release_lock(node_id);
+	#else
+	sem_post(&scc_lock[node_id]);
+	#endif
+	if (paxos_state == NEW_AGENT){
+		//paxos_state = PAXOS_ACTIVE;
+		//common_node_actions(local_scen_directory, local_scen_num);
+	}
+	
+	//fprintf(log_file,"paxos_state : %s", id2string(paxos_state));
+	if (paxos_state == NEW_IDAG){
+		fprintf(log_file, "My state is %s %s\n", id2string(state), id2string(paxos_state));
+		rollback();
+		fprintf(log_file, "My state 2 is %s %s\n", id2string(state), id2string(paxos_state));
+		signals_enable();
+		fprintf(log_file, "My state 3 is %s %s\n", id2string(state), id2string(paxos_state));
+		idle_agent_actions("", "");
+	}
+	signals_enable();
+}
+
+void scc_pause(void) {
+	int dummy=0, i;
+
+	
+	#ifdef LOW_VOLTAGE_0
+	if ((node_id >= 0 && node_id <= 3) || (node_id >= 12 && node_id <= 15))
+		for (i=0; i<125; i++) //667
+			dummy++;
+	else
+		for (i=0; i<1000; i++)
+			dummy++; 
+	#else
+	for (i=0; i<1000; i++)
+		//for(j=0; j<1000; j++)
+			dummy++;
+	#endif	
+}	

+ 11 - 0
scc_signals.h

@@ -0,0 +1,11 @@
+#ifndef __SCC_SIGNALS_H__
+#define __SCC_SIGNALS_H__
+
+#include "structs.h"
+
+int scc_kill(int target_ID, int sig, inter_list *ref_inter_list);
+void scc_signals_check(void);
+void scc_pause(void);
+int find_sender_id(int SID);
+//void scc_update_slowest(struct timeval time_val, int agent_id);
+#endif

+ 105 - 0
sig_aux.c

@@ -0,0 +1,105 @@
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <signal.h>
+
+#include "sig_aux.h"
+
+/* Disable delivery of SIG_INIT and SIG_ACK. */
+void
+signals_disable(void)
+{
+	sigset_t sigset;
+
+	sigemptyset(&sigset);
+	sigaddset(&sigset, SIG_TIMER);
+	sigaddset(&sigset, SIG_CTIMER);
+	sigaddset(&sigset, SIG_EPFD_TIMER);
+	sigaddset(&sigset, SIG_ITIMER);
+	sigaddset(&sigset, SIG_PFD_TIMER);
+	if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
+		perror("signals_disable: sigprocmask");
+		exit(1);
+	}
+}
+
+/* Enable delivery of SIG_INIT and SIG_ACK.  */
+void signals_enable(void)
+{
+	sigset_t sigset;
+
+	sigemptyset(&sigset);
+	sigaddset(&sigset, SIG_TIMER);
+	sigaddset(&sigset, SIG_CTIMER);
+	sigaddset(&sigset, SIG_EPFD_TIMER);
+	sigaddset(&sigset, SIG_ITIMER);
+	sigaddset(&sigset, SIG_PFD_TIMER);
+
+	if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
+		perror("signals_enable: sigprocmask");
+		exit(1);
+	}
+}
+
+void
+sig_SEGV_enable(void)
+{
+	sigset_t sigset;
+	sigaddset(&sigset, SIGSEGV);
+	if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
+		perror("signals_enable: sigprocmask");
+		exit(1);
+	}
+}
+
+/* Install two signal handlers.
+ * One for SIGCHLD, one for SIGALRM.
+ * Make sure both signals are masked when one of them is running.
+ */
+void install_signal_handlers(void)
+{
+	sigset_t sigset;
+	struct sigaction sa;
+
+	sa.sa_flags = SA_RESTART | SA_SIGINFO;
+	sigemptyset(&sigset);
+	sa.sa_mask = sigset;
+
+	sa.sa_sigaction = sig_TIMER_handler;
+	if (sigaction(SIG_TIMER, &sa, NULL) < 0) {
+		perror("sigaction: SIG_TIMER");
+		exit(1);
+	}
+	
+	#ifdef BASIC_PAXOS
+	sa.sa_sigaction = sig_CTIMER_handler;
+	if (sigaction(SIG_CTIMER, &sa, NULL) < 0) {
+		perror("sigaction: SIG_CTIMER");
+		exit(1);
+	}
+	
+	sa.sa_sigaction = sig_ITIMER_handler;
+	if (sigaction(SIG_ITIMER, &sa, NULL) < 0) {
+		perror("sigaction: SIG_ITIMER");
+		exit(1);
+	}
+	#endif
+	
+	#if defined(EPFD) || defined(tEPFD)
+	sa.sa_sigaction = sig_EPFD_TIMER_handler;
+	if (sigaction(SIG_EPFD_TIMER, &sa, NULL) < 0) {
+		perror("sigaction: SIG_EPFD_TIMER");
+		exit(1);
+	}	
+	#endif
+	
+	#if defined(PFD) || defined(tPFD)
+	sa.sa_sigaction = sig_PFD_TIMER_handler;
+	if (sigaction(SIG_PFD_TIMER, &sa, NULL) < 0) {
+		perror("sigaction: SIG_PFD_TIMER");
+		exit(1);
+	}
+	#endif
+
+}

+ 13 - 0
sig_aux.h

@@ -0,0 +1,13 @@
+#ifndef __SIG_AUX_H__
+#define __SIG_AUX_H__
+
+#include "my_rtrm.h"
+#include "signal_handlers.h"
+#include "paxos_signal_handlers.h"
+
+void signals_disable(void);
+void sig_SEGV_enable(void);
+void signals_enable(void);
+void install_signal_handlers(void);
+
+#endif

Fichier diff supprimé car celui-ci est trop grand
+ 3933 - 0
signal_handlers.c


+ 31 - 0
signal_handlers.h

@@ -0,0 +1,31 @@
+#ifndef __SIGNAL_HANDLERS_H__
+#define __SIGNAL_HANDLERS_H__
+
+#include "my_rtrm.h"
+
+#ifdef PLAT_LINUX
+void new_RCCE_get(int target[], int *src, int index, int num_of_ints, int ID);
+void my_RCCE_get(int *target, int *src, int num_of_ints, int ID);
+#endif
+void sig_TIMER_handler(int signo, siginfo_t *info, void *context);
+void sig_INIT_handler(int sender_id);
+void sig_ACK_handler(int sender_id);
+void sig_TERMINATE_handler(int sender_id);
+void sig_INIT_APP_handler(int sender_id);
+void sig_IDAG_FIND_IDAGS_handler(int sender_id, int *inc_cnt, int cur_index_top);
+void sig_REQ_DDS_handler(int sender_id);
+void sig_REQ_CORES_handler(int sender_id);
+void sig_REJECT_handler(int sender_id);
+void sig_REP_OFFERS_handler(int sender_id);
+void sig_INIT_AGENT_handler(int sender_id);
+void sig_ADD_CORES_DDS_handler(int sender_id, int *inc_cnt, int cur_index_top);
+void sig_REM_CORES_DDS_handler(int sender_id, int *inc_cnt, int cur_index_top);
+void sig_APPOINT_WORK_handler(int sender_id, int *inc_cnt, int cur_index_top);
+//void sig_APPOINT_WORK_handler(int sender_id);
+void sig_CHECK_REM_TIME_handler(int sender_id);
+void sig_FINISH_handler(int sender_id, int *inc_cnt, int cur_index_top);
+/*void sig_SEGV_handler(int signo, siginfo_t *info, void *context);
+void sig_FAR_REQ_handler(int signo, siginfo_t *info, void *context);
+void sig_REMOVE_FAR_MAN_handler(int signo, siginfo_t *info, void *context);*/
+void trigger_shit(int failed_core);
+#endif

+ 312 - 0
structs.h

@@ -0,0 +1,312 @@
+#ifndef __STRUCTS_H__
+#define __STRUCTS_H__
+
+#define OLD_INIT_AREAS_NUM 8
+
+#include <time.h>
+#include <sys/time.h>
+
+
+typedef enum available_core_states {
+	IDLE_CORE, 		//0
+	WORKING_NODE, 		//1
+	TERMINATED, 		//2
+	/* Controller States */
+	IDLE_IDAG, 		//3
+	IDLE_IDAG_INIT_SEND, 	//4
+	IDLE_CHK_APP_FILE, 	//5
+	CHK_APP_FILE, 		//6
+	USER_INPUT, 		//7 //FIXME change to a reasonable name
+	/* Initial core States */
+	INIT_MANAGER, 		//8
+	INIT_MANAGER_SEND_OFFERS,//9
+	IDLE_INIT_MAN, 		//10
+	INIT_MAN_CHK_OFFERS, 	//11
+	/* Manager States */
+	IDLE_AGENT, 		//12
+	IDLE_AGENT_WAITING_OFF, //13
+	AGENT_INIT_STATE, 	//14
+	AGENT_SELF_OPT, 	//15
+	AGENT_SELF_CHK_OFFERS, 	//16
+	AGENT_ENDING, 		//17
+	IDAG_ENDING, 		//18
+	NO_PENDING_STATE, 	//19
+	AGENT_ZOMBIE, 		//20
+	/* Multiple Pending States */
+	AGENT_INIT_APP_INIT, 	//21
+	AGENT_INIT_CHK_OFFERS, 	//22
+	AGENT_INIT_IDLE_INIT, 	//23
+	IDLE_INIT_IDLE_AGENT, 	//24
+	IDLE_INIT_AGENT_SELFOPT,//25
+	INIT_CHK_OFFERS_IDLE_AGENT, //26
+	INIT_CHK_OFFERS_SELFOPT,//27
+	/*PAXOS STATES*/
+	PAXOS_ACTIVE, 		//28
+	NEW_IDAG, 		//29
+	NEW_AGENT, 		//30
+	FAILED_CORE		//31
+} core_states;//avail_states;
+
+typedef enum available_app_states {
+	NO_APP, 		//0
+	APP_TERMINATED, 	//1
+	RUNNING, 		//2
+	RESIZING, 		//3
+} application_states;//avail_states;
+
+typedef enum available_exec_apps{
+	MATRIX_MUL,
+	SVM,
+	FFT
+} app_exec;
+
+typedef enum interaction_types {
+	/* General Interaction Types */
+	INIT_CORE, 		//0
+	REMOVE_APP, 		//1
+	/* 0 <--> Initial */
+	INIT_APP, 		//2
+	DECLARE_INIT_AVAILABILITY,//3
+	/* 0 --> Controller */
+	DEBUG_IDAG_REQ_DDS, 	//4 FIXME Find better name
+	/* Initial <--> Controller Related Interaction Types */
+	IDAG_FIND_IDAGS_PENDING, //5
+	IDAG_FIND_IDAGS,	//6
+	IDAG_REQ_DDS_PENDING, 	//7
+	IDAG_REQ_DDS, 		//8
+	REP_IDAG_FIND_IDAGS, 	//9
+	REP_IDAG_REQ_DDS, 	//10
+	/* Initial --> Manager OR Controller */
+	AGENT_REQ_CORES, 	//11
+	AGENT_REQ_CORES_PENDING,//12
+	/* Manager <--> Manager OR Controller */
+	REP_AGENT_REQ_CORES, 	//13
+	AGENT_OFFER_SENT, 	//14
+	REP_AGENT_OFFER_SENT, 	//15
+	REP_AGENT_OFFER_PENDING,//16
+	/* Manager --> Controller */
+	SELFOPT_IDAG_FIND_IDAGS_PENDING, //17
+	SELFOPT_IDAG_FIND_IDAGS,//18
+	SELFOPT_IDAG_REQ_DDS_PENDING,//19
+	SELFOPT_IDAG_REQ_DDS, 	//20
+	SELFOPT_REQ_CORES_PENDING,//21
+	SELFOPT_REQ_CORES, 	//22
+	IDAG_ADD_CORES_DDS, 	//23
+	IDAG_REM_CORES_DDS, 	//24
+	/* Initial --> Manager */
+	INIT_AGENT, 		//25
+	/* Manager --> Worker */
+	INIT_WORK_NODE_PENDING, //26
+	APPOINT_WORK_NODE_PENDING,//27
+	INIT_WORK_NODE, 	//28
+	APPOINT_WORK_NODE, 	//29
+	/* Controller <--> Cores */
+	TERMINATION_STATS, 	//30
+	REP_STATISTICS,		//31
+	/* PAXOS INTERACTIONS */
+	PAXOS_INIT, 		//32
+	PREPARE_REQUEST, 	//33
+	PREPARE_ACCEPT_NO_PREVIOUS,//34
+	PREPARE_ACCEPT, 	//35
+	ACCEPT_REQUEST, 	//36
+	ACCEPTED, 		//37
+	LEARN, 			//38
+	LEARN_ACK, 		//39
+	LEARN_ACK_CONTR, 	//40
+	REINIT_APP, 		//41
+	CONTR_TO, 		//42
+	REMOVE_FROM_DDS, 	//43
+	ADD_TO_DDS, 		//44
+	HEARTBEAT_REQ, 		//45
+	HEARTBEAT_REP, 		//46
+	PAXOS_STATS_REQ, 	//47
+	PAXOS_STATS_REP, 	//48
+	RECOVERED		//49
+	/* END */
+} inter_types;
+
+typedef struct app_tag app;
+
+struct app_tag {
+	int id;
+	int array_size; // 0 = 1024, 1= 2048, 3= 4096
+	int workld;
+	int num_of_cores;
+	int app_type;
+	//int segment_id;
+};
+typedef struct region_tag region;
+
+struct region_tag {
+	int C;
+	int r;
+};
+typedef struct offer_tag offer;
+
+struct offer_tag {
+	int num_of_cores;
+	int *offered_cores;
+	float spd_loss;
+	//float spd_gain;
+};
+
+typedef struct offer_list_tag offer_list;
+
+struct offer_list_tag {
+	offer off;
+	int sender;
+	int *answer;
+	offer_list *next;
+};
+
+typedef struct target_list_tag target_list;
+
+struct target_list_tag {
+	int target;
+	int num_of_regions;
+	region region_arr[OLD_INIT_AREAS_NUM];
+	target_list *next;
+};
+
+
+struct region_array_tag {
+	int num_of_regions;
+	region *region_arr;
+};
+
+typedef struct region_array_tag region_array;
+
+struct offer_array_tag {
+	int num_of_offers;
+	offer *offer_arr;
+};
+
+typedef struct offer_array_tag offer_array;
+
+struct metrics_tag {
+	long long int msg_count;
+	int fd_msg_count;
+	int message_size;
+	int distance;
+	int app_turnaround;
+	int comp_effort;
+	int cores_utilized;
+	int times_accessed;
+};
+typedef struct metrics_tag metrics;
+
+/*
+struct far_req_info_tag {
+	int orig_sender;
+	app far_app;
+	region reg;
+};
+typedef struct far_req_info_tag far_req_info;
+*/
+
+struct my_time_stamp_tag {
+	int tm_sec;  /* seconds */
+	int tm_min;  /* minutes */
+	int tm_hour; /* hours */
+	suseconds_t tm_usec;
+};
+typedef struct my_time_stamp_tag my_time_stamp;
+
+struct init_app_info_tag {
+	app new_app;
+	my_time_stamp new_app_times[2];
+	int *new_app_cores;
+};
+
+typedef struct init_app_info_tag init_app_info;
+
+typedef struct core_list_tag core_list;
+
+struct core_list_tag {
+	int core_id;
+	int offered_to; //-1 if offered to nobody
+	int workload[2]; /* 27.6.2016 Added by dimos. If worker fails i have to know the workload given in order to reappoint */
+	core_list *next;
+};
+
+typedef struct DDS_tag DDS_list;
+
+struct DDS_tag {
+	int agent_id;
+	int num_of_cores;
+	DDS_list *next;
+};
+
+typedef struct coworkers_list_tag coworkers_list;
+
+struct coworkers_list_tag{
+	int core_id;
+	int agent_id;
+	coworkers_list *next;
+};
+
+typedef struct agent_info_tag agent_info;
+
+struct agent_info_tag {
+	int my_agent;
+	int array_size;
+	int work_bounds[2];
+	int segment_id;
+	int app_type;
+};
+
+typedef struct interact_list_tag inter_list;
+
+struct interact_list_tag {
+	//int core_id;
+	inter_types type;
+	union {
+		region reg;
+		region_array reg_arr;
+		app new_app;
+		init_app_info one_app;
+		offer my_offer;
+		offer_array off_arr;
+		metrics stats;
+		int *idags_in_reg;
+		int *agents_in_reg;
+		int *app_cores;//first element is num of cores
+		int offer_accepted;
+		int *offer_acc_array;
+		//int far_req_man;
+		//far_req_info far_req; 
+		int work_bounds[3];
+		int agent_ended;
+		/* PAXOS */
+		int proposal_number;
+		int accepted_values[3]; // 0 is proposal_number, 1 is value, 2 is state
+		int learn_ack_info[2];
+		app reappointed_app;
+		int controller_index;
+		int failed_node;
+		int workers_info[9];
+		int paxos_stats[2];
+	} data;
+	inter_list *next;
+};
+
+typedef struct{
+	int highest_acc_n; //Highest accepted proposal number
+	int highest_acc_value; //Value paired with highest accepted proposal number
+	int highest_proposed_n; //Highest proposed proposal number
+}acceptor_var;
+
+typedef struct{
+	int highest_replied_n;
+	int highest_replied_value;
+	int cores_promised;
+	int cores_accepted;
+	int *core_states;
+}proposer_var;
+
+typedef struct{
+	int accepted_value;
+	int cores_accepted;
+}learner_var;
+
+#endif

+ 243 - 0
variables.h

@@ -0,0 +1,243 @@
+#ifndef __VARIABLES_H__
+#define __VARIABLES_H__
+
+#include <semaphore.h>
+#include <signal.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <math.h>
+
+#ifdef PLAT_SCC
+#include "RCCE.h"
+#define X_max 6
+#define Y_max 8
+#define MAX_SIGNAL_LIST_LEN 128
+#endif
+
+#include "structs.h"
+
+/* Printing Material */
+#define KNRM  "\x1B[0m"
+#define KBLK  "\x1B[30m"
+#define KRED  "\x1B[31m"
+#define KGRN  "\x1B[32m"
+#define KYEL  "\x1B[33m"
+#define KBLU  "\x1B[34m"
+#define KMAG  "\x1B[35m"
+#define KCYN  "\x1B[36m"
+#define KWHT  "\x1B[37m"
+/*********************/
+
+/* Static Variables */
+#define MS 1000000
+#define INIT_NODE_INTERVAL 1000
+#define LINE_SIZE 8
+#define SIG_BASE_NUM 42
+#define NUM_OF_MATRICES 3
+#define MAX_WORKERS_COUNT 8 //FIXME
+#define MAX_ARRAY_SIZE 4096
+#define MAX_DATA_LIST_LEN 3
+#define LEAST_SELF_OPT_INTERVAL_MS 500
+#define MAX_SELF_OPT_INTERVAL_MS 12800
+#define MAX_STR_NAME_SIZE 256
+#define SCEN_NUM_SIZE MAX_STR_NAME_SIZE
+#define SCEN_DIR_SIZE MAX_STR_NAME_SIZE
+#define PAXOS_SCEN_SIZE 32
+/**************************/
+
+/* Signals */
+#define NO_SIG 0
+#define SIG_ACK SIG_BASE_NUM
+#define SIG_INIT SIG_BASE_NUM+1
+#define SIG_TERMINATE SIG_BASE_NUM+2
+#define SIG_INIT_APP SIG_BASE_NUM+3
+#define SIG_IDAG_FIND_IDAGS SIG_BASE_NUM+4
+#define SIG_REQ_DDS SIG_BASE_NUM+5
+#define SIG_REQ_CORES SIG_BASE_NUM+6
+#define SIG_REP_OFFERS SIG_BASE_NUM+7
+#define SIG_INIT_AGENT SIG_BASE_NUM+8
+#define SIG_ADD_CORES_DDS SIG_BASE_NUM+9
+#define SIG_REM_CORES_DDS SIG_BASE_NUM+10
+#define SIG_APPOINT_WORK SIG_BASE_NUM+11
+#define SIG_FINISH SIG_BASE_NUM+12
+#define SIG_REJECT SIG_BASE_NUM+13
+#define SIG_APP_TERMINATED SIG_BASE_NUM+14
+//PAXOS_SIGNALS
+#define SIG_PREPARE_REQUEST SIG_BASE_NUM+15
+#define SIG_PREPARE_ACCEPT_NO_PREVIOUS SIG_BASE_NUM+16
+#define SIG_PREPARE_ACCEPT SIG_BASE_NUM+17
+#define SIG_ACCEPT_REQUEST SIG_BASE_NUM+18
+#define SIG_ACCEPTED SIG_BASE_NUM+19
+#define SIG_LEARN SIG_BASE_NUM+20
+#define SIG_LEARN_ACK SIG_BASE_NUM+21
+#define SIG_LEARN_ACK_CONTR SIG_BASE_NUM+22
+#define SIG_REINIT_APP SIG_BASE_NUM+23
+#define SIG_CONTR_TO SIG_BASE_NUM+24
+#define SIG_REMOVE_FROM_DDS SIG_BASE_NUM+25
+#define SIG_ADD_TO_DDS SIG_BASE_NUM+26
+#define SIG_HEARTBEAT_REQ SIG_BASE_NUM+27
+#define SIG_HEARTBEAT_REP SIG_BASE_NUM+28
+#define SIG_FAIL SIG_BASE_NUM+29
+#define SIG_PAXOS_STATS_REQ SIG_BASE_NUM+30
+#define SIG_PAXOS_STATS_REP SIG_BASE_NUM+31
+
+#define SIG_RECOVER SIG_BASE_NUM+32
+
+
+
+#define SIG_TIMER SIGRTMIN
+#define SIG_CTIMER SIGRTMIN+1
+#define SIG_EPFD_TIMER SIGRTMIN+2
+#define SIG_ITIMER SIGRTMIN+3
+#define SIG_PFD_TIMER SIGRTMIN+4
+/*****************************************/
+
+#ifdef SCC
+extern int idag_mask[X_max*Y_max];
+extern int low_voltage_core[X_max*Y_max];
+extern int timer_schedule[X_max*Y_max];
+
+extern volatile int *manager_result_out;
+extern volatile int *index_bottom;
+
+extern RCCE_FLAG flag_data_written;
+extern RCCE_FLAG proposal_number_lock;
+
+extern int num_idags_x;
+
+#else
+extern int X_max, Y_max;
+extern int *pid_num;
+extern int *idag_mask;
+extern int *low_voltage_core;
+extern int *timer_schedule;
+extern int *manager_result_out;
+extern int *index_bottom;
+extern int num_idags_x;
+extern sem_t *flag_data_written, *scc_lock, *proposal_number_lock;
+#endif
+
+extern int node_id;
+extern int my_idag;
+extern int num_idags;
+extern int DDS_count;
+extern int my_cores_count;
+extern int nodes_ended_cnt;
+extern int nodes_initialised;
+extern int stats_replied;
+extern int paxos_stats_replied;
+extern int num_apps_terminated;
+extern int num_apps;
+extern int idags_replied;
+extern int index_top;
+extern int last_index_bottom;
+extern int NUES;
+extern int selfopt_interval;
+extern int init_DDS_replies;
+extern int init_DDS_idags;
+extern int selfopt_DDS_replies;
+extern int selfopt_DDS_idags;
+extern int base_offset;
+extern int old_cores_cnt;
+extern int active_working_cores;
+extern int delay;
+extern int R;
+
+extern int *sig_array;
+extern int *data_array;
+extern int *idag_id_arr;
+extern int *proposal_number_global;
+extern int sig_read_ar[2 * LINE_SIZE];
+
+extern long int selfopt_time_rem;
+
+extern metrics my_stats;
+extern metrics total_stats;
+extern metrics paxos_node_stats; 
+extern metrics paxos_total_stats;
+
+extern FILE *log_file;
+extern FILE *init_ack_file;
+extern FILE *app_log_file;
+
+extern float old_Speedup;
+extern float my_Speedup;
+
+/* SVM */
+
+extern agent_info cur_agent;
+extern agent_info pending_agent;
+
+extern core_states state;
+extern core_states pending_state;
+
+extern application_states app_state;
+
+extern inter_list **core_inter_head;
+extern inter_list **core_inter_tail;
+extern inter_list *init_pending_head;
+extern inter_list *init_pending_tail;
+
+extern DDS_list *DDS;
+extern DDS_list *DDS_tail;
+
+extern core_list *my_cores;
+extern core_list *my_cores_tail;
+
+extern offer_list *init_man_offers;
+extern offer_list *selfopt_man_offers;
+
+extern target_list *init_targets_head;
+extern target_list *init_targets_tail;
+extern target_list *selfopt_targets_head;
+extern target_list *selfopt_targets_tail;
+
+extern app my_app;
+extern app init_app;
+
+extern time_t cur_time;
+extern timer_t timerid, inter_timer;
+extern struct tm *cur_t;
+extern struct sigevent sev;
+extern struct itimerspec its, chk_timer;
+extern struct timeval time_val;
+
+extern char scen_num[SCEN_NUM_SIZE];
+extern char scen_directory[SCEN_DIR_SIZE];
+
+extern my_time_stamp init_app_times[2];
+extern my_time_stamp my_app_times[2];
+
+extern app_exec executed_app;
+
+/* PAXOS */
+extern int first_time;
+extern int worker_app_id;
+extern int worker_flag;
+extern int manager_to_fail;
+extern int faulty_core;
+extern int fail_flag;
+
+extern int pending_workload[2];
+
+extern int *alive;
+extern int *suspected;
+
+
+extern core_states paxos_state;
+
+extern acceptor_var acceptor_vars;
+extern proposer_var proposer_vars;
+
+extern coworkers_list *coworkers;
+
+extern timer_t controller_timer;
+extern timer_t epfd_timer;
+extern timer_t pfd_timer;
+
+extern struct timeval fail_time_val;
+#endif