Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ cinclude_tmp.*

syntax: regexp
.*\.[0-9]*p*\..*\.sc$
.*\.se[0-9]$

.*\.se[0-9]$
12 changes: 10 additions & 2 deletions src/rule/tcell-sc1.rule
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,24 @@
(extendrule statement tcell-sc1
((#?(do-two ,stat1 ,stat2 ({handles} ,id
{(:guard ,@guard-body ,guard-exp)}
{(:node ,@node-body ,node-exp)}
(:put ,@put-body) (:get ,@get-body))))
~(do-two (begin ,(statement stat1)) (begin ,(statement stat2))
(handles ,id
,@(if-pattern-variable guard-exp
(list ~(:guard ,@(function-body guard-body)
,(expression guard-exp))))
,@(if-pattern-variable node-exp
(list ~(:node ,@(function-body node-body)
,(expression node-exp))))
(:put ,@(function-body put-body))
(:get ,@(function-body get-body)))) )
((#?(do-many for ,var from ,from to ,to
,@body
({handles} ,id
{(:guard ,@guard-body ,guard-exp)}
{(:spawn-from ,@spn-from-body ,spn-from-exp)}
{(:node ,@node-body ,node-exp)}
(:put from ,put-from to ,put-to ,@put-body)
(:get ,@get-body))))
~(do-many for ,var from ,(expression from) to ,(expression to)
Expand All @@ -77,6 +82,9 @@
,@(if-pattern-variable spn-from-exp
(list ~(:spawn-from ,@(function-body spn-from-body)
,(expression spn-from-exp))))
,@(if-pattern-variable node-exp
(list ~(:node ,@(function-body node-body)
,(expression node-exp))))
(:put from ,put-from to ,put-to ,@(function-body put-body))
(:get ,@(function-body get-body)))) )
((#?(do-many* (,init-exp ,cond-exp ,loop-exp)
Expand All @@ -89,8 +97,8 @@
(handles ,id
(:put ,@(function-body put-body))
(:get ,@(function-body get-body)))) )
(#?(tcell-broadcast ,id (:put ,@put-body))
~(tcell-broadcast ,id (:put ,@(function-body put-body))))
(#?(tcell-broadcast ,id (:put ,@put-body) @body)
~(tcell-broadcast ,id (:put ,@(function-body put-body)) ,@(function-body body)))
((#?(dynamic-wind
(:before ,@bef-body)
(:body ,@body)
Expand Down
16 changes: 14 additions & 2 deletions src/rule/tcell-type.rule
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
((#?(do-two ,stat1 ,stat2
({handles} ,id[identifier]
{(:guard ,@guard-body ,guard-exp)}
{(:node ,@node-body ,node-exp)}
(:put ,@put-body) (:get ,@get-body))))
~(do-two ,(block-item stat1) ,(block-item stat2)
,(tcell-type:with-task id
Expand All @@ -94,13 +95,19 @@
(let ((fb (function-body guard-body))
(exp (expression guard-exp)))
~(:guard ,@fb ,exp)))))
,@(if-pattern-variable node-exp
(list (type:with-new-environment
(let ((fb (function-body node-body))
(exp (expression node-exp)))
~(:node ,@fb ,exp)))))
(:put ,@(type:with-new-environment (function-body put-body)))
(:get ,@(type:with-new-environment (function-body get-body)))))) )
((#?(do-many for ,var from ,from to ,to
,@body
({handles} ,id
{(:guard ,@guard-body ,guard-exp)}
{(:spawn-from ,@spn-from-body ,spn-from-exp)}
{(:node ,@node-body ,node-exp)}
(:put from ,put-from to ,put-to ,@put-body)
(:get ,@get-body))))
(type:with-new-environment
Expand All @@ -119,6 +126,11 @@
(let ((fb (function-body spn-from-body))
(exp (expression spn-from-exp)))
~(:spawn-from ,@fb ,exp)))))
,@(if-pattern-variable node-exp
(list (type:with-new-environment
(let ((fb (function-body node-body))
(exp (expression node-exp)))
~(:node ,@fb ,exp)))))
(:put from ,put-from to ,put-to
,@(type:with-new-environment
(type:add-variable put-from ~int)
Expand All @@ -137,9 +149,9 @@
~(handles ,id
(:put ,@(type:with-new-environment (function-body put-body)))
(:get ,@(type:with-new-environment (function-body get-body))))))) )
(#?(tcell-broadcast ,id (:put ,@put-body))
(#?(tcell-broadcast ,id (:put ,@put-body) ,@body)
~(tcell-broadcast ,id (:put ,@(type:with-new-environment
(function-body! put-body)))) )
(function-body! put-body))) ,@(type:with-new-environment (function-body! body)) ) )
((#?(dynamic-wind
(:before ,@bef-body)
(:body ,@body)
Expand Down
127 changes: 104 additions & 23 deletions src/rule/tcell.rule
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,17 @@
;; <stat1>が終わり,sendした仕事の結果が返ってきたら,:get 以下を実行.
(#?(do-two ,stat1 ,stat2 ({handles} ,id
{(:guard ,@guard-body ,guard-exp)}
{(:node ,@node-body ,node-exp)}
(:put ,@put-body) (:get ,@get-body)))
(when (ruleset-param 'no-nestfunc)
(return-from statement ~(begin ,(block-item stat1)
,(block-item stat2)) ))
(tcell:with-task id
(let* ((spn-id (generate-id "spawned"))
(ancestor-id (generate-id "ancestor"))
(tdat-id (generate-id "st"))
(bk-id (generate-id "do_two_bk"))
(subptr-id (generate-id "subptr"))
(b-stat1 (tcell:with-new-bk bk-id (block-item stat1)))
(b-stat2 (block-item stat2))
(b-put-body (function-body put-body))
Expand All @@ -214,6 +217,8 @@
(def pthis (ptr (struct ,(tcell:task-struct-id)))
#+comment (ptr ,tdat-id))
(def ,spn-id int 0) ; すでに仕事をsendしていたら '1'
(def ,ancestor-id int 1)
(def ,subptr-id (ptr (struct task-home)))
(begin
;; <-- Nestfunc start ---
;; Called for backtracking to handle a task request or an exception
Expand All @@ -224,29 +229,50 @@
(begin
;; Wait for spawned tasks to be completed
(while (> (dec ,spn-id) 0)
(wait-rslt -thr 0))
(wait-rslt -thr ,subptr-id 0))
;; Continue backtracking (never returns)
(,(tcell:latest-bk))))
;; If this do-two has spawned a task:
(if ,spn-id (return 0))
(if ,ancestor-id (= ,ancestor-id (,(tcell:latest-bk))))
;; Try further backtracking
(,(tcell:latest-bk)) ; より根元での分割を試みる
(while -thr->treq-top ; タスク作成待ちスタックに要素があれば
;;(,(tcell:latest-bk)) ; より根元での分割を試みる
(def hx (ptr (struct task-home)) -thr->treq-top)
(while (and hx ; タスク作成待ちスタックに要素があれば
(not ,spn-id))
(begin
,@(if-pattern-variable guard-exp
(list
~(begin
,@guard-body
(if (csym::guard-task-request-prob -thr ,guard-exp)
(continue)))))
(def temp-next (ptr (struct task-home)) hx->next)
(if (csym::guard-task-request-prob -thr hx ,guard-exp)
(= hx temp-next)
(continue)
))))
,@(if-pattern-variable node-exp
(list
~(begin
,@node-body
(def temp-next (ptr (struct task-home)) hx->next)
(if (csym::guard-node-task-request -thr hx ,node-exp)
(begin
(= hx temp-next)
;;(csym::fprintf stderr "node-exp=%d~%" ,node-exp)
(continue)
)
))))
(= pthis
(cast (ptr (struct ,(tcell:task-struct-id)))
(csym::malloc (sizeof (struct ,(tcell:task-struct-id))))))
(begin ,@b-put-body)
(= ,spn-id 1)
(csym::make-and-send-task -thr ,(tcell:task-no) pthis 1)
(return 1)))
(return 0))
(def temp (ptr (struct task-home)) hx->next)
(= ,subptr-id (csym::make-and-send-task -thr hx ,(tcell:task-no) pthis 1))
;;(csym::fprintf stderr "CHECK-POINTER:rule POINTER:%p~%" ,subptr-id)
(= hx temp)

))
(return (or ,ancestor-id (not ,spn-id))))
;; --- Nestfunc End -->
;; Polling for cancel message requests, cancellation flags,
;; and task requests.
Expand All @@ -258,7 +284,7 @@
,b-stat1)
(if ,spn-id
;; If a subtask is spawned, wait for the result.
(if (= pthis (wait-rslt -thr 1))
(if (= pthis (wait-rslt -thr ,subptr-id 1))
(begin
(begin ,@b-get-body)
(csym::free pthis))
Expand All @@ -279,6 +305,7 @@
({handles} ,id
{(:guard ,@guard-body ,guard-exp)}
{(:spawn-from ,@spn-from-body ,spn-from-exp)}
{(:node ,@node-body ,node-exp)}
(:put from ,put-from to ,put-to ,@put-body)
(:get ,@get-body)))
(when (ruleset-param 'no-nestfunc)
Expand All @@ -292,13 +319,19 @@
,@(function-body body))) )))
(let ((spn-id (generate-id "spawned"))
(bk-id (generate-id "do_many_bk"))
(ancestor-id (generate-id "ancestor"))
(subptrs-id (generate-id "subptrs"))
(subptrs-size-id (generate-id "subptrs-size"))
(var2 (generate-id (string+ (get-retval var) "_end"))))
(tcell:with-task id
~(begin
(def ,var int ,(expression from))
(def ,var2 int ,(expression to)) ; ,var <= i < ,var2 が未処理
(def pthis (ptr (struct ,(tcell:task-struct-id)))) ; 送信用 task-body
(def ,spn-id int 0) ; 仕事を他所にsendしている数
(def ,ancestor-id int 1) ; 祖先が仕事を生成できる可能性があれば1
(def ,subptrs-size-id int 32) ;;size is subptrs-size-id
(def ,subptrs-id (ptr (ptr (struct task-home))) 0)
;; <-- Nestfunc start ---
;; Called for backtracking to handle a task request or an exception
(def (,bk-id) ,(tcell:nestfunc-type)
Expand All @@ -309,40 +342,64 @@
;; Wait for spawned tasks to be completed
(while (> (dec ,spn-id) 0)
(= pthis (cast (ptr (struct ,(tcell:task-struct-id)))
(wait-rslt -thr 0)))
(wait-rslt -thr (aref ,subptrs-id ,spn-id) 0)))
(csym::free pthis))
(csym::free ,subptrs-id)
;; Continue backtracking (never returns)
(,(tcell:latest-bk))))

