瀏覽代碼

reduce variable scope when possible

Nathalie Furmento 7 年之前
父節點
當前提交
1020cf37cc

+ 20 - 17
examples/mlr/mlr.c

@@ -151,25 +151,28 @@ static struct starpu_codelet cl_final =
 int main(int argc, char **argv)
 {
 	/* Initialization */
-	unsigned i,j;
+	unsigned i;
 	int ret;
+
 	ret = starpu_init(NULL);
 	if (ret == -ENODEV)
 		return 77;
 
 	sum=0;
-	int m,n,k;
-	int* vector_mn = calloc( 2, sizeof(int) );
+	int* vector_mn = calloc(2, sizeof(int));
 	starpu_data_handle_t vector_mn_handle;
 
-	starpu_vector_data_register( &vector_mn_handle,
-				     STARPU_MAIN_RAM,
-				     (uintptr_t)vector_mn, 2,
-				     sizeof(int) );
+	starpu_vector_data_register(&vector_mn_handle,
+				    STARPU_MAIN_RAM,
+				    (uintptr_t)vector_mn, 2,
+				    sizeof(int));
 
 	/* Giving pseudo-random values to the M,N,K parameters and inserting tasks */
-	for ( i = 0; i < 42; i++)
+	for (i = 0; i < 42; i++)
 	{
+		int j;
+		int m,n,k;
+
 		m = (int) ((rand() % 10)+1);
 		n = (int) ((rand() % 10)+1);
 		k = (int) ((rand() % 10)+1);
@@ -180,16 +183,16 @@ int main(int argc, char **argv)
 		vector_mn[1] = n;
 		starpu_data_release(vector_mn_handle);
 
-		for ( j = 0; j < 42; j++)
+		for (j = 0; j < 42; j++)
 		{
-			starpu_insert_task( &cl_init,
-					    STARPU_R, vector_mn_handle,
-					    STARPU_VALUE, &k, sizeof(int),
-					    0 );
-			starpu_insert_task( &cl_final,
-					    STARPU_R, vector_mn_handle,
-					    STARPU_VALUE, &k, sizeof(int),
-					    0 );
+			starpu_insert_task(&cl_init,
+					   STARPU_R, vector_mn_handle,
+					   STARPU_VALUE, &k, sizeof(int),
+					   0);
+			starpu_insert_task(&cl_final,
+					   STARPU_R, vector_mn_handle,
+					   STARPU_VALUE, &k, sizeof(int),
+					   0);
 		}
 	}
 

+ 8 - 6
src/common/rbtree.c

@@ -145,8 +145,7 @@ static void starpu_rbtree_rotate(struct starpu_rbtree *tree, struct starpu_rbtre
 void starpu_rbtree_insert_rebalance(struct starpu_rbtree *tree, struct starpu_rbtree_node *parent,
                              int index, struct starpu_rbtree_node *node)
 {
-    struct starpu_rbtree_node *grand_parent, *uncle, *tmp;
-    int left, right;
+    struct starpu_rbtree_node *grand_parent, *tmp;
 
     assert(starpu_rbtree_check_alignment(parent));
     assert(starpu_rbtree_check_alignment(node));
@@ -162,7 +161,10 @@ void starpu_rbtree_insert_rebalance(struct starpu_rbtree *tree, struct starpu_rb
 
     for (;;)
     {
-        if (parent == NULL)
+	struct starpu_rbtree_node *uncle;
+	int left, right;
+
+	if (parent == NULL)
 	{
             starpu_rbtree_set_black(node);
             break;
@@ -414,11 +416,11 @@ struct starpu_rbtree_node * starpu_rbtree_walk(struct starpu_rbtree_node *node,
     }
     else
     {
-        struct starpu_rbtree_node *parent;
-        int index;
-
         for (;;)
 	{
+            struct starpu_rbtree_node *parent;
+	    int index;
+
             parent = starpu_rbtree_parent(node);
 
             if (parent == NULL)

+ 6 - 6
src/core/perfmodel/multiple_regression.c

@@ -29,10 +29,10 @@ int dgels_(char *trans, integer *m, integer *n, integer *nrhs, doublereal *a, in
 
 static long count_file_lines(FILE *f)
 {
-	int ch, lines=0;
+	int lines=0;
 	while(!feof(f))
 	{
-		ch = fgetc(f);
+		int ch = fgetc(f);
 		if(ch == '\n')
 		{
 			lines++;
@@ -62,8 +62,8 @@ static void dump_multiple_regression_list(double *mpar, double *my, int start, u
 static void load_old_calibration(double *mx, double *my, unsigned nparameters, char *filepath)
 {
 	char buffer[1024];
-	char *record,*line;
-	int i=0,j=0;
+	char *line;
+	int i=0;
 
 	FILE *f=NULL;
 	f = fopen(filepath, "a+");
@@ -72,10 +72,10 @@ static void load_old_calibration(double *mx, double *my, unsigned nparameters, c
 	fgets(buffer,sizeof(buffer),f);//skipping first line
 	while((line=fgets(buffer,sizeof(buffer),f))!=NULL)
 	{
-		record = strtok(line,",");
+		char *record = strtok(line,",");
 		my[i] = atof(record);
 		record = strtok(NULL,",");
-		j=0;
+		int j=0;
 		while(record != NULL)
 		{
 			mx[i*nparameters+j] = atof(record) ;

+ 2 - 2
src/core/sched_ctx.c

@@ -161,10 +161,10 @@ static void _starpu_update_workers_with_ctx(int *workerids, int nworkers, int sc
 static void _starpu_update_notified_workers_with_ctx(int *workerids, int nworkers, int sched_ctx_id)
 {
 	int i;
-	struct _starpu_worker *worker = NULL;
 
 	for(i = 0; i < nworkers; i++)
 	{
+		struct _starpu_worker *worker;
 		worker = _starpu_get_worker_struct(workerids[i]);
 		_starpu_worker_gets_into_ctx(sched_ctx_id, worker);
 	}
@@ -201,10 +201,10 @@ static void _starpu_update_workers_without_ctx(int *workerids, int nworkers, int
 static void _starpu_update_notified_workers_without_ctx(int *workerids, int nworkers, int sched_ctx_id, unsigned now)
 {
 	int i;
-	struct _starpu_worker *worker = NULL;
 
 	for(i = 0; i < nworkers; i++)
 	{
+		struct _starpu_worker *worker;
 		worker = _starpu_get_worker_struct(workerids[i]);
 		if(now)
 		{

+ 12 - 10
src/core/sched_policy.c

@@ -1049,17 +1049,18 @@ void _starpu_sched_pre_exec_hook(struct starpu_task *task)
 	{
 		int workerid = starpu_worker_get_id();
 		struct _starpu_worker *worker =  _starpu_get_worker_struct(workerid);
-		struct _starpu_sched_ctx *other_sched_ctx;
-		struct _starpu_sched_ctx_elt *e = NULL;
 		struct _starpu_sched_ctx_list_iterator list_it;
-		
+
 		_starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
 		while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
 		{
+			struct _starpu_sched_ctx *other_sched_ctx;
+			struct _starpu_sched_ctx_elt *e = NULL;
+
 			e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
 			other_sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
-			if (other_sched_ctx != sched_ctx && 
-			    other_sched_ctx->sched_policy != NULL && 
+			if (other_sched_ctx != sched_ctx &&
+			    other_sched_ctx->sched_policy != NULL &&
 			    other_sched_ctx->sched_policy->pre_exec_hook)
 			{
 				_STARPU_SCHED_BEGIN;
@@ -1086,17 +1087,18 @@ void _starpu_sched_post_exec_hook(struct starpu_task *task)
 	{
 		int workerid = starpu_worker_get_id();
 		struct _starpu_worker *worker =  _starpu_get_worker_struct(workerid);
-		struct _starpu_sched_ctx *other_sched_ctx;
-		struct _starpu_sched_ctx_elt *e = NULL;
 		struct _starpu_sched_ctx_list_iterator list_it;
-		
+
 		_starpu_sched_ctx_list_iterator_init(worker->sched_ctx_list, &list_it);
 		while (_starpu_sched_ctx_list_iterator_has_next(&list_it))
 		{
+			struct _starpu_sched_ctx *other_sched_ctx;
+			struct _starpu_sched_ctx_elt *e = NULL;
+
 			e = _starpu_sched_ctx_list_iterator_get_next(&list_it);
 			other_sched_ctx = _starpu_get_sched_ctx_struct(e->sched_ctx);
-			if (other_sched_ctx != sched_ctx && 
-			    other_sched_ctx->sched_policy != NULL && 
+			if (other_sched_ctx != sched_ctx &&
+			    other_sched_ctx->sched_policy != NULL &&
 			    other_sched_ctx->sched_policy->post_exec_hook)
 			{
 				_STARPU_SCHED_BEGIN;

+ 3 - 1
src/datawizard/interfaces/data_interface.c

@@ -148,7 +148,7 @@ struct starpu_data_interface_ops *_starpu_data_interface_get_ops(unsigned interf
  * some handle, the new mapping shadows the previous one.   */
 void _starpu_data_register_ram_pointer(starpu_data_handle_t handle, void *ptr)
 {
-	struct handle_entry *entry, *old_entry;
+	struct handle_entry *entry;
 
 	_STARPU_MALLOC(entry, sizeof(*entry));
 
@@ -174,6 +174,8 @@ void _starpu_data_register_ram_pointer(starpu_data_handle_t handle, void *ptr)
 	else
 #endif
 	{
+		struct handle_entry *old_entry;
+
 		_starpu_spin_lock(&registered_handles_lock);
 		HASH_FIND_PTR(registered_handles, &ptr, old_entry);
 		if (old_entry)

+ 1 - 1
src/debug/traces/starpu_fxt_mpi.c

@@ -220,7 +220,6 @@ static unsigned long mpi_com_id = 0;
 static void display_all_transfers_from_trace(FILE *out_paje_file, unsigned n)
 {
 	unsigned slot[MAX_MPI_NODES] = { 0 }, node;
-	int src;
 	struct mpi_transfer_list pending_receives; /* Sorted list of matches which have not happened yet */
 	double current_out_bandwidth[MAX_MPI_NODES] = { 0. };
 	double current_in_bandwidth[MAX_MPI_NODES] = { 0. };
@@ -236,6 +235,7 @@ static void display_all_transfers_from_trace(FILE *out_paje_file, unsigned n)
 	{
 		float start_date;
 		struct mpi_transfer *cur, *match;
+		int src;
 
 		/* Find out which event comes first: a pending receive, or a new send */
 

+ 2 - 3
src/drivers/mp_common/source_common.c

@@ -209,16 +209,15 @@ static void _starpu_src_common_handle_stored_async(struct _starpu_mp_node *node)
  * return 1 if the message has been stored
  * return 0 if the message is unknown or synchrone */
 int _starpu_src_common_store_message(struct _starpu_mp_node *node,
-		void * arg, int arg_size, enum _starpu_mp_command answer)
+				     void * arg, int arg_size, enum _starpu_mp_command answer)
 {
-	struct mp_message * message = NULL;
 	switch(answer)
 	{
 		case STARPU_MP_COMMAND_EXECUTION_COMPLETED:
 		case STARPU_MP_COMMAND_EXECUTION_DETACHED_COMPLETED:
 		case STARPU_MP_COMMAND_PRE_EXECUTION:
 		{
-			message = mp_message_new();
+			struct mp_message *message = mp_message_new();
 			message->type = answer;
 			_STARPU_MALLOC(message->buffer, arg_size);
 			memcpy(message->buffer, arg, arg_size);

+ 3 - 1
src/drivers/mpi/driver_mpi_sink.c

@@ -52,7 +52,7 @@ void (*_starpu_mpi_sink_lookup (const struct _starpu_mp_node * node STARPU_ATTRI
 void _starpu_mpi_sink_launch_workers(struct _starpu_mp_node *node)
 {
         //TODO
-        int i, ret;
+        int i;
         struct arg_sink_thread * arg;
         cpu_set_t cpuset;
         starpu_pthread_attr_t attr;
@@ -60,6 +60,8 @@ void _starpu_mpi_sink_launch_workers(struct _starpu_mp_node *node)
 
         for(i=0; i < node->nb_cores; i++)
         {
+		int ret;
+
                 //init the set
                 CPU_ZERO(&cpuset);
                 CPU_SET(i,&cpuset);

+ 1 - 1
tests/datawizard/allocate.c

@@ -176,7 +176,6 @@ int main(int argc, char **argv)
 {
 	int ret;
 	unsigned memnodes, i;
-	starpu_ssize_t available_size;
 
 	setenv("STARPU_LIMIT_CUDA_MEM", STR_LIMIT, 1);
 	setenv("STARPU_LIMIT_OPENCL_MEM", STR_LIMIT, 1);
@@ -189,6 +188,7 @@ int main(int argc, char **argv)
 	memnodes = starpu_memory_nodes_get_count();
 	for(i=0 ; i<memnodes ; i++)
 	{
+		starpu_ssize_t available_size;
 		available_size = starpu_memory_get_available(i);
 		if (available_size == -1)
 		{

+ 8 - 7
tests/errorcheck/workers_cpuid.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2012, 2015-2017  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2016  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2016, 2017  CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -132,20 +132,18 @@ static int test_combination(long *combination, unsigned n)
 
 static long * generate_arrangement(int arr_size, long *set, int set_size)
 {
-	int i, j;
-	long tmp;
+	int i;
 
 	STARPU_ASSERT(arr_size <= set_size);
-
 	srandom(time(0));
 
 	for (i=0; i<arr_size; i++)
 	{
 		/* Pick a random value in the set */
-		j = starpu_lrand48() % (set_size - i);
+		int j = starpu_lrand48() % (set_size - i);
 
 		/* Switch the value picked up with the beginning value of set */
-		tmp = set[i+j];
+		long tmp = set[i+j];
 		set[i] = set[i+j];
 		set[i+j] = tmp;
 	}
@@ -165,7 +163,7 @@ static void init_array(long *a, int n)
 
 int main(int argc, char **argv)
 {
-	int ret, i, j;
+	int i;
 	long *cpuids;
 	hwloc_topology_t topology;
 
@@ -189,8 +187,11 @@ int main(int argc, char **argv)
 	 */
 	for (i=1; i<=nhwpus; i++)
 	{
+		int j;
 		for (j=0; j<NB_TESTS; j++)
 		{
+			int ret;
+
 			init_array(cpuids, nhwpus);
 			generate_arrangement(i, cpuids, nhwpus);
 			ret = test_combination(cpuids, i);

+ 4 - 4
tests/main/declare_deps_after_submission.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2011, 2016  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2017  CNRS
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -35,7 +35,7 @@ void dummy_func(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg STARPU_ATTRIBUT
 {
 }
 
-static struct starpu_codelet dummy_codelet = 
+static struct starpu_codelet dummy_codelet =
 {
 	.cpu_funcs = {dummy_func},
 	.cuda_funcs = {dummy_func},
@@ -64,10 +64,10 @@ int main(int argc, char **argv)
 	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
-	struct starpu_task *taskA, *taskB;
-
 	for (loop = 0; loop < nloops; loop++)
 	{
+		struct starpu_task *taskA, *taskB;
+
 		taskA = create_dummy_task();
 		taskB = create_dummy_task();
 

+ 1 - 2
tests/main/tag_task_data_deps.c

@@ -95,8 +95,6 @@ int main(int argc, char **argv)
 	starpu_void_data_register(&handle2);
 	starpu_data_set_sequential_consistency_flag(handle2, 0);
 
-	struct starpu_task *taskA, *taskB, *taskC;
-
 #if 1
 	for (loop = 0; loop < nloops; loop++)
 	{
@@ -112,6 +110,7 @@ int main(int argc, char **argv)
 		int writeB, dataB;
 		int writeC, dataC;
 		starpu_data_handle_t handleA, handleB, handleC;
+		struct starpu_task *taskA, *taskB, *taskC;
 
 		handleA = handle1;
 		writeA = !!(loop & 8);

+ 5 - 3
tests/openmp/parallel_single_copyprivate_inline_01.c

@@ -48,15 +48,17 @@ void parallel_region_f(void *buffers[], void *args)
 	(void) args;
 	int worker_id;
 	pthread_t tid;
+	int single_worker_id;
+	int i;
+
 	tid = pthread_self();
 	worker_id = starpu_worker_get_id();
-	int single_worker_id;
-	int *single_data;
 	printf("[tid %p] task thread = %d -- parallel -->\n", (void *)tid, worker_id);
-	int i;
 
 	for (i=0; i<4; i++)
 	{
+		int *single_data;
+
 		if ((single_data = starpu_omp_single_copyprivate_inline_begin(&single_worker_id)) == NULL)
 		{
 			printf("[tid %p] task thread = %d -- single\n", (void *)tid, worker_id);

+ 3 - 3
tools/starpu_perfmodel_plot.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2011-2014  Université de Bordeaux
- * Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016  CNRS
+ * Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017  CNRS
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -271,7 +271,7 @@ static void display_history_based_perf_models(FILE *gnuplot_file, struct starpu_
 	struct starpu_perfmodel_history_list *ptr;
 	char arch_name[32];
 	int col;
-	unsigned long last, minimum = 0;
+	unsigned long minimum = 0;
 
 	datafile = fopen(options->avg_file_name, "w");
 	col = 2;
@@ -306,7 +306,7 @@ static void display_history_based_perf_models(FILE *gnuplot_file, struct starpu_
 	/* Dump entries in size order */
 	while (1)
 	{
-		last = minimum;
+		unsigned long last = minimum;
 
 		minimum = ULONG_MAX;
 		/* Get the next minimum */