I am using \write18 enabled (or --shell-escape) with externalization to compile a bunch of PGFplots. The first run takes much time, and I noticed that pdflatex only runs on one CPU core. Is there any way to have pdflatex use multiple cores? (at least when \write18 is enabled)
1 Answer
The externalize in tikz may generated individual picture for every \begin{tikzpicture}...\end{tikzpicture}.
\usepgfplotslibrary{external}let all pgf-plots outside of the compile.
Let pdflatex know those pictures are compiled with make.
\tikzexternalize[mode=list and make]let tikz to know we would use themake. Because at present only themakesupport multi-thread.
I'm lazy to set the name for every pgfplots figure, so I let it done by system.
external/system callset names for individual picture file, or the pdflatex doesn't know what file name should be set. (Origin code is from package tikz&pgf Manual for Version 2.10 page 345.)
My tex file is named test.tex
\documentclass{standalone} \usepackage{pgfplots} %use tikz based pgfplots \usepgfplotslibrary{external} \tikzexternalize[mode=list and make] \tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"} } % to let pdflatex work %% compile picture: pdflatex --shell-escape xxxxxxx.tex \begin{document} \begin{tikzpicture} \begin{axis}[ xlabel=$x$, ylabel={$f(x) = x^2 - x +4$} ] \addplot {x^2 - x +4}; \end{axis} \end{tikzpicture} \begin{tikzpicture} \begin{loglogaxis}[xlabel=Cost,ylabel=Gain] \addplot[color=red,mark=x] coordinates { (10,100) (20,150) (40,225) (80,340) (160,510) (320,765) (640,1150) }; \end{loglogaxis} \end{tikzpicture} \end{document} After first pdflatex compiling, do the make -j 4 -f test.makefile. 4 compiles the pictures with 4 thread.
Then run pdflatex second time.
The option --shell-escape also work fine in my system.
My system is:
- Win 7(x64) + Miktex 2.9 + make under cygwin environment
- Linux(x64) + Texlive2013 + make
- 1Interesting, but could you elaborate what you are doing here? What is the sense of tikzexternalize ?Keks Dose– Keks Dose2013-12-25 11:38:32 +00:00Commented Dec 25, 2013 at 11:38
- I try explain the option I used, But it looks a bit weird in style.Tawei– Tawei2013-12-26 06:15:02 +00:00Commented Dec 26, 2013 at 6:15
- This approach does not seem to work when the
tikzpictures are imported with an\input{file.tikz}command. But maybe it's just a matter of properly naming the imported files.tigerjack– tigerjack2019-03-13 18:15:18 +00:00Commented Mar 13, 2019 at 18:15 - Reviewing chapter 53 of the pgfplots manual may clarify some of the techniques @selwyndd21 is using here.ZaydH– ZaydH2020-01-10 21:17:41 +00:00Commented Jan 10, 2020 at 21:17
external: you can configure the external library to run inmode=list and make. The resulting makefile can be processed in parallel usingmake -j 8 -f <file>.makefile(in this case on 8 threads). Only feasible if you can resort to make, though...\write18with an ampersand character (&) to have the shell spawn a new process for the external command.