Browse Source

new function ssize_t starpu_memory_get_available (unsigned node)

    If a memory limit is defined on the given node, return the amount
    of available memory on the node. Otherwise return -1
Nathalie Furmento 12 years ago
parent
commit
d8561d4a31

+ 6 - 0
doc/chapters/basic-api.texi

@@ -284,6 +284,12 @@ This function frees memory by specifying its size. The given
 @code{starpu_malloc_flags} when allocating the memory.
 @end deftypefun
 
+@deftypefun ssize_t starpu_memory_get_available (unsigned @var{node})
+If a memory limit is defined on the given node (@pxref{Limit memory}),
+return the amount of available memory on the node. Otherwise return
+@code{-1}.
+@end deftypefun
+
 @node Workers' Properties
 @section Workers' Properties
 

+ 2 - 0
doc/chapters/tips-tricks.texi

@@ -89,3 +89,5 @@ Talk about
 @code{STARPU_LIMIT_OPENCL_devid_MEM}, @code{STARPU_LIMIT_OPENCL_MEM}
 and @code{STARPU_LIMIT_CPU_MEM}
 
+@code{starpu_memory_get_available}
+

+ 2 - 0
include/starpu_stdlib.h

@@ -36,6 +36,8 @@ int starpu_free(void *A);
 int starpu_malloc_flags(void **A, size_t dim, int flags);
 int starpu_free_flags(void *A, size_t dim, int flags);
 
+ssize_t starpu_memory_get_available(unsigned node);
+
 #ifdef __cplusplus
 }
 #endif

+ 8 - 0
src/datawizard/memory_manager.c

@@ -68,3 +68,11 @@ void _starpu_memory_manager_deallocate_size(size_t size, unsigned node)
 {
 	used_size[node] -= size;
 }
+
+ssize_t starpu_memory_get_available(unsigned node)
+{
+	if (global_size[node] == 0)
+		return -1;
+	else
+		return global_size[node] - used_size[node];
+}