gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master b772687 1/2: Library (fits.h): using fits_is_r


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master b772687 1/2: Library (fits.h): using fits_is_reentrant for parallel reading of tables
Date: Wed, 1 Dec 2021 12:18:47 -0500 (EST)

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

    Library (fits.h): using fits_is_reentrant for parallel reading of tables
    
    Until now, the new parallelized table-reading feature of
    'gal_fits_tab_read' was simply using the
    'GAL_CONFIG_HAVE_FITS_IS_REENTRANT' macro as a reference to see if
    CFITSIO's multi-threaded file reading is available or not. However, this
    was wrong! That macro was only in place to make sure that the function
    providing this test result is available or not!
    
    With this commit, we are now using this macro and the CFITSIO function
    properly. Also, a message is now printed if the user's CFITSIO version is
    not up to date (and doesn't have the function to see if it allows parallel
    access to a file).
    
    This issue was found by Raul Infante-Sainz.
---
 configure.ac | 12 +++++++++++-
 lib/fits.c   | 11 ++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index b8a357f..6ea559d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -516,7 +516,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM(
 # If the CFITSIO library has the 'fits_is_reentrant' function (it was added
 # since version 3.30 of April 2012).
 AC_CHECK_LIB([cfitsio], [fits_is_reentrant], [has_fits_is_reentrant=1],
-             [has_fits_is_reentrant=0], [-lm])
+             [has_fits_is_reentrant=0; anywarnings=yes], [-lm])
 AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_FITS_IS_REENTRANT],
                    [$has_fits_is_reentrant],
                    [CFITSIO has the fits_is_reentrant function])
@@ -1114,6 +1114,16 @@ AS_IF([test x$enable_guide_message = xyes],
                AS_ECHO(["    released in October 2015)."])
                AS_ECHO([]) ])
 
+        AS_IF([test "x$has_fits_is_reentrant" = "x0"],
+              [dependency_notice=yes
+               AS_ECHO(["  - CFITSIO (https://heasarc.gsfc.nasa.gov/fitsio/) 
version on"])
+               AS_ECHO(["    this computer doesn't have the 
'fits_is_reentrant' function"])
+               AS_ECHO(["    which is used to see if FITS files can be read in 
parallel"])
+               AS_ECHO(["    or not (it was introduced in version 3.30 
released in April"])
+               AS_ECHO(["    2012). This won't affect the outputs of the 
programs, but"])
+               AS_ECHO(["    can slow them down."])
+               AS_ECHO([]) ])
+
         AS_IF([test "x$has_wcslib_dis_h" = "x0"],
               [dependency_notice=yes
                AS_ECHO(["  - WCSLIB 
(https://www.atnf.csiro.au/people/mcalabre/WCS) version"])
diff --git a/lib/fits.c b/lib/fits.c
index 0b2ea7d..82fbcfb 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -3508,10 +3508,19 @@ gal_fits_tab_read(char *filename, char *hdu, size_t 
numrows,
                   gal_data_t *allcols, gal_list_sizet_t *indexll,
                   size_t numthreads, size_t minmapsize, int quietmmap)
 {
+  size_t i;
   gal_data_t *out=NULL;
   gal_list_sizet_t *ind;
   struct fits_tab_read_onecol_params p;
-  size_t i, nthreads=GAL_CONFIG_HAVE_FITS_IS_REENTRANT ? numthreads : 1;
+
+  /* If the 'fits_is_reentrant' function exists, then use it to see if
+     CFITSIO was configured in multi-thread mode. Otherwise, just use a
+     single thread. */
+#if GAL_CONFIG_HAVE_FITS_IS_REENTRANT == 1
+  size_t nthreads = fits_is_reentrant() ? numthreads : 1;
+#else
+  size_t nthreads=1;
+#endif
 
   /* We actually do have columns to read. */
   if(numrows)



reply via email to

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