;; If this do-many has not spawned any tasks, continue backtracking
(if (not ,spn-id) (,(tcell:latest-bk)))
(while (and -thr->treq-top ; there remains a treq?
(if ,ancestor-id (= ,ancestor-id (,(tcell:latest-bk))))
(def hx (ptr (struct task-home)) -thr->treq-top)
(while (and hx ; there remains a treq?
(<= 2 (- ,var2 ,var))) ; there remains any spawnable iterations?
(def ,put-to int ,var2)
(def ,put-from int)
,@(if-pattern-variable guard-exp
(list
~(begin
,@guard-body
(if (csym::guard-task-request-prob -thr ,guard-exp)
(continue)))))
(def temp-next (ptr (struct task-home)) hx->next)
(if (csym::guard-task-request-prob -thr hx ,guard-exp)
(begin (= hx temp-next)
(continue))
))))
,(if-pattern-variable spn-from-exp
~(begin
,@spn-from-body
(= ,put-from ,spn-from-exp)
;; Check the range
(if (< ,put-from ,var)
(= ,put-from (- ,var2 (- ,var ,put-from)))
)
(if (<= ,put-from ,var)
(= ,put-from (+ ,var 1)))
(if (>= ,put-from ,put-to)
(break)))
~(= ,put-from (/ (+ 1 ,var ,var2) 2)))
,@(if-pattern-variable node-exp
(list
~(begin
,@node-body
(def temp-next (ptr (struct task-home)) hx->next)
(if (csym::guard-node-task-request -thr hx ,node-exp)
(begin (= hx temp-next)
(continue))
))))
(= ,var2 ,put-from)
(= pthis
(cast (ptr (struct ,(tcell:task-struct-id)))
(csym::malloc (sizeof (struct ,(tcell:task-struct-id))))))
(begin ,@(function-body put-body))
(inc ,spn-id)
(csym::make-and-send-task -thr ,(tcell:task-no) pthis (== ,spn-id 1)))
(return 0))
(if (> ,spn-id ,subptrs-size-id)
(= ,subptrs-size-id (* ,subptrs-size-id 2))
)
(= ,subptrs-id (cast (ptr (ptr (struct task-home))) (csym::realloc ,subptrs-id (* (sizeof (ptr (struct task-home))) ,subptrs-size-id))))
(def temp (ptr (struct task-home)) hx->next)
(= (aref ,subptrs-id (- ,spn-id 1)) (csym::make-and-send-task -thr hx ,(tcell:task-no) pthis (== ,spn-id 1)))
(= hx temp))
(return (or ,ancestor-id (<= 2 (- ,var2 ,var)))))
;; --- Nestfunc End -->
;; Polling for cancel message requests, cancellation flags,
;; and task requests.
Expand All @@ -357,10 +414,11 @@
;; Collect the results of spawned tasks
(while (> (dec ,spn-id) 0)
(= pthis (cast (ptr (struct ,(tcell:task-struct-id)))
(wait-rslt -thr 1)))
(if pthis (begin
,@(function-body get-body)
(csym::free pthis))))
(wait-rslt -thr (aref ,subptrs-id ,spn-id) 1)))
(if pthis (begin
,@(function-body get-body)
(csym::free pthis))))
(csym::free ,subptrs-id)
;; If there is a subtask that has thrown an exception, propagate it.
(if (== -thr->exiting EXITING-EXCEPTION)
,(wfn-add-argids ~(handle-exception -thr->exception-tag)))
Expand Down Expand Up @@ -416,15 +474,38 @@
;; * タスクを全ノードに送りつける
;; * 全ノードからのackを待ち合わせる
;; * タスクオブジェクトの初期化方法は:putで指定
(#?(tcell-broadcast ,id (:put ,@put-body))
#|(#?(tcell-broadcast ,id (:put ,@put-body))
(tcell:with-task id
~(begin
(def pthis (ptr (struct ,(tcell:task-struct-id))))
(= pthis
(cast (ptr (struct ,(tcell:task-struct-id)))
(csym::malloc (sizeof (struct ,(tcell:task-struct-id))))))
(begin ,@(function-body put-body))
(csym::broadcast-task -thr ,(tcell:task-no) pthis))))
(csym::broadcast-task -thr ,(tcell:task-no) pthis))))|#
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(#?(tcell-broadcast ,id (:put ,@put-body) ,@body)
(tcell:with-task id
~(begin
(def pthis (ptr (struct ,(tcell:task-struct-id))))
(= pthis
(cast (ptr (struct ,(tcell:task-struct-id)))
(csym::malloc (sizeof (struct ,(tcell:task-struct-id))))))
(begin ,@(function-body put-body))
(csym::broadcast-task -thr ,(tcell:task-no) pthis)

(begin ,@(function-body body))



(csym::pthread-mutex-lock (ptr -thr->mut))
(while -thr->w-bcak
(csym::pthread-cond-wait (ptr -thr->cond) (ptr -thr->mut)))
(csym::pthread-mutex-unlock (ptr -thr->mut))

)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; dynamic-wind
;; * do-two, do-many の(動的)スコープ内で使用
Expand Down
Loading