Bläddra i källkod

cleaning + better managing the types of workers

Andra Hugo 11 år sedan
förälder
incheckning
e66dd53eab

+ 7 - 7
sc_hypervisor/include/sc_hypervisor.h

@@ -47,10 +47,10 @@ struct sc_hypervisor_policy
 	unsigned custom;
 
 	/* Distribute workers to contexts even at the begining of the program */
-	void (*size_ctxs)(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
+	void (*size_ctxs)(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
 
 	/* Require explicit resizing */
-	void (*resize_ctxs)(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
+	void (*resize_ctxs)(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
 
 	/* the hypervisor takes a decision when the worker was idle for another cyle in this ctx */
 	void (*handle_idle_cycle)(unsigned sched_ctx, int worker);
@@ -90,7 +90,7 @@ void sc_hypervisor_unregister_ctx(unsigned sched_ctx);
 void sc_hypervisor_post_resize_request(unsigned sched_ctx, int task_tag);
 
 /* reevaluate the distribution of the resources and eventually resize if needed */
-void sc_hypervisor_resize_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
+void sc_hypervisor_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
 
 /* don't allow the hypervisor to resize a context */
 void sc_hypervisor_stop_resize(unsigned sched_ctx);
@@ -111,13 +111,13 @@ void sc_hypervisor_remove_workers_from_sched_ctx(int* workers_to_remove, unsigne
 void sc_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now);
 
 /* ask the hypervisor to chose a distribution of workers in the required contexts */
-void sc_hypervisor_size_ctxs(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
+void sc_hypervisor_size_ctxs(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
 
 /* check if there are pending demands of resizing */
-unsigned sc_hypervisor_get_size_req(int **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers);
+unsigned sc_hypervisor_get_size_req(unsigned **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers);
 
 /* save a demand of resizing */
-void sc_hypervisor_save_size_req(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
+void sc_hypervisor_save_size_req(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
 
 /* clear the list of pending demands of resizing */
 void sc_hypervisor_free_size_req(void);
@@ -126,7 +126,7 @@ void sc_hypervisor_free_size_req(void);
 unsigned sc_hypervisor_can_resize(unsigned sched_ctx);
 
 /* indicate the types of tasks a context will execute in order to better decide the sizing of ctxs */
-	void sc_hypervisor_set_type_of_task(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
+void sc_hypervisor_set_type_of_task(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
 
 #ifdef __cplusplus
 }

+ 6 - 6
sc_hypervisor/include/sc_hypervisor_lp.h

@@ -33,9 +33,9 @@ extern "C"
 #endif //STARPU_HAVE_GLPK_H
 
 struct sc_hypervisor_policy_task_pool; 
-
+struct types_of_workers;
 /* returns tmax, and computes in table res the nr of workers needed by each context st the system ends up in the smallest tmax*/
-double sc_hypervisor_lp_get_nworkers_per_ctx(int nsched_ctxs, int ntypes_of_workers, double res[nsched_ctxs][ntypes_of_workers], int total_nw[ntypes_of_workers]);
+double sc_hypervisor_lp_get_nworkers_per_ctx(int nsched_ctxs, int ntypes_of_workers, double res[nsched_ctxs][ntypes_of_workers], int total_nw[ntypes_of_workers], struct types_of_workers *tw);
 
 /* returns tmax of the system */
 double sc_hypervisor_lp_get_tmax(int nw, int *workers);
@@ -44,13 +44,13 @@ double sc_hypervisor_lp_get_tmax(int nw, int *workers);
 void sc_hypervisor_lp_round_double_to_int(int ns, int nw, double res[ns][nw], int res_rounded[ns][nw]);
 
 /* redistribute the ressource in contexts by assigning the first x available ressources to each one */
-void sc_hypervisor_lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *sched_ctxs);
+void sc_hypervisor_lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], unsigned *sched_ctxs, struct types_of_workers *tw);
 
 /* make the first distribution of ressource in contexts by assigning the first x available ressources to each one */
-void sc_hypervisor_lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *workers, int nworkers);
+void sc_hypervisor_lp_distribute_resources_in_ctxs(unsigned* sched_ctxs, int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *workers, int nworkers, struct types_of_workers *tw);
 
 /* place resources in contexts dependig on whether they already have workers or not */
-void sc_hypervisor_lp_place_resources_in_ctx(int ns, int nw, double w_in_s[ns][nw], int *sched_ctxs, int *workers, unsigned do_size);
+void sc_hypervisor_lp_place_resources_in_ctx(int ns, int nw, double w_in_s[ns][nw], unsigned *sched_ctxs, int *workers, unsigned do_size, struct types_of_workers *tw);
 
 /* dichotomy btw t1 & t2 */
 double sc_hypervisor_lp_find_tmax(double t1, double t2);
@@ -69,7 +69,7 @@ double sc_hypervisor_lp_simulate_distrib_flops(int nsched_ctxs, int ntypes_of_wo
 
 /* linear program that simulates a distribution of tasks that minimises the execution time of the tasks in the pool */
 double sc_hypervisor_lp_simulate_distrib_tasks(int ns, int nw, int nt, double w_in_s[ns][nw], double tasks[nw][nt],
-					       double times[nw][nt], unsigned is_integer, double tmax, int *in_sched_ctxs,
+					       double times[nw][nt], unsigned is_integer, double tmax, unsigned *in_sched_ctxs,
 					       struct sc_hypervisor_policy_task_pool *tmp_task_pools);
 
 #endif // STARPU_HAVE_GLPK_H

+ 1 - 1
sc_hypervisor/include/sc_hypervisor_monitoring.h

@@ -105,7 +105,7 @@ struct sc_hypervisor_wrapper
 struct sc_hypervisor_wrapper *sc_hypervisor_get_wrapper(unsigned sched_ctx);
 
 /* get the list of registered contexts */
-int *sc_hypervisor_get_sched_ctxs();
+unsigned *sc_hypervisor_get_sched_ctxs();
 
 /* get the number of registered contexts */
 int sc_hypervisor_get_nsched_ctxs();

+ 19 - 3
sc_hypervisor/include/sc_hypervisor_policy.h

@@ -31,6 +31,13 @@ extern "C"
 #define SC_IDLE 1
 #define SC_SPEED 2
 
+struct types_of_workers
+{
+	unsigned ncpus;
+	unsigned ncuda;
+	unsigned nw;
+};
+
 struct sc_hypervisor_policy_task_pool
 {
 	struct starpu_codelet *cl;
@@ -42,7 +49,7 @@ struct sc_hypervisor_policy_task_pool
 };
 
 /* add task information to a task wrapper linked list */
-	void sc_hypervisor_policy_add_task_to_pool(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, struct sc_hypervisor_policy_task_pool **task_pools, size_t data_size);
+void sc_hypervisor_policy_add_task_to_pool(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, struct sc_hypervisor_policy_task_pool **task_pools, size_t data_size);
 
 /* remove task information from a task wrapper linked list */
 void sc_hypervisor_policy_remove_task_from_pool(struct starpu_task *task, uint32_t footprint, struct sc_hypervisor_policy_task_pool **task_pools);
@@ -63,7 +70,7 @@ int* sc_hypervisor_get_idlest_workers(unsigned sched_ctx, int *nworkers, enum st
 int* sc_hypervisor_get_idlest_workers_in_list(int *start, int *workers, int nall_workers,  int *nworkers, enum starpu_worker_archtype arch);
 
 /* find workers that can be moved from a context (if the constraints of min, max, etc allow this) */
-unsigned sc_hypervisor_get_movable_nworkers(struct sc_hypervisor_policy_config *config, unsigned sched_ctx, enum starpu_worker_archtype arch);
+int sc_hypervisor_get_movable_nworkers(struct sc_hypervisor_policy_config *config, unsigned sched_ctx, enum starpu_worker_archtype arch);
 
 /* compute how many workers should be moved from this context */
 int sc_hypervisor_compute_nworkers_to_move(unsigned req_sched_ctx);
@@ -93,7 +100,13 @@ double sc_hypervisor_get_speed_per_worker_type(struct sc_hypervisor_wrapper* sc_
 double sc_hypervisor_get_ref_speed_per_worker_type(struct sc_hypervisor_wrapper* sc_w, enum starpu_worker_archtype arch);
 
 /* get the list of workers grouped by type */
-void sc_hypervisor_group_workers_by_type(int *workers, int nworkers, int ntypes_of_workers, int total_nw[ntypes_of_workers]);
+void sc_hypervisor_group_workers_by_type(struct types_of_workers *tw, int *total_nw);
+
+/* get what type of worker corresponds to a certain index of types of workers */
+enum starpu_worker_archtype sc_hypervisor_get_arch_for_index(unsigned w, struct types_of_workers *tw);
+
+/* get the index of types of workers corresponding to the type of workers indicated */
+unsigned sc_hypervisor_get_index_for_arch(enum starpu_worker_archtype arch, struct types_of_workers *tw);
 
 /* check if we trigger resizing or not */
 unsigned sc_hypervisor_criteria_fulfilled(unsigned sched_ctx, int worker);
@@ -107,6 +120,9 @@ unsigned sc_hypervisor_check_speed_gap_btw_ctxs(void);
 /* check what triggers resizing (idle, speed, etc.)*/
 unsigned sc_hypervisor_get_resize_criteria();
 
+/* load information concerning the type of workers into a types_of_workers struct */
+struct types_of_workers* sc_hypervisor_get_types_of_workers(int *workers, unsigned nworkers);
+
 #ifdef __cplusplus
 }
 #endif

+ 33 - 29
sc_hypervisor/src/hypervisor_policies/debit_lp_policy.c

@@ -20,14 +20,14 @@
 #include <math.h>
 #include <sys/time.h>
 
-static double _glp_resolve(int ns, int nw, double speed[ns][nw], double w_in_s[ns][nw], int *workers, unsigned integer);
+static double _glp_resolve(int ns, int nw, double speed[ns][nw], double w_in_s[ns][nw], unsigned integer);
 
 
-static unsigned _compute_max_speed(int ns, int nw, double w_in_s[ns][nw], int *in_sched_ctxs, int *workers)
+static unsigned _compute_max_speed(int ns, int nw, double w_in_s[ns][nw], unsigned *in_sched_ctxs, int *workers)
 {
 	double speed[ns][nw];
 
-	int *sched_ctxs = in_sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : in_sched_ctxs;
+	unsigned *sched_ctxs = in_sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : in_sched_ctxs;
 	
 	int w,s;
 
@@ -50,7 +50,7 @@ static unsigned _compute_max_speed(int ns, int nw, double w_in_s[ns][nw], int *i
 	struct timeval end_time;
 	gettimeofday(&start_time, NULL);
 
-	double res = _glp_resolve(ns, nw, speed, w_in_s, workers, 1);
+	double res = _glp_resolve(ns, nw, speed, w_in_s, 1);
 	gettimeofday(&end_time, NULL);
 
 	long diff_s = end_time.tv_sec  - start_time.tv_sec;
@@ -68,9 +68,9 @@ static unsigned _compute_max_speed(int ns, int nw, double w_in_s[ns][nw], int *i
  */
 #ifdef STARPU_HAVE_GLPK_H
 #include <glpk.h>
-static double _glp_resolve(int ns, int nw, double speed[ns][nw], double w_in_s[ns][nw], int *workers, unsigned integer)
+static double _glp_resolve(int ns, int nw, double speed[ns][nw], double w_in_s[ns][nw], unsigned integer)
 {
-	int w, s;
+	int w = 0, s = 0;
 	glp_prob *lp;
 
 	lp = glp_create_prob();
@@ -225,10 +225,10 @@ static double _glp_resolve(int ns, int nw, double speed[ns][nw], double w_in_s[n
 }
 
 
-static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+static void _try_resizing(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
 	int ns = sched_ctxs == NULL ? sc_hypervisor_get_nsched_ctxs() : nsched_ctxs;
-	int nw = workers == NULL ? starpu_worker_get_count() : nworkers; /* Number of different workers */
+	int nw = workers == NULL ? (int)starpu_worker_get_count() : nworkers; /* Number of different workers */
 	
 	sched_ctxs = sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs;
 
@@ -237,16 +237,17 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int n
 	/* if we did find at least one solution redistribute the resources */
 	if(found_sol)
 	{
+		struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, nw);
 		int w, s;
-		double nworkers_per_ctx[ns][2];
-		int nworkers_per_ctx_rounded[ns][2];
+		double nworkers_per_ctx[ns][tw->nw];
+		int nworkers_per_ctx_rounded[ns][tw->nw];
 		for(s = 0; s < ns; s++)
 		{
-			nworkers_per_ctx[s][0] = 0.0;
-			nworkers_per_ctx[s][1] = 0.0;
-			nworkers_per_ctx_rounded[s][0] = 0;
-			nworkers_per_ctx_rounded[s][1] = 0;
-			
+			for(w = 0; w < nw; w++)
+			{
+				nworkers_per_ctx[s][w] = 0.0;
+				nworkers_per_ctx_rounded[s][w] = 0;
+			}
 		}
 		
 		for(s = 0; s < ns; s++)
@@ -254,18 +255,20 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int n
 			for(w = 0; w < nw; w++)
 			{
 				enum starpu_worker_archtype arch = starpu_worker_get_type(w);
+				int idx = sc_hypervisor_get_index_for_arch(STARPU_CUDA_WORKER, tw);
+				nworkers_per_ctx[s][idx] += w_in_s[s][w];
 				
 				if(arch == STARPU_CUDA_WORKER)
 				{
-					nworkers_per_ctx[s][0] += w_in_s[s][w];
 					if(w_in_s[s][w] >= 0.3)
-						nworkers_per_ctx_rounded[s][0]++;
+						nworkers_per_ctx_rounded[s][idx]++;
 				}
 				else
 				{
-					nworkers_per_ctx[s][1] += w_in_s[s][w];
+					int idx = sc_hypervisor_get_index_for_arch(STARPU_CPU_WORKER, tw);
+					nworkers_per_ctx[s][idx] += w_in_s[s][w];
 					if(w_in_s[s][w] > 0.5)
-						nworkers_per_ctx_rounded[s][1]++;
+						nworkers_per_ctx_rounded[s][idx]++;
 				}
 			}
 		}
@@ -273,12 +276,14 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int n
 /* 					printf("%d: cpus = %lf gpus = %lf cpus_round = %d gpus_round = %d\n", s, nworkers[s][1], nworkers[s][0], */
 /* 					       nworkers_rounded[s][1], nworkers_rounded[s][0]); */
 		
-		sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, 2, nworkers_per_ctx_rounded, nworkers_per_ctx, sched_ctxs);
+
+		sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, tw->nw, nworkers_per_ctx_rounded, nworkers_per_ctx, sched_ctxs, tw);
 		
 	}
 }
 
-static void debit_lp_handle_poped_task(unsigned sched_ctx, int worker, struct starpu_task *task, uint32_t footprint)
+static void debit_lp_handle_poped_task(__attribute__((unused))unsigned sched_ctx, __attribute__((unused))int worker, 
+				       __attribute__((unused))struct starpu_task *task, __attribute__((unused))uint32_t footprint)
 {
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
         if(ret != EBUSY)
@@ -295,7 +300,7 @@ static void debit_lp_handle_poped_task(unsigned sched_ctx, int worker, struct st
 	}
 }
 
-static debit_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
+static void debit_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
 {
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
         if(ret != EBUSY)
@@ -307,15 +312,14 @@ static debit_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
 			if(sc_hypervisor_check_idle(sched_ctx, worker))
                         {
                                 _try_resizing(NULL, -1, NULL, -1);
-//                              sc_hypervisor_move_workers(sched_ctx, 3 - sched_ctx, &worker, 1, 1);                                                                                                               \
-                                                                                                                                                                                                                    
-                        }
+//                              sc_hypervisor_move_workers(sched_ctx, 3 - sched_ctx, &worker, 1, 1);
+			}
                 }
                 starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
         }
 }
 
-static void debit_lp_resize_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+static void debit_lp_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 	if(ret != EBUSY)
@@ -325,10 +329,10 @@ static void debit_lp_resize_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers
 	}
 }
 
-static void debit_lp_end_ctx(unsigned sched_ctx)
+static void debit_lp_end_ctx(__attribute__((unused))unsigned sched_ctx)
 {
-	struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx);
-	int worker;
+/* 	struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx); */
+/* 	int worker; */
 /* 	for(worker = 0; worker < 12; worker++) */
 /* 		printf("%d/%d: speed %lf\n", worker, sched_ctx, sc_w->ref_speed[worker]); */
 

+ 29 - 29
sc_hypervisor/src/hypervisor_policies/feft_lp_policy.c

@@ -20,28 +20,27 @@
 #include <sys/time.h>
 
 #ifdef STARPU_HAVE_GLPK_H
-static void _try_resizing(int *sched_ctxs, int nsched_ctxs)
+static void _try_resizing(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
 {
 	/* for vite */
 	starpu_trace_user_event(2);
 	int ns = sched_ctxs == NULL ? sc_hypervisor_get_nsched_ctxs() : nsched_ctxs;
-	int curr_sched_ctxs = sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs;
+	unsigned *curr_sched_ctxs = sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs;
+	unsigned curr_nworkers = nworkers == -1 ? starpu_worker_get_count() : (unsigned)nworkers;
+	
+	struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, curr_nworkers);
+	int nw = tw->nw;
+	double nworkers_per_ctx[ns][nw];
 
-	double nworkers_per_ctx[ns][2];
-	int nw = 1;
-#ifdef STARPU_USE_CUDA
-	int ncuda = starpu_worker_get_count_by_type(STARPU_CUDA_WORKER);
-	nw = ncuda != 0 ? 2 : 1;
-#endif
 	int total_nw[nw];
-	sc_hypervisor_group_workers_by_type(NULL, -1, nw, total_nw);
+	sc_hypervisor_group_workers_by_type(tw, total_nw);
 	
 	
 	struct timeval start_time;
 	struct timeval end_time;
 	gettimeofday(&start_time, NULL);
-	printf("###########################################try resize\n");
-	double vmax = sc_hypervisor_lp_get_nworkers_per_ctx(ns, nw, nworkers_per_ctx, total_nw);
+	
+	double vmax = sc_hypervisor_lp_get_nworkers_per_ctx(ns, nw, nworkers_per_ctx, total_nw, tw);
 	gettimeofday(&end_time, NULL);
 	
 	long diff_s = end_time.tv_sec  - start_time.tv_sec;
@@ -53,7 +52,7 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs)
 	{
 		int nworkers_per_ctx_rounded[nsched_ctxs][nw];
 		sc_hypervisor_lp_round_double_to_int(ns, nw, nworkers_per_ctx, nworkers_per_ctx_rounded);
-		sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, nw, nworkers_per_ctx_rounded, nworkers_per_ctx, curr_sched_ctxs);
+		sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, nw, nworkers_per_ctx_rounded, nworkers_per_ctx, curr_sched_ctxs, tw);
 	}
 }
 
