浏览代码

fix atomicity of warnings that we want to display only once

Samuel Thibault 10 年之前
父节点
当前提交
dec0dfb47e
共有 1 个文件被更改,包括 14 次插入10 次删除
  1. 14 10
      src/datawizard/memalloc.c

+ 14 - 10
src/datawizard/memalloc.c

@@ -711,12 +711,14 @@ size_t _starpu_memory_reclaim_generic(unsigned node, unsigned force, size_t recl
 
 	if (reclaim && !force)
 	{
-		static int warned;
+		static unsigned warned;
 		if (!warned) {
-			char name[32];
-			_starpu_memory_node_get_name(node, name, sizeof(name));
-			_STARPU_DISP("Not enough memory left on node %s. Your application data set seems too huge to fit on the device, StarPU will cope by trying to purge %lu MiB out. This message will not be printed again for further purges\n", name, (unsigned long) (reclaim / 1048576));
-			warned = 1;
+			if (STARPU_ATOMIC_ADD(&warned, 1) == 1)
+			{
+				char name[32];
+				_starpu_memory_node_get_name(node, name, sizeof(name));
+				_STARPU_DISP("Not enough memory left on node %s. Your application data set seems too huge to fit on the device, StarPU will cope by trying to purge %lu MiB out. This message will not be printed again for further purges\n", name, (unsigned long) (reclaim / 1048576));
+			}
 		}
 	}
 
@@ -767,12 +769,14 @@ void starpu_memchunk_tidy(unsigned node)
 	target = (total * target_p) / 100;
 	amount = target - available;
 
-	static int warned;
+	static unsigned warned;
 	if (!warned) {
-		char name[32];
-		_starpu_memory_node_get_name(node, name, sizeof(name));
-		_STARPU_DISP("Low memory left on node %s (%luMiB over %luMiB). Your application data set seems too huge to fit on the device, StarPU will cope by trying to purge %lu MiB out. This message will not be printed again for further purges. The thresholds can be tuned using the STARPU_MINIMUM_AVAILABLE_MEM and STARPU_TARGET_AVAILABLE_MEM environment variables.\n", name, (unsigned long) (available / 1048576), (unsigned long) (total / 1048576), (unsigned long) (amount / 1048576));
-		warned = 1;
+		if (STARPU_ATOMIC_ADD(&warned, 1) == 1)
+		{
+			char name[32];
+			_starpu_memory_node_get_name(node, name, sizeof(name));
+			_STARPU_DISP("Low memory left on node %s (%luMiB over %luMiB). Your application data set seems too huge to fit on the device, StarPU will cope by trying to purge %lu MiB out. This message will not be printed again for further purges. The thresholds can be tuned using the STARPU_MINIMUM_AVAILABLE_MEM and STARPU_TARGET_AVAILABLE_MEM environment variables.\n", name, (unsigned long) (available / 1048576), (unsigned long) (total / 1048576), (unsigned long) (amount / 1048576));
+		}
 	}
 
 	free_potentially_in_use_mc(node, 0, amount);