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
7 changes: 4 additions & 3 deletions src/sample/tcell/fib.tcell
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)))))
22 changes: 13 additions & 9 deletions src/sample/tcell/grav.tcell
Original file line number Diff line number Diff line change
Expand Up @@ -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))
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
22 changes: 3 additions & 19 deletions src/sample/tcell/nq.tcell
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)))


Expand Down
26 changes: 17 additions & 9 deletions src/sample/tcell/pen6x17.tcell
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
71 changes: 59 additions & 12 deletions src/sample/tcell/sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions src/sample/tcell/sendrecv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down