You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a magick-based function that essentially converts PDF to PNG files. I'm using that function via parallel::mclapply which, in principle, works fine. However, if I call it first outside of mclapply then the subsequent application in mclapply hangs and does not proceed.
Minimal reproducible example
First, I generate four PDF files for illustration:
Imagemagick (like most c libraries) is not intended to get forked while in use the way mcparallel does, this will probably corrupt the state of the main process. You can use imagemagick's built-in threading:
magick:::magick_threads(4)
That might also speed things up a bit.
Other than that I can only recommend to avoid using imagemagick both in the parent process and children at the same time.
So it's ok to load the library within the parallelization but not before? And what would be the clean way to unload it, if necessary, prior to the parallelization?
Thanks for the hint regarding the built-in threading. But if I understand correctly, then this does not help with many small "embarrassingly parallel" tasks, right? But it might help if I merge my many PDF files before converting them to PNGs.
Summary
I have a magick-based function that essentially converts PDF to PNG files. I'm using that function via
parallel::mclapply
which, in principle, works fine. However, if I call it first outside ofmclapply
then the subsequent application inmclapply
hangs and does not proceed.Minimal reproducible example
First, I generate four PDF files for illustration:
The
magick
-based functionto_png
can be used to convert a PDF file to a PNG file:Using that function sequentially works fine, as expected:
However, if I do the analogous operation on four cores, the
to_png()
function hands and does not proceed:Curiously, several slight adaptations work:
mclapply
first (before the sequentialfor()
version), then it works.mc.cores = 1
it works.Is there anything I can - or should - do to avoid this problem?
This is in Debian GNU/Linux with R 4.4.1 and
magick
2.8.5.The text was updated successfully, but these errors were encountered: