Skip to content

Mpi latency hiding #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: mpi-latency-hiding
Choose a base branch
from
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
126 changes: 106 additions & 20 deletions src/sample/tcell/cmp.tcell
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,29 @@

(def (task-sender cmp)
;; (def i int)
(DEBUG-PRINT 1 "tasksender~%")
;; (DEBUG-PRINT 1 "task-sender~%" )
(if (> 0 this.n2) (return))
(csym::send-int32s this.d1 this.n1)
;; (for ((= i 0) (< i this.n1) (inc i))
;; (csym::send-int (aref this.d1 i)))
(csym::send-int32s this.d2 this.n2)
;; (for ((= i 0) (< i this.n2) (inc i))
;; (csym::send-int (aref this.d2 i)))
;; (DEBUG-PRINT 1 "send-n1 %d %d %d~%" this.n1 (aref this.d1 0) (aref this.d1 (- this.n1 1)))
;; (DEBUG-PRINT 1 "send-n2 %d %d %d~%" this.n2 (aref this.d2 0) (aref this.d2 (- this.n2 1)))
(if (> this.n1 this.n2)
(begin
(csym::send-int32s this.d2 this.n2)
;; (DEBUG-PRINT 1 "n1~%" )
(csym::send-int32s this.d1 (/ this.n1 2))
(csym::send-int32s (+ this.d1 (/ this.n1 2)) (- this.n1 (/ this.n1 2)))
)
(begin
(csym::send-int32s this.d1 this.n1)
;; (DEBUG-PRINT 1 "n2~%" )
(csym::send-int32s this.d2 (/ this.n2 2))
(csym::send-int32s (+ this.d2 (/ this.n2 2)) (- this.n2 (/ this.n2 2)))
))
)

(def (task-receiver cmp)
(def i int)
(DEBUG-PRINT 1 "taskreceiver~%")
(csym::set-progress pprogress 1)
;; (DEBUG-PRINT 1 "task-receiver~%" )
(if (not (> 0 this.n2))
(begin
(= this.d1
Expand All @@ -99,12 +109,26 @@
(= this.d2
(cast (ptr INT32)
(csym::malloc (* (sizeof INT32) this.n2))))
(csym::recv-int32s this.d1 this.n1)
;; (for ((= i 0) (< i this.n1) (inc i))
;; (= (aref this.d1 i) (csym::recv-int)))
(csym::recv-int32s this.d2 this.n2)
;; (for ((= i 0) (< i this.n2) (inc i))
;; (= (aref this.d2 i) (csym::recv-int)))
(if (> this.n1 this.n2)
(begin
(csym::recv-int32s this.d2 this.n2)
(csym::recv-int32s this.d1 (/ this.n1 2))
;; (DEBUG-PRINT 1 "recv-n1a %d %d %d~%" (/ this.n1 2) (aref this.d1 0) (aref this.d1 (- (/ this.n1 2) 1)))
(csym::set-progress pprogress 2)
(csym::recv-int32s (+ this.d1 (/ this.n1 2)) (- this.n1 (/ this.n1 2)))
;; (DEBUG-PRINT 1 "recv-n1b %d %d %d~%" (- this.n1 (/ this.n1 2)) (aref this.d1 (/ this.n1 2)) (aref this.d1 (- this.n1 1)))
(csym::set-progress pprogress 3)
)
(begin
(csym::recv-int32s this.d1 this.n1)
(csym::recv-int32s this.d2 (/ this.n2 2))
;; (DEBUG-PRINT 1 "recv-n2a %d %d %d~%" (/ this.n2 2) (aref this.d2 0) (aref this.d2 (- (/ this.n2 2) 1)))
(csym::set-progress pprogress 2)
(csym::recv-int32s (+ this.d2 (/ this.n2 2)) (- this.n2 (/ this.n2 2)))
;; (DEBUG-PRINT 1 "recv-n2b %d %d %d~%" (- this.n2 (/ this.n2 2)) (aref this.d2 (/ this.n2 2)) (aref this.d2 (- this.n2 1)))
(csym::set-progress pprogress 3)
)
)
))
)

Expand All @@ -114,12 +138,14 @@

;;; (rslt-receiver cmp) = default

(decl (cmp-1b n1 n2 d1 d2) (wfn int int int (ptr INT32) (ptr INT32)))
(decl (cmp-1 n1 n2 d1 d2) (wfn int int int (ptr INT32) (ptr INT32)))

(def (task-body cmp)
(decl tp (array (struct timeval) 2))
(def i int) (def j int)
(DEBUG-PRINT 1 "taskbody~%")
;; (DEBUG-PRINT 1 "task-body~%")
(csym::wait-progress -thr 1)
(DEBUG-PRINT 1 "start %d %d~%" this.n1 this.n2)
(if (> 0 this.n2) ; n2<0 のときは,新しい問題を作って解く
(begin
Expand All @@ -138,15 +164,18 @@
(= N0 this.n1)
(= PROBABILITY 1.0))
(csym::gettimeofday tp 0)
;; (DEBUG-PRINT 1 "checkpoint1~%" )
(= this.r
(cmp-1 this.n1 this.n2
(cmp-1b this.n1 this.n2
this.d1 this.d2))
;; (DEBUG-PRINT 1 "checkpointxx~%" )
(csym::gettimeofday (+ tp 1) 0)
(csym::fprintf stderr "time: %lf~%" (csym::elapsed-time tp))
)
(begin
(%ifdef* USE-PROBABILITY
(= PROBABILITY (cmp-probability (csym::MIN this.n1 this.n2))))
(csym::wait-progress -thr 2)
(= this.r
(cmp-1 this.n1 this.n2
this.d1 this.d2)))))
Expand All @@ -162,14 +191,71 @@

(def (cmp-1 n1 n2 d1 d2) (wfn int int int (ptr INT32) (ptr INT32))
(decl s1 int) (decl s2 int)
;; (DEBUG-PRINT 1 "cmp-1 n1=%d %d %d n2=%d %d %d~%" n1 (aref d1 0) (aref d1 (- n1 1)) n2 (aref d2 0) (aref d2 (- n2 1)))
(if (< n1 5)
(begin
(csym::wait-progress -thr 3)
(return (csym::cmp-2 n1 n2 d1 d2))))
(if (> n1 n2)
(begin
;; (DEBUG-PRINT 1 "checkpointa~%" )
(def n1-1 int (/ n1 2))
(def n1-2 int (- n1 n1-1))
;; (DEBUG-PRINT 1 "wait-n1a %d %d %d~%" n1-1 (aref d1 0) (aref d1 (- n1-1 1)))
(do-two
(= s1 (cmp-1b n1-1 n2 d1 d2))
(begin
;; (DEBUG-PRINT 1 "checkpointb~%" )
(csym::wait-progress -thr 3)(= s2 (cmp-1b n1-2 n2 (+ d1 n1-1) d2)))
(handles cmp
(:put
(%ifdef* USE-PROBABILITY
(= PROBABILITY (cmp-probability n1-1)))
(csym::wait-progress -thr 3)
;; (DEBUG-PRINT 1 "wait-n1b %d %d %d~%" n1-2 (aref d1 n1-1) (aref d1 (- n1 1)))
(= this.n1 n1-2)
(= this.n2 n2)
(= this.d1 (+ d1 n1-1) )
(= this.d2 d2))
(:get
(= s2 this.r)))))
(begin
;; (DEBUG-PRINT 1 "checkpointa~%" )
(def n2-1 int (/ n2 2))
(def n2-2 int (- n2 n2-1))
;; (DEBUG-PRINT 1 "wait-n2a %d %d %d~%" n2-1 (aref d2 0) (aref d2 (- n2-1 1)))
(do-two
(= s1 (cmp-1b n1 n2-1 d1 d2))
(begin
;; (DEBUG-PRINT 1 "checkpointb~%" )
(csym::wait-progress -thr 3)(= s2 (cmp-1b n1 n2-2 d1 (+ d2 n2-1))))
(cmp
(:put
(%ifdef* USE-PROBABILITY
(= PROBABILITY (cmp-probability n2-1)))
(csym::wait-progress -thr 3)
;; (DEBUG-PRINT 1 "wait-n2b %d %d %d~%" n2-2 (aref d2 n2-1) (aref d2 (- n2 1)))
(= this.n1 n1)
(= this.n2 n2-2)
(= this.d1 d1)
(= this.d2 (+ d2 n2-1)))
(:get
(= s2 this.r))))))
(return (+ s1 s2)))

(def (cmp-1b n1 n2 d1 d2) (wfn int int int (ptr INT32) (ptr INT32))
(decl s1 int) (decl s2 int)
;; (DEBUG-PRINT 1 "cmp-1b n1=%d %d %d n2=%d %d %d~%" n1 (aref d1 0) (aref d1 (- n1 1)) n2 (aref d2 0) (aref d2 (- n2 1)))
;; (DEBUG-PRINT 1 "cmp-1b~%")
(if (< n1 5) (return (csym::cmp-2 n1 n2 d1 d2)))
(if (> n1 n2)
(begin
;; (DEBUG-PRINT 1 "checkpointa2~%" )
(def n1-1 int (/ n1 2))
(def n1-2 int (- n1 n1-1))
(do-two
(= s1 (cmp-1 n1-1 n2 d1 d2))
(= s2 (cmp-1 n1-2 n2 (+ d1 n1-1) d2))
(= s1 (cmp-1b n1-1 n2 d1 d2))
(= s2 (cmp-1b n1-2 n2 (+ d1 n1-1) d2))
(handles cmp
(:put
(%ifdef* USE-PROBABILITY
Expand All @@ -184,8 +270,8 @@
(def n2-1 int (/ n2 2))
(def n2-2 int (- n2 n2-1))
(do-two
(= s1 (cmp-1 n1 n2-1 d1 d2))
(= s2 (cmp-1 n1 n2-2 d1 (+ d2 n2-1)))
(= s1 (cmp-1b n1 n2-1 d1 d2))
(= s2 (cmp-1b n1 n2-2 d1 (+ d2 n2-1)))
(cmp
(:put
(%ifdef* USE-PROBABILITY
Expand Down
4 changes: 2 additions & 2 deletions src/sample/tcell/cmpdebug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#QSUB -q gr10034b
#QSUB -ug gr10034
#QSUB -W 2:00
#QSUB -A p=1:t=1:c=1:m=120G
#QSUB -N cmpdebug711
#QSUB -A p=2:t=1:c=1:m=120G
#QSUB -N cmpd2-1
#============ Shell Script ============
set -x
cd $QSUB_WORKDIR
Expand Down
104 changes: 64 additions & 40 deletions src/sample/tcell/lu.tcell
Original file line number Diff line number Diff line change
Expand Up @@ -357,71 +357,95 @@

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(def (csym::input-mat a n1 n2 nx) (csym::fn void (ptr double) int int int)
(decl i int)
(def swp int)
(= swp (csym::recv-binary-header 0 0))
(for ((= i 0) (< i n1) (inc i))
(csym::recv-double-seq (+ a (* i nx)) n2))
(csym::recv-binary-terminator)
(if swp
(for ((= i 0) (< i n1) (inc i))
(csym::swap-doubles (+ a (* i nx)) n2))))

(def (csym::output-mat a n1 n2 nx) (fn void (ptr double) int int int)
(def i int)
(csym::send-binary-header (sizeof double) (* n1 n2))
(for ((= i 0) (< i n1) (inc i))
(csym::send-double-seq (+ a (* i nx)) n2))
(csym::send-binary-terminator))

#+comment ; easy but less efficient implementation
;; (def (csym::input-mat a n1 n2 nx) (csym::fn void (ptr double) int int int)
;; (decl i int)
;; (def swp int)
;; (= swp (csym::recv-binary-header 0 0))
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::recv-double-seq (+ a (* i nx)) n2))
;; (csym::recv-binary-terminator)
;; (if swp
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::swap-doubles (+ a (* i nx)) n2))))

;; (def (csym::output-mat a n1 n2 nx) (fn void (ptr double) int int int)
;; (def i int)
;; (csym::send-binary-header (sizeof double) (* n1 n2))
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::send-double-seq (+ a (* i nx)) n2))
;; (csym::send-binary-terminator))

;; #+comment ; easy but less efficient implementation
(def (csym::input-mat a n1 n2 nx) (csym::fn void (ptr double) int int int)
(decl i int)
(for ((= i 0) (< i n1) (inc i))
(csym::recv-doubles (+ a (* i nx)) n2)))

#+comment ; easy but less efficient implementation
;; #+comment ; easy but less efficient implementation
(def (csym::output-mat a n1 n2 nx) (fn void (ptr double) int int int)
(def i int)
(for ((= i 0) (< i n1) (inc i))
(csym::send-doubles (+ a (* i nx)) n2)))

(def (csym::input-mat-l a n1 nx) (fn void (ptr double) int int)
(decl i int)
(decl swp int)
(= swp (csym::recv-binary-header 0 0))
(for ((= i 0) (< i n1) (inc i))
(csym::recv-double-seq (+ a (* i nx)) (+ i 1)))
(csym::recv-binary-terminator)
(if swp
(for ((= i 0) (< i n1) (inc i))
(csym::swap-doubles (+ a (* i nx)) (+ i 1)))))
(csym::recv-doubles (+ a (* i nx)) (+ i 1)))
)

(def (csym::output-mat-l a n1 nx) (fn void (ptr double) int int)
(decl i int)
(csym::send-binary-header (sizeof double) (/ (* n1 (+ n1 1)) 2))
(for ((= i 0) (< i n1) (inc i))
(csym::send-double-seq (+ a (* i nx)) (+ i 1)))
(csym::send-binary-terminator))
(csym::send-doubles (+ a (* i nx)) (+ i 1)))
)

(def (csym::input-mat-u a n1 nx) (fn void (ptr double) int int)
(decl i int)
(decl swp int)
(= swp (csym::recv-binary-header 0 0))
(for ((= i 0) (< i n1) (inc i))
(csym::recv-double-seq (+ a (* i nx) i 1) (- n1 i 1)))
(csym::recv-binary-terminator)
(if swp
(for ((= i 0) (< i n1) (inc i))
(csym::swap-doubles (+ a (* i nx) i 1) (- n1 i 1)))))
(csym::recv-doubles (+ a (* i nx) i 1) (- n1 i 1)))
)

