gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master c1ad20ce 2/4: Configuration: automatically obt


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master c1ad20ce 2/4: Configuration: automatically obtaining the number of threads
Date: Thu, 2 Jun 2022 12:50:33 -0400 (EDT)

branch: master
commit c1ad20ce05a44f0a6240c4a767ff4de452a1d8b0
Author: Raul Infante-Sainz <infantesainz@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Configuration: automatically obtaining the number of threads
    
    Until now, when informing the user the number of cores to be used in the
    make step ('make' and 'make check'), we simply recommended using
    '-j8'. However, depending on the particular machine, the number of threads
    could be higher or lower.
    
    With this commit, the number of available threads is automatically computed
    in the './configure' phase. The way of obtaining it is different depending
    on the system (GNU/Linux or macOS). Once it has been computed, in the
    messages, that value is used after '-j' to help guide the user.
---
 Makefile.am  |  4 ++--
 configure.ac | 22 ++++++++++++++++++++--
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 683bddf9..dc48dae5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -356,9 +356,9 @@ all-local: bin/completion.bash
         echo "Gnuastro $(VERSION), was successfully built.";                   
     \
         echo "Please check the build on your system by running:";              
     \
         echo;                                                                  
     \
-        echo "    make check -j8";                                             
     \
+        echo "    make check -j$(SUGGESTEDJOBS)";                              
     \
         echo;                                                                  
     \
-        echo "(You can change the 8 to the number of CPU threads available.)"; 
     \
+        echo "(You can change the $(SUGGESTEDJOBS) to any number of CPU 
threads.)"; \
         echo "(The following \"Leaving directory\" notices can be ignored.)";  
     \
         echo 
"==================================================================="; \
         echo 
"==================================================================="; \
diff --git a/configure.ac b/configure.ac
index a1e0a55f..a4740213 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,6 +76,24 @@ LT_INIT
 
 
 
+# Check the number of jobs. Depending on the operative system (GNU/Linux or
+# macOS), the way of getting the number of cores is different. If the
+# number of cores can not be obtained, set it to 8.
+AC_CHECK_PROG(has_nproc, nproc, [yes], [no])
+AS_IF([test $has_nproc = yes],
+      [jobs=$(nproc --all)],
+      [
+        AC_CHECK_PROG(has_sysctl, sysctl, [yes], [no])
+        AS_IF([test $has_sysctl = yes],
+              [jobs=$(sysctl -a | awk '/^hw\.ncpu/{print $2}')],
+              [jobs=8])
+      ])
+AC_SUBST(SUGGESTEDJOBS, [$jobs])
+
+
+
+
+
 # This macro will let the libraries know that we are now in the Gnuastro
 # build system, not on the user's system. While we are building Gnuastro,
 # we have the important installation information in 'config.h'. But in the
@@ -1304,9 +1322,9 @@ AS_IF([test x$enable_guide_message = xyes],
      )
   AS_ECHO(["To build Gnuastro $PACKAGE_VERSION, please run:"])
   AS_ECHO([])
-  AS_ECHO(["    make -j8"])
+  AS_ECHO(["    make -j$jobs"])
   AS_ECHO([])
-  AS_ECHO(["(You can change the 8 to the number of CPU threads available.)"])
+  AS_ECHO(["(You can change the $jobs to any number of CPU threads.)"])
   AS_ECHO(["(Configure with '--disable-guide-message' for no messages.)"])
   AS_ECHO(["(Please be patient, some libraries can take a few minutes to 
compile.)"])
   
AS_ECHO([=======================================================================])



reply via email to

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