@@ -68,27 +67,29 @@ static void feft_lp_handle_poped_task(__attribute__((unused))unsigned sched_ctx,
 		{
 			if(sc_hypervisor_check_speed_gap_btw_ctxs())
 			{
-				_try_resizing(NULL, -1);
+				_try_resizing(NULL, -1, NULL, -1);
 			}
 		}
 		starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
 	}
 
 }
-static void feft_lp_size_ctxs(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
+static void feft_lp_size_ctxs(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
 {
 	int ns = sched_ctxs == NULL ? sc_hypervisor_get_nsched_ctxs() : nsched_ctxs;
-	int nw = 1;
-#ifdef STARPU_USE_CUDA
-	int ncuda = starpu_worker_get_count_by_type(STARPU_CUDA_WORKER);
-	nw = ncuda != 0 ? 2 : 1;
-#endif
+	unsigned *curr_sched_ctxs = sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs;
+	unsigned curr_nworkers = nworkers == -1 ? starpu_worker_get_count() : (unsigned)nworkers;
+	
+	struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, curr_nworkers);
+	int nw = tw->nw;
 	double nworkers_per_type[ns][nw];
+
 	int total_nw[nw];
-	sc_hypervisor_group_workers_by_type(workers, nworkers, nw, total_nw);
+	sc_hypervisor_group_workers_by_type(tw, total_nw);
+	
 
 	starpu_pthread_mutex_lock(&act_hypervisor_mutex);
-	double vmax = sc_hypervisor_lp_get_nworkers_per_ctx(ns, nw, nworkers_per_type, total_nw);
+	double vmax = sc_hypervisor_lp_get_nworkers_per_ctx(ns, nw, nworkers_per_type, total_nw, tw);
 	if(vmax != 0.0)
 	{
 // 		printf("********size\n");
@@ -113,13 +114,12 @@ static void feft_lp_size_ctxs(int *sched_ctxs, int nsched_ctxs, int *workers, in
 /* 				printf("ctx %d/worker type %d: n = %d \n", i, 1, nworkers_per_type_rounded[i][1]); */
 /* #endif */
 /* 		} */
-		int *current_sched_ctxs = sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs;
 
 		unsigned has_workers = 0;
 		int s;
 		for(s = 0; s < ns; s++)
 		{
-			int nworkers_ctx = sc_hypervisor_get_nworkers_ctx(current_sched_ctxs[s], STARPU_ANY_WORKER);
+			int nworkers_ctx = sc_hypervisor_get_nworkers_ctx(curr_sched_ctxs[s], STARPU_ANY_WORKER);
 			if(nworkers_ctx != 0)
 			{
 				has_workers = 1;
@@ -127,9 +127,9 @@ static void feft_lp_size_ctxs(int *sched_ctxs, int nsched_ctxs, int *workers, in
 			}
 		}
 		if(has_workers)
-			sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, nw, nworkers_per_type_rounded, nworkers_per_type, current_sched_ctxs);
+			sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, nw, nworkers_per_type_rounded, nworkers_per_type, curr_sched_ctxs, tw);
 		else
-			sc_hypervisor_lp_distribute_resources_in_ctxs(sched_ctxs, ns, nw, nworkers_per_type_rounded, nworkers_per_type, workers, nworkers);
+			sc_hypervisor_lp_distribute_resources_in_ctxs(sched_ctxs, ns, nw, nworkers_per_type_rounded, nworkers_per_type, workers, curr_nworkers, tw);
 	}
 	starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
 }
@@ -145,7 +145,7 @@ static void feft_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
 			
 			if(sc_hypervisor_check_idle(sched_ctx, worker))
 			{
-				_try_resizing(NULL, -1);
+				_try_resizing(NULL, -1, NULL, -1);
 //				sc_hypervisor_move_workers(sched_ctx, 3 - sched_ctx, &worker, 1, 1);
 			}
 		}
@@ -153,8 +153,8 @@ static void feft_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
 	}
 }
 
-static void feft_lp_resize_ctxs(int *sched_ctxs, int nsched_ctxs , 
-				__attribute__((unused))int *workers, __attribute__((unused))int nworkers)
+static void feft_lp_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs , 
+				int *workers, int nworkers)
 {
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 	if(ret != EBUSY)
@@ -172,7 +172,7 @@ static void feft_lp_resize_ctxs(int *sched_ctxs, int nsched_ctxs ,
 			 }
 		}
 
-		_try_resizing(sched_ctxs, nsched_ctxs);
+		_try_resizing(sched_ctxs, nsched_ctxs, workers, nworkers);
 		starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
 	}
 }

+ 10 - 9
sc_hypervisor/src/hypervisor_policies/gflops_rate_policy.c

@@ -70,11 +70,11 @@ static int* _get_workers_to_move(unsigned sender_sched_ctx, unsigned receiver_sc
         if(nworkers_needed > 0)
         {
                 struct sc_hypervisor_policy_config *sender_config = sc_hypervisor_get_config(sender_sched_ctx);
-                unsigned potential_moving_cpus = sc_hypervisor_get_movable_nworkers(sender_config, sender_sched_ctx, STARPU_CPU_WORKER);
-                unsigned potential_moving_gpus = sc_hypervisor_get_movable_nworkers(sender_config, sender_sched_ctx, STARPU_CUDA_WORKER);
-                unsigned sender_nworkers = starpu_sched_ctx_get_nworkers(sender_sched_ctx);
+                int potential_moving_cpus = sc_hypervisor_get_movable_nworkers(sender_config, sender_sched_ctx, STARPU_CPU_WORKER);
+                int potential_moving_gpus = sc_hypervisor_get_movable_nworkers(sender_config, sender_sched_ctx, STARPU_CUDA_WORKER);
+                int sender_nworkers = (int)starpu_sched_ctx_get_nworkers(sender_sched_ctx);
                 struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(receiver_sched_ctx);
-                unsigned nworkers_ctx = starpu_sched_ctx_get_nworkers(receiver_sched_ctx);
+                int nworkers_ctx = (int)starpu_sched_ctx_get_nworkers(receiver_sched_ctx);
 
                 if(nworkers_needed < (potential_moving_cpus + 5 * potential_moving_gpus))
                 {
@@ -119,7 +119,7 @@ static int* _get_workers_to_move(unsigned sender_sched_ctx, unsigned receiver_sc
 
                         if(sender_nworkers - nworkers_to_move >= sender_config->min_nworkers)
                         {
-                                unsigned nshared_workers = starpu_sched_ctx_get_nshared_workers(sender_sched_ctx, receiver_sched_ctx);
+                                int nshared_workers = (int)starpu_sched_ctx_get_nshared_workers(sender_sched_ctx, receiver_sched_ctx);
                                 if((nworkers_ctx + nworkers_to_move - nshared_workers) > config->max_nworkers)
                                         nworkers_to_move = nworkers_ctx > config->max_nworkers ? 0 : (config->max_nworkers - nworkers_ctx + nshared_workers);
 
@@ -165,11 +165,11 @@ static unsigned _gflops_rate_resize(unsigned sender_sched_ctx, unsigned receiver
 
 static int _find_fastest_sched_ctx()
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 	double first_exp_end = _get_exp_end(sched_ctxs[0]);
-	int fastest_sched_ctx = first_exp_end == -1.0  ? -1 : sched_ctxs[0];
+	int fastest_sched_ctx = first_exp_end == -1.0  ? -1 : (int)sched_ctxs[0];
 	double curr_exp_end = 0.0;
 	int i;
 	for(i = 1; i < nsched_ctxs; i++)
@@ -188,7 +188,7 @@ static int _find_fastest_sched_ctx()
 
 static int _find_slowest_sched_ctx()
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 	int slowest_sched_ctx = -1;
@@ -214,7 +214,7 @@ static int _find_slowest_sched_ctx()
 
 static int _find_slowest_available_sched_ctx(unsigned sched_ctx)
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 	int slowest_sched_ctx = -1;
@@ -296,6 +296,7 @@ static void gflops_rate_handle_poped_task(unsigned sched_ctx, int worker)
 
 struct sc_hypervisor_policy gflops_rate_policy = {
 	.size_ctxs = NULL,
+	.resize_ctxs = NULL,
 	.handle_poped_task = gflops_rate_handle_poped_task,
 	.handle_pushed_task = NULL,
 	.handle_idle_cycle = NULL,

+ 1 - 1
sc_hypervisor/src/hypervisor_policies/idle_policy.c

@@ -18,7 +18,7 @@
 
 unsigned worker_belong_to_other_sched_ctx(unsigned sched_ctx, int worker)
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 	int i;

+ 24 - 20
sc_hypervisor/src/hypervisor_policies/ispeed_lp_policy.c

@@ -253,7 +253,7 @@ static double _glp_resolve (int ns, int nw, double final_w_in_s[ns][nw],
 	return res;
 }
 
-static unsigned _compute_flops_distribution_over_ctxs(int ns, int nw, double w_in_s[ns][nw], double **flops_on_w, int *in_sched_ctxs, int *workers)
+static unsigned _compute_flops_distribution_over_ctxs(int ns, int nw, double w_in_s[ns][nw], double **flops_on_w, unsigned *in_sched_ctxs, int *workers)
 {
 //	double flops[ns];
 //	double speed[ns][nw];
@@ -263,7 +263,7 @@ static unsigned _compute_flops_distribution_over_ctxs(int ns, int nw, double w_i
 	for(i = 0; i < ns; i++)
 		speed[i] = (double*)malloc(nw*sizeof(double));
 
-	int *sched_ctxs = in_sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : in_sched_ctxs;
+	unsigned *sched_ctxs = in_sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : in_sched_ctxs;
 	
 	int w,s;
 
@@ -323,13 +323,17 @@ static unsigned _compute_flops_distribution_over_ctxs(int ns, int nw, double w_i
 	return found_sol;
 }
 
-static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+static void _try_resizing(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
-	int ns = sched_ctxs == NULL ? sc_hypervisor_get_nsched_ctxs() : nsched_ctxs;
-	int nw = nworkers == -1 ? (int)starpu_worker_get_count() : nworkers; /* Number of different workers */
+	starpu_trace_user_event(2);
+        int ns = sched_ctxs == NULL ? sc_hypervisor_get_nsched_ctxs() : nsched_ctxs;
+        unsigned *curr_sched_ctxs = sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs;
+        unsigned curr_nworkers = nworkers == -1 ? starpu_worker_get_count() : (unsigned)nworkers;
+
+        struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, curr_nworkers);
+        int nw = tw->nw;
+
 
-	sched_ctxs = sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs;
-	
 	double w_in_s[ns][nw];
 //			double flops_on_w[ns][nw];
 	double **flops_on_w = (double**)malloc(ns*sizeof(double*));
@@ -337,20 +341,20 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int n
 	for(i = 0; i < ns; i++)
 		flops_on_w[i] = (double*)malloc(nw*sizeof(double));
 	
-	unsigned found_sol = _compute_flops_distribution_over_ctxs(ns, nw,  w_in_s, flops_on_w, sched_ctxs, workers);
+	unsigned found_sol = _compute_flops_distribution_over_ctxs(ns, nw,  w_in_s, flops_on_w, curr_sched_ctxs, workers);
 	/* if we did find at least one solution redistribute the resources */
 	if(found_sol)
 	{
 		int w, s;
-		double nworkers_per_ctx[ns][2];
-		int nworkers_per_ctx_rounded[ns][2];
+		double nworkers_per_ctx[ns][nw];
+		int nworkers_per_ctx_rounded[ns][nw];
 		for(s = 0; s < ns; s++)
 		{
-			nworkers_per_ctx[s][0] = 0.0;
-			nworkers_per_ctx[s][1] = 0.0;
-			nworkers_per_ctx_rounded[s][0] = 0;
-			nworkers_per_ctx_rounded[s][1] = 0;
-			
+			for(w = 0; w < nw; w++)
+			{
+				nworkers_per_ctx[s][w] = 0.0;
+				nworkers_per_ctx_rounded[s][w] = 0;
+			}
 		}
 		
 		for(s = 0; s < ns; s++)
@@ -358,16 +362,16 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int n
 			for(w = 0; w < nw; w++)
 			{
 				enum starpu_worker_archtype arch = starpu_worker_get_type(w);
-				
+		
+				int idx = sc_hypervisor_get_index_for_arch(arch, tw);
+				nworkers_per_ctx[s][idx] += w_in_s[s][w];
 				if(arch == STARPU_CUDA_WORKER)
 				{
-					nworkers_per_ctx[s][0] += w_in_s[s][w];
 					if(w_in_s[s][w] >= 0.3)
 						nworkers_per_ctx_rounded[s][0]++;
 				}
 				else
 				{
-					nworkers_per_ctx[s][1] += w_in_s[s][w];
 					if(w_in_s[s][w] > 0.5)
 						nworkers_per_ctx_rounded[s][1]++;
 				}
@@ -377,7 +381,7 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int n
 /* 					printf("%d: cpus = %lf gpus = %lf cpus_round = %d gpus_round = %d\n", s, nworkers[s][1], nworkers[s][0], */
 /* 					       nworkers_rounded[s][1], nworkers_rounded[s][0]); */
 		
-		sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, 2, nworkers_per_ctx_rounded, nworkers_per_ctx, sched_ctxs);
+		sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, nw, nworkers_per_ctx_rounded, nworkers_per_ctx, curr_sched_ctxs, tw);
 	}
 	for(i = 0; i < ns; i++)
 		free(flops_on_w[i]);
@@ -421,7 +425,7 @@ static void ispeed_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
         }
 }
 
-static void ispeed_lp_resize_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+static void ispeed_lp_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 	if(ret != EBUSY)

+ 3 - 3
sc_hypervisor/src/hypervisor_policies/ispeed_policy.c

@@ -18,7 +18,7 @@
 
 static unsigned _get_fastest_sched_ctx(void)
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 	int fastest_sched_ctx = STARPU_NMAX_SCHED_CTXS;
@@ -40,7 +40,7 @@ static unsigned _get_fastest_sched_ctx(void)
 
 static unsigned _get_slowest_sched_ctx(void)
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 	double smallest_speed = sc_hypervisor_get_ctx_speed(sc_hypervisor_get_wrapper(sched_ctxs[0]));
@@ -141,7 +141,7 @@ static int* _get_slowest_workers(unsigned sched_ctx, int *nworkers, enum starpu_
 	return curr_workers;
 }			
 
-static void ispeed_handle_poped_task(unsigned sched_ctx, int worker, struct starpu_task *task, uint32_t footprint)
+static void ispeed_handle_poped_task(unsigned sched_ctx, int worker, __attribute__((unused))struct starpu_task *task, __attribute__((unused))uint32_t footprint)
 {
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 	if(ret != EBUSY)

+ 19 - 12
sc_hypervisor/src/hypervisor_policies/teft_lp_policy.c

@@ -28,7 +28,7 @@ struct teft_lp_data
 {
 	int nt;
 	double **tasks;
-	int *in_sched_ctxs;
+	unsigned *in_sched_ctxs;
 	int *workers;
 	struct sc_hypervisor_policy_task_pool *tmp_task_pools;
 	unsigned size_ctxs;
@@ -41,7 +41,7 @@ static double _compute_workers_distrib(int ns, int nw, double final_w_in_s[ns][n
 
 	int nt = sd->nt;
 	double **final_tasks = sd->tasks;
-	int *in_sched_ctxs = sd->in_sched_ctxs;
+	unsigned *in_sched_ctxs = sd->in_sched_ctxs;
 	int *workers = sd->workers;
 	struct sc_hypervisor_policy_task_pool *tmp_task_pools = sd->tmp_task_pools;
 	unsigned size_ctxs = sd->size_ctxs;
@@ -74,7 +74,7 @@ static double _compute_workers_distrib(int ns, int nw, double final_w_in_s[ns][n
 	return res;
 }
 	
-static void _size_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+static void _size_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
 	int ns = sched_ctxs == NULL ? sc_hypervisor_get_nsched_ctxs() : nsched_ctxs;
 	int nw = workers == NULL ? (int)starpu_worker_get_count() : nworkers; /* Number of different workers */
@@ -114,7 +114,10 @@ static void _size_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nwor
 	starpu_pthread_mutex_unlock(&mutex);
 	/* if we did find at least one solution redistribute the resources */
 	if(found_sol)
-		sc_hypervisor_lp_place_resources_in_ctx(ns, nw, w_in_s, sched_ctxs, workers, 1);
+	{
+		struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, nw);
+		sc_hypervisor_lp_place_resources_in_ctx(ns, nw, w_in_s, sched_ctxs, workers, 1, tw);
+	}
 	
 	for(i = 0; i < nw; i++)
 		free(tasks[i]);
@@ -125,7 +128,8 @@ static void _size_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nwor
 static void size_if_required()
 {
 	int nsched_ctxs, nworkers;
-	int *sched_ctxs, *workers;
+	unsigned *sched_ctxs;
+	int *workers;
 	unsigned has_req = sc_hypervisor_get_size_req(&sched_ctxs, &nsched_ctxs, &workers, &nworkers);
 
 	if(has_req)
@@ -161,7 +165,7 @@ static void teft_lp_handle_submitted_job(struct starpu_codelet *cl, unsigned sch
 	size_if_required();
 }
 
-static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+static void _try_resizing(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
 	starpu_trace_user_event(2);
 	int ns = sched_ctxs == NULL ? sc_hypervisor_get_nsched_ctxs() : nsched_ctxs;
@@ -214,7 +218,10 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int n
 	
 	/* if we did find at least one solution redistribute the resources */
 	if(found_sol)
-		sc_hypervisor_lp_place_resources_in_ctx(ns, nw, w_in_s, sched_ctxs, workers, 0);
+	{
+		struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, nw);
+		sc_hypervisor_lp_place_resources_in_ctx(ns, nw, w_in_s, sched_ctxs, workers, 0, tw);
+	}
 	
 	struct sc_hypervisor_policy_task_pool *next = NULL;
 	struct sc_hypervisor_policy_task_pool *tmp_tp = tmp_task_pools;
@@ -230,7 +237,7 @@ static void _try_resizing(int *sched_ctxs, int nsched_ctxs , int *workers, int n
 	free(tasks_per_worker);
 }
 
-static void teft_lp_handle_poped_task(unsigned sched_ctx, int worker, struct starpu_task *task, uint32_t footprint)
+static void teft_lp_handle_poped_task(unsigned sched_ctx, __attribute__((unused))int worker, struct starpu_task *task, uint32_t footprint)
 {
 	struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx);
 
@@ -262,7 +269,7 @@ static void teft_lp_handle_poped_task(unsigned sched_ctx, int worker, struct sta
 
 }
 
-static int teft_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
+static void teft_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
 {
 	struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx);
 
@@ -288,15 +295,15 @@ static int teft_lp_handle_idle_cycle(unsigned sched_ctx, int worker)
 		}
 		starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
 	}
-	return 0;
+	return;
 }
 
-static void teft_lp_size_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+static void teft_lp_size_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
 	sc_hypervisor_save_size_req(sched_ctxs, nsched_ctxs, workers, nworkers);
 }
 
-static void teft_lp_resize_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+static void teft_lp_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
 	int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
 	if(ret != EBUSY)

+ 3 - 3
sc_hypervisor/src/policies_utils/lp_programs.c

@@ -23,7 +23,7 @@
 #ifdef STARPU_HAVE_GLPK_H
 
 double sc_hypervisor_lp_simulate_distrib_tasks(int ns, int nw, int nt, double w_in_s[ns][nw], double tasks[nw][nt],
-					       double times[nw][nt], unsigned is_integer, double tmax, int *in_sched_ctxs,
+					       double times[nw][nt], unsigned is_integer, double tmax, unsigned *in_sched_ctxs,
 					       struct sc_hypervisor_policy_task_pool *tmp_task_pools)
 {
 	struct sc_hypervisor_policy_task_pool * tp;
@@ -80,7 +80,7 @@ double sc_hypervisor_lp_simulate_distrib_tasks(int ns, int nw, int nt, double w_
 					glp_set_col_bnds(lp, nw*nt+s*nw+w+1, GLP_DB, 0.0, 1.0);
 			}
 
-		int *sched_ctxs = in_sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : in_sched_ctxs;
+		unsigned *sched_ctxs = in_sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : in_sched_ctxs;
 
 		int curr_row_idx = 0;
 		/* Total worker execution time */
@@ -110,7 +110,7 @@ double sc_hypervisor_lp_simulate_distrib_tasks(int ns, int nw, int nt, double w_
 				glp_set_row_name(lp, curr_row_idx+s*nw+w+1, title);
 				for (t = 0, tp = tmp_task_pools; tp; t++, tp = tp->next)
 				{
-					if((int)tp->sched_ctx_id == sched_ctxs[s])
+					if(tp->sched_ctx_id == sched_ctxs[s])
 					{
 						ia[n] = curr_row_idx+s*nw+w+1;
 						ja[n] = colnum(w, t);

+ 64 - 78
sc_hypervisor/src/policies_utils/lp_tools.c

@@ -25,30 +25,35 @@
 
 #endif //STARPU_HAVE_GLPK_H
 
-double sc_hypervisor_lp_get_nworkers_per_ctx(int nsched_ctxs, int ntypes_of_workers, double res[nsched_ctxs][ntypes_of_workers], int total_nw[ntypes_of_workers])
+double sc_hypervisor_lp_get_nworkers_per_ctx(int nsched_ctxs, int ntypes_of_workers, double res[nsched_ctxs][ntypes_of_workers], 
+					     int total_nw[ntypes_of_workers], struct types_of_workers *tw)
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 #ifdef STARPU_HAVE_GLPK_H
 	double v[nsched_ctxs][ntypes_of_workers];
 	double flops[nsched_ctxs];
 
+	int nw = tw->nw;
 	int i = 0;
 	struct sc_hypervisor_wrapper* sc_w;
 	for(i = 0; i < nsched_ctxs; i++)
 	{
 		sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
-#ifdef STARPU_USE_CUDA
-		int ncuda = starpu_worker_get_count_by_type(STARPU_CUDA_WORKER);
-		if(ncuda != 0)
-		{
-			v[i][0] = sc_hypervisor_get_speed(sc_w, STARPU_CUDA_WORKER);
-			v[i][1] = sc_hypervisor_get_speed(sc_w, STARPU_CPU_WORKER);
-		}
-		else
-			v[i][0] = sc_hypervisor_get_speed(sc_w, STARPU_CPU_WORKER);
-#else
-		v[i][0] = sc_hypervisor_get_speed(sc_w, STARPU_CPU_WORKER);
-#endif // STARPU_USE_CUDA
+/* #ifdef STARPU_USE_CUDA */
+/* 		int ncuda = starpu_worker_get_count_by_type(STARPU_CUDA_WORKER); */
+/* 		if(ncuda != 0) */
+/* 		{ */
+/* 			v[i][0] = sc_hypervisor_get_speed(sc_w, STARPU_CUDA_WORKER); */
+/* 			v[i][1] = sc_hypervisor_get_speed(sc_w, STARPU_CPU_WORKER); */
+/* 		} */
+/* 		else */
+/* 			v[i][0] = sc_hypervisor_get_speed(sc_w, STARPU_CPU_WORKER); */
+/* #else */
+/* 		v[i][0] = sc_hypervisor_get_speed(sc_w, STARPU_CPU_WORKER); */
+/* #endif // STARPU_USE_CUDA */
+		int w;
+		for(w = 0; w < nw; w++)
+			v[i][w] = sc_hypervisor_get_speed(sc_w, sc_hypervisor_get_arch_for_index(w, tw)); 
 		
 		flops[i] = sc_w->remaining_flops < 0.0 ? 0.0 : sc_w->remaining_flops/1000000000; //sc_w->total_flops/1000000000; /* in gflops*/
 //		printf("%d: flops %lf\n", sched_ctxs[i], flops[i]);
@@ -74,16 +79,18 @@ double sc_hypervisor_lp_get_nworkers_per_ctx(int nsched_ctxs, int ntypes_of_work
 #endif//STARPU_HAVE_GLPK_H
 }
 
-double sc_hypervisor_lp_get_tmax(int nw, int *workers)
+double sc_hypervisor_lp_get_tmax(int nworkers, int *workers)
 {
-	int ntypes_of_workers = 2;
-	int total_nw[ntypes_of_workers];
-	sc_hypervisor_group_workers_by_type(workers, nw, 2, total_nw);
+	struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, nworkers);
+        int nw = tw->nw;
+
+        int total_nw[nw];
+        sc_hypervisor_group_workers_by_type(tw, total_nw);
 
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
-	double res[nsched_ctxs][ntypes_of_workers];
-	return sc_hypervisor_lp_get_nworkers_per_ctx(nsched_ctxs, ntypes_of_workers, res, total_nw) * 1000.0;
+	double res[nsched_ctxs][nw];
+	return sc_hypervisor_lp_get_nworkers_per_ctx(nsched_ctxs, nw, res, total_nw, tw) * 1000.0;
 }
 
 void sc_hypervisor_lp_round_double_to_int(int ns, int nw, double res[ns][nw], int res_rounded[ns][nw])
@@ -147,18 +154,16 @@ void sc_hypervisor_lp_round_double_to_int(int ns, int nw, double res[ns][nw], in
 void _lp_find_workers_to_give_away(int nw, int ns, unsigned sched_ctx, int sched_ctx_idx, 
 				  int tmp_nw_move[nw], int tmp_workers_move[nw][STARPU_NMAXWORKERS], 
 				  int tmp_nw_add[nw], int tmp_workers_add[nw][STARPU_NMAXWORKERS],
-				  int res_rounded[ns][nw], double res[ns][nw])
+				   int res_rounded[ns][nw], double res[ns][nw], struct types_of_workers *tw)
 {
 	int w;
 	for(w = 0; w < nw; w++)
 	{
-		enum starpu_worker_archtype arch = STARPU_ANY_WORKER;
+		enum starpu_worker_archtype arch = sc_hypervisor_get_arch_for_index(w, tw);
 		
-		if(w == 1 || nw == 1) 
+		if(arch == STARPU_CPU_WORKER) 
 		{
-			arch = STARPU_CPU_WORKER;
 			int nworkers_ctx = sc_hypervisor_get_nworkers_ctx(sched_ctx, arch);
-			printf("%d: cpus in ctx %d\n", sched_ctx, nworkers_ctx);
 			if(nworkers_ctx > res_rounded[sched_ctx_idx][w])
 			{
 				int nworkers_to_move = nworkers_ctx - res_rounded[sched_ctx_idx][w];
@@ -171,7 +176,6 @@ void _lp_find_workers_to_give_away(int nw, int ns, unsigned sched_ctx, int sched
 		}
 		else
 		{
-			arch = STARPU_CUDA_WORKER;
 			double nworkers_ctx = sc_hypervisor_get_nworkers_ctx(sched_ctx, arch) * 1.0;
 			if(nworkers_ctx > res[sched_ctx_idx][w])
 			{
@@ -220,21 +224,14 @@ void _lp_find_workers_to_accept(int nw, int ns, unsigned sched_ctx, int sched_ct
 				int tmp_nw_add[nw], int tmp_workers_add[nw][STARPU_NMAXWORKERS],
 				int *nw_move, int workers_move[STARPU_NMAXWORKERS], 
 				int *nw_add, int workers_add[STARPU_NMAXWORKERS],
-				int res_rounded[ns][nw], double res[ns][nw])
+				int res_rounded[ns][nw], double res[ns][nw], struct types_of_workers *tw)
 {
 	int w;
 	int j = 0, k = 0;
 	for(w = 0; w < nw; w++)
 	{
-		enum starpu_worker_archtype arch = STARPU_ANY_WORKER;
-		if(nw == 1)
-			arch = STARPU_CPU_WORKER;
-		else
-		{
-			if(w == 0) arch = STARPU_CUDA_WORKER;
-			if(w == 1) arch = STARPU_CPU_WORKER;
-		}
-
+		enum starpu_worker_archtype arch = sc_hypervisor_get_arch_for_index(w, tw);
+		
 		int nw_ctx2 = sc_hypervisor_get_nworkers_ctx(sched_ctx, arch);
 		int nw_needed = res_rounded[sched_ctx_idx][w] - nw_ctx2;
 		
@@ -304,7 +301,7 @@ void _lp_find_workers_to_remove(int nw, int tmp_nw_move[nw], int tmp_workers_mov
 	}
 }
 
-void sc_hypervisor_lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *sched_ctxs)
+void sc_hypervisor_lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], unsigned *sched_ctxs, struct types_of_workers *tw)
 {
 	int s, s2, w;
 	for(s = 0; s < ns; s++)
@@ -331,7 +328,7 @@ void sc_hypervisor_lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rou
 		/* find workers that ctx s has to give away */
 		_lp_find_workers_to_give_away(nw, ns, sched_ctxs[s], s, 
 					      tmp_nw_move, tmp_workers_move, 
-					      tmp_nw_add, tmp_workers_add, res_rounded, res);
+					      tmp_nw_add, tmp_workers_add, res_rounded, res, tw);
 
 		for(s2 = 0; s2 < ns; s2++)
 		{
@@ -351,7 +348,7 @@ void sc_hypervisor_lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rou
 							   tmp_nw_add, tmp_workers_add,
 							   &nw_move, workers_move, 
 							   &nw_add, workers_add,
-							   res_rounded, res);
+							   res_rounded, res, tw);
 				
 				if(nw_move > 0)
 				{
@@ -379,9 +376,8 @@ void sc_hypervisor_lp_redistribute_resources_in_ctxs(int ns, int nw, int res_rou
 	}
 }
 
-void sc_hypervisor_lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *workers, int nworkers)
+void sc_hypervisor_lp_distribute_resources_in_ctxs(unsigned* sched_ctxs, int ns, int nw, int res_rounded[ns][nw], double res[ns][nw], int *workers, int nworkers, struct types_of_workers *tw)
 {
-	unsigned current_nworkers = workers == NULL ? starpu_worker_get_count() : (unsigned)nworkers;
 	int s, w;
 	int start[nw];
 	for(w = 0; w < nw; w++)
@@ -390,33 +386,21 @@ void sc_hypervisor_lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int
 	{
 		int workers_add[STARPU_NMAXWORKERS];
                 int nw_add = 0;
-		
+
 		for(w = 0; w < nw; w++)
 		{
-			enum starpu_worker_archtype arch;
-
-#ifdef STARPU_USE_CUDA
-			int ncuda = starpu_worker_get_count_by_type(STARPU_CUDA_WORKER);
-			if(ncuda != 0)
-			{
-				if(w == 0) arch = STARPU_CUDA_WORKER;
-				if(w == 1) arch = STARPU_CPU_WORKER;
-			}
-			else
-				if(w == 0) arch = STARPU_CPU_WORKER;
-#else
-			if(w == 0) arch = STARPU_CPU_WORKER;
-#endif //STARPU_USE_CUDA
-			if(w == 1)
+			enum starpu_worker_archtype arch = sc_hypervisor_get_arch_for_index(w, tw);
+			
+			if(arch == STARPU_CPU_WORKER) 
 			{
+				
 				int nworkers_to_add = res_rounded[s][w];
-				int *workers_to_add = sc_hypervisor_get_idlest_workers_in_list(&start[w], workers, current_nworkers, &nworkers_to_add, arch);
+				int *workers_to_add = sc_hypervisor_get_idlest_workers_in_list(&start[w], workers, nworkers, &nworkers_to_add, arch);
 				int i;
 				for(i = 0; i < nworkers_to_add; i++)
 					workers_add[nw_add++] = workers_to_add[i];
 				free(workers_to_add);
 			}
-			
 			else
 			{
 				double nworkers_to_add = res[s][w];
@@ -425,7 +409,7 @@ void sc_hypervisor_lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int
 				double diff = nworkers_to_add - x_double;
 				if(diff == 0.0)
 				{
-					int *workers_to_add = sc_hypervisor_get_idlest_workers_in_list(&start[w], workers, current_nworkers, &x, arch);
+					int *workers_to_add = sc_hypervisor_get_idlest_workers_in_list(&start[w], workers, nworkers, &x, arch);
 					int i;
 					for(i = 0; i < x; i++)
 						workers_add[nw_add++] = workers_to_add[i];
@@ -434,7 +418,7 @@ void sc_hypervisor_lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int
 				else
 				{
 					x+=1;
-					int *workers_to_add = sc_hypervisor_get_idlest_workers_in_list(&start[w], workers, current_nworkers, &x, arch);
+					int *workers_to_add = sc_hypervisor_get_idlest_workers_in_list(&start[w], workers, nworkers, &x, arch);
 					int i;
 					if(diff >= 0.3)
 						for(i = 0; i < x; i++)
@@ -442,7 +426,7 @@ void sc_hypervisor_lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int
 					else
 						for(i = 0; i < x-1; i++)
 							workers_add[nw_add++] = workers_to_add[i];
-
+					
 					free(workers_to_add);
 				}
 			}
@@ -458,17 +442,19 @@ void sc_hypervisor_lp_distribute_resources_in_ctxs(int* sched_ctxs, int ns, int
 }
 
 /* nw = all the workers (either in a list or on all machine) */
-void sc_hypervisor_lp_place_resources_in_ctx(int ns, int nw, double w_in_s[ns][nw], int *sched_ctxs_input, int *workers_input, unsigned do_size)
+void sc_hypervisor_lp_place_resources_in_ctx(int ns, int nw, double w_in_s[ns][nw], unsigned *sched_ctxs_input, int *workers_input, unsigned do_size, struct types_of_workers *tw)
 {
 	int w, s;
-	double nworkers[ns][2];
-	int nworkers_rounded[ns][2];
+	int ntypes_of_workers = tw->nw; 
+	double nworkers[ns][ntypes_of_workers];
+	int nworkers_rounded[ns][ntypes_of_workers];
 	for(s = 0; s < ns; s++)
 	{
-		nworkers[s][0] = 0.0;
-		nworkers[s][1] = 0.0;
-		nworkers_rounded[s][0] = 0;
-		nworkers_rounded[s][1] = 0;
+		for(w = 0; w < ntypes_of_workers; w++)
+		{
+			nworkers[s][w] = 0.0;
+			nworkers_rounded[s][w] = 0;
+		}
 		
 	}
 	
@@ -477,27 +463,27 @@ void sc_hypervisor_lp_place_resources_in_ctx(int ns, int nw, double w_in_s[ns][n
 		for(w = 0; w < nw; w++)
 		{
 			enum starpu_worker_archtype arch = starpu_worker_get_type(w);
-			
+			int idx = sc_hypervisor_get_index_for_arch(arch, tw);
+			nworkers[s][idx] += w_in_s[s][w];
+				
 			if(arch == STARPU_CUDA_WORKER)
 			{
-				nworkers[s][0] += w_in_s[s][w];
 				if(w_in_s[s][w] >= 0.3)
-					nworkers_rounded[s][0]++;
+					nworkers_rounded[s][idx]++;
 			}
 			else
 			{
-				nworkers[s][1] += w_in_s[s][w];
 				if(w_in_s[s][w] > 0.5)
-					nworkers_rounded[s][1]++;
+					nworkers_rounded[s][idx]++;
 			}
 		}
 	}
 	
 	if(!do_size)
-		sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, 2, nworkers_rounded, nworkers, sched_ctxs_input);
+		sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, ntypes_of_workers, nworkers_rounded, nworkers, sched_ctxs_input, tw);
 	else
 	{
-		int *current_sched_ctxs = sched_ctxs_input == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs_input;
+		unsigned *current_sched_ctxs = sched_ctxs_input == NULL ? sc_hypervisor_get_sched_ctxs() : sched_ctxs_input;
 
 		unsigned has_workers = 0;
 		for(s = 0; s < ns; s++)
@@ -511,9 +497,9 @@ void sc_hypervisor_lp_place_resources_in_ctx(int ns, int nw, double w_in_s[ns][n
 			}
 		}
 		if(has_workers)
-			sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, 2, nworkers_rounded, nworkers, current_sched_ctxs);
+			sc_hypervisor_lp_redistribute_resources_in_ctxs(ns, ntypes_of_workers, nworkers_rounded, nworkers, current_sched_ctxs, tw);
 		else
-			sc_hypervisor_lp_distribute_resources_in_ctxs(current_sched_ctxs, ns, 2, nworkers_rounded, nworkers, workers_input, nw);
+			sc_hypervisor_lp_distribute_resources_in_ctxs(current_sched_ctxs, ns, ntypes_of_workers, nworkers_rounded, nworkers, workers_input, nw, tw);
 	}
 	return;
 }

+ 82 - 99
sc_hypervisor/src/policies_utils/policy_tools.c

@@ -47,7 +47,7 @@ unsigned sc_hypervisor_find_lowest_prio_sched_ctx(unsigned req_sched_ctx, int nw
 	int highest_priority = -1;
 	int current_priority = 0;
 	unsigned sched_ctx = STARPU_NMAX_SCHED_CTXS;
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 
@@ -57,7 +57,7 @@ unsigned sc_hypervisor_find_lowest_prio_sched_ctx(unsigned req_sched_ctx, int nw
 	{
 		if(sched_ctxs[i] != STARPU_NMAX_SCHED_CTXS && sched_ctxs[i] != req_sched_ctx)
 		{
-			unsigned nworkers = starpu_sched_ctx_get_nworkers(sched_ctxs[i]);
+			int nworkers = (int)starpu_sched_ctx_get_nworkers(sched_ctxs[i]);
 			config  = sc_hypervisor_get_config(sched_ctxs[i]);
 			if((nworkers + nworkers_to_move) <= config->max_nworkers)
 			{
@@ -177,11 +177,11 @@ int* sc_hypervisor_get_idlest_workers(unsigned sched_ctx, int *nworkers, enum st
 }
 
 /* get the number of workers in the context that are allowed to be moved (that are not fixed) */
-unsigned sc_hypervisor_get_movable_nworkers(struct sc_hypervisor_policy_config *config, unsigned sched_ctx, enum starpu_worker_archtype arch)
+int sc_hypervisor_get_movable_nworkers(struct sc_hypervisor_policy_config *config, unsigned sched_ctx, enum starpu_worker_archtype arch)
 {
 	struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
 
-	unsigned potential_workers = 0;
+	int potential_workers = 0;
 	int worker;
 
 	struct starpu_sched_ctx_iterator it;
@@ -207,10 +207,10 @@ unsigned sc_hypervisor_get_movable_nworkers(struct sc_hypervisor_policy_config *
 int sc_hypervisor_compute_nworkers_to_move(unsigned req_sched_ctx)
 {
        	struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(req_sched_ctx);
-	unsigned nworkers = starpu_sched_ctx_get_nworkers(req_sched_ctx);
-	unsigned nworkers_to_move = 0;
+	int nworkers = (int)starpu_sched_ctx_get_nworkers(req_sched_ctx);
+	int nworkers_to_move = 0;
 
-	unsigned potential_moving_workers = sc_hypervisor_get_movable_nworkers(config, req_sched_ctx, STARPU_ANY_WORKER);
+	int potential_moving_workers = (int)sc_hypervisor_get_movable_nworkers(config, req_sched_ctx, STARPU_ANY_WORKER);
 	if(potential_moving_workers > 0)
 	{
 		if(potential_moving_workers <= config->min_nworkers)
@@ -263,14 +263,14 @@ unsigned sc_hypervisor_policy_resize(unsigned sender_sched_ctx, unsigned receive
 			unsigned poor_sched_ctx = STARPU_NMAX_SCHED_CTXS;
 			if(receiver_sched_ctx == STARPU_NMAX_SCHED_CTXS)
 			{
-				poor_sched_ctx = sc_hypervisor_find_lowest_prio_sched_ctx(sender_sched_ctx, nworkers_to_move);
+				poor_sched_ctx = sc_hypervisor_find_lowest_prio_sched_ctx(sender_sched_ctx, (unsigned)nworkers_to_move);
 			}
 			else
 			{
 				poor_sched_ctx = receiver_sched_ctx;
 				struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(poor_sched_ctx);
-				unsigned nworkers = starpu_sched_ctx_get_nworkers(poor_sched_ctx);
-				unsigned nshared_workers = starpu_sched_ctx_get_nshared_workers(sender_sched_ctx, poor_sched_ctx);
+				int nworkers = (int)starpu_sched_ctx_get_nworkers(poor_sched_ctx);
+				int nshared_workers = (int)starpu_sched_ctx_get_nshared_workers(sender_sched_ctx, poor_sched_ctx);
 				if((nworkers+nworkers_to_move-nshared_workers) > config->max_nworkers)
 					nworkers_to_move = nworkers > config->max_nworkers ? 0 : (config->max_nworkers - nworkers+nshared_workers);
 				if(nworkers_to_move == 0) poor_sched_ctx = STARPU_NMAX_SCHED_CTXS;
@@ -301,56 +301,9 @@ unsigned sc_hypervisor_policy_resize_to_unknown_receiver(unsigned sender_sched_c
 	return sc_hypervisor_policy_resize(sender_sched_ctx, STARPU_NMAX_SCHED_CTXS, 0, now);
 }
 
-static double _get_ispeed_sample_for_type_of_worker(struct sc_hypervisor_wrapper* sc_w, enum starpu_worker_archtype req_arch)
-{
-	struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sc_w->sched_ctx);
-        int worker;
-
-	double avg = 0.0;
-	int n = 0;
-	struct starpu_sched_ctx_iterator it;
-	if(workers->init_iterator)
-                workers->init_iterator(workers, &it);
-
-        while(workers->has_next(workers, &it))
-	{
-                worker = workers->get_next(workers, &it);
-                enum starpu_worker_archtype arch = starpu_worker_get_type(worker);
-                if(arch == req_arch)
-                {
-			struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(sc_w->sched_ctx);
-			avg += config->ispeed_w_sample[worker];
-			n++;
-		}
-        }
-
-	return n != 0 ? avg/n : 0;
-}
-
-static double _get_ispeed_sample_for_sched_ctx(unsigned sched_ctx)
-{
-	struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx);
-	struct sc_hypervisor_policy_config *config = sc_hypervisor_get_config(sched_ctx);
-        
-	int worker;
-	double ispeed_sample = 0.0;
-	struct starpu_sched_ctx_iterator it;
-
-	if(workers->init_iterator)
-                workers->init_iterator(workers, &it);
-
-        while(workers->has_next(workers, &it))
-	{
-                worker = workers->get_next(workers, &it);
-	        ispeed_sample += config->ispeed_w_sample[worker];
-        }
-
-	return ispeed_sample;
-}
-
 double sc_hypervisor_get_slowest_ctx_exec_time(void)
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 /* 	double curr_time = starpu_timing_now(); */
@@ -374,7 +327,7 @@ double sc_hypervisor_get_slowest_ctx_exec_time(void)
 
 double sc_hypervisor_get_fastest_ctx_exec_time(void)
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
 	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
 
 	double curr_time = starpu_timing_now();
@@ -397,26 +350,58 @@ double sc_hypervisor_get_fastest_ctx_exec_time(void)
 	return fastest_time;
 }
 
-void sc_hypervisor_group_workers_by_type(int *workers, int nworkers, int ntypes_of_workers, int total_nw[ntypes_of_workers])
+void sc_hypervisor_group_workers_by_type(struct types_of_workers *tw, int *total_nw)
 {
-	int current_nworkers = workers == NULL ? starpu_worker_get_count() : nworkers;
 	int w;
-	for(w = 0; w < ntypes_of_workers; w++)
+	for(w = 0; w < tw->nw; w++)
 		total_nw[w] = 0;
 
-	for(w = 0; w < current_nworkers; w++)
+	if(tw->ncpus != 0)
+	{
+		total_nw[0] = tw->ncpus;
+		if(tw->ncuda != 0)
+			total_nw[1] = tw->ncuda;
+	}
+	else
+	{
+		if(tw->ncuda != 0)
+			total_nw[0] =tw->ncuda;
+	}
+
+}
+
+enum starpu_worker_archtype sc_hypervisor_get_arch_for_index(unsigned w, struct types_of_workers *tw)
+{
+	if(w == 0)
 	{
- 		enum starpu_worker_archtype arch = workers == NULL ? starpu_worker_get_type(w) :
-			starpu_worker_get_type(workers[w]);
-		if(ntypes_of_workers == 2)
+		if(tw->ncpus != 0)
+			return STARPU_CPU_WORKER;
+		else
+			return STARPU_CUDA_WORKER;
+	}
+	else
+		if(tw->ncuda != 0)
+			return STARPU_CUDA_WORKER;
+}
+
+
+unsigned sc_hypervisor_get_index_for_arch(enum starpu_worker_archtype arch, struct types_of_workers *tw)
+{
+	
+	if(arch == STARPU_CPU_WORKER)
+	{
+		if(tw->ncpus != 0)
+			return 0;
+	}
+	else
+	{
+		if(arch == STARPU_CUDA_WORKER)
 		{
-			if(arch == STARPU_CPU_WORKER)
-				total_nw[1]++;
+			if(tw->ncpus != 0)
+				return 1;
 			else
-				total_nw[0]++;
+				return 0;
 		}
-		else
-			total_nw[0]++;
 	}
 }
 
@@ -491,16 +476,18 @@ unsigned sc_hypervisor_check_idle(unsigned sched_ctx, int worker)
 /* check if there is a big speed gap between the contexts */
 unsigned sc_hypervisor_check_speed_gap_btw_ctxs(void)
 {
-	int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
-	int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
+	unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
+	int ns = sc_hypervisor_get_nsched_ctxs();
+	int *workers = NULL;
+	int nworkers = starpu_worker_get_count();
 	int i = 0, j = 0;
 	struct sc_hypervisor_wrapper* sc_w;
 	struct sc_hypervisor_wrapper* other_sc_w;
 
 	
-	double optimal_v[nsched_ctxs];
+	double optimal_v[ns];
 	unsigned has_opt_v = 1;
-	for(i = 0; i < nsched_ctxs; i++)
+	for(i = 0; i < ns; i++)
 	{
 		optimal_v[i] = _get_optimal_v(i);
 		if(optimal_v[i] == 0.0)
@@ -513,33 +500,29 @@ unsigned sc_hypervisor_check_speed_gap_btw_ctxs(void)
 /*if an optimal speed has not been computed yet do it now */
 	if(!has_opt_v)
 	{
-		int nw = 1;
-#ifdef STARPU_USE_CUDA
-		int ncuda = starpu_worker_get_count_by_type(STARPU_CUDA_WORKER);
-		nw = ncuda != 0 ? 2 : 1;
-#endif	
-		double nworkers_per_type[nsched_ctxs][nw];
+		struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(workers, nworkers);
+		int nw = tw->nw;
+		double nworkers_per_ctx[ns][nw];
 		int total_nw[nw];
-		for(i = 0; i < nw; i++)
-		{
-			for(j = 0; j < nsched_ctxs; j++)
-				nworkers_per_type[j][i] = 0.0;
-			total_nw[i] = 0;
-		}
-		sc_hypervisor_group_workers_by_type(NULL, -1, nw, total_nw);
-		
-		double vmax = sc_hypervisor_lp_get_nworkers_per_ctx(nsched_ctxs, nw, nworkers_per_type, total_nw);
+		sc_hypervisor_group_workers_by_type(tw, total_nw);
+
+		double vmax = sc_hypervisor_lp_get_nworkers_per_ctx(ns, nw, nworkers_per_ctx, total_nw, tw);
+
 		
 		if(vmax != 0.0)
 		{
-			for(i = 0; i < nsched_ctxs; i++)
+			for(i = 0; i < ns; i++)
 			{
 				sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
 				double v[nw];
-				v[0] = sc_hypervisor_get_speed(sc_w, STARPU_CUDA_WORKER);
-				v[1] = sc_hypervisor_get_speed(sc_w, STARPU_CPU_WORKER);
-				
-				optimal_v[i] = nworkers_per_type[i][0] * v[0] + nworkers_per_type[i][1]* v[1];
+				optimal_v[i] = 0.0;
+				int w;
+				for(w = 0; w < nw; w++)
+				{
+					v[w] = sc_hypervisor_get_speed(sc_w, sc_hypervisor_get_arch_for_index(w, tw));
+					
+					optimal_v[i] += nworkers_per_ctx[i][w];
+				}
 				_set_optimal_v(i, optimal_v[i]);
 			}
 			has_opt_v = 1;
@@ -550,7 +533,7 @@ unsigned sc_hypervisor_check_speed_gap_btw_ctxs(void)
    theoretical one */
 	if(has_opt_v)
 	{
-		for(i = 0; i < nsched_ctxs; i++)
+		for(i = 0; i < ns; i++)
 		{
 			sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
 			
@@ -559,7 +542,7 @@ unsigned sc_hypervisor_check_speed_gap_btw_ctxs(void)
 				return 0;
 		}
 
-		for(i = 0; i < nsched_ctxs; i++)
+		for(i = 0; i < ns; i++)
 		{
 			sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
 			
@@ -572,13 +555,13 @@ unsigned sc_hypervisor_check_speed_gap_btw_ctxs(void)
 		SC_MAX_SPEED_GAP and compare the speed of the contexts, whenever the difference
 		btw them is greater than the max value the function returns true */
 	{
-		for(i = 0; i < nsched_ctxs; i++)
+		for(i = 0; i < ns; i++)
 		{
 			sc_w = sc_hypervisor_get_wrapper(sched_ctxs[i]);
 			double ctx_v = sc_hypervisor_get_ctx_speed(sc_w);
 			if(ctx_v != -1.0)
 			{
-				for(j = 0; j < nsched_ctxs; j++)
+				for(j = 0; j < ns; j++)
 				{
 					if(sched_ctxs[i] != sched_ctxs[j])
 					{

+ 38 - 27
sc_hypervisor/src/sc_hypervisor.c

@@ -133,7 +133,6 @@ static struct sc_hypervisor_policy *_select_hypervisor_policy(struct sc_hypervis
 /* initializez the performance counters that starpu will use to retrive hints for resizing */
 struct starpu_sched_ctx_performance_counters* sc_hypervisor_init(struct sc_hypervisor_policy *hypervisor_policy)
 {
-	printf("****************$$$$$$$$$$$$$$$$$$$hereeeeeeeeeeeeeeeeeeeeeeeeeeeee\n");
 	hypervisor.min_tasks = 0;
 	hypervisor.nsched_ctxs = 0;
 	char* vel_gap = getenv("SC_HYPERVISOR_MAX_SPEED_GAP");
@@ -292,7 +291,7 @@ void sc_hypervisor_register_ctx(unsigned sched_ctx, double total_flops)
 	starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
 }
 
-static int _get_first_free_sched_ctx(int *sched_ctxs, int nsched_ctxs)
+static int _get_first_free_sched_ctx(unsigned *sched_ctxs, int nsched_ctxs)
 {
 	int i;
 	for(i = 0; i < nsched_ctxs; i++)
@@ -306,7 +305,7 @@ static int _get_first_free_sched_ctx(int *sched_ctxs, int nsched_ctxs)
    and have instead {5, 7, MAXVAL, MAXVAL, MAXVAL}
    it is easier afterwards to iterate the array
 */
-static void _rearange_sched_ctxs(int *sched_ctxs, int old_nsched_ctxs)
+static void _rearange_sched_ctxs(unsigned *sched_ctxs, int old_nsched_ctxs)
 {
 	int first_free_id = STARPU_NMAX_SCHED_CTXS;
 	int i;
@@ -333,7 +332,7 @@ void sc_hypervisor_unregister_ctx(unsigned sched_ctx)
 	unsigned i;
 	for(i = 0; i < hypervisor.nsched_ctxs; i++)
 	{
-		if(hypervisor.sched_ctxs[i] == (int)sched_ctx)
+		if(hypervisor.sched_ctxs[i] == sched_ctx)
 		{
 			hypervisor.sched_ctxs[i] = STARPU_NMAX_SCHED_CTXS;
 			break;
@@ -377,21 +376,6 @@ static int get_ntasks( int *tasks)
 	return ntasks;
 }
 
-
-static void _get_cpus(int *workers, int nworkers, int *cpus, int *ncpus)
-{
-	int i, worker;
-	*ncpus = 0;
-
-	for(i = 0; i < nworkers; i++)
-	{
-		worker = workers[i];
-		enum starpu_worker_archtype arch = starpu_worker_get_type(worker);
-		if(arch == STARPU_CPU_WORKER)
-			cpus[(*ncpus)++] = worker;
-	}
-}
-
 int sc_hypervisor_get_nworkers_ctx(unsigned sched_ctx, enum starpu_worker_archtype arch)
 {
 	int nworkers_ctx = 0;
@@ -628,7 +612,7 @@ static unsigned _ack_resize_completed(unsigned sched_ctx, int worker)
 			struct sc_hypervisor_wrapper *sc_w = &hypervisor.sched_ctx_w[hypervisor.sched_ctxs[i]];
 			starpu_pthread_mutex_lock(&sc_w->mutex);
 			unsigned only_remove = 0;
-			if(sc_w->resize_ack.receiver_sched_ctx == -1 && hypervisor.sched_ctxs[i] != (int)sched_ctx &&
+			if(sc_w->resize_ack.receiver_sched_ctx == -1 && hypervisor.sched_ctxs[i] != sched_ctx &&
 			   sc_w->resize_ack.nmoved_workers > 0 && starpu_sched_ctx_contains_worker(worker, hypervisor.sched_ctxs[i]))
 			{
 				int j;
@@ -735,7 +719,7 @@ void sc_hypervisor_post_resize_request(unsigned sched_ctx, int task_tag)
 	starpu_pthread_mutex_unlock(&hypervisor.resize_mut[sched_ctx]);
 }
 
-void sc_hypervisor_resize_ctxs(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
+void sc_hypervisor_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers)
 {
 	if(hypervisor.policy.resize_ctxs)
 		hypervisor.policy.resize_ctxs(sched_ctxs, nsched_ctxs, workers, nworkers);
@@ -899,11 +883,11 @@ static void notify_delete_context(unsigned sched_ctx)
 	sc_hypervisor_unregister_ctx(sched_ctx);
 }
 
-void sc_hypervisor_size_ctxs(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
+void sc_hypervisor_size_ctxs(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
 {
 	starpu_pthread_mutex_lock(&act_hypervisor_mutex);
-	unsigned curr_nsched_ctxs = sched_ctxs == NULL ? hypervisor.nsched_ctxs : nsched_ctxs;
-	int *curr_sched_ctxs = sched_ctxs == NULL ? hypervisor.sched_ctxs : sched_ctxs;
+	int curr_nsched_ctxs = sched_ctxs == NULL ? hypervisor.nsched_ctxs : nsched_ctxs;
+	unsigned *curr_sched_ctxs = sched_ctxs == NULL ? hypervisor.sched_ctxs : sched_ctxs;
 	starpu_pthread_mutex_unlock(&act_hypervisor_mutex);
 	unsigned s;
 	for(s = 0; s < curr_nsched_ctxs; s++)
@@ -918,7 +902,7 @@ struct sc_hypervisor_wrapper* sc_hypervisor_get_wrapper(unsigned sched_ctx)
 	return &hypervisor.sched_ctx_w[sched_ctx];
 }
 
-int* sc_hypervisor_get_sched_ctxs()
+unsigned* sc_hypervisor_get_sched_ctxs()
 {
 	return hypervisor.sched_ctxs;
 }
@@ -930,7 +914,7 @@ int sc_hypervisor_get_nsched_ctxs()
 	return ns;
 }
 
-void sc_hypervisor_save_size_req(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
+void sc_hypervisor_save_size_req(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
 {
 	hypervisor.sr = (struct size_request*)malloc(sizeof(struct size_request));
 	hypervisor.sr->sched_ctxs = sched_ctxs;
@@ -939,7 +923,7 @@ void sc_hypervisor_save_size_req(int *sched_ctxs, int nsched_ctxs, int *workers,
 	hypervisor.sr->nworkers = nworkers;
 }
 
-unsigned sc_hypervisor_get_size_req(int **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers)
+unsigned sc_hypervisor_get_size_req(unsigned **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers)
 {
 	if(hypervisor.sr != NULL)
 	{
@@ -970,3 +954,30 @@ void _set_optimal_v(unsigned sched_ctx, double optimal_v)
 {
 	hypervisor.optimal_v[sched_ctx] = optimal_v;
 }
+
+static struct types_of_workers* _init_structure_types_of_workers(void)
+{
+	struct types_of_workers *tw = (struct types_of_workers*)malloc(sizeof(struct types_of_workers));
+        tw->ncpus = 0;
+	tw->ncuda = 0;
+        tw->nw = 0;
+        return tw;
+}
+
+struct types_of_workers* sc_hypervisor_get_types_of_workers(int *workers, unsigned nworkers)
+{
+	struct types_of_workers *tw = _init_structure_types_of_workers();
+
+        unsigned w;
+	for(w = 0; w < nworkers; w++)
+        {
+                enum starpu_worker_archtype arch = workers == NULL ? starpu_worker_get_type((int)w) : starpu_worker_get_type(workers[w]);
+                if(arch == STARPU_CPU_WORKER)
+			tw->ncpus++;
+                if(arch == STARPU_CUDA_WORKER)
+			tw->ncuda++;
+        }
+        if(tw->ncpus > 0) tw->nw++;
+        if(tw->ncuda > 0) tw->nw++;
+	return tw;
+}

+ 2 - 2
sc_hypervisor/src/sc_hypervisor_intern.h

@@ -23,7 +23,7 @@ struct size_request
 {
 	int *workers;
 	int nworkers;
-	int *sched_ctxs;
+	unsigned *sched_ctxs;
 	int nsched_ctxs;
 };
 
@@ -58,7 +58,7 @@ struct configuration_entry
 struct sc_hypervisor
 {
 	struct sc_hypervisor_wrapper sched_ctx_w[STARPU_NMAX_SCHED_CTXS];
-	int sched_ctxs[STARPU_NMAX_SCHED_CTXS];
+	unsigned sched_ctxs[STARPU_NMAX_SCHED_CTXS];
 	unsigned nsched_ctxs;
 	unsigned resize[STARPU_NMAX_SCHED_CTXS];
 	unsigned allow_remove[STARPU_NMAX_SCHED_CTXS];

+ 1 - 0
src/core/workers.c

@@ -1238,6 +1238,7 @@ void starpu_shutdown(void)
 	_STARPU_DEBUG("Shutdown finished\n");
 }
 
+
 unsigned starpu_worker_get_count(void)
 {
 	return config.topology.nworkers;