(def (csym::output-mat-u a n1 nx) (csym::fn void (ptr double) int int)
(decl i int)
(csym::send-binary-header (sizeof double) (/ (* n1 (- n1 1)) 2))
(for ((= i 0) (< i n1) (inc i))
(csym::send-double-seq (+ a (* i nx) i 1) (- n1 i 1)))
(csym::send-binary-terminator))
(csym::send-doubles (+ a (* i nx) i 1) (- n1 i 1)))
)

;; (def (csym::input-mat-l a n1 nx) (fn void (ptr double) int int)
;; (decl i int)
;; (decl swp int)
;; (= swp (csym::recv-binary-header 0 0))
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::recv-double-seq (+ a (* i nx)) (+ i 1)))
;; (csym::recv-binary-terminator)
;; (if swp
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::swap-doubles (+ a (* i nx)) (+ i 1)))))

;; (def (csym::output-mat-l a n1 nx) (fn void (ptr double) int int)
;; (decl i int)
;; (csym::send-binary-header (sizeof double) (/ (* n1 (+ n1 1)) 2))
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::send-double-seq (+ a (* i nx)) (+ i 1)))
;; (csym::send-binary-terminator))

;; (def (csym::input-mat-u a n1 nx) (fn void (ptr double) int int)
;; (decl i int)
;; (decl swp int)
;; (= swp (csym::recv-binary-header 0 0))
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::recv-double-seq (+ a (* i nx) i 1) (- n1 i 1)))
;; (csym::recv-binary-terminator)
;; (if swp
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::swap-doubles (+ a (* i nx) i 1) (- n1 i 1)))))

;; (def (csym::output-mat-u a n1 nx) (csym::fn void (ptr double) int int)
;; (decl i int)
;; (csym::send-binary-header (sizeof double) (/ (* n1 (- n1 1)) 2))
;; (for ((= i 0) (< i n1) (inc i))
;; (csym::send-double-seq (+ a (* i nx) i 1) (- n1 i 1)))
;; (csym::send-binary-terminator))

(def (csym::zero-mat a n1 n2 nx) (fn void (ptr double) int int int)
(decl i int)
Expand Down
Loading