gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master e1d1f13a: Makefile extensions: batch by RAM ta


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e1d1f13a: Makefile extensions: batch by RAM takes empty RAM usage
Date: Sun, 14 Apr 2024 11:05:22 -0400 (EDT)

branch: master
commit e1d1f13ad7fc9ada6bdce3e48c79ff61f068af19
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Makefile extensions: batch by RAM takes empty RAM usage
    
    Until now, when calling the newly added 'ast-text-prev-batch-by-ram'
    function, giving a RAM value (as a number in Gigabytes) was
    mandatory. However, when this function is used in a Makefile that is itself
    later used in higher-level script, it happens that the RAM check is only
    necessary in some calls to the Makefile, not all. In such cases, the user
    would have to put the whole target+prerequisite structure in conditionals,
    making the Makefile hard to read and buggy.
    
    With this commit, as in other GNU Make functions, this Gnuastro Makefile
    extension now returns 'NULL' when the value in the gigabyte argument is an
    empty string (removing its effect in the prerequisite list).
---
 NEWS              | 19 +++++++++----------
 doc/gnuastro.texi |  5 ++++-
 lib/makeplugin.c  |  8 +++++++-
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index ed9c8f4c..868c20a3 100644
--- a/NEWS
+++ b/NEWS
@@ -44,24 +44,23 @@ See the end of the file for license conditions.
 
 *** Makefile extensions
   - $(ast-text-prev TARGET, LIST): select the word that is previous to
-    'TARGET' in a list of words. See the documentation for a fully working
-    example and how this can be useful.
+    'TARGET' in a list of words. See the minimal working example in the
+    book for more.
 
   - $(ast-text-prev-batch TARGET, NUM, LIST): select the previous "batch"
     of 'NUM' words (in relation to the batch that contains 'TARGET'). This
     is useful for steps in your pipelines were you need to limit the
-    parallelization to batches. See the example in the book for a fully
-    working example.
+    parallelization to batches. See the minimal working example in the book
+    for more.
 
   - $(ast-text-prev-batch-by-ram TARGET, NEEDED_RAM_GB, LIST): select the
     previous batch of words in 'LIST' such that the total consumed RAM by
     all the parallel executions does not exceed the available RAM when Make
-    starts. The 'NEEDED_RAM_GB' variable is the amount of RAM that is
-    needed to create one target (in Gigabytes). Like 'ast-text-prev-batch',
-    this is useful for steps in a pipeline that require a large amount of
-    RAM (thus not allowing parallel execution), but this is more generic
-    and adapts to different systems with very different RAM and/or CPU
-    threads.
+    starts. Like 'ast-text-prev-batch', this is useful for steps in a
+    pipeline that require a large amount of RAM (thus not allowing parallel
+    execution), but this is more generic and adapts to different systems
+    with very different RAM and/or CPU threads. See the minimal working
+    example in the book for more.
 
 ** Removed features
 ** Changed features
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index fbc79a3a..fbe2c297 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -36075,8 +36075,11 @@ Any other rule that is later added to this make file 
(as a prerequisite/parent o
 @cindex RAM
 Similar to @code{ast-text-prev-batch}, but instead of taking the number of 
words/files in each batch, this function takes the maximum amount of RAM that 
is needed by one instance of the recipe.
 Through the @code{NEEDED_RAM_GB} argument, you should specify the amount of 
ram that a @emph{single} instance of the recipe in this rule needs.
-The number of files in each batch is then calculated internally by reading the 
available RAM on the system.
+If @code{NEEDED_RAM_GB} is an empty string, this function will return an empty 
string (having no effect in your prerequisite list).
+
+The number of files in each batch is calculated internally by reading the 
available RAM on the system at the moment Make calls this function.
 Therefore this function is more generalizable to different computers (with 
very different RAM and/or CPU threads).
+But to avoid overlapping with other rules that may consume a lot of RAM, it is 
better to design your Makefile such that other rules are only executed once all 
instances of this rule have been completed.
 
 For example, assume evey instance of one rule in your Makefile requires a 
maximum of 5.2 GB of RAM during its execution, and your computer has 32 GB of 
RAM and 2 threads.
 In this case, you do not need to manage the targets at all: at the worst 
moment your pipeline will consume 10.4GB of RAM (much smaller than the 32GB of 
RAM that you have).
diff --git a/lib/makeplugin.c b/lib/makeplugin.c
index 57daeeb5..081311d0 100644
--- a/lib/makeplugin.c
+++ b/lib/makeplugin.c
@@ -369,9 +369,15 @@ makeplugin_text_prev_batch_by_ram(const char *caller, 
unsigned int argc,
 {
   void *nptr;
   float needed_gb;
-  char *target=argv[0], *list=argv[2];
+  char *c, *target=argv[0], *list=argv[2];
   size_t num, ram_b=gal_checkset_ram_available(1);
 
+  /* In case the second argument (Gigabytes) is an empty string (only
+     containing the C locale space characters identified with 'isspace'),
+     then just return an empty string. */
+  for(c=argv[1]; *c!='\0'; ++c) if(!isspace(*c)) break;
+  if(*c=='\0') return NULL; /* Only when the string is only "space". */
+
   /* Interpret the number. */
   nptr=&needed_gb;
   if( gal_type_from_string(&nptr, argv[1], GAL_TYPE_FLOAT32) )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]