Annotation of OpenXM/doc/Papers/ox_math_interruption.tex, Revision 1.3
1.3 ! ohara 1: % $OpenXM: OpenXM/doc/Papers/ox_math_interruption.tex,v 1.2 2003/02/13 01:47:23 ohara Exp $
1.1 ohara 2: % 第二回 OpenXM committers meeting 講演原稿
1.3 ! ohara 3: % 第11回 Risa Consortium 研究集会講演原稿
1.1 ohara 4: % pdfファイルの生成法
5: % > platex ox_math_interruption.tex
6: % > dvips ox_math_interruption.dvi > ox_math_interruption.ps
7: % > ps2pdf ox_math_interruption.ps
8: % > acroread ox_math_interruption.pdf
9: \documentclass[pdf,slideColor,colorBG,darkblue]{prosper}
10: \usepackage{amsmath}
11: \usepackage{pst-node}
12: \title{ox\_mathへの計算中断機能の実装}
13: \author{小原功任}
14: \email{ohara@OpenXM.org}
15: \institution{金沢大学理学部計算科学科}
16:
17: \begin{document}
18:
19: \maketitle
20:
1.3 ! ohara 21: \overlays{3}{
1.1 ohara 22: \begin{slide}{ox\_math とは}
1.3 ! ohara 23: \begin{itemize}
1.1 ohara 24: \item OpenXM プロトコルをサポートするための
25: Mathematica Kernel の wrapper
26: \item MathLink (Mathematicaの通信ライブラリ)と
27: OpenXM プロトコルの両方を扱う
28: \item 今回、ox\_math に計算中断機能を実装した \\
1.3 ! ohara 29: \fromSlide*{2}{
! 30: \item[] {\yellow (MathLink の非公開機能を用いる)}
! 31: }
! 32: \fromSlide*{3}{
! 33: \item テスト環境\\
! 34: Mathematica 4.x (Linux, Windows), \\
! 35: Mathematica 3.x (Solaris)
! 36: }
! 37: \end{itemize}
1.1 ohara 38: \end{slide}
39: }
40:
1.3 ! ohara 41: \overlays{2}{
1.1 ohara 42: \begin{slide}{OpenXM と MathLink の比較}
1.3 ! ohara 43: \begin{itemize}
1.1 ohara 44: \item OpenXM\\
45: プロトコルを公開。仕組みが明らかだが自分で実装しなければならない。
46: \item MathLink\\
47: ライブラリを公開。実装しなくてよいが中身が分からない。
48: またソースが公開されていない。
1.3 ! ohara 49: \fromSlide*{2}{
! 50: \item[] {\yellow 文書化されていないことをするときに困る}
! 51: }
! 52: \end{itemize}
1.1 ohara 53: \end{slide}
54: }
55:
56: \begin{slide}{概念図}
57: \begin{pspicture}(12,6)
58: \psset{linecolor=white}
59: \rput[r](2.0,1.2){\rnode{Client}{\psovalbox{client}}}
60: \psframe[framearc=0.3](4.5,0)(11.5,5.4)
1.3 ! ohara 61: \rput[B](8,5.5){同一マシン(親・子・孫)}
1.1 ohara 62: \rput[l](5.0,1.2){\rnode{Engine}{\psovalbox{ox\_math}}}
63: \rput[l](9.4,1.2){\rnode{Kernel}{\psovalbox{math}}}
64: \rput[l](4.8,4.2){\rnode{Control}{\psovalbox{controller}}}
65: \ncline[linewidth=2pt]{<->}{Client}{Engine}
66: \ncline[linewidth=2pt]{<->}{Client}{Control}
1.3 ! ohara 67: \ncline[linewidth=2pt,linestyle=dotted]{->}{Control}{Engine}
1.1 ohara 68: \ncline[linewidth=2pt,linecolor=yellow]{<->}{Engine}{Kernel}
69: \end{pspicture}
70: \end{slide}
71:
72: \begin{slide}{OpenXM の仕組み}
1.3 ! ohara 73: \begin{itemize}
1.1 ohara 74: \item サーバ・クライアント方式
75: \item ネットワーク透過性がある
76: \item サーバはコントローラとエンジンの 2 プロセスからなる
77: \item エンジンはスタックマシン
78: \item 計算を途中で中断できる
1.3 ! ohara 79: \end{itemize}
1.1 ohara 80: \end{slide}
81:
82: \overlays{5}{
83: \begin{slide}{OpenXM の計算中断機能}
84: \begin{pspicture}(12,6)
85: \psset{linecolor=white}
86: \rput[r](2.0,1.2){\rnode{Client}{\psovalbox{client}}}
87: \psframe[framearc=0.3](7.5,0)(11.5,5.4)
88: \rput[B](9.5,5.5){同一マシン}
89: \rput[l](8.0,1.2){\rnode{Engine}{\psovalbox{engine}}}
90: \rput[l](7.8,4.2){\rnode{Control}{\psovalbox{controller}}}
91: \ncline[linewidth=2pt]{<->}{Client}{Control}
92: \onlySlide*{2}{\Aput{\yellow reset}}
1.3 ! ohara 93: \ncline[linewidth=2pt,linestyle=dotted]{->}{Control}{Engine}
1.1 ohara 94: \onlySlide*{3}{\Aput{\yellow SIGUSR1}}
95: \ncline[linewidth=2pt]{<->}{Client}{Engine}
96: \onlySlide*{4}{\Bput{\yellow OX\_SYNC\_BALL}}
97: \end{pspicture}
98: \end{slide}
99: }
100:
1.3 ! ohara 101: \overlays{4}{
1.1 ohara 102: \begin{slide}{MathLink の仕組み}
103: \begin{itemize}
1.3 ! ohara 104: \item (ほとんど)ネットワーク透過性がある
1.1 ohara 105: \fromSlide*{2}{\item 通信路で送られるのは{\yellow Mathematicaの式}}
106: \fromSlide*{3}{\item[]
107: \begin{itemize}
108: \item[例:] EvaluatePacket[Sin[\$VersionNumber]]
109: \item[] ReturnPacket[Sin[x]]
110: \item[] InputNamePacket["In[1]:= "]
111: \item[] MenuPacket[1,"Interrupt> "]
112: \end{itemize}
113: }
114: \fromSlide*{4}{\item *Packet[]をMathematica Bookではパケットと呼ぶ}
115: \end{itemize}
116: \end{slide}
117: }
118:
119: \begin{slide}{MathLinkプログラムの書き方(1)}
120: \begin{verbatim}
121: char *s = "Mathematicaの式";
122: MLPutFunction(link, "EvaluatePacket", 1);
123: MLPutFunction(link, "ToExpression", 1);
124: MLPutString(link, string);
125: MLEndPacket(link);
126: \end{verbatim}
127: \end{slide}
128:
129: \begin{slide}{MathLinkプログラムの書き方(2)}
130: \begin{verbatim}
131: char *s;
132: while (MLNextPacket(link) != RETURNPKT)
133: MLNewPacket(link);
134: switch(MLGetNext(link)) {
135: MLTKSTR:
136: MLGetString(link, &s);
137: ...
138: MLTKINT:
139: }
140: MLNewPacket(link);
141: \end{verbatim}
142: \end{slide}
143:
144: \overlays{4}{
1.3 ! ohara 145: \begin{slide}{Mathematica の割り込み}
! 146: \begin{pspicture}(12,6)
! 147: \psset{linecolor=white}
! 148: \rput[r](2.0,3.0){\rnode{Engine}{\psovalbox{ox\_math}}}
! 149: \rput[l](7.0,3.0){\rnode{Kernel}{\psovalbox{MathKernel}}}
! 150: \onlySlide*{1}{
! 151: \ncline[linewidth=2pt]{->}{Engine}{Kernel}
! 152: \Aput{\yellow EvaluatePacket[...]}
! 153: }
! 154: \onlySlide*{2}{
! 155: \ncline[linewidth=2pt,linestyle=dotted]{->}{Engine}{Kernel}
! 156: \Aput{\yellow SIGINT}
! 157: }
! 158: \onlySlide*{3}{
! 159: \ncline[linewidth=2pt]{<->}{Engine}{Kernel}
! 160: \Aput{\yellow 割り込みの後始末}
! 161: }
! 162: \onlySlide*{4}{
! 163: \ncline[linewidth=2pt]{<-}{Engine}{Kernel}
! 164: \Aput{\yellow ReturnPacket[\$Aborted]}
! 165: }
! 166: \end{pspicture}
1.1 ohara 167: \end{slide}
168: }
169:
1.3 ! ohara 170: \overlays{3}{
1.1 ohara 171: \begin{slide}{MLPutMessage}
1.3 ! ohara 172: \begin{itemize}
1.1 ohara 173: \item MathLink の非公開関数
1.3 ! ohara 174: \item ネットワーク透過性はない
! 175: \fromSlide*{2}{
1.1 ohara 176: \item MLPutMessage(link, MLInterruptMessage)\\
177: で link の指すプロセスに {\yellow SIGINT} を送る。\\
1.3 ! ohara 178: (Unix の場合)
! 179: }
! 180: \fromSlide*{3}{
! 181: \item 割り込んだあとの後始末は、{\yellow 相手方のプログラムの作りに依存する}
! 182: }
! 183: \end{itemize}
1.1 ohara 184: \end{slide}
185: }
186:
1.3 ! ohara 187: \overlays{5}{
! 188: \begin{slide}{割り込みの後始末}
1.1 ohara 189: \begin{itemstep}
190: \item MenuPacket[1,"Interrupt> "] を受け取れば計算が中断されている
191: \item MLPutString("$\backslash$n")
192: \item MenuPacket[0,"Interrupt> "] を受け取る
193: \item MLPutString("a")
1.3 ! ohara 194: \item TextPacket["..."] を受け取る
1.1 ohara 195: \end{itemstep}
196: \end{slide}
197: }
1.3 ! ohara 198:
! 199: \overlays{3}{
! 200: \begin{slide}{計算結果 \$Aborted}
! 201: \begin{itemize}
! 202: \item ReturnPacket[\$Aborted] が返ってくるか? \\
! 203: 3.x $\Rightarrow$ ○, $\quad$ 4.x $\Rightarrow$ ×
! 204: \fromSlide*{2}{
! 205: \item 4.x では、{\yellow 次の計算}を行うと、\$Aborted が返ってくる!!
! 206: }
! 207: \fromSlide*{3}{
! 208: \item ``割り込みの後始末''のあと、EvaluatePacket[0] を送って、
! 209: ReturnPacket[...] をふたつ受け取るとよい。最初のものが \$Aborted
! 210: }
! 211: \end{itemize}
! 212: \end{slide}
! 213: }
! 214:
! 215: \begin{slide}{参考文献}
! 216: \begin{itemize}
! 217: \item[{[1]}] Mathematica Book, Wolfram Research
! 218: \item[{[2]}] MathArchive にあった Todd Gayley のメール([mg17015], 1999/Apr)
! 219: \item[{[3]}] 昔の MathLink にあった MLSignal(\ ) の解説
! 220: (Google のキャッシュにあった)
! 221: \item[{[4]}] mathlink.h, nm libMLa の出力, mprep の生成するソース
! 222: \end{itemize}
! 223: \end{slide}
1.1 ohara 224:
225: \end{document}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>