1
# ---------------------------------------------------------------------------
3
# - afnix example : chapter 6 : example 07 -
4
# ---------------------------------------------------------------------------
5
# - This program is free software; you can redistribute it and/or modify -
6
# - it provided that this copyright notice is kept intact. -
8
# - This program is distributed in the hope that it will be useful, but -
9
# - without any warranty; without even the implied warranty of -
10
# - merchantability or fitness for a particular purpose. In no event shall -
11
# - the copyright holder be liable for any direct, indirect, incidental or -
12
# - special damages arising in any way out of the use of this software. -
13
# ---------------------------------------------------------------------------
14
# - copyright (c) 1999-2007 amaury darsch -
15
# ---------------------------------------------------------------------------
17
# initialize the shared library
18
interp:library "afnix-sys"
20
# shared vector of threads descriptors
21
const thr-group (Vector)
23
# this procedure waits until all threads in the group are finished
24
const wait-all nil (for (thr) (thr-group) (thr:wait))
26
# this procedure initialize a matrix with random numbers
27
# the matrix is a square one with its size as an argument
28
const init-matrix (n) {
32
trans v (m:append (Vector))
35
v:append (afnix:sys:get-random)
41
# this procedure multiply one line with one column
42
const mult-line-column (u v) {
43
assert (u:length) (v:length)
45
for (x y) (u v) (result:+= (* x y))
49
# this procedure multiply two vectors assuming one is a line and one is
50
# a column coming from the matrix
51
const mult-matrix (mx my) {
53
assert true (vector-p lv)
55
assert true (vector-p cv)
56
thr-group:append (launch (mult-line-column lv cv))
61
# check for some arguments
62
if (== 0 (interp:argv:length)) {
63
errorln "usage: axi 0807.als size"
67
# get the integer and multiply
68
const n (Integer (interp:argv:get 0))
69
mult-matrix (init-matrix n) (init-matrix n)
71
# wait for all threads to complete
74
# make sure we have the right number
75
assert (* n n) (thr-group:length)