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