diff --git a/src/sample/tcell/fib.tcell b/src/sample/tcell/fib.tcell index a5b8962..7775163 100644 --- a/src/sample/tcell/fib.tcell +++ b/src/sample/tcell/fib.tcell @@ -103,11 +103,11 @@ (csym::fprintf stderr "time: %lf~%" (csym::elapsed-time tp))) (def (task-receiver fib) - ;;(csym::fprintf stderr "receive %d~%" this.n) + ;; (csym::fprintf stderr "receive %d~%" this.n) ) (def (task-sender fib) - ;;(csym::fprintf stderr "send %d~%" this.n) + ;; (csym::fprintf stderr "send %d~%" this.n) ) (def (rslt-sender fib) @@ -132,5 +132,6 @@ (%if* USE-PROBGUARD (= PROBABILITY (csym::my-probability (- n 2)))) (= this.n (- n 2))) - (:get (= s2 this.r)))) + (:get + (= s2 this.r)))) (return (+ s1 s2))))) diff --git a/src/sample/tcell/grav.tcell b/src/sample/tcell/grav.tcell index eb58861..7f41900 100644 --- a/src/sample/tcell/grav.tcell +++ b/src/sample/tcell/grav.tcell @@ -53,26 +53,30 @@ (* 0.000001 (- (fref (aref tp 1) tv-usec) (fref (aref tp 0) tv-usec)))))) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a (def (task gravity) (def f (array double 3)) ; result (def rf (array double 3)) ; 小さい値を蓄積してく場所 - (def minx int :in) - (def miny int :in) - (def minz int :in) - (def maxx int :in) - (def maxy int :in) - (def maxz int :in) + (def minx int ) + (def miny int ) + (def minz int ) + (def maxx int ) + (def maxy int ) + (def maxz int ) (def cur (array double 3)) ; 入力座標:ここへの重力ベクトルを計算 ;;(def dummy (array char 4000)) ) (def (task-sender gravity) - (csym::send-doubles this.cur 3)) + (csym::send-bytes (cast (ptr void) (ptr this.minx)) (- (sizeof this) (- (cast (ptr char)(ptr this.minx)) (cast (ptr char)(ptr this))))) + ) + +;; sizeof (this) - ((char*)&this.minx - (char*)&this)) (def (task-receiver gravity) - (csym::recv-doubles this.cur 3)) + (csym::recv-bytes (cast (ptr void) (ptr this.minx)) (- (sizeof this) (- (cast (ptr char)(ptr this.minx)) (cast (ptr char)(ptr this))))) + ) (def (rslt-sender gravity) (csym::send-doubles this.f 3)) diff --git a/src/sample/tcell/lu.tcell b/src/sample/tcell/lu.tcell index 178369e..9833cae 100644 --- a/src/sample/tcell/lu.tcell +++ b/src/sample/tcell/lu.tcell @@ -357,31 +357,31 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(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)) @@ -389,39 +389,63 @@ (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) diff --git a/src/sample/tcell/nq.tcell b/src/sample/tcell/nq.tcell index 886de50..3e0c071 100644 --- a/src/sample/tcell/nq.tcell +++ b/src/sample/tcell/nq.tcell @@ -66,31 +66,15 @@ ) (def (task-sender nqueens) - (def i int 0) (if (>= this.k 0) (begin - (csym::send-int this.i1) - (csym::send-int this.i2) - (for ((= i 0) (< i this.n) (inc i)) - (csym::send-int (aref this.a i))) - (for ((= i 0) (< i (- (* 2 this.n) 1)) (inc i)) - (csym::send-int (aref this.lb i))) - (for ((= i 0) (< i (- (* 2 this.n) 1)) (inc i)) - (csym::send-int (aref this.rb i))))) - ) + (csym::send-bytes (cast (ptr void) (ptr this)) (sizeof this)) + ))) (def (task-receiver nqueens) - (def i int 0) (if (>= this.k 0) (begin - (= this.i1 (csym::recv-int)) - (= this.i2 (csym::recv-int)) - (for ((= i 0) (< i this.n) (inc i)) - (= (aref this.a i) (csym::recv-int))) - (for ((= i 0) (< i (- (* 2 this.n) 1)) (inc i)) - (= (aref this.lb i) (csym::recv-int))) - (for ((= i 0) (< i (- (* 2 this.n) 1)) (inc i)) - (= (aref this.rb i) (csym::recv-int))) + (csym::recv-bytes (cast (ptr void) (ptr this)) (sizeof this)) ))) diff --git a/src/sample/tcell/pen6x17.tcell b/src/sample/tcell/pen6x17.tcell index 93c7e69..31639a1 100644 --- a/src/sample/tcell/pen6x17.tcell +++ b/src/sample/tcell/pen6x17.tcell @@ -56,16 +56,24 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (def (task pentomino) (def r int :out) - (def k int :in) - (def i0 int :in) - (def i1 int :in) - (def i2 int :in) - (def maxp int :in) ; number of pieces - (def maxk int :in) ; the last empty cell - (def a (array int ASIZE) :in) - (def b (array int BSIZE) :in)) + (def k int ) + (def i0 int ) + (def i1 int ) + (def i2 int ) + (def maxp int ) ; number of pieces + (def maxk int ) ; the last empty cell + (def a (array int ASIZE)) + (def b (array int BSIZE))) -;; task/rslt-sender/receiver = default +(def (task-sender pentomino) + (csym::send-bytes (cast (ptr void) (ptr this)) (sizeof this)) + ) + +(def (task-receiver pentomino) + (csym::recv-bytes (cast (ptr void) (ptr this)) (sizeof this)) + ) + +;; rslt-sender/receiver = default (decl (search k j0 j1 j2 maxp maxk tsk) (wfn int int int int int int int (ptr (struct pentomino)))) (def (task-body pentomino) diff --git a/src/sample/tcell/sendrecv.c b/src/sample/tcell/sendrecv.c index a6e4ef4..c62c09f 100644 --- a/src/sample/tcell/sendrecv.c +++ b/src/sample/tcell/sendrecv.c @@ -70,15 +70,37 @@ int recv_int(void) /**/ void send_long(long n) { - char buf[16]; - snprintf (buf, 16, "%ld\n", n); - send_string (buf, sv_socket); + if(RANK < 0) + { + char buf[16]; + snprintf (buf, 16, "%ld\n", n); + send_string (buf, sv_socket); + } + else + { + send_longs (&n, 1); + } + // char buf[16]; + // snprintf (buf, 16, "%ld\n", n); + // send_string (buf, sv_socket); } long recv_long(void) { - char buf[16]; - receive_line (buf, 16, sv_socket); - return atol(buf); + if(RANK < 0) + { + char buf[16]; + receive_line (buf, 16, sv_socket); + return atol(buf); + } + else + { + long dst[1]; + recv_longs (dst, 1); + return dst[0]; + } + // char buf[16]; + // receive_line (buf, 16, sv_socket); + // return atol(buf); } /**/ @@ -160,6 +182,36 @@ int recv_int32s (INT32 *a, int nelm) return ret; } +/**/ +int send_longs (long *a, int nelm) +{ + int ret; + ret = send_binary (a, sizeof(long), nelm, sv_socket); + return ret; +} + +int recv_longs (long *a, int nelm) +{ + int ret; + ret = receive_binary (a, sizeof(long), nelm, sv_socket); + return ret; +} + +/**/ +int send_bytes (void *a, int size) +{ + int ret; + ret = send_binary (a, size, 1, sv_socket); + return ret; +} + +int recv_bytes (void *a, int size) +{ + int ret; + ret = receive_binary (a, size, 1, sv_socket); + return ret; +} + /* reverse byte order of double values */ /* assuming that long is 32-bit, and double is 64-bit */ void swap_doubles (double *a, int n) @@ -222,19 +274,14 @@ int recv_double_seq (double *a, int nelm) int send_doubles (double *a, int nelm) { int ret; - send_binary_header (sizeof(double), nelm); ret = send_binary (a, sizeof(double), nelm, sv_socket); - send_binary_terminator (); return ret; } int recv_doubles (double *a, int nelm) { - int ret, swp; - swp = recv_binary_header (0, 0); + int ret; ret = receive_binary (a, sizeof(double), nelm, sv_socket); - if (swp) swap_doubles (a, nelm); - recv_binary_terminator (); return ret; } diff --git a/src/sample/tcell/sendrecv.h b/src/sample/tcell/sendrecv.h index eaadf74..5b47fea 100644 --- a/src/sample/tcell/sendrecv.h +++ b/src/sample/tcell/sendrecv.h @@ -56,6 +56,14 @@ void swap_int32s (INT32 *a, int n); int send_int32s (INT32 *a, int nelm); int recv_int32s (INT32 *a, int nelm); +/**/ +int send_longs (long *a, int nelm); +int recv_longs (long *a, int nelm); + +/**/ +int send_bytes (void *a, int size); +int recv_bytes (void *a, int size); + /**/ void swap_doubles (double *a, int n);