GraphicsMagick: ReadPNMImage(): Compute the number of threads to...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.37923.1672345085.1350.graphicsmagick-commit@lists.sourceforge.net>
changeset c2f340f17279 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=c2f340f17279
summary: ReadPNMImage(): Compute the number of threads to use.

diffstat:

 ChangeLog          |   3 +++
 coders/pnm.c       |  27 ++++++++++++++++++++++-----
 www/Changelog.html |   2 ++
 3 files changed, 27 insertions(+), 5 deletions(-)

diffs (77 lines):

diff -r 5b5f8e90be72 -r c2f340f17279 ChangeLog
--- a/ChangeLog	Thu Dec 29 13:14:51 2022 -0600
+++ b/ChangeLog	Thu Dec 29 14:17:51 2022 -0600
@@ -1,5 +1,8 @@
 2022-12-29  Bob Friesenhahn  <[email protected]>
 
+	* coders/pnm.c (ReadPNMImage): Compute the number of threads to
+	use.
+
 	* NEWS.txt: Update the news.
 
 	* magick/command.c: Add use of GetFirstImageInList() where needed
diff -r 5b5f8e90be72 -r c2f340f17279 coders/pnm.c
--- a/coders/pnm.c	Thu Dec 29 13:14:51 2022 -0600
+++ b/coders/pnm.c	Thu Dec 29 14:17:51 2022 -0600
@@ -268,10 +268,20 @@
     XV_332_Format /* P7 332 */
   } PNMSubformat;
 
-#if defined(HAVE_OPENMP) && !defined(DisableSlowOpenMP)
+#if defined(HAVE_OPENMP)
 #  define PNMReadUseOpenMP 1
-#  define PNMReadThreads (Min(2,omp_get_max_threads()))
-#endif
+
+static int PNMReadThreads(const Image* image, const size_t bytes_per_row)
+{
+  const int omp_max_threads = omp_get_max_threads();
+  long threads;
+  ARG_NOT_USED(image);
+  threads=(Min(bytes_per_row/4096UL,(unsigned long) omp_max_threads));
+  if (0 == threads)
+    threads=1;
+  return (int) threads;
+}
+#endif /* defined(HAVE_OPENMP) */
 
 static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
@@ -868,9 +878,9 @@
             unsigned int
               sample_max;
 
-#if defined(HAVE_OPENMP) && !defined(DisableSlowOpenMP)
+#if defined(HAVE_OPENMP)
             int
-              pnm_read_threads = PNMReadThreads;
+              pnm_read_threads;
 #endif
 
             (void) LogMagickEvent(CoderEvent,GetMagickModule(),"Reading PAM");
@@ -1017,6 +1027,13 @@
                   }
               }
 
+#if defined(HAVE_OPENMP)
+            pnm_read_threads = PNMReadThreads(image,bytes_per_row);
+            if (image->logging)
+              (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                                    "Using %d thread%s...", pnm_read_threads,
+                                    pnm_read_threads > 1 ? "s" : "");
+#endif
             scanline_set=AllocateThreadViewDataArray(image,exception,bytes_per_row,1);
             if (scanline_set == (ThreadViewDataSet *) NULL)
               ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
diff -r 5b5f8e90be72 -r c2f340f17279 www/Changelog.html
--- a/www/Changelog.html	Thu Dec 29 13:14:51 2022 -0600
+++ b/www/Changelog.html	Thu Dec 29 14:17:51 2022 -0600
@@ -40,6 +40,8 @@
 <p>2022-12-29  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 <blockquote>
 <ul class="simple">
+<li><p>coders/pnm.c (ReadPNMImage): Compute the number of threads to
+use.</p></li>
 <li><p>NEWS.txt: Update the news.</p></li>
 <li><p>magick/command.c: Add use of GetFirstImageInList() where needed
 to assure that the list pointer is to the first image.</p></li>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.