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)
Asked
Active
Viewed 6,885 times
39
Stephan Lehmke
- 24,361
M.Reza
- 3,237
1 Answers
19
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
Tawei
- 1,254
- 12
- 15
-
1Interesting, but could you elaborate what you are doing here? What is the sense of tikzexternalize ? – Keks Dose Dec 25 '13 at 11:38
-
-
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 Mar 13 '19 at 18:15 -
Reviewing chapter 53 of the pgfplots manual may clarify some of the techniques @selwyndd21 is using here. – ZaydH Jan 10 '20 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... – Christian Feuersänger Oct 06 '13 at 14:12\write18with an ampersand character (&) to have the shell spawn a new process for the external command. – Daniel Nov 21 '13 at 13:20\write18{\pgf@tempa\string&}on systems that support this. The only problem would be not to include the image immediately afterwards, but wait at the end of the first run for all images to finish and then include them in the second run. On systems with several cores, this is probably much faster than waiting for every image to finish. – Stephan Lehmke Dec 03 '13 at 22:15