瀏覽代碼

perfmodel: store the file name instead of the file handle, and open the file each time we need to write something

	It will avoid the error <Too many open files> when running examples/cg/cg
Nathalie Furmento 13 年之前
父節點
當前提交
7d5f9e13b8
共有 2 個文件被更改,包括 13 次插入11 次删除
  1. 2 2
      include/starpu_perfmodel.h
  2. 11 9
      src/core/perfmodel/perfmodel_history.c

+ 2 - 2
include/starpu_perfmodel.h

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010, 2011  Université de Bordeaux 1
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -142,7 +142,7 @@ struct starpu_per_arch_perfmodel
 	struct starpu_history_list *list;
 	struct starpu_regression_model regression;
 #ifdef STARPU_MODEL_DEBUG
-	FILE *debug_file;
+	char debug_path[256];
 #endif
 };
 

+ 11 - 9
src/core/perfmodel/perfmodel_history.c

@@ -592,10 +592,7 @@ int _starpu_register_model(struct starpu_perfmodel *model)
 	{
 		for (nimpl = 0; nimpl < STARPU_MAXIMPLEMENTATIONS; nimpl++)
 		{
-			char debugpath[256];
-			starpu_perfmodel_debugfilepath(model, arch, debugpath, 256, nimpl);
-			model->per_arch[arch][nimpl].debug_file = fopen(debugpath, "a+");
-			STARPU_ASSERT(model->per_arch[arch][nimpl].debug_file);
+			starpu_perfmodel_debugfilepath(model, arch, model->per_arch[arch][nimpl].debug_path, 256, nimpl);
 		}
 	}
 #endif
@@ -1066,14 +1063,19 @@ void _starpu_update_perfmodel_history(struct _starpu_job *j, struct starpu_perfm
 
 #ifdef STARPU_MODEL_DEBUG
 		struct starpu_task *task = j->task;
-		FILE * debug_file = per_arch_model->debug_file;
+		FILE *f = fopen(per_arch_model->debug_path, "a+");
+		if (f == NULL)
+		{
+			_STARPU_DISP("Error <%s> when opening file <%s>\n", strerror(errno), per_arch_model->debug_path);
+			STARPU_ASSERT(0);
+		}
 
 		if (!j->footprint_is_computed)
 			(void) _starpu_compute_buffers_footprint(model, arch, nimpl, j);
 
 		STARPU_ASSERT(j->footprint_is_computed);
 
-		fprintf(debug_file, "0x%x\t%lu\t%f\t%f\t%f\t%d\t\t", j->footprint, (unsigned long) _starpu_job_get_data_size(model, arch, nimpl, j), measured, task->predicted, task->predicted_transfer, cpuid);
+		fprintf(f, "0x%x\t%lu\t%f\t%f\t%f\t%d\t\t", j->footprint, (unsigned long) _starpu_job_get_data_size(model, arch, nimpl, j), measured, task->predicted, task->predicted_transfer, cpuid);
 		unsigned i;
 
 		for (i = 0; i < task->cl->nbuffers; i++)
@@ -1082,10 +1084,10 @@ void _starpu_update_perfmodel_history(struct _starpu_job *j, struct starpu_perfm
 
 			STARPU_ASSERT(handle->ops);
 			STARPU_ASSERT(handle->ops->display);
-			handle->ops->display(handle, debug_file);
+			handle->ops->display(handle, f);
 		}
-		fprintf(debug_file, "\n");
-
+		fprintf(f, "\n");
+		fclose(f);
 #endif
 		_STARPU_PTHREAD_RWLOCK_UNLOCK(&model->model_rwlock);
 	}