Serge D. Mechveliani wrote:
>
> Dear Axiom developers,
>
> I am trying to build a string interface between C and Axiom
> by
> named pipes in Linux (Unix)
>
> (in future, the C end needs to change to Haskell).
>
> The C <--> C interface works,
> The C <--> Axiom interface works in half.
>
> The pipes are created by the Linux shell commands
>
> > mkfifo toA
> > mkfifo fromA
>
> The user programs operate with these pipes as with files:
> open, close, read, write, ....
> The difference to files is that the named pipe operations for the two
> processes are automatically synchronized.
>
> A C function cAxiom
> * outputs the given line string to toA,
> waits for the respond from Axiom in fromA,
> * inputs a string from fromA to the array pointed by res.
>
> fricas is run first -- in the terminal-2:
>
> > fricas
> ...
> (1) )read fifoToC
>
> Then, ./fifoToAxiom is run in terminal-1.
>
> A loop body in the program fifoToC.input
>
> for the Axiom interpreter does the following.
> * Reads a string from toA,
> * parses, interprets it,
> * converts the result to a string resStr,
> * writes resStr to fromA.
>
> The C part also has the function main,
>
> which makes certain n different strings and applies cAxiom
> to each string.
> For example, for n = 3, the strings are
> "((2*x + y + x^2*z^3) ^ 2) + 0",
> "((2*x + y + x^2*z^3) ^ 2) + 1",
> "((2*x + y + x^2*z^3) ^ 2) + 2".
>
> As the preliminary test, I replaced Axiom with the C program fifoToC.c.
> It inputs from toA, then skips evaluation, and only outputs a single
> letter to fromA.
>
> Now, C <--> C works correct,
> but slow: 6600 strings/sec for a 1 GHz machine
> (probably, the speed can be fixed, probably, repeated fclose needs
> to be replaced by something, but this is another subject).
>
> C <--> Axiom only does the first string (so, it looks almost correct),
> but then, the very fricas breaks silently.
>
> Please, what might this mean ?
>
> The Axiom part is in fifoToC.input :
>
> -------------------------------------------------------
> repeat
> toA: File String := open("toA", "input")
> iStr := readIfCan! toA
> close! toA
> if iStr = "failed" then (output ""; output "input -> failed"; break)
> output "iStr = "
> output iStr
>
> -- parse iStr, interpret, unparse, output to fromA
> iForm := parse(iStr)$InputForm
> oForm := interpret iForm
> resIForm := oForm :: InputForm
> resStr := unparse(resIForm)$InputForm
> output "resStr = "
> output resStr
>
> fromA: File String := open("fromA", "output")
> write!(fromA, resStr)
> close! fromA
> output "resStr is output"
> output ""
> -------------------------------------------------------
>
>
>
> terminal-2 shows
>
> ----------------------------------------------
> (1) -> )r fifoToC
> repeat
> toA: File String := open("toA", "input")
> <the loop body printing>
> ...
>
> iStr =
> "((2*x + y + x^2*z^3) ^ 2) + 0"
> ----------------------------------------------
> -- and fricas breaks out.
>
>
> terminal-1 shows
>
> -----------------------------------
> n = 4
> line = "((2*x + y + x^2*z^3) ^ 2) + 0"
> res = "x^4*z^6+(2*x^2*y+4*x^3)*z^3+(y^2+4*x*y+4*x^2)"
>
> line = "((2*x + y + x^2*z^3) ^ 2) + 1"
> -----------------------------------
> -- hangs at this point.
>
>
> The files fifoToAxiom.c, fifoToC.c
>
> are not large to consider but, probably, are too large for this broad
> mail list. Can you, please, take them from
>
> http://botik.ru/pub/local/Mechveliani/axiQuest/fifoC.zip
>
> and comment the effect ?
>
You are closing and opening pipes in each iteration. I did
not analyse this in detail, but it looks like asking for
trouble (and certainly is huge performance sink). OTOH
it seems that code which simply writes and reads lines
does not work due to bug in sbcl (in version used for release,
seems to be fixed in newer versions).
--
Waldek Hebisch
[email protected]
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.