Ver código fonte

src/core/disk_ops: 2 bugs fixes: - files opened with fdopen only need to be closed with fclose and - reopen files when necessary

Nathalie Furmento 9 anos atrás
pai
commit
e009dfc674

+ 16 - 10
src/core/disk_ops/disk_stdio.c

@@ -73,7 +73,6 @@ static struct starpu_stdio_obj *_starpu_stdio_init(int descriptor, char *path, s
 		/* Too many opened files, avoid keeping this one opened */
 		fclose(f);
 		f = NULL;
-		close(descriptor);
 		descriptor = -1;
 	}
 	else
@@ -102,9 +101,7 @@ static FILE *_starpu_stdio_reopen(struct starpu_stdio_obj *obj)
 
 static void _starpu_stdio_reclose(FILE *f)
 {
-	int id = fileno(f);
 	fclose(f);
-	close(id);
 }
 
 static void _starpu_stdio_close(struct starpu_stdio_obj *obj)
@@ -116,7 +113,6 @@ static void _starpu_stdio_close(struct starpu_stdio_obj *obj)
 		(void) STARPU_ATOMIC_ADD(&starpu_stdio_opened_files, -1);
 
 	fclose(obj->file);
-	close(obj->descriptor);
 }
 
 static void _starpu_stdio_fini(struct starpu_stdio_obj *obj)
@@ -380,15 +376,20 @@ static int get_stdio_bandwidth_between_disk_and_main_ram(unsigned node)
 	start = starpu_timing_now();
 	for (iter = 0; iter < NITER; ++iter)
 	{
+		FILE *f = tmp->file;
+
 		_starpu_disk_write(STARPU_MAIN_RAM, node, mem, buf, 0, SIZE_DISK_MIN, NULL);
+
+		if (!f)
+			f = _starpu_stdio_reopen(tmp);
 		/* clean cache memory */
-		int res = fflush(tmp->file);
+		int res = fflush(f);
 		STARPU_ASSERT_MSG(res == 0, "Slowness computation failed \n");
 
 #ifdef STARPU_HAVE_WINDOWS
-		res = _commit(tmp->descriptor);
+		res = _commit(fileno(f));
 #else
-		res = fsync(tmp->descriptor);
+		res = fsync(fileno(f));
 #endif
 		STARPU_ASSERT_MSG(res == 0, "Slowness computation failed \n");
 	}
@@ -407,15 +408,20 @@ static int get_stdio_bandwidth_between_disk_and_main_ram(unsigned node)
 	start = starpu_timing_now();
 	for (iter = 0; iter < NITER; ++iter)
 	{
+		FILE *f = tmp->file;
+
 		_starpu_disk_write(STARPU_MAIN_RAM, node, mem, buf, rand() % (SIZE_DISK_MIN -1) , 1, NULL);
 
-		int res = fflush(tmp->file);
+		if (!f)
+			f = _starpu_stdio_reopen(tmp);
+
+		int res = fflush(f);
 		STARPU_ASSERT_MSG(res == 0, "Latency computation failed");
 
 #ifdef STARPU_HAVE_WINDOWS
-		res = _commit(tmp->descriptor);
+		res = _commit(fileno(f));
 #else
-		res = fsync(tmp->descriptor);
+		res = fsync(fileno(f));
 #endif
 		STARPU_ASSERT_MSG(res == 0, "Latency computation failed");
 	}

+ 15 - 5
src/core/disk_ops/unistd/disk_unistd_global.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2013 Corentin Salingue
- * Copyright (C) 2015 CNRS
+ * Copyright (C) 2015, 2016 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
@@ -423,12 +423,17 @@ int get_unistd_global_bandwidth_between_disk_and_main_ram(unsigned node)
 	start = starpu_timing_now();
 	for (iter = 0; iter < NITER; ++iter)
 	{
+		int fd = tmp->descriptor;
+
 		_starpu_disk_write(STARPU_MAIN_RAM, node, mem, buf, 0, SIZE_DISK_MIN, NULL);
 
+		if (fd < 0)
+			fd = _starpu_unistd_reopen(tmp);
+
 #ifdef STARPU_HAVE_WINDOWS
-		res = _commit(tmp->descriptor);
+		res = _commit(fd);
 #else
-		res = fsync(tmp->descriptor);
+		res = fsync(fd);
 #endif
 
 		STARPU_ASSERT_MSG(res == 0, "bandwidth computation failed");
@@ -448,12 +453,17 @@ int get_unistd_global_bandwidth_between_disk_and_main_ram(unsigned node)
 	start = starpu_timing_now();
 	for (iter = 0; iter < NITER; ++iter)
 	{
+		int fd = tmp->descriptor;
+
 		_starpu_disk_write(STARPU_MAIN_RAM, node, mem, buf, (rand() % (SIZE_DISK_MIN/MEM_SIZE)) * MEM_SIZE, MEM_SIZE, NULL);
 
+		if (fd < 0)
+			fd = _starpu_unistd_reopen(tmp);
+
 #ifdef STARPU_HAVE_WINDOWS
-		res = _commit(tmp->descriptor);
+		res = _commit(fd);
 #else
-		res = fsync(tmp->descriptor);
+		res = fsync(fd);
 #endif
 
 		STARPU_ASSERT_MSG(res == 0, "Latency computation